Skip to content

Commit aa20c7d

Browse files
authored
Add new event onShutdown (#3732)
1 parent ff84958 commit aa20c7d

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

Server/mods/deathmatch/logic/CConsoleCommands.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "CDatabaseManager.h"
2525
#include "CGame.h"
2626
#include "CMainConfig.h"
27+
#include "CMapManager.h"
2728

2829
extern CGame* g_pGame;
2930

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

1115+
CLuaArguments arguments;
1116+
arguments.PushNil();
1117+
11141118
if (szArguments && strlen(szArguments) > 0)
11151119
{
11161120
// Copy to a buffer and strip it for bad characters
11171121
COPY_CSTR_TO_TEMP_BUFFER(szBuffer, szArguments, 256);
11181122

11191123
// Output the action + reason to the console
11201124
CLogger::LogPrintf("SHUTDOWN: Got shutdown command from %s (Reason: %s)\n", GetAdminNameForLog(pClient).c_str(), szBuffer);
1125+
arguments.PushString(szBuffer);
11211126
}
11221127
else
11231128
{
11241129
// Output the action to the console
11251130
CLogger::LogPrintf("SHUTDOWN: Got shutdown command from %s (No reason specified)\n", GetAdminNameForLog(pClient).c_str());
1131+
arguments.PushString("No reason specified");
11261132
}
11271133

1134+
// Call event
1135+
g_pGame->GetMapManager()->GetRootElement()->CallEvent("onShutdown", arguments);
1136+
11281137
// Shut the server down asap
11291138
g_pGame->SetIsFinished(true);
11301139
return true;

Server/mods/deathmatch/logic/CGame.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,7 @@ void CGame::AddBuiltInEvents()
16741674
m_Events.AddEvent("onSettingChange", "setting, oldValue, newValue", NULL, false);
16751675
m_Events.AddEvent("onChatMessage", "message, element", NULL, false);
16761676
m_Events.AddEvent("onExplosion", "x, y, z, type, origin", nullptr, false);
1677+
m_Events.AddEvent("onShutdown", "resource, reason", nullptr, false);
16771678

16781679
// Weapon events
16791680
m_Events.AddEvent("onWeaponFire", "", NULL, false);

Server/mods/deathmatch/logic/luadefs/CLuaFunctionDefs.Server.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "ASE.h"
1717
#include "CStaticFunctionDefinitions.h"
1818
#include "CPerfStatManager.h"
19+
#include "CMapManager.h"
1920

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

353+
// Call event
354+
CLuaArguments arguments;
355+
arguments.PushResource(&resource);
356+
arguments.PushString(reason.data());
357+
g_pGame->GetMapManager()->GetRootElement()->CallEvent("onShutdown", arguments);
358+
352359
g_pGame->SetIsFinished(true);
353360
return true;
354361
}

0 commit comments

Comments
 (0)