Scripts/Commands: Small QoL adjustments
This commit is contained in:
1 parent
3ba6ba19a4
commit
e4eb3c841c
12 files changed
+912
-65
No files matched your search
@@ -53,12 +53,14 @@ public:
|
||||
static std::vector<ChatCommand> serverRestartCommandTable =
|
||||
{
|
||||
{ "cancel", rbac::RBAC_PERM_COMMAND_SERVER_RESTART_CANCEL, true, &HandleServerShutDownCancelCommand, "" },
|
||||
{ "force", rbac::RBAC_PERM_COMMAND_SERVER_RESTART_FORCE, true, &HandleServerForceRestartCommand, "" },
|
||||
{ "" , rbac::RBAC_PERM_COMMAND_SERVER_RESTART, true, &HandleServerRestartCommand, "" },
|
||||
};
|
||||
|
||||
static std::vector<ChatCommand> serverShutdownCommandTable =
|
||||
{
|
||||
{ "cancel", rbac::RBAC_PERM_COMMAND_SERVER_SHUTDOWN_CANCEL, true, &HandleServerShutDownCancelCommand, "" },
|
||||
{ "force", rbac::RBAC_PERM_COMMAND_SERVER_SHUTDOWN_FORCE, true, &HandleServerForceShutDownCommand, "" },
|
||||
{ "" , rbac::RBAC_PERM_COMMAND_SERVER_SHUTDOWN, true, &HandleServerShutDownCommand, "" },
|
||||
};
|
||||
|
||||
@@ -74,19 +76,19 @@ public:
|
||||
{
|
||||
{ "corpses", rbac::RBAC_PERM_COMMAND_SERVER_CORPSES, true, &HandleServerCorpsesCommand, "" },
|
||||
{ "exit", rbac::RBAC_PERM_COMMAND_SERVER_EXIT, true, &HandleServerExitCommand, "" },
|
||||
{ "idlerestart", rbac::RBAC_PERM_COMMAND_SERVER_IDLERESTART, true, NULL, "", serverIdleRestartCommandTable },
|
||||
{ "idleshutdown", rbac::RBAC_PERM_COMMAND_SERVER_IDLESHUTDOWN, true, NULL, "", serverIdleShutdownCommandTable },
|
||||
{ "idlerestart", rbac::RBAC_PERM_COMMAND_SERVER_IDLERESTART, true, nullptr, "", serverIdleRestartCommandTable },
|
||||
{ "idleshutdown", rbac::RBAC_PERM_COMMAND_SERVER_IDLESHUTDOWN, true, nullptr, "", serverIdleShutdownCommandTable },
|
||||
{ "info", rbac::RBAC_PERM_COMMAND_SERVER_INFO, true, &HandleServerInfoCommand, "" },
|
||||
{ "motd", rbac::RBAC_PERM_COMMAND_SERVER_MOTD, true, &HandleServerMotdCommand, "" },
|
||||
{ "plimit", rbac::RBAC_PERM_COMMAND_SERVER_PLIMIT, true, &HandleServerPLimitCommand, "" },
|
||||
{ "restart", rbac::RBAC_PERM_COMMAND_SERVER_RESTART, true, NULL, "", serverRestartCommandTable },
|
||||
{ "shutdown", rbac::RBAC_PERM_COMMAND_SERVER_SHUTDOWN, true, NULL, "", serverShutdownCommandTable },
|
||||
{ "set", rbac::RBAC_PERM_COMMAND_SERVER_SET, true, NULL, "", serverSetCommandTable },
|
||||
{ "restart", rbac::RBAC_PERM_COMMAND_SERVER_RESTART, true, nullptr, "", serverRestartCommandTable },
|
||||
{ "shutdown", rbac::RBAC_PERM_COMMAND_SERVER_SHUTDOWN, true, nullptr, "", serverShutdownCommandTable },
|
||||
{ "set", rbac::RBAC_PERM_COMMAND_SERVER_SET, true, nullptr, "", serverSetCommandTable },
|
||||
};
|
||||
|
||||
static std::vector<ChatCommand> commandTable =
|
||||
{
|
||||
{ "server", rbac::RBAC_PERM_COMMAND_SERVER, true, NULL, "", serverCommandTable },
|
||||
{ "server", rbac::RBAC_PERM_COMMAND_SERVER, true, nullptr, "", serverCommandTable },
|
||||
};
|
||||
return commandTable;
|
||||
}
|
||||
@@ -193,19 +195,34 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool HandleServerShutDownCommand(ChatHandler* /*handler*/, char const* args)
|
||||
static inline bool IsOnlyUser(WorldSession* mySession)
|
||||
{
|
||||
return ShutdownServer(args, 0, SHUTDOWN_EXIT_CODE);
|
||||
// check if there is any session connected from a different address
|
||||
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())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
static bool HandleServerShutDownCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
return ShutdownServer(args, IsOnlyUser(handler->GetSession()) ? SHUTDOWN_MASK_FORCE : 0, SHUTDOWN_EXIT_CODE);
|
||||
}
|
||||
|
||||
static bool HandleServerRestartCommand(ChatHandler* /*handler*/, char const* args)
|
||||
static bool HandleServerRestartCommand(ChatHandler* handler, char const* args)
|
||||
{
|
||||
return ShutdownServer(args, 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 HandleServerIdleRestartCommand(ChatHandler* /*handler*/, char const* args)
|
||||
static bool HandleServerForceShutDownCommand(ChatHandler* /*handler*/, char const* args)
|
||||
{
|
||||
return ShutdownServer(args, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, RESTART_EXIT_CODE);
|
||||
return ShutdownServer(args, SHUTDOWN_MASK_FORCE, SHUTDOWN_EXIT_CODE);
|
||||
}
|
||||
|
||||
static bool HandleServerForceRestartCommand(ChatHandler* /*handler*/, char const* args)
|
||||
{
|
||||
return ShutdownServer(args, SHUTDOWN_MASK_FORCE | SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE);
|
||||
}
|
||||
|
||||
static bool HandleServerIdleShutDownCommand(ChatHandler* /*handler*/, char const* args)
|
||||
@@ -213,6 +230,11 @@ public:
|
||||
return ShutdownServer(args, SHUTDOWN_MASK_IDLE, SHUTDOWN_EXIT_CODE);
|
||||
}
|
||||
|
||||
static bool HandleServerIdleRestartCommand(ChatHandler* /*handler*/, char const* args)
|
||||
{
|
||||
return ShutdownServer(args, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, RESTART_EXIT_CODE);
|
||||
}
|
||||
|
||||
// Exit the realm
|
||||
static bool HandleServerExitCommand(ChatHandler* handler, char const* /*args*/)
|
||||
{
|
||||
@@ -257,8 +279,8 @@ public:
|
||||
return false;
|
||||
|
||||
char* type = strtok((char*)args, " ");
|
||||
char* name = strtok(NULL, " ");
|
||||
char* level = strtok(NULL, " ");
|
||||
char* name = strtok(nullptr, " ");
|
||||
char* level = strtok(nullptr, " ");
|
||||
|
||||
if (!type || !name || !level || *name == '\0' || *level == '\0' || (*type != 'a' && *type != 'l'))
|
||||
return false;
|
||||
@@ -359,6 +381,9 @@ private:
|
||||
if (!ParseExitCode(exitCodeStr, exitCode))
|
||||
return false;
|
||||
|
||||
if (delay < (int32)sWorld->getIntConfig(CONFIG_FORCE_SHUTDOWN_THRESHOLD) && !(shutdownMask & SHUTDOWN_MASK_FORCE))
|
||||
return false;
|
||||
|
||||
sWorld->ShutdownServ(delay, shutdownMask, static_cast<uint8>(exitCode), std::string(reason));
|
||||
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user