Scripts/Commands: Small QoL adjustments
- .debug hostil now shows spawn ID (DBGUID) in addition to current GUID (so you can .go creature to it)
- .npc temp now takes an additional argument before the creature entry that determines whether the spawned creature instantly despawns upon death. Default is instant despawn (current behavior).
- Add .npc evade command.
- Add .pet level command.
- .server shutdown and .server restart now fail with an error message if time is below a config var (GM.ForceShutdownThreshold, default 30s) as long as another player is connected.
- New commands .server shutdown force and .server restart force bypass this limitation.
(cherry picked from commit 0e1eb460d687e545f95caf0f38a16c3feb7132a3)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -196,19 +198,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)
|
||||
@@ -216,6 +233,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*/)
|
||||
{
|
||||
@@ -260,8 +282,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;
|
||||
@@ -362,6 +384,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