Skip to content

Commit

Permalink
Add new event onShutdown (multitheftauto#3732)
Browse files Browse the repository at this point in the history
  • Loading branch information
FileEX authored Dec 21, 2024
1 parent ff84958 commit aa20c7d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Server/mods/deathmatch/logic/CConsoleCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "CDatabaseManager.h"
#include "CGame.h"
#include "CMainConfig.h"
#include "CMapManager.h"

extern CGame* g_pGame;

Expand Down Expand Up @@ -1111,20 +1112,28 @@ bool CConsoleCommands::Shutdown(CConsole* pConsole, const char* szArguments, CCl
{
// shutdown <reason>

CLuaArguments arguments;
arguments.PushNil();

if (szArguments && strlen(szArguments) > 0)
{
// Copy to a buffer and strip it for bad characters
COPY_CSTR_TO_TEMP_BUFFER(szBuffer, szArguments, 256);

// Output the action + reason to the console
CLogger::LogPrintf("SHUTDOWN: Got shutdown command from %s (Reason: %s)\n", GetAdminNameForLog(pClient).c_str(), szBuffer);
arguments.PushString(szBuffer);
}
else
{
// Output the action to the console
CLogger::LogPrintf("SHUTDOWN: Got shutdown command from %s (No reason specified)\n", GetAdminNameForLog(pClient).c_str());
arguments.PushString("No reason specified");
}

// Call event
g_pGame->GetMapManager()->GetRootElement()->CallEvent("onShutdown", arguments);

// Shut the server down asap
g_pGame->SetIsFinished(true);
return true;
Expand Down
1 change: 1 addition & 0 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,7 @@ void CGame::AddBuiltInEvents()
m_Events.AddEvent("onSettingChange", "setting, oldValue, newValue", NULL, false);
m_Events.AddEvent("onChatMessage", "message, element", NULL, false);
m_Events.AddEvent("onExplosion", "x, y, z, type, origin", nullptr, false);
m_Events.AddEvent("onShutdown", "resource, reason", nullptr, false);

// Weapon events
m_Events.AddEvent("onWeaponFire", "", NULL, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ASE.h"
#include "CStaticFunctionDefinitions.h"
#include "CPerfStatManager.h"
#include "CMapManager.h"

#define MIN_SERVER_REQ_CALLREMOTE_QUEUE_NAME "1.5.3-9.11270"
#define MIN_SERVER_REQ_CALLREMOTE_CONNECTION_ATTEMPTS "1.3.0-9.04563"
Expand Down Expand Up @@ -349,6 +350,12 @@ bool CLuaFunctionDefs::Shutdown(lua_State* luaVM, std::optional<std::string_view
if (maybeExitCode.has_value())
g_pServerInterface->GetModManager()->SetExitCode(maybeExitCode.value());

// Call event
CLuaArguments arguments;
arguments.PushResource(&resource);
arguments.PushString(reason.data());
g_pGame->GetMapManager()->GetRootElement()->CallEvent("onShutdown", arguments);

g_pGame->SetIsFinished(true);
return true;
}
Expand Down

0 comments on commit aa20c7d

Please sign in to comment.