refactor(Scripts/Commands): convert cs_server to new system (#9078)
This commit is contained in:
committed by
GitHub
parent
8773bacd34
commit
06bc64d1c3
@@ -41,10 +41,6 @@ EndScriptData */
|
|||||||
#include <openssl/opensslv.h>
|
#include <openssl/opensslv.h>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
|
||||||
#if AC_COMPILER == AC_COMPILER_GNU
|
|
||||||
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using namespace Acore::ChatCommands;
|
using namespace Acore::ChatCommands;
|
||||||
|
|
||||||
class server_commandscript : public CommandScript
|
class server_commandscript : public CommandScript
|
||||||
@@ -56,66 +52,66 @@ public:
|
|||||||
{
|
{
|
||||||
static ChatCommandTable serverIdleRestartCommandTable =
|
static ChatCommandTable serverIdleRestartCommandTable =
|
||||||
{
|
{
|
||||||
{ "cancel", SEC_ADMINISTRATOR, true, &HandleServerShutDownCancelCommand, "" },
|
{ "cancel", HandleServerShutDownCancelCommand, SEC_ADMINISTRATOR, Console::Yes },
|
||||||
{ "", SEC_CONSOLE, true, &HandleServerIdleRestartCommand, "" }
|
{ "", HandleServerIdleRestartCommand, SEC_CONSOLE, Console::Yes }
|
||||||
};
|
};
|
||||||
|
|
||||||
static ChatCommandTable serverIdleShutdownCommandTable =
|
static ChatCommandTable serverIdleShutdownCommandTable =
|
||||||
{
|
{
|
||||||
{ "cancel", SEC_ADMINISTRATOR, true, &HandleServerShutDownCancelCommand, "" },
|
{ "cancel", HandleServerShutDownCancelCommand, SEC_ADMINISTRATOR, Console::Yes },
|
||||||
{ "", SEC_CONSOLE, true, &HandleServerIdleShutDownCommand, "" }
|
{ "", HandleServerIdleShutDownCommand, SEC_CONSOLE, Console::Yes }
|
||||||
};
|
};
|
||||||
|
|
||||||
static ChatCommandTable serverRestartCommandTable =
|
static ChatCommandTable serverRestartCommandTable =
|
||||||
{
|
{
|
||||||
{ "cancel", SEC_ADMINISTRATOR, true, &HandleServerShutDownCancelCommand, "" },
|
{ "cancel", HandleServerShutDownCancelCommand, SEC_ADMINISTRATOR, Console::Yes },
|
||||||
{ "", SEC_ADMINISTRATOR, true, &HandleServerRestartCommand, "" }
|
{ "", HandleServerRestartCommand, SEC_ADMINISTRATOR, Console::Yes }
|
||||||
};
|
};
|
||||||
|
|
||||||
static ChatCommandTable serverShutdownCommandTable =
|
static ChatCommandTable serverShutdownCommandTable =
|
||||||
{
|
{
|
||||||
{ "cancel", SEC_ADMINISTRATOR, true, &HandleServerShutDownCancelCommand, "" },
|
{ "cancel", HandleServerShutDownCancelCommand, SEC_ADMINISTRATOR, Console::Yes },
|
||||||
{ "", SEC_ADMINISTRATOR, true, &HandleServerShutDownCommand, "" }
|
{ "", HandleServerShutDownCommand, SEC_ADMINISTRATOR, Console::Yes }
|
||||||
};
|
};
|
||||||
|
|
||||||
static ChatCommandTable serverSetCommandTable =
|
static ChatCommandTable serverSetCommandTable =
|
||||||
{
|
{
|
||||||
{ "difftime", SEC_CONSOLE, true, &HandleServerSetDiffTimeCommand, "" },
|
{ "difftime", HandleServerSetDiffTimeCommand, SEC_CONSOLE, Console::Yes },
|
||||||
{ "loglevel", SEC_CONSOLE, true, &HandleServerSetLogLevelCommand, "" },
|
{ "loglevel", HandleServerSetLogLevelCommand, SEC_CONSOLE, Console::Yes },
|
||||||
{ "motd", SEC_ADMINISTRATOR, true, &HandleServerSetMotdCommand, "" },
|
{ "motd", HandleServerSetMotdCommand, SEC_ADMINISTRATOR, Console::Yes },
|
||||||
{ "closed", SEC_CONSOLE, true, &HandleServerSetClosedCommand, "" }
|
{ "closed", HandleServerSetClosedCommand, SEC_CONSOLE, Console::Yes },
|
||||||
};
|
};
|
||||||
|
|
||||||
static ChatCommandTable serverCommandTable =
|
static ChatCommandTable serverCommandTable =
|
||||||
{
|
{
|
||||||
{ "corpses", SEC_GAMEMASTER, true, &HandleServerCorpsesCommand, "" },
|
{ "corpses", HandleServerCorpsesCommand, SEC_GAMEMASTER, Console::Yes },
|
||||||
{ "debug", SEC_ADMINISTRATOR, true, &HandleServerDebugCommand, "" },
|
{ "debug", HandleServerDebugCommand, SEC_ADMINISTRATOR, Console::Yes },
|
||||||
{ "exit", SEC_CONSOLE, true, &HandleServerExitCommand, "" },
|
{ "exit", HandleServerExitCommand, SEC_CONSOLE, Console::Yes },
|
||||||
{ "idlerestart", SEC_CONSOLE, true, nullptr, "", serverIdleRestartCommandTable },
|
{ "idlerestart", serverIdleRestartCommandTable },
|
||||||
{ "idleshutdown", SEC_CONSOLE, true, nullptr, "", serverIdleShutdownCommandTable },
|
{ "idleshutdown", serverIdleShutdownCommandTable },
|
||||||
{ "info", SEC_PLAYER, true, &HandleServerInfoCommand, "" },
|
{ "info", HandleServerInfoCommand, SEC_PLAYER, Console::Yes },
|
||||||
{ "motd", SEC_PLAYER, true, &HandleServerMotdCommand, "" },
|
{ "motd", HandleServerMotdCommand, SEC_PLAYER, Console::Yes },
|
||||||
{ "restart", SEC_ADMINISTRATOR, true, nullptr, "", serverRestartCommandTable },
|
{ "restart", serverRestartCommandTable },
|
||||||
{ "shutdown", SEC_ADMINISTRATOR, true, nullptr, "", serverShutdownCommandTable },
|
{ "shutdown", serverShutdownCommandTable },
|
||||||
{ "set", SEC_ADMINISTRATOR, true, nullptr, "", serverSetCommandTable }
|
{ "set", serverSetCommandTable }
|
||||||
};
|
};
|
||||||
|
|
||||||
static ChatCommandTable commandTable =
|
static ChatCommandTable commandTable =
|
||||||
{
|
{
|
||||||
{ "server", SEC_PLAYER, true, nullptr, "", serverCommandTable }
|
{ "server", serverCommandTable }
|
||||||
};
|
};
|
||||||
|
|
||||||
return commandTable;
|
return commandTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Triggering corpses expire check in world
|
// Triggering corpses expire check in world
|
||||||
static bool HandleServerCorpsesCommand(ChatHandler* /*handler*/, char const* /*args*/)
|
static bool HandleServerCorpsesCommand(ChatHandler* /*handler*/)
|
||||||
{
|
{
|
||||||
sWorld->RemoveOldCorpses();
|
sWorld->RemoveOldCorpses();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleServerDebugCommand(ChatHandler* handler, char const* /*args*/)
|
static bool HandleServerDebugCommand(ChatHandler* handler)
|
||||||
{
|
{
|
||||||
uint16 worldPort = uint16(sWorld->getIntConfig(CONFIG_PORT_WORLD));
|
uint16 worldPort = uint16(sWorld->getIntConfig(CONFIG_PORT_WORLD));
|
||||||
std::string dbPortOutput;
|
std::string dbPortOutput;
|
||||||
@@ -226,7 +222,7 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleServerInfoCommand(ChatHandler* handler, char const* /*args*/)
|
static bool HandleServerInfoCommand(ChatHandler* handler)
|
||||||
{
|
{
|
||||||
std::string realmName = sWorld->GetRealmName();
|
std::string realmName = sWorld->GetRealmName();
|
||||||
uint32 playerCount = sWorld->GetPlayerCount();
|
uint32 playerCount = sWorld->GetPlayerCount();
|
||||||
@@ -258,163 +254,77 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Display the 'Message of the day' for the realm
|
// Display the 'Message of the day' for the realm
|
||||||
static bool HandleServerMotdCommand(ChatHandler* handler, char const* /*args*/)
|
static bool HandleServerMotdCommand(ChatHandler* handler)
|
||||||
{
|
{
|
||||||
handler->PSendSysMessage(LANG_MOTD_CURRENT, Motd::GetMotd());
|
handler->PSendSysMessage(LANG_MOTD_CURRENT, Motd::GetMotd());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleServerShutDownCancelCommand(ChatHandler* /*handler*/, char const* /*args*/)
|
static bool HandleServerShutDownCancelCommand(ChatHandler* /*handler*/)
|
||||||
{
|
{
|
||||||
sWorld->ShutdownCancel();
|
sWorld->ShutdownCancel();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleServerShutDownCommand(ChatHandler* /*handler*/, char const* args)
|
static bool HandleServerShutDownCommand(ChatHandler* /*handler*/, int32 time, Optional<int32> exitCode)
|
||||||
{
|
{
|
||||||
if (!*args)
|
if (exitCode && *exitCode >= 0 && *exitCode <= 125)
|
||||||
return false;
|
|
||||||
|
|
||||||
char* timeStr = strtok((char*) args, " ");
|
|
||||||
char* exitCodeStr = strtok(nullptr, "");
|
|
||||||
|
|
||||||
int32 time = atoi(timeStr);
|
|
||||||
|
|
||||||
// Prevent interpret wrong arg value as 0 secs shutdown time
|
|
||||||
if ((time == 0 && (timeStr[0] != '0' || timeStr[1] != '\0')) || time < 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (exitCodeStr)
|
|
||||||
{
|
{
|
||||||
int32 exitCode = atoi(exitCodeStr);
|
sWorld->ShutdownServ(time, 0, *exitCode);
|
||||||
|
|
||||||
// Handle atoi() errors
|
|
||||||
if (exitCode == 0 && (exitCodeStr[0] != '0' || exitCodeStr[1] != '\0'))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Exit code should be in range of 0-125, 126-255 is used
|
|
||||||
// in many shells for their own return codes and code > 255
|
|
||||||
// is not supported in many others
|
|
||||||
if (exitCode < 0 || exitCode > 125)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
sWorld->ShutdownServ(time, 0, exitCode);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
sWorld->ShutdownServ(time, 0, SHUTDOWN_EXIT_CODE);
|
sWorld->ShutdownServ(time, 0, SHUTDOWN_EXIT_CODE);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleServerRestartCommand(ChatHandler* /*handler*/, char const* args)
|
static bool HandleServerRestartCommand(ChatHandler* /*handler*/, int32 time, Optional<int32> exitCode)
|
||||||
{
|
{
|
||||||
if (!*args)
|
if (exitCode && *exitCode >= 0 && *exitCode <= 125)
|
||||||
return false;
|
|
||||||
|
|
||||||
char* timeStr = strtok((char*) args, " ");
|
|
||||||
char* exitCodeStr = strtok(nullptr, "");
|
|
||||||
|
|
||||||
int32 time = atoi(timeStr);
|
|
||||||
|
|
||||||
// Prevent interpret wrong arg value as 0 secs shutdown time
|
|
||||||
if ((time == 0 && (timeStr[0] != '0' || timeStr[1] != '\0')) || time < 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (exitCodeStr)
|
|
||||||
{
|
{
|
||||||
int32 exitCode = atoi(exitCodeStr);
|
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART, *exitCode);
|
||||||
|
|
||||||
// Handle atoi() errors
|
|
||||||
if (exitCode == 0 && (exitCodeStr[0] != '0' || exitCodeStr[1] != '\0'))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Exit code should be in range of 0-125, 126-255 is used
|
|
||||||
// in many shells for their own return codes and code > 255
|
|
||||||
// is not supported in many others
|
|
||||||
if (exitCode < 0 || exitCode > 125)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART, exitCode);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE);
|
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleServerIdleRestartCommand(ChatHandler* /*handler*/, char const* args)
|
static bool HandleServerIdleRestartCommand(ChatHandler* /*handler*/, int32 time, Optional<int32> exitCode)
|
||||||
{
|
{
|
||||||
if (!*args)
|
if (exitCode && *exitCode >= 0 && *exitCode <= 125)
|
||||||
return false;
|
|
||||||
|
|
||||||
char* timeStr = strtok((char*) args, " ");
|
|
||||||
char* exitCodeStr = strtok(nullptr, "");
|
|
||||||
|
|
||||||
int32 time = atoi(timeStr);
|
|
||||||
|
|
||||||
// Prevent interpret wrong arg value as 0 secs shutdown time
|
|
||||||
if ((time == 0 && (timeStr[0] != '0' || timeStr[1] != '\0')) || time < 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (exitCodeStr)
|
|
||||||
{
|
{
|
||||||
int32 exitCode = atoi(exitCodeStr);
|
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, *exitCode);
|
||||||
|
|
||||||
// Handle atoi() errors
|
|
||||||
if (exitCode == 0 && (exitCodeStr[0] != '0' || exitCodeStr[1] != '\0'))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Exit code should be in range of 0-125, 126-255 is used
|
|
||||||
// in many shells for their own return codes and code > 255
|
|
||||||
// is not supported in many others
|
|
||||||
if (exitCode < 0 || exitCode > 125)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
sWorld->ShutdownServ(time, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, exitCode);
|
|
||||||
}
|
}
|
||||||
else
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool HandleServerIdleShutDownCommand(ChatHandler* /*handler*/, char const* args)
|
static bool HandleServerIdleShutDownCommand(ChatHandler* /*handler*/, int32 time, Optional<int32> exitCode)
|
||||||
{
|
{
|
||||||
if (!*args)
|
if (exitCode && *exitCode >= 0 && *exitCode <= 125)
|
||||||
return false;
|
|
||||||
|
|
||||||
char* timeStr = strtok((char*) args, " ");
|
|
||||||
char* exitCodeStr = strtok(nullptr, "");
|
|
||||||
|
|
||||||
int32 time = atoi(timeStr);
|
|
||||||
|
|
||||||
// Prevent interpret wrong arg value as 0 secs shutdown time
|
|
||||||
if ((time == 0 && (timeStr[0] != '0' || timeStr[1] != '\0')) || time < 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (exitCodeStr)
|
|
||||||
{
|
{
|
||||||
int32 exitCode = atoi(exitCodeStr);
|
sWorld->ShutdownServ(time, SHUTDOWN_MASK_IDLE, *exitCode);
|
||||||
|
|
||||||
// Handle atoi() errors
|
|
||||||
if (exitCode == 0 && (exitCodeStr[0] != '0' || exitCodeStr[1] != '\0'))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Exit code should be in range of 0-125, 126-255 is used
|
|
||||||
// in many shells for their own return codes and code > 255
|
|
||||||
// is not supported in many others
|
|
||||||
if (exitCode < 0 || exitCode > 125)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
sWorld->ShutdownServ(time, SHUTDOWN_MASK_IDLE, exitCode);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
sWorld->ShutdownServ(time, SHUTDOWN_MASK_IDLE, SHUTDOWN_EXIT_CODE);
|
sWorld->ShutdownServ(time, SHUTDOWN_MASK_IDLE, SHUTDOWN_EXIT_CODE);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exit the realm
|
// Exit the realm
|
||||||
static bool HandleServerExitCommand(ChatHandler* handler, char const* /*args*/)
|
static bool HandleServerExitCommand(ChatHandler* handler)
|
||||||
{
|
{
|
||||||
handler->SendSysMessage(LANG_COMMAND_EXIT);
|
handler->SendSysMessage(LANG_COMMAND_EXIT);
|
||||||
World::StopNow(SHUTDOWN_EXIT_CODE);
|
World::StopNow(SHUTDOWN_EXIT_CODE);
|
||||||
@@ -422,23 +332,23 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Define the 'Message of the day' for the realm
|
// Define the 'Message of the day' for the realm
|
||||||
static bool HandleServerSetMotdCommand(ChatHandler* handler, char const* args)
|
static bool HandleServerSetMotdCommand(ChatHandler* handler, std::string motd)
|
||||||
{
|
{
|
||||||
Motd::SetMotd(args);
|
Motd::SetMotd(motd);
|
||||||
handler->PSendSysMessage(LANG_MOTD_NEW, args);
|
handler->PSendSysMessage(LANG_MOTD_NEW, motd);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set whether we accept new clients
|
// Set whether we accept new clients
|
||||||
static bool HandleServerSetClosedCommand(ChatHandler* handler, char const* args)
|
static bool HandleServerSetClosedCommand(ChatHandler* handler, Optional<std::string> args)
|
||||||
{
|
{
|
||||||
if (strncmp(args, "on", 3) == 0)
|
if (StringStartsWith("on", *args))
|
||||||
{
|
{
|
||||||
handler->SendSysMessage(LANG_WORLD_CLOSED);
|
handler->SendSysMessage(LANG_WORLD_CLOSED);
|
||||||
sWorld->SetClosed(true);
|
sWorld->SetClosed(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (strncmp(args, "off", 4) == 0)
|
else if (StringStartsWith("off", *args))
|
||||||
{
|
{
|
||||||
handler->SendSysMessage(LANG_WORLD_OPENED);
|
handler->SendSysMessage(LANG_WORLD_OPENED);
|
||||||
sWorld->SetClosed(false);
|
sWorld->SetClosed(false);
|
||||||
@@ -451,33 +361,15 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the level of logging
|
// Set the level of logging
|
||||||
static bool HandleServerSetLogLevelCommand(ChatHandler* /*handler*/, char const* args)
|
static bool HandleServerSetLogLevelCommand(ChatHandler* /*handler*/, bool isLogger, std::string const& name, int32 level)
|
||||||
{
|
{
|
||||||
if (!*args)
|
sLog->SetLogLevel(name, level, isLogger);
|
||||||
return false;
|
|
||||||
|
|
||||||
char* type = strtok((char*)args, " ");
|
|
||||||
char* name = strtok(nullptr, " ");
|
|
||||||
char* level = strtok(nullptr, " ");
|
|
||||||
|
|
||||||
if (!type || !name || !level || *name == '\0' || *level == '\0' || (*type != 'a' && *type != 'l'))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
sLog->SetLogLevel(name, *Acore::StringTo<uint32>(level), *type == 'l');
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set diff time record interval
|
// set diff time record interval
|
||||||
static bool HandleServerSetDiffTimeCommand(ChatHandler* /*handler*/, char const* args)
|
static bool HandleServerSetDiffTimeCommand(ChatHandler* /*handler*/, int32 newTime)
|
||||||
{
|
{
|
||||||
if (!*args)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
char* newTimeStr = strtok((char*)args, " ");
|
|
||||||
if (!newTimeStr)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
int32 newTime = atoi(newTimeStr);
|
|
||||||
if (newTime < 0)
|
if (newTime < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user