mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-02-01 10:03:47 +00:00
feat(Scripts/Commands): Implement restart/shutdown reasons (#9242)
This commit is contained in:
@@ -545,9 +545,9 @@ public:
|
||||
virtual void SendServerMessage(ServerMessageType type, const char* text = "", Player* player = nullptr) = 0;
|
||||
virtual bool IsShuttingDown() const = 0;
|
||||
virtual uint32 GetShutDownTimeLeft() const = 0;
|
||||
virtual void ShutdownServ(uint32 time, uint32 options, uint8 exitcode) = 0;
|
||||
virtual void ShutdownServ(uint32 time, uint32 options, uint8 exitcode, const std::string& reason = std::string()) = 0;
|
||||
virtual void ShutdownCancel() = 0;
|
||||
virtual void ShutdownMsg(bool show = false, Player* player = nullptr) = 0;
|
||||
virtual void ShutdownMsg(bool show = false, Player* player = nullptr, const std::string& reason = std::string()) = 0;
|
||||
virtual void Update(uint32 diff) = 0;
|
||||
virtual void UpdateSessions(uint32 diff) = 0;
|
||||
virtual void setRate(Rates rate, float value) = 0;
|
||||
|
||||
@@ -2712,7 +2712,7 @@ void World::_UpdateGameTime()
|
||||
}
|
||||
|
||||
/// Shutdown the server
|
||||
void World::ShutdownServ(uint32 time, uint32 options, uint8 exitcode)
|
||||
void World::ShutdownServ(uint32 time, uint32 options, uint8 exitcode, const std::string& reason)
|
||||
{
|
||||
// ignore if server shutdown at next tick
|
||||
if (IsStopped())
|
||||
@@ -2733,14 +2733,14 @@ void World::ShutdownServ(uint32 time, uint32 options, uint8 exitcode)
|
||||
else
|
||||
{
|
||||
m_ShutdownTimer = time;
|
||||
ShutdownMsg(true);
|
||||
ShutdownMsg(true, nullptr, reason);
|
||||
}
|
||||
|
||||
sScriptMgr->OnShutdownInitiate(ShutdownExitCode(exitcode), ShutdownMask(options));
|
||||
}
|
||||
|
||||
/// Display a shutdown message to the user(s)
|
||||
void World::ShutdownMsg(bool show, Player* player)
|
||||
void World::ShutdownMsg(bool show, Player* player, const std::string& reason)
|
||||
{
|
||||
// not show messages for idle shutdown mode
|
||||
if (m_ShutdownMask & SHUTDOWN_MASK_IDLE)
|
||||
@@ -2756,6 +2756,11 @@ void World::ShutdownMsg(bool show, Player* player)
|
||||
{
|
||||
std::string str = secsToTimeString(m_ShutdownTimer).append(".");
|
||||
|
||||
if (!reason.empty())
|
||||
{
|
||||
str += " - " + reason;
|
||||
}
|
||||
|
||||
ServerMessageType msgid = (m_ShutdownMask & SHUTDOWN_MASK_RESTART) ? SERVER_MSG_RESTART_TIME : SERVER_MSG_SHUTDOWN_TIME;
|
||||
|
||||
SendServerMessage(msgid, str.c_str(), player);
|
||||
|
||||
@@ -265,9 +265,9 @@ public:
|
||||
/// Are we in the middle of a shutdown?
|
||||
bool IsShuttingDown() const { return m_ShutdownTimer > 0; }
|
||||
uint32 GetShutDownTimeLeft() const { return m_ShutdownTimer; }
|
||||
void ShutdownServ(uint32 time, uint32 options, uint8 exitcode);
|
||||
void ShutdownServ(uint32 time, uint32 options, uint8 exitcode, const std::string& reason = std::string());
|
||||
void ShutdownCancel();
|
||||
void ShutdownMsg(bool show = false, Player* player = nullptr);
|
||||
void ShutdownMsg(bool show = false, Player* player = nullptr, const std::string& reason = std::string());
|
||||
static uint8 GetExitCode() { return m_ExitCode; }
|
||||
static void StopNow(uint8 exitcode) { m_stopEvent = true; m_ExitCode = exitcode; }
|
||||
static bool IsStopped() { return m_stopEvent; }
|
||||
|
||||
@@ -267,57 +267,121 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleServerShutDownCommand(ChatHandler* /*handler*/, int32 time, Optional<int32> exitCode)
|
||||
static bool HandleServerShutDownCommand(ChatHandler* /*handler*/, int32 time, Optional<int32> exitCode, Tail reason)
|
||||
{
|
||||
std::wstring wReason = std::wstring();
|
||||
std::string strReason = std::string();
|
||||
|
||||
if (!reason.empty())
|
||||
{
|
||||
if (!Utf8toWStr(reason, wReason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!WStrToUtf8(wReason, strReason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (exitCode && *exitCode >= 0 && *exitCode <= 125)
|
||||
{
|
||||
sWorld->ShutdownServ(time, 0, *exitCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
sWorld->ShutdownServ(time, 0, SHUTDOWN_EXIT_CODE);
|
||||
sWorld->ShutdownServ(time, 0, SHUTDOWN_EXIT_CODE, strReason);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleServerRestartCommand(ChatHandler* /*handler*/, int32 time, Optional<int32> exitCode)
|
||||
static bool HandleServerRestartCommand(ChatHandler* /*handler*/, int32 time, Optional<int32> exitCode, Tail reason)
|
||||
{
|
||||
std::wstring wReason = std::wstring();
|
||||
std::string strReason = std::string();
|
||||
|
||||
if (!reason.empty())
|
||||
{
|
||||
if (!Utf8toWStr(reason, wReason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!WStrToUtf8(wReason, strReason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (exitCode && *exitCode >= 0 && *exitCode <= 125)
|
||||
{
|
||||
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART, *exitCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE);
|
||||
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE, strReason);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleServerIdleRestartCommand(ChatHandler* /*handler*/, int32 time, Optional<int32> exitCode)
|
||||
static bool HandleServerIdleRestartCommand(ChatHandler* /*handler*/, int32 time, Optional<int32> exitCode, Tail reason)
|
||||
{
|
||||
std::wstring wReason = std::wstring();
|
||||
std::string strReason = std::string();
|
||||
|
||||
if (!reason.empty())
|
||||
{
|
||||
if (!Utf8toWStr(reason, wReason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!WStrToUtf8(wReason, strReason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (exitCode && *exitCode >= 0 && *exitCode <= 125)
|
||||
{
|
||||
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, *exitCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, RESTART_EXIT_CODE);
|
||||
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, RESTART_EXIT_CODE, strReason);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleServerIdleShutDownCommand(ChatHandler* /*handler*/, int32 time, Optional<int32> exitCode)
|
||||
static bool HandleServerIdleShutDownCommand(ChatHandler* /*handler*/, int32 time, Optional<int32> exitCode, Tail reason)
|
||||
{
|
||||
std::wstring wReason = std::wstring();
|
||||
std::string strReason = std::string();
|
||||
|
||||
if (!reason.empty())
|
||||
{
|
||||
if (!Utf8toWStr(reason, wReason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!WStrToUtf8(wReason, strReason))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (exitCode && *exitCode >= 0 && *exitCode <= 125)
|
||||
{
|
||||
sWorld->ShutdownServ(time, SHUTDOWN_MASK_IDLE, *exitCode);
|
||||
}
|
||||
else
|
||||
{
|
||||
sWorld->ShutdownServ(time, SHUTDOWN_MASK_IDLE, SHUTDOWN_EXIT_CODE);
|
||||
sWorld->ShutdownServ(time, SHUTDOWN_MASK_IDLE, SHUTDOWN_EXIT_CODE, strReason);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -86,9 +86,9 @@ public:
|
||||
MOCK_METHOD(void, SendServerMessage, (ServerMessageType type, const char* text, Player* player));
|
||||
MOCK_METHOD(bool, IsShuttingDown, (), (const));
|
||||
MOCK_METHOD(uint32, GetShutDownTimeLeft, (), (const));
|
||||
MOCK_METHOD(void, ShutdownServ, (uint32 time, uint32 options, uint8 exitcode), ());
|
||||
MOCK_METHOD(void, ShutdownServ, (uint32 time, uint32 options, uint8 exitcode, const std::string& reason), ());
|
||||
MOCK_METHOD(void, ShutdownCancel, ());
|
||||
MOCK_METHOD(void, ShutdownMsg, (bool show, Player* player), ());
|
||||
MOCK_METHOD(void, ShutdownMsg, (bool show, Player* player, const std::string& reason), ());
|
||||
MOCK_METHOD(void, Update, (uint32 diff), ());
|
||||
MOCK_METHOD(void, UpdateSessions, (uint32 diff), ());
|
||||
MOCK_METHOD(void, setRate, (Rates rate, float value), ());
|
||||
|
||||
Reference in New Issue
Block a user