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)
This commit is contained in:
jackpoz
2017-02-11 22:02:08 +01:00
committed by joschiwald
parent 85a16fae3d
commit a3384bdc70
+6 -9
View File
@@ -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));