Skip to content

Commit

Permalink
Add shutdown command for #171
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazrius committed Feb 3, 2023
1 parent 0f30c28 commit 1f18e3e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/FLHook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ class CCmds
void CmdListPlugins();
void CmdUnloadPlugin(const std::wstring& wscPlugin);
void CmdReloadPlugin(const std::wstring& wscPlugin);
void CmdShutdown();

void ExecuteCommandString(const std::wstring& wscCmd);
void SetRightsByString(const std::string& scRightStr);
Expand Down
23 changes: 23 additions & 0 deletions source/CCmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,25 @@ void CCmds::CmdUnloadPlugin(const std::wstring& wscPlugin)
Print("OK");
}

void CCmds::CmdShutdown()
{
RIGHT_CHECK(RIGHT_SUPERADMIN);

Print("Shutting down Server");

// Kick everyone first and force a save
PlayerData* playerDb = nullptr;
while (playerDb = Players.traverse_active(playerDb))
{
Hk::Player::SaveChar(playerDb->iOnlineId);
Hk::Player::Kick(playerDb->iOnlineId);
}

auto* unkThis = (void*)0x00426C58;
HWND handle = *(HWND*)(*((DWORD*)unkThis + 8) + 32);
PostMessageA(handle, WM_CLOSE, 0, 0);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////

/** Chase a player. Only works in system as you'd need a client hook to do across system */
Expand Down Expand Up @@ -1248,6 +1267,10 @@ void CCmds::ExecuteCommandString(const std::wstring& wscCmdStr)
{
CmdLoadPlugin(ArgStrToEnd(1));
}
else if (wscCmd == L"shutdown")
{
CmdShutdown();
}
else if (wscCmd == L"listplugins")
{
CmdListPlugins();
Expand Down

0 comments on commit 1f18e3e

Please sign in to comment.