From 39d8e3a49800892cef0f63f9742eba985bec5aa0 Mon Sep 17 00:00:00 2001 From: FileEX Date: Tue, 17 Sep 2024 23:18:46 +0200 Subject: [PATCH] onShutdown --- Server/mods/deathmatch/logic/CConsoleCommands.cpp | 9 +++++++++ Server/mods/deathmatch/logic/CGame.cpp | 1 + .../deathmatch/logic/luadefs/CLuaFunctionDefs.Server.cpp | 7 +++++++ 3 files changed, 17 insertions(+) diff --git a/Server/mods/deathmatch/logic/CConsoleCommands.cpp b/Server/mods/deathmatch/logic/CConsoleCommands.cpp index 5f19e566f3..a22c872eeb 100644 --- a/Server/mods/deathmatch/logic/CConsoleCommands.cpp +++ b/Server/mods/deathmatch/logic/CConsoleCommands.cpp @@ -24,6 +24,7 @@ #include "CDatabaseManager.h" #include "CGame.h" #include "CMainConfig.h" +#include "CMapManager.h" extern CGame* g_pGame; @@ -1111,6 +1112,9 @@ bool CConsoleCommands::Shutdown(CConsole* pConsole, const char* szArguments, CCl { // shutdown + CLuaArguments arguments; + arguments.PushNil(); + if (szArguments && strlen(szArguments) > 0) { // Copy to a buffer and strip it for bad characters @@ -1118,13 +1122,18 @@ bool CConsoleCommands::Shutdown(CConsole* pConsole, const char* szArguments, CCl // 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; diff --git a/Server/mods/deathmatch/logic/CGame.cpp b/Server/mods/deathmatch/logic/CGame.cpp index 58989394ec..e4ffd31ed9 100644 --- a/Server/mods/deathmatch/logic/CGame.cpp +++ b/Server/mods/deathmatch/logic/CGame.cpp @@ -1663,6 +1663,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); diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaFunctionDefs.Server.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaFunctionDefs.Server.cpp index 554bf2efc9..4aa82ac5f9 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaFunctionDefs.Server.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaFunctionDefs.Server.cpp @@ -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" @@ -349,6 +350,12 @@ bool CLuaFunctionDefs::Shutdown(lua_State* luaVM, std::optionalGetModManager()->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; }