diff options
author | jackpoz <giacomopoz@gmail.com> | 2016-08-04 15:03:58 +0200 |
---|---|---|
committer | joschiwald <joschiwald.trinity@gmail.com> | 2017-02-11 22:02:08 +0100 |
commit | a3384bdc70d239d79dac40b52fcbe076c0474591 (patch) | |
tree | 83014912424ff7b296cba0436851c788fb2ecb99 | |
parent | 85a16fae3d3eaedf05c0d94604bae15ffac88e60 (diff) |
Scripts/Commands: Change "server shutdown" behavior
Change "server shutdown 0" behavior to delay the shutdown by the force threshold specified in configs if there are still players connected, set to 30 by default
(cherry picked from commit b37c7101de272d1b3d599f26d6b5077cfacfb121)
-rw-r--r-- | src/server/scripts/Commands/cs_server.cpp | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/server/scripts/Commands/cs_server.cpp b/src/server/scripts/Commands/cs_server.cpp index fb6df1f8863..b75cdb2f4fd 100644 --- a/src/server/scripts/Commands/cs_server.cpp +++ b/src/server/scripts/Commands/cs_server.cpp @@ -198,14 +198,10 @@ public: return true; } - static bool AlwaysForceShutdown(WorldSession* mySession) + static bool IsOnlyUser(WorldSession* mySession) { - // if mySession is null then the shutdown command was issued from console (local or remote), always shutdown in this case - if (!mySession) - return true; - // check if there is any session connected from a different address - std::string myAddr = mySession->GetRemoteAddress(); + std::string myAddr = mySession ? mySession->GetRemoteAddress() : ""; SessionMap const& sessions = sWorld->GetAllSessions(); for (SessionMap::value_type const& session : sessions) if (session.second && myAddr != session.second->GetRemoteAddress()) @@ -214,12 +210,12 @@ public: } static bool HandleServerShutDownCommand(ChatHandler* handler, char const* args) { - return ShutdownServer(args, AlwaysForceShutdown(handler->GetSession()) ? SHUTDOWN_MASK_FORCE : 0, SHUTDOWN_EXIT_CODE); + return ShutdownServer(args, IsOnlyUser(handler->GetSession()) ? SHUTDOWN_MASK_FORCE : 0, SHUTDOWN_EXIT_CODE); } static bool HandleServerRestartCommand(ChatHandler* handler, char const* args) { - return ShutdownServer(args, AlwaysForceShutdown(handler->GetSession()) ? (SHUTDOWN_MASK_FORCE | SHUTDOWN_MASK_RESTART) : SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE); + return ShutdownServer(args, IsOnlyUser(handler->GetSession()) ? (SHUTDOWN_MASK_FORCE | SHUTDOWN_MASK_RESTART) : SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE); } static bool HandleServerForceShutDownCommand(ChatHandler* /*handler*/, char const* args) @@ -388,8 +384,9 @@ private: if (!ParseExitCode(exitCodeStr, exitCode)) return false; + // Override parameter "delay" with the configuration value if there are still players connected and "force" parameter was not specified if (delay < (int32)sWorld->getIntConfig(CONFIG_FORCE_SHUTDOWN_THRESHOLD) && !(shutdownMask & SHUTDOWN_MASK_FORCE)) - return false; + delay = (int32)sWorld->getIntConfig(CONFIG_FORCE_SHUTDOWN_THRESHOLD); sWorld->ShutdownServ(delay, shutdownMask, static_cast<uint8>(exitCode), std::string(reason)); |