TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
server_commandscript Class Reference

Public Member Functions

 server_commandscript ()
 
std::vector< ChatCommandGetCommands () const override
 
- Public Member Functions inherited from ScriptObject
const std::string & GetName () const
 

Static Public Member Functions

static bool HandleServerCorpsesCommand (ChatHandler *, char const *)
 
static bool HandleServerInfoCommand (ChatHandler *handler, char const *)
 
static bool HandleServerMotdCommand (ChatHandler *handler, char const *)
 
static bool HandleServerPLimitCommand (ChatHandler *handler, char const *args)
 
static bool HandleServerShutDownCancelCommand (ChatHandler *, char const *)
 
static bool HandleServerShutDownCommand (ChatHandler *, char const *args)
 
static bool HandleServerRestartCommand (ChatHandler *, char const *args)
 
static bool HandleServerIdleRestartCommand (ChatHandler *, char const *args)
 
static bool HandleServerIdleShutDownCommand (ChatHandler *, char const *args)
 
static bool HandleServerExitCommand (ChatHandler *handler, char const *)
 
static bool HandleServerSetMotdCommand (ChatHandler *handler, char const *args)
 
static bool HandleServerSetClosedCommand (ChatHandler *handler, char const *args)
 
static bool HandleServerSetLogLevelCommand (ChatHandler *, char const *args)
 
static bool HandleServerSetDiffTimeCommand (ChatHandler *, char const *args)
 

Static Private Member Functions

static bool ParseExitCode (char const *exitCodeStr, int32 &exitCode)
 
static bool ShutdownServer (char const *args, uint32 shutdownMask, int32 defaultExitCode)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name)
 
virtual ~ScriptObject ()
 

Constructor & Destructor Documentation

server_commandscript::server_commandscript ( )
inline
36 : CommandScript("server_commandscript") { }
CommandScript(const char *name)
Definition: ScriptMgr.cpp:1616

Member Function Documentation

std::vector<ChatCommand> server_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

39  {
40  static std::vector<ChatCommand> serverIdleRestartCommandTable =
41  {
44  };
45 
46  static std::vector<ChatCommand> serverIdleShutdownCommandTable =
47  {
50  };
51 
52  static std::vector<ChatCommand> serverRestartCommandTable =
53  {
56  };
57 
58  static std::vector<ChatCommand> serverShutdownCommandTable =
59  {
62  };
63 
64  static std::vector<ChatCommand> serverSetCommandTable =
65  {
70  };
71 
72  static std::vector<ChatCommand> serverCommandTable =
73  {
76  { "idlerestart", rbac::RBAC_PERM_COMMAND_SERVER_IDLERESTART, true, NULL, "", serverIdleRestartCommandTable },
77  { "idleshutdown", rbac::RBAC_PERM_COMMAND_SERVER_IDLESHUTDOWN, true, NULL, "", serverIdleShutdownCommandTable },
81  { "restart", rbac::RBAC_PERM_COMMAND_SERVER_RESTART, true, NULL, "", serverRestartCommandTable },
82  { "shutdown", rbac::RBAC_PERM_COMMAND_SERVER_SHUTDOWN, true, NULL, "", serverShutdownCommandTable },
83  { "set", rbac::RBAC_PERM_COMMAND_SERVER_SET, true, NULL, "", serverSetCommandTable },
84  };
85 
86  static std::vector<ChatCommand> commandTable =
87  {
88  { "server", rbac::RBAC_PERM_COMMAND_SERVER, true, NULL, "", serverCommandTable },
89  };
90  return commandTable;
91  }
static bool HandleServerIdleShutDownCommand(ChatHandler *, char const *args)
Definition: cs_server.cpp:213
arena_t NULL
Definition: jemalloc_internal.h:624
static bool HandleServerShutDownCommand(ChatHandler *, char const *args)
Definition: cs_server.cpp:198
static bool HandleServerRestartCommand(ChatHandler *, char const *args)
Definition: cs_server.cpp:203
static bool HandleServerSetMotdCommand(ChatHandler *handler, char const *args)
Definition: cs_server.cpp:227
static bool HandleServerSetDiffTimeCommand(ChatHandler *, char const *args)
Definition: cs_server.cpp:273
static bool HandleServerExitCommand(ChatHandler *handler, char const *)
Definition: cs_server.cpp:219
Definition: RBAC.h:625
static bool HandleServerSetClosedCommand(ChatHandler *handler, char const *args)
Definition: cs_server.cpp:235
static bool HandleServerCorpsesCommand(ChatHandler *, char const *)
Definition: cs_server.cpp:94
static bool HandleServerInfoCommand(ChatHandler *handler, char const *)
Definition: cs_server.cpp:100
static bool HandleServerMotdCommand(ChatHandler *handler, char const *)
Definition: cs_server.cpp:123
static bool HandleServerSetLogLevelCommand(ChatHandler *, char const *args)
Definition: cs_server.cpp:256
static bool HandleServerIdleRestartCommand(ChatHandler *, char const *args)
Definition: cs_server.cpp:208
static bool HandleServerPLimitCommand(ChatHandler *handler, char const *args)
Definition: cs_server.cpp:132
static bool HandleServerShutDownCancelCommand(ChatHandler *, char const *)
Definition: cs_server.cpp:191

+ Here is the call graph for this function:

static bool server_commandscript::HandleServerCorpsesCommand ( ChatHandler ,
char const  
)
inlinestatic
95  {
96  sWorld->RemoveOldCorpses();
97  return true;
98  }
#define sWorld
Definition: World.h:887

+ Here is the caller graph for this function:

static bool server_commandscript::HandleServerExitCommand ( ChatHandler handler,
char const  
)
inlinestatic
220  {
223  return true;
224  }
Definition: World.h:73
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: Language.h:869
static void StopNow(uint8 exitcode)
Definition: World.h:662

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool server_commandscript::HandleServerIdleRestartCommand ( ChatHandler ,
char const args 
)
inlinestatic
209  {
211  }
Definition: World.h:67
Definition: World.h:75
static bool ShutdownServer(char const *args, uint32 shutdownMask, int32 defaultExitCode)
Definition: cs_server.cpp:310
Definition: World.h:68

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool server_commandscript::HandleServerIdleShutDownCommand ( ChatHandler ,
char const args 
)
inlinestatic
214  {
216  }
Definition: World.h:73
static bool ShutdownServer(char const *args, uint32 shutdownMask, int32 defaultExitCode)
Definition: cs_server.cpp:310
Definition: World.h:68

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool server_commandscript::HandleServerInfoCommand ( ChatHandler handler,
char const  
)
inlinestatic
101  {
102  uint32 playersNum = sWorld->GetPlayerCount();
103  uint32 maxPlayersNum = sWorld->GetMaxPlayerCount();
104  uint32 activeClientsNum = sWorld->GetActiveSessionCount();
105  uint32 queuedClientsNum = sWorld->GetQueuedSessionCount();
106  uint32 maxActiveClientsNum = sWorld->GetMaxActiveSessionCount();
107  uint32 maxQueuedClientsNum = sWorld->GetMaxQueuedSessionCount();
108  std::string uptime = secsToTimeString(sWorld->GetUptime());
109  uint32 updateTime = sWorld->GetUpdateTime();
110 
112  handler->PSendSysMessage(LANG_CONNECTED_PLAYERS, playersNum, maxPlayersNum);
113  handler->PSendSysMessage(LANG_CONNECTED_USERS, activeClientsNum, maxActiveClientsNum, queuedClientsNum, maxQueuedClientsNum);
114  handler->PSendSysMessage(LANG_UPTIME, uptime.c_str());
115  handler->PSendSysMessage(LANG_UPDATE_DIFF, updateTime);
116  // Can't use sWorld->ShutdownMsg here in case of console command
117  if (sWorld->IsShuttingDown())
118  handler->PSendSysMessage(LANG_SHUTDOWN_TIMELEFT, secsToTimeString(sWorld->GetShutDownTimeLeft()).c_str());
119 
120  return true;
121  }
Definition: Language.h:45
Definition: Language.h:52
std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
Definition: Util.cpp:109
Definition: Language.h:93
TC_COMMON_API char const * GetFullVersion()
Definition: GitRevision.cpp:51
#define sWorld
Definition: World.h:887
Definition: Language.h:53
uint32_t uint32
Definition: Define.h:150
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: Language.h:46
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool server_commandscript::HandleServerMotdCommand ( ChatHandler handler,
char const  
)
inlinestatic
124  {
125  std::string motd;
126  for (std::string const& line : sWorld->GetMotd())
127  motd += line;
128  handler->PSendSysMessage(LANG_MOTD_CURRENT, motd.c_str());
129  return true;
130  }
#define sWorld
Definition: World.h:887
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
Definition: Language.h:89

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool server_commandscript::HandleServerPLimitCommand ( ChatHandler handler,
char const args 
)
inlinestatic
133  {
134  if (*args)
135  {
136  char* paramStr = strtok((char*)args, " ");
137  if (!paramStr)
138  return false;
139 
140  int32 limit = strlen(paramStr);
141 
142  if (strncmp(paramStr, "player", limit) == 0)
143  sWorld->SetPlayerSecurityLimit(SEC_PLAYER);
144  else if (strncmp(paramStr, "moderator", limit) == 0)
145  sWorld->SetPlayerSecurityLimit(SEC_MODERATOR);
146  else if (strncmp(paramStr, "gamemaster", limit) == 0)
147  sWorld->SetPlayerSecurityLimit(SEC_GAMEMASTER);
148  else if (strncmp(paramStr, "administrator", limit) == 0)
149  sWorld->SetPlayerSecurityLimit(SEC_ADMINISTRATOR);
150  else if (strncmp(paramStr, "reset", limit) == 0)
151  {
152  sWorld->SetPlayerAmountLimit(sConfigMgr->GetIntDefault("PlayerLimit", 100));
153  sWorld->LoadDBAllowedSecurityLevel();
154  }
155  else
156  {
157  int32 value = atoi(paramStr);
158  if (value < 0)
159  sWorld->SetPlayerSecurityLimit(AccountTypes(-value));
160  else
161  sWorld->SetPlayerAmountLimit(uint32(value));
162  }
163  }
164 
165  uint32 playerAmountLimit = sWorld->GetPlayerAmountLimit();
166  AccountTypes allowedAccountType = sWorld->GetPlayerSecurityLimit();
167  char const* secName = "";
168  switch (allowedAccountType)
169  {
170  case SEC_PLAYER:
171  secName = "Player";
172  break;
173  case SEC_MODERATOR:
174  secName = "Moderator";
175  break;
176  case SEC_GAMEMASTER:
177  secName = "Gamemaster";
178  break;
179  case SEC_ADMINISTRATOR:
180  secName = "Administrator";
181  break;
182  default:
183  secName = "<unknown>";
184  break;
185  }
186  handler->PSendSysMessage("Player limits: amount %u, min. security level %s.", playerAmountLimit, secName);
187 
188  return true;
189  }
Definition: Common.h:111
#define sConfigMgr
Definition: Config.h:61
Definition: Common.h:108
#define sWorld
Definition: World.h:887
Definition: Common.h:110
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
AccountTypes
Definition: Common.h:106
Definition: Common.h:109
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72
const FieldDescriptor value
Definition: descriptor.h:1522
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool server_commandscript::HandleServerRestartCommand ( ChatHandler ,
char const args 
)
inlinestatic
204  {
206  }
Definition: World.h:67
Definition: World.h:75
static bool ShutdownServer(char const *args, uint32 shutdownMask, int32 defaultExitCode)
Definition: cs_server.cpp:310

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool server_commandscript::HandleServerSetClosedCommand ( ChatHandler handler,
char const args 
)
inlinestatic
236  {
237  if (strncmp(args, "on", 3) == 0)
238  {
240  sWorld->SetClosed(true);
241  return true;
242  }
243  else if (strncmp(args, "off", 4) == 0)
244  {
246  sWorld->SetClosed(false);
247  return true;
248  }
249 
250  handler->SendSysMessage(LANG_USE_BOL);
251  handler->SetSentErrorMessage(true);
252  return false;
253  }
void SetSentErrorMessage(bool val)
Definition: Chat.h:138
#define sWorld
Definition: World.h:887
Definition: Language.h:290
Definition: Language.h:1154
virtual void SendSysMessage(char const *str, bool escapeCharacters=false)
Definition: Chat.cpp:152
Definition: Language.h:1153

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool server_commandscript::HandleServerSetDiffTimeCommand ( ChatHandler ,
char const args 
)
inlinestatic
274  {
275  if (!*args)
276  return false;
277 
278  char* newTimeStr = strtok((char*)args, " ");
279  if (!newTimeStr)
280  return false;
281 
282  int32 newTime = atoi(newTimeStr);
283  if (newTime < 0)
284  return false;
285 
286  sWorld->SetRecordDiffInterval(newTime);
287  printf("Record diff every %i ms\n", newTime);
288 
289  return true;
290  }
#define sWorld
Definition: World.h:887
int32_t int32
Definition: Define.h:146
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool server_commandscript::HandleServerSetLogLevelCommand ( ChatHandler ,
char const args 
)
inlinestatic
257  {
258  if (!*args)
259  return false;
260 
261  char* type = strtok((char*)args, " ");
262  char* name = strtok(NULL, " ");
263  char* level = strtok(NULL, " ");
264 
265  if (!type || !name || !level || *name == '\0' || *level == '\0' || (*type != 'a' && *type != 'l'))
266  return false;
267 
268  sLog->SetLogLevel(name, level, *type == 'l');
269  return true;
270  }
arena_t NULL
Definition: jemalloc_internal.h:624
#define sLog
Definition: Log.h:154

+ Here is the caller graph for this function:

static bool server_commandscript::HandleServerSetMotdCommand ( ChatHandler handler,
char const args 
)
inlinestatic
228  {
229  sWorld->SetMotd(args);
230  handler->PSendSysMessage(LANG_MOTD_NEW, args);
231  return true;
232  }
#define sWorld
Definition: World.h:887
Definition: Language.h:904
void PSendSysMessage(const char *fmt, Args &&...args)
Definition: Chat.h:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool server_commandscript::HandleServerShutDownCancelCommand ( ChatHandler ,
char const  
)
inlinestatic
192  {
193  sWorld->ShutdownCancel();
194 
195  return true;
196  }
#define sWorld
Definition: World.h:887

+ Here is the caller graph for this function:

static bool server_commandscript::HandleServerShutDownCommand ( ChatHandler ,
char const args 
)
inlinestatic
199  {
200  return ShutdownServer(args, 0, SHUTDOWN_EXIT_CODE);
201  }
Definition: World.h:73
static bool ShutdownServer(char const *args, uint32 shutdownMask, int32 defaultExitCode)
Definition: cs_server.cpp:310

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static bool server_commandscript::ParseExitCode ( char const exitCodeStr,
int32 exitCode 
)
inlinestaticprivate
294  {
295  exitCode = atoi(exitCodeStr);
296 
297  // Handle atoi() errors
298  if (exitCode == 0 && (exitCodeStr[0] != '0' || exitCodeStr[1] != '\0'))
299  return false;
300 
301  // Exit code should be in range of 0-125, 126-255 is used
302  // in many shells for their own return codes and code > 255
303  // is not supported in many others
304  if (exitCode < 0 || exitCode > 125)
305  return false;
306 
307  return true;
308  }

+ Here is the caller graph for this function:

static bool server_commandscript::ShutdownServer ( char const args,
uint32  shutdownMask,
int32  defaultExitCode 
)
inlinestaticprivate
311  {
312  if (!*args)
313  return false;
314 
315  if (strlen(args) > 255)
316  return false;
317 
318  // #delay [#exit_code] [reason]
319  char* delayStr = strtok((char*)args, " ");
320  if (!delayStr || !isNumeric(delayStr))
321  return false;
322 
323  char* exitCodeStr = nullptr;
324 
325  char reason[256] = { 0 };
326 
327  while (char* nextToken = strtok(nullptr, " "))
328  {
329  if (isNumeric(nextToken))
330  exitCodeStr = nextToken;
331  else
332  {
333  strcat(reason, nextToken);
334  if (char* remainingTokens = strtok(nullptr, "\0"))
335  {
336  strcat(reason, " ");
337  strcat(reason, remainingTokens);
338  }
339  break;
340  }
341  }
342 
343  int32 delay = atoi(delayStr);
344 
345  // Prevent interpret wrong arg value as 0 secs shutdown time
346  if ((delay == 0 && (delayStr[0] != '0' || delayStr[1] != '\0')) || delay < 0)
347  return false;
348 
349  int32 exitCode = defaultExitCode;
350  if (exitCodeStr)
351  if (!ParseExitCode(exitCodeStr, exitCode))
352  return false;
353 
354  sWorld->ShutdownServ(delay, shutdownMask, static_cast<uint8>(exitCode), std::string(reason));
355 
356  return true;
357  }
#define sWorld
Definition: World.h:887
static bool ParseExitCode(char const *exitCodeStr, int32 &exitCode)
Definition: cs_server.cpp:293
int32_t int32
Definition: Define.h:146
bool isNumeric(wchar_t wchar)
Definition: Util.h:194

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


The documentation for this class was generated from the following file: