feat(Core/Command): Use timestring with all commands (#12050)

This commit is contained in:
Kempec Halk
2022-06-13 19:05:26 +02:00
committed by GitHub
parent d236dc9d07
commit 3c434cee12
6 changed files with 285 additions and 51 deletions
@@ -0,0 +1,18 @@
--
DELETE FROM `acore_string` WHERE `entry` IN (283,298,300,301,11003);
INSERT INTO `acore_string` (`entry`, `content_default`, `locale_koKR`, `locale_frFR`, `locale_deDE`, `locale_zhCN`, `locale_zhTW`, `locale_esES`, `locale_esMX`, `locale_ruRU`) VALUES
(283, "%s has disabled %s's chat for %s, effective at the player's next login. Reason: %s.", NULL, NULL, "Ihr habt dem Spieler %s das chatten für %s gesperrt, beginnend mit dem nächsten Login des Spielers. Grund: %s.", "你已经被 %s 禁言 %s,将在下一次登陆时生效。原因: %s。", NULL, "%s ha deshabilitado el chat de %s por %s, efectivo en el próximo ingreso del jugador. Razón: %s.", "%s ha deshabilitado el chat de %s por %s, efectivo en el próximo ingreso del jugador. Razón: %s.", NULL),
(298, "Spawn time changed to: %s", NULL, NULL, "Spawnzeit wurde auf: %s abgeändert", "复生时间改变为: %s", NULL, "Tiempo de desove cambiado a: %s", "Tiempo de desove cambiado a: %s", NULL),
(300, "Your chat has been disabled for %s. By: %s, Reason: %s.", NULL, NULL, "Euer Chat wurde für %s abgeschaltet. Von: %s, Grund: %s", "你将被禁言 %s.", NULL, "Tu chat ha sido desactivado durante %u. Por: %s ,Razón: %s.", "Tu chat ha sido desactivado durante %u. Por: %s ,Razón: %s.", NULL),
(301, "%s has disabled %s's chat for %s. Reason: %s.", NULL, NULL, "Ihr hab den Chat von %s für %s abgeschaltet. Von: %s, Grund: %s", NULL, NULL, "%s ha desactivado el chat de %s durante %s. Razón: %s.", "%s ha desactivado el chat de %s durante %s. Razón: %s.", NULL),
(11003, "Server: %s has muted %s for %s, reason: %s", NULL, NULL, NULL, "系统公告: %s has muted %s for %s, 原因: %s", NULL, NULL, NULL, "Server: %s замутил %s на %s, причина: %s");
UPDATE `command` SET `help` = "Syntax: .mute [$playerName] $mutetime [$reason]\r\nDisible chat messaging for any character from account of character $playerName (or currently selected) at $mutetime time. Player can be offline.\n$mutetime: use a timestring like \"1d15h33s\"." WHERE `name` = "mute";
UPDATE `command` SET `help` = "Syntax: .npc set spawntime #time\r\nAdjust spawntime of selected creature to #time.\n#time: use a timestring like \"10m30s\"." WHERE `name` = "npc set spawntime";
UPDATE `command` SET `help` = "Syntax: .server idlerestart #delay\r\nRestart the server after #delay if no active connections are present (no players). Use #exist_code or 2 as program exist code.\n#delay: use a timestring like \"1h15m30s\"." WHERE `name` = "server idlerestart";
UPDATE `command` SET `help` = "Syntax: .server idleshutdown #delay [#exist_code]\r\nShut the server down after #delay if no active connections are present (no players). Use #exist_code or 0 as program exist code.\n#delay: use a timestring like \"1h15m30s\"." WHERE `name` = "server idleshutdown";
UPDATE `command` SET `help` = "Syntax: .server restart #delay\r\nRestart the server after #delay. Use #exist_code or 2 as program exist code.\n#delay: use a timestring like \"1h15m30s\"." WHERE `name` = "server restart";
UPDATE `command` SET `help` = "Syntax: .server shutdown #delay [#exit_code]\r\nShut the server down after #delay. Use #exit_code or 0 as program exit code.\n#delay: use a timestring like \"1h15m30s\"." WHERE `name` = "server shutdown";
UPDATE `command` SET `help` = "Syntax: .bf timer #battleid #timer\n#timer: use a timestring like \"1h15m30s\"." WHERE `name` = "bf timer";
UPDATE `command` SET `help` = "Syntax: .deserter bg add $playerName <$time>\r\nAdds the bg deserter debuff to a player or your target with $time.\nOptional $time: use a timestring like \"1h15m30s\".Default: 15m" WHERE `name` = "deserter bg add";
UPDATE `command` SET `help` = "Syntax: .deserter instance add $playerName <$time>\r\nAdds the instance deserter debuff to a player or your target with $time.\nOptional $time: use a timestring like \"1h15m30s\". Default: 30m" WHERE `name` = "deserter instance add";
+26 -1
View File
@@ -117,8 +117,33 @@ public:
return true; return true;
} }
static bool HandleBattlefieldTimer(ChatHandler* handler, uint32 battleId, uint32 time) static bool HandleBattlefieldTimer(ChatHandler* handler, uint32 battleId, std::string timeStr)
{ {
if (timeStr.empty())
{
return false;
}
if (Acore::StringTo<int32>(timeStr).value_or(0) < 0)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
int32 time = TimeStringToSecs(timeStr);
if (time <= 0)
{
time = Acore::StringTo<int32>(timeStr).value_or(0);
}
if (time <= 0)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId); Battlefield* bf = sBattlefieldMgr->GetBattlefieldByBattleId(battleId);
if (!bf) if (!bf)
+69 -28
View File
@@ -79,7 +79,8 @@ public:
* selected player, with the provided duration in seconds. * selected player, with the provided duration in seconds.
* *
* @param handler The ChatHandler, passed by the system. * @param handler The ChatHandler, passed by the system.
* @param time The provided duration in seconds. * @param playerName Player by name. Optional, defaults to selected or self.
* @param time The provided duration as TimeString. Optional, defaults to bg/instance default time.
* @param isInstance provided by the relaying functions, so we don't have * @param isInstance provided by the relaying functions, so we don't have
* to write that much code :) * to write that much code :)
* *
@@ -87,40 +88,80 @@ public:
* *
* Example Usage: * Example Usage:
* @code * @code
* .deserter instance add 3600 (one hour) * .deserter instance add 1h30m
* -or- * -or-
* .deserter bg add 3600 (one hour) * .deserter bg add 1h30m
* @endcode * @endcode
*/ */
static bool HandleDeserterAdd(ChatHandler* handler, Optional<PlayerIdentifier> player, uint32 time, bool isInstance) static bool HandleDeserterAdd(ChatHandler* handler, Optional<std::string> playerName, Optional<std::string> time, bool isInstance)
{ {
if (!player) Player* target = handler->getSelectedPlayerOrSelf();
{ ObjectGuid guid;
player = PlayerIdentifier::FromTargetOrSelf(handler);
}
if (!player) if (playerName)
{ {
handler->SendSysMessage(LANG_NO_CHAR_SELECTED); if (!normalizePlayerName(*playerName))
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true); handler->SetSentErrorMessage(true);
return false; return false;
} }
guid = sCharacterCache->GetCharacterGuidByName(*playerName);
if (guid)
{
target = ObjectAccessor::FindPlayerByName(*playerName);
}
else
{
if (time)
{
handler->SendSysMessage(LANG_PLAYER_NOT_FOUND);
handler->SetSentErrorMessage(true);
return false;
}
time = playerName;
playerName = "";
}
}
if (!playerName || playerName->empty())
{
if (!handler->GetSession())
{
return false;
}
playerName = target->GetName();
guid = target->GetGUID();
}
if (!time) if (!time)
{
time = isInstance ? "30m" : "15m";
}
int32 duration = TimeStringToSecs(*time);
if (duration == 0)
{
duration = Acore::StringTo<int32>(*time).value_or(0);
}
if (duration == 0)
{ {
handler->SendSysMessage(LANG_BAD_VALUE); handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true); handler->SetSentErrorMessage(true);
return false; return false;
} }
Player* target = player->GetConnectedPlayer();
if (target) if (target)
{ {
Aura* aura = target->GetAura(isInstance ? LFG_SPELL_DUNGEON_DESERTER : BG_SPELL_DESERTER); Aura* aura = target->GetAura(isInstance ? LFG_SPELL_DUNGEON_DESERTER : BG_SPELL_DESERTER);
if (aura && aura->GetDuration() >= (int32)time * IN_MILLISECONDS) if (aura && aura->GetDuration() >= duration * IN_MILLISECONDS)
{ {
handler->PSendSysMessage("Player %s already has a longer %s Deserter active.", handler->playerLink(player->GetName()), isInstance ? "Instance" : "Battleground"); handler->PSendSysMessage("Player %s already has a longer %s Deserter active.", handler->playerLink(*playerName), isInstance ? "Instance" : "Battleground");
return true; return true;
} }
@@ -131,29 +172,29 @@ public:
handler->SetSentErrorMessage(true); handler->SetSentErrorMessage(true);
return false; return false;
} }
aura->SetDuration(time * IN_MILLISECONDS); aura->SetDuration(duration * IN_MILLISECONDS);
return true; return true;
} }
int32 duration = 0; int32 remainTime = 0;
if (QueryResult result = CharacterDatabase.Query("SELECT remainTime FROM character_aura WHERE guid = {} AND spell = {}", player->GetGUID().GetCounter(), isInstance ? LFG_SPELL_DUNGEON_DESERTER : BG_SPELL_DESERTER)) if (QueryResult result = CharacterDatabase.Query("SELECT remainTime FROM character_aura WHERE guid = {} AND spell = {}", guid.GetCounter(), isInstance ? LFG_SPELL_DUNGEON_DESERTER : BG_SPELL_DESERTER))
{ {
Field* fields = result->Fetch(); Field* fields = result->Fetch();
duration = fields[0].Get<int32>(); remainTime = fields[0].Get<int32>();
if (duration < 0 || duration >= (int32)time * IN_MILLISECONDS) if (remainTime < 0 || remainTime >= duration * IN_MILLISECONDS)
{ {
handler->PSendSysMessage("Player %s already has a longer %s Deserter active.", handler->playerLink(player->GetName()), isInstance ? "Instance" : "Battleground"); handler->PSendSysMessage("Player %s already has a longer %s Deserter active.", handler->playerLink(*playerName), isInstance ? "Instance" : "Battleground");
return true; return true;
} }
CharacterDatabase.Query("DELETE FROM character_aura WHERE guid = {} AND spell = {}", player->GetGUID().GetCounter(), isInstance ? LFG_SPELL_DUNGEON_DESERTER : BG_SPELL_DESERTER); CharacterDatabase.Query("DELETE FROM character_aura WHERE guid = {} AND spell = {}", guid.GetCounter(), isInstance ? LFG_SPELL_DUNGEON_DESERTER : BG_SPELL_DESERTER);
} }
uint8 index = 0; uint8 index = 0;
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_AURA); CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_AURA);
stmt->SetData(index++, player->GetGUID().GetCounter()); stmt->SetData(index++, guid.GetCounter());
stmt->SetData(index++, player->GetGUID().GetCounter()); stmt->SetData(index++, guid.GetCounter());
stmt->SetData(index++, 0); stmt->SetData(index++, 0);
stmt->SetData(index++, isInstance ? LFG_SPELL_DUNGEON_DESERTER : BG_SPELL_DESERTER); stmt->SetData(index++, isInstance ? LFG_SPELL_DUNGEON_DESERTER : BG_SPELL_DESERTER);
stmt->SetData(index++, 1); stmt->SetData(index++, 1);
@@ -166,7 +207,7 @@ public:
stmt->SetData(index++, 0); stmt->SetData(index++, 0);
stmt->SetData(index++, 0); stmt->SetData(index++, 0);
stmt->SetData(index++, isInstance ? 1800000 : 900000); stmt->SetData(index++, isInstance ? 1800000 : 900000);
stmt->SetData(index++, time * 1000); stmt->SetData(index++, duration * 1000);
stmt->SetData(index, 0); stmt->SetData(index, 0);
CharacterDatabase.Execute(stmt); CharacterDatabase.Execute(stmt);
@@ -240,15 +281,15 @@ public:
} }
/// @sa HandleDeserterAdd() /// @sa HandleDeserterAdd()
static bool HandleDeserterInstanceAdd(ChatHandler* handler, Optional<PlayerIdentifier> player, uint32 time) static bool HandleDeserterInstanceAdd(ChatHandler* handler, Optional<std::string> playerName, Optional<std::string> time)
{ {
return HandleDeserterAdd(handler, player, time, true); return HandleDeserterAdd(handler, playerName, time, true);
} }
/// @sa HandleDeserterAdd() /// @sa HandleDeserterAdd()
static bool HandleDeserterBGAdd(ChatHandler* handler, Optional<PlayerIdentifier> player, uint32 time) static bool HandleDeserterBGAdd(ChatHandler* handler, Optional<std::string> playerName, Optional<std::string> time)
{ {
return HandleDeserterAdd(handler, player, time, false); return HandleDeserterAdd(handler, playerName, time, false);
} }
/// @sa HandleDeserterRemove() /// @sa HandleDeserterRemove()
+33 -8
View File
@@ -2374,10 +2374,22 @@ public:
} }
// mute player for some times // mute player for some times
static bool HandleMuteCommand(ChatHandler* handler, Optional<PlayerIdentifier> player, uint32 notSpeakTime, Tail muteReason) static bool HandleMuteCommand(ChatHandler* handler, Optional<PlayerIdentifier> player, std::string notSpeakTime, Tail muteReason)
{ {
std::string muteReasonStr{ muteReason }; std::string muteReasonStr{ muteReason };
if (notSpeakTime.empty())
{
return false;
}
if (Acore::StringTo<int32>(notSpeakTime).value_or(0) < 0)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
if (muteReason.empty()) if (muteReason.empty())
{ {
muteReasonStr = handler->GetAcoreString(LANG_NO_REASON); muteReasonStr = handler->GetAcoreString(LANG_NO_REASON);
@@ -2412,6 +2424,19 @@ public:
} }
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_MUTE_TIME); LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_MUTE_TIME);
int32 muteDuration = TimeStringToSecs(notSpeakTime);
if (muteDuration <= 0)
{
muteDuration = Acore::StringTo<int32>(notSpeakTime).value_or(0);
}
if (muteDuration <= 0)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
std::string muteBy = ""; std::string muteBy = "";
if (handler->GetSession()) if (handler->GetSession())
{ {
@@ -2425,22 +2450,22 @@ public:
if (target) if (target)
{ {
// Target is online, mute will be in effect right away. // Target is online, mute will be in effect right away.
int64 muteTime = GameTime::GetGameTime().count() + notSpeakTime * MINUTE; int64 muteTime = GameTime::GetGameTime().count() + muteDuration;
target->GetSession()->m_muteTime = muteTime; target->GetSession()->m_muteTime = muteTime;
stmt->SetData(0, muteTime); stmt->SetData(0, muteTime);
std::string nameLink = handler->playerLink(player->GetName()); std::string nameLink = handler->playerLink(player->GetName());
if (sWorld->getBoolConfig(CONFIG_SHOW_MUTE_IN_WORLD)) if (sWorld->getBoolConfig(CONFIG_SHOW_MUTE_IN_WORLD))
{ {
sWorld->SendWorldText(LANG_COMMAND_MUTEMESSAGE_WORLD, muteBy.c_str(), nameLink.c_str(), notSpeakTime, muteReasonStr.c_str()); sWorld->SendWorldText(LANG_COMMAND_MUTEMESSAGE_WORLD, muteBy.c_str(), nameLink.c_str(), secsToTimeString(muteDuration, true).c_str(), muteReasonStr.c_str());
} }
ChatHandler(target->GetSession()).PSendSysMessage(LANG_YOUR_CHAT_DISABLED, notSpeakTime, muteBy.c_str(), muteReasonStr.c_str()); ChatHandler(target->GetSession()).PSendSysMessage(LANG_YOUR_CHAT_DISABLED, secsToTimeString(muteDuration, true).c_str(), muteBy.c_str(), muteReasonStr.c_str());
} }
else else
{ {
// Target is offline, mute will be in effect starting from the next login. // Target is offline, mute will be in effect starting from the next login.
stmt->SetData(0, -int32(notSpeakTime * MINUTE)); stmt->SetData(0, -int32(muteDuration));
} }
stmt->SetData(1, muteReasonStr); stmt->SetData(1, muteReasonStr);
@@ -2450,7 +2475,7 @@ public:
stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_MUTE); stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT_MUTE);
stmt->SetData(0, accountId); stmt->SetData(0, accountId);
stmt->SetData(1, notSpeakTime); stmt->SetData(1, muteDuration / MINUTE);
stmt->SetData(2, muteBy); stmt->SetData(2, muteBy);
stmt->SetData(3, muteReasonStr); stmt->SetData(3, muteReasonStr);
LoginDatabase.Execute(stmt); LoginDatabase.Execute(stmt);
@@ -2459,7 +2484,7 @@ public:
if (sWorld->getBoolConfig(CONFIG_SHOW_MUTE_IN_WORLD) && !target) if (sWorld->getBoolConfig(CONFIG_SHOW_MUTE_IN_WORLD) && !target)
{ {
sWorld->SendWorldText(LANG_COMMAND_MUTEMESSAGE_WORLD, muteBy.c_str(), nameLink.c_str(), notSpeakTime, muteReasonStr.c_str()); sWorld->SendWorldText(LANG_COMMAND_MUTEMESSAGE_WORLD, muteBy.c_str(), nameLink.c_str(), secsToTimeString(muteDuration, true).c_str(), muteReasonStr.c_str());
} }
else else
{ {
@@ -2469,7 +2494,7 @@ public:
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
if (itr->second->GetSession()->GetSecurity()) if (itr->second->GetSession()->GetSecurity())
ChatHandler(itr->second->GetSession()).PSendSysMessage(target ? LANG_YOU_DISABLE_CHAT : LANG_COMMAND_DISABLE_CHAT_DELAYED, ChatHandler(itr->second->GetSession()).PSendSysMessage(target ? LANG_YOU_DISABLE_CHAT : LANG_COMMAND_DISABLE_CHAT_DELAYED,
(handler->GetSession() ? handler->GetSession()->GetPlayerName().c_str() : handler->GetAcoreString(LANG_CONSOLE)), nameLink.c_str(), notSpeakTime, muteReasonStr.c_str()); (handler->GetSession() ? handler->GetSession()->GetPlayerName().c_str() : handler->GetAcoreString(LANG_CONSOLE)), nameLink.c_str(), secsToTimeString(muteDuration, true).c_str(), muteReasonStr.c_str());
} }
return true; return true;
+27 -2
View File
@@ -987,19 +987,44 @@ public:
} }
//spawn time handling //spawn time handling
static bool HandleNpcSetSpawnTimeCommand(ChatHandler* handler, uint32 spawnTime) static bool HandleNpcSetSpawnTimeCommand(ChatHandler* handler, std::string spawnTimeStr)
{ {
if (spawnTimeStr.empty())
{
return false;
}
if (Acore::StringTo<int32>(spawnTimeStr).value_or(0) < 0)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
Creature* creature = handler->getSelectedCreature(); Creature* creature = handler->getSelectedCreature();
if (!creature) if (!creature)
return false; return false;
int32 spawnTime = TimeStringToSecs(spawnTimeStr);
if (spawnTime <= 0)
{
spawnTime = Acore::StringTo<int32>(spawnTimeStr).value_or(0);
}
if (spawnTime <= 0)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_CREATURE_SPAWN_TIME_SECS); WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_UPD_CREATURE_SPAWN_TIME_SECS);
stmt->SetData(0, spawnTime); stmt->SetData(0, spawnTime);
stmt->SetData(1, creature->GetSpawnId()); stmt->SetData(1, creature->GetSpawnId());
WorldDatabase.Execute(stmt); WorldDatabase.Execute(stmt);
creature->SetRespawnDelay(spawnTime); creature->SetRespawnDelay(spawnTime);
handler->PSendSysMessage(LANG_COMMAND_SPAWNTIME, spawnTime); handler->PSendSysMessage(LANG_COMMAND_SPAWNTIME, secsToTimeString(spawnTime, true).c_str());
return true; return true;
} }
+112 -12
View File
@@ -269,11 +269,23 @@ public:
return true; return true;
} }
static bool HandleServerShutDownCommand(ChatHandler* /*handler*/, int32 time, Optional<int32> exitCode, Tail reason) static bool HandleServerShutDownCommand(ChatHandler* handler, std::string time, Optional<int32> exitCode, Tail reason)
{ {
std::wstring wReason = std::wstring(); std::wstring wReason = std::wstring();
std::string strReason = std::string(); std::string strReason = std::string();
if (time.empty())
{
return false;
}
if (Acore::StringTo<int32>(time).value_or(0) < 0)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
if (!reason.empty()) if (!reason.empty())
{ {
if (!Utf8toWStr(reason, wReason)) if (!Utf8toWStr(reason, wReason))
@@ -287,23 +299,48 @@ public:
} }
} }
int32 delay = TimeStringToSecs(time);
if (delay <= 0)
{
delay = Acore::StringTo<int32>(time).value_or(0);
}
if (delay <= 0)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
if (exitCode && *exitCode >= 0 && *exitCode <= 125) if (exitCode && *exitCode >= 0 && *exitCode <= 125)
{ {
sWorld->ShutdownServ(time, 0, *exitCode); sWorld->ShutdownServ(delay, 0, *exitCode);
} }
else else
{ {
sWorld->ShutdownServ(time, 0, SHUTDOWN_EXIT_CODE, strReason); sWorld->ShutdownServ(delay, 0, SHUTDOWN_EXIT_CODE, strReason);
} }
return true; return true;
} }
static bool HandleServerRestartCommand(ChatHandler* /*handler*/, int32 time, Optional<int32> exitCode, Tail reason) static bool HandleServerRestartCommand(ChatHandler* handler, std::string time, Optional<int32> exitCode, Tail reason)
{ {
std::wstring wReason = std::wstring(); std::wstring wReason = std::wstring();
std::string strReason = std::string(); std::string strReason = std::string();
if (time.empty())
{
return false;
}
if (Acore::StringTo<int32>(time).value_or(0) < 0)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
if (!reason.empty()) if (!reason.empty())
{ {
if (!Utf8toWStr(reason, wReason)) if (!Utf8toWStr(reason, wReason))
@@ -317,23 +354,48 @@ public:
} }
} }
int32 delay = TimeStringToSecs(time);
if (delay <= 0)
{
delay = Acore::StringTo<int32>(time).value_or(0);
}
if (delay <= 0)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
if (exitCode && *exitCode >= 0 && *exitCode <= 125) if (exitCode && *exitCode >= 0 && *exitCode <= 125)
{ {
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART, *exitCode); sWorld->ShutdownServ(delay, SHUTDOWN_MASK_RESTART, *exitCode);
} }
else else
{ {
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE, strReason); sWorld->ShutdownServ(delay, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE, strReason);
} }
return true; return true;
} }
static bool HandleServerIdleRestartCommand(ChatHandler* /*handler*/, int32 time, Optional<int32> exitCode, Tail reason) static bool HandleServerIdleRestartCommand(ChatHandler* handler, std::string time, Optional<int32> exitCode, Tail reason)
{ {
std::wstring wReason = std::wstring(); std::wstring wReason = std::wstring();
std::string strReason = std::string(); std::string strReason = std::string();
if (time.empty())
{
return false;
}
if (Acore::StringTo<int32>(time).value_or(0) < 0)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
if (!reason.empty()) if (!reason.empty())
{ {
if (!Utf8toWStr(reason, wReason)) if (!Utf8toWStr(reason, wReason))
@@ -347,23 +409,48 @@ public:
} }
} }
int32 delay = TimeStringToSecs(time);
if (delay <= 0)
{
delay = Acore::StringTo<int32>(time).value_or(0);
}
if (delay <= 0)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
if (exitCode && *exitCode >= 0 && *exitCode <= 125) if (exitCode && *exitCode >= 0 && *exitCode <= 125)
{ {
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, *exitCode); sWorld->ShutdownServ(delay, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, *exitCode);
} }
else else
{ {
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, RESTART_EXIT_CODE, strReason); sWorld->ShutdownServ(delay, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, RESTART_EXIT_CODE, strReason);
} }
return true; return true;
} }
static bool HandleServerIdleShutDownCommand(ChatHandler* /*handler*/, int32 time, Optional<int32> exitCode, Tail reason) static bool HandleServerIdleShutDownCommand(ChatHandler* handler, std::string time, Optional<int32> exitCode, Tail reason)
{ {
std::wstring wReason = std::wstring(); std::wstring wReason = std::wstring();
std::string strReason = std::string(); std::string strReason = std::string();
if (time.empty())
{
return false;
}
if (Acore::StringTo<int32>(time).value_or(0) < 0)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
if (!reason.empty()) if (!reason.empty())
{ {
if (!Utf8toWStr(reason, wReason)) if (!Utf8toWStr(reason, wReason))
@@ -377,13 +464,26 @@ public:
} }
} }
int32 delay = TimeStringToSecs(time);
if (delay <= 0)
{
delay = Acore::StringTo<int32>(time).value_or(0);
}
if (delay <= 0)
{
handler->SendSysMessage(LANG_BAD_VALUE);
handler->SetSentErrorMessage(true);
return false;
}
if (exitCode && *exitCode >= 0 && *exitCode <= 125) if (exitCode && *exitCode >= 0 && *exitCode <= 125)
{ {
sWorld->ShutdownServ(time, SHUTDOWN_MASK_IDLE, *exitCode); sWorld->ShutdownServ(delay, SHUTDOWN_MASK_IDLE, *exitCode);
} }
else else
{ {
sWorld->ShutdownServ(time, SHUTDOWN_MASK_IDLE, SHUTDOWN_EXIT_CODE, strReason); sWorld->ShutdownServ(delay, SHUTDOWN_MASK_IDLE, SHUTDOWN_EXIT_CODE, strReason);
} }
return true; return true;