Skip to content

Commit

Permalink
* Save players on closing server
Browse files Browse the repository at this point in the history
  • Loading branch information
João Paulo committed Mar 8, 2024
1 parent ac3f183 commit 5862e6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
28 changes: 16 additions & 12 deletions src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ CanaryServer::CanaryServer(
rsa(rsa),
serviceManager(serviceManager) {
logInfos();
toggleForceCloseButton();
g_game().setGameState(GAME_STATE_STARTUP);
std::set_new_handler(badAllocationHandler);
srand(static_cast<unsigned int>(OTSYS_TIME()));
Expand All @@ -51,6 +50,7 @@ CanaryServer::CanaryServer(

#ifdef _WIN32
SetConsoleTitleA(ProtocolStatus::SERVER_NAME.c_str());
saveServerAtClose();
#endif
}

Expand Down Expand Up @@ -216,18 +216,22 @@ void CanaryServer::logInfos() {
}

/**
*It is preferable to keep the close button off as it closes the server without saving (this can cause the player to lose items from houses and others informations, since windows automatically closes the process in five seconds, when forcing the close)
* Choose to use "CTROL + C" or "CTROL + BREAK" for security close
* To activate/deactivate window;
* \param MF_GRAYED Disable the "x" (force close) button
* \param MF_ENABLED Enable the "x" (force close) button
*Save players on server closing
*/
void CanaryServer::toggleForceCloseButton() {
#ifdef OS_WINDOWS
const HWND hwnd = GetConsoleWindow();
const HMENU hmenu = GetSystemMenu(hwnd, FALSE);
EnableMenuItem(hmenu, SC_CLOSE, MF_GRAYED);
#endif
void CanaryServer::saveServerAtClose() {
SetConsoleCtrlHandler(

Check failure on line 222 in src/canary_server.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-release

‘SetConsoleCtrlHandler’ was not declared in this scope

Check failure on line 222 in src/canary_server.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-linux-release

‘SetConsoleCtrlHandler’ was not declared in this scope

Check failure on line 222 in src/canary_server.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

‘SetConsoleCtrlHandler’ was not declared in this scope

Check failure on line 222 in src/canary_server.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-linux-debug

‘SetConsoleCtrlHandler’ was not declared in this scope
[](DWORD ctrlType) -> BOOL {

Check failure on line 223 in src/canary_server.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-release

‘DWORD’ has not been declared

Check failure on line 223 in src/canary_server.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-release

‘BOOL’ does not name a type

Check failure on line 223 in src/canary_server.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-linux-release

‘DWORD’ has not been declared

Check failure on line 223 in src/canary_server.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-linux-release

‘BOOL’ does not name a type

Check failure on line 223 in src/canary_server.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

‘DWORD’ has not been declared

Check failure on line 223 in src/canary_server.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

‘BOOL’ does not name a type

Check failure on line 223 in src/canary_server.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-linux-debug

‘DWORD’ has not been declared

Check failure on line 223 in src/canary_server.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-linux-debug

‘BOOL’ does not name a type
if (ctrlType == CTRL_CLOSE_EVENT) {
if (!g_game().getGameState() == GAME_STATE_STARTUP) {
g_logger().info("Closing the server and saving the players");
g_saveManager().scheduleAll();
exit(0);
}
}
return FALSE;
},
TRUE

Check failure on line 233 in src/canary_server.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-release

‘TRUE’ was not declared in this scope

Check failure on line 233 in src/canary_server.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-linux-release

‘TRUE’ was not declared in this scope

Check failure on line 233 in src/canary_server.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-22.04-linux-debug

‘TRUE’ was not declared in this scope

Check failure on line 233 in src/canary_server.cpp

View workflow job for this annotation

GitHub Actions / ubuntu-20.04-linux-debug

‘TRUE’ was not declared in this scope
);
}

void CanaryServer::badAllocationHandler() {
Expand Down
2 changes: 1 addition & 1 deletion src/canary_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class CanaryServer {
std::atomic<LoaderStatus> loaderStatus = LoaderStatus::LOADING;

void logInfos();
static void toggleForceCloseButton();
static void badAllocationHandler();
static void shutdown();

Expand All @@ -67,4 +66,5 @@ class CanaryServer {
void loadMaps() const;
void setupHousesRent();
void modulesLoadHelper(bool loaded, std::string moduleName);
void saveServerAtClose();

Check warning on line 69 in src/canary_server.hpp

View workflow job for this annotation

GitHub Actions / cppcheck

[cppcheck] reported by reviewdog 🐶 Unused private function: 'CanaryServer::saveServerAtClose' Raw Output: src/canary_server.hpp:69:Unused private function: 'CanaryServer::saveServerAtClose'
};

0 comments on commit 5862e6e

Please sign in to comment.