Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new event onShutdown #3732

Merged
merged 2 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading