AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
server_commandscript Class Reference
Inheritance diagram for server_commandscript:
CommandScript ScriptObject

Public Member Functions

 server_commandscript ()
 
ChatCommandTable GetCommands () const override
 
virtual std::vector< Acore::ChatCommands::ChatCommandBuilderGetCommands () const =0
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
const std::string & GetName () const
 
uint16 GetTotalAvailableHooks ()
 

Static Public Member Functions

static bool HandleServerCorpsesCommand (ChatHandler *)
 
static bool HandleServerDebugCommand (ChatHandler *handler)
 
static bool HandleServerInfoCommand (ChatHandler *handler)
 
static bool HandleServerMotdCommand (ChatHandler *handler)
 
static bool HandleServerShutDownCancelCommand (ChatHandler *)
 
static bool HandleServerShutDownCommand (ChatHandler *handler, std::string time, Optional< int32 > exitCode, Tail reason)
 
static bool HandleServerRestartCommand (ChatHandler *handler, std::string time, Optional< int32 > exitCode, Tail reason)
 
static bool HandleServerIdleRestartCommand (ChatHandler *handler, std::string time, Optional< int32 > exitCode, Tail reason)
 
static bool HandleServerIdleShutDownCommand (ChatHandler *handler, std::string time, Optional< int32 > exitCode, Tail reason)
 
static bool HandleServerExitCommand (ChatHandler *handler)
 
static bool HandleServerSetMotdCommand (ChatHandler *handler, Optional< int32 > realmId, Optional< std::string > locale, Tail motd)
 
static bool HandleServerSetClosedCommand (ChatHandler *handler, Optional< std::string > args)
 
static bool HandleServerSetLogLevelCommand (ChatHandler *, bool isLogger, std::string const &name, int32 level)
 

Additional Inherited Members

- Protected Member Functions inherited from CommandScript
 CommandScript (const char *name)
 
- Protected Member Functions inherited from ScriptObject
 ScriptObject (const char *name, uint16 totalAvailableHooks=0)
 
virtual ~ScriptObject ()=default
 

Detailed Description

Constructor & Destructor Documentation

◆ server_commandscript()

server_commandscript::server_commandscript ( )
inline
50: CommandScript("server_commandscript") { }
Definition: CommandScript.h:25

Member Function Documentation

◆ GetCommands()

ChatCommandTable server_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

53 {
54 static ChatCommandTable serverIdleRestartCommandTable =
55 {
56 { "cancel", HandleServerShutDownCancelCommand, SEC_ADMINISTRATOR, Console::Yes },
57 { "", HandleServerIdleRestartCommand, SEC_CONSOLE, Console::Yes }
58 };
59
60 static ChatCommandTable serverIdleShutdownCommandTable =
61 {
62 { "cancel", HandleServerShutDownCancelCommand, SEC_ADMINISTRATOR, Console::Yes },
63 { "", HandleServerIdleShutDownCommand, SEC_CONSOLE, Console::Yes }
64 };
65
66 static ChatCommandTable serverRestartCommandTable =
67 {
68 { "cancel", HandleServerShutDownCancelCommand, SEC_ADMINISTRATOR, Console::Yes },
70 };
71
72 static ChatCommandTable serverShutdownCommandTable =
73 {
74 { "cancel", HandleServerShutDownCancelCommand, SEC_ADMINISTRATOR, Console::Yes },
76 };
77
78 static ChatCommandTable serverSetCommandTable =
79 {
80 { "loglevel", HandleServerSetLogLevelCommand, SEC_CONSOLE, Console::Yes },
81 { "motd", HandleServerSetMotdCommand, SEC_ADMINISTRATOR, Console::Yes },
82 { "closed", HandleServerSetClosedCommand, SEC_CONSOLE, Console::Yes },
83 };
84
85 static ChatCommandTable serverCommandTable =
86 {
87 { "corpses", HandleServerCorpsesCommand, SEC_GAMEMASTER, Console::Yes },
88 { "debug", HandleServerDebugCommand, SEC_ADMINISTRATOR, Console::Yes },
89 { "exit", HandleServerExitCommand, SEC_CONSOLE, Console::Yes },
90 { "idlerestart", serverIdleRestartCommandTable },
91 { "idleshutdown", serverIdleShutdownCommandTable },
92 { "info", HandleServerInfoCommand, SEC_PLAYER, Console::Yes },
93 { "motd", HandleServerMotdCommand, SEC_PLAYER, Console::Yes },
94 { "restart", serverRestartCommandTable },
95 { "shutdown", serverShutdownCommandTable },
96 { "set", serverSetCommandTable }
97 };
98
99 static ChatCommandTable commandTable =
100 {
101 { "server", serverCommandTable }
102 };
103
104 return commandTable;
105 }
@ SEC_PLAYER
Definition: Common.h:57
@ SEC_ADMINISTRATOR
Definition: Common.h:60
@ SEC_GAMEMASTER
Definition: Common.h:59
@ SEC_CONSOLE
Definition: Common.h:61
std::vector< ChatCommandBuilder > ChatCommandTable
Definition: ChatCommand.h:46
static bool HandleServerCorpsesCommand(ChatHandler *)
Definition: cs_server.cpp:108
static bool HandleServerSetLogLevelCommand(ChatHandler *, bool isLogger, std::string const &name, int32 level)
Definition: cs_server.cpp:630
static bool HandleServerSetClosedCommand(ChatHandler *handler, Optional< std::string > args)
Definition: cs_server.cpp:610
static bool HandleServerRestartCommand(ChatHandler *handler, std::string time, Optional< int32 > exitCode, Tail reason)
Definition: cs_server.cpp:360
static bool HandleServerShutDownCommand(ChatHandler *handler, std::string time, Optional< int32 > exitCode, Tail reason)
Definition: cs_server.cpp:307
static bool HandleServerInfoCommand(ChatHandler *handler)
Definition: cs_server.cpp:259
static bool HandleServerMotdCommand(ChatHandler *handler)
Definition: cs_server.cpp:290
static bool HandleServerIdleShutDownCommand(ChatHandler *handler, std::string time, Optional< int32 > exitCode, Tail reason)
Definition: cs_server.cpp:466
static bool HandleServerExitCommand(ChatHandler *handler)
Definition: cs_server.cpp:520
static bool HandleServerDebugCommand(ChatHandler *handler)
Definition: cs_server.cpp:114
static bool HandleServerIdleRestartCommand(ChatHandler *handler, std::string time, Optional< int32 > exitCode, Tail reason)
Definition: cs_server.cpp:413
static bool HandleServerShutDownCancelCommand(ChatHandler *)
Definition: cs_server.cpp:300
static bool HandleServerSetMotdCommand(ChatHandler *handler, Optional< int32 > realmId, Optional< std::string > locale, Tail motd)
Definition: cs_server.cpp:528

References HandleServerCorpsesCommand(), HandleServerDebugCommand(), HandleServerExitCommand(), HandleServerIdleRestartCommand(), HandleServerIdleShutDownCommand(), HandleServerInfoCommand(), HandleServerMotdCommand(), HandleServerRestartCommand(), HandleServerSetClosedCommand(), HandleServerSetLogLevelCommand(), HandleServerSetMotdCommand(), HandleServerShutDownCancelCommand(), HandleServerShutDownCommand(), SEC_ADMINISTRATOR, SEC_CONSOLE, SEC_GAMEMASTER, and SEC_PLAYER.

◆ HandleServerCorpsesCommand()

static bool server_commandscript::HandleServerCorpsesCommand ( ChatHandler )
inlinestatic
109 {
110 sWorld->RemoveOldCorpses();
111 return true;
112 }
#define sWorld
Definition: World.h:443

References sWorld.

Referenced by GetCommands().

◆ HandleServerDebugCommand()

static bool server_commandscript::HandleServerDebugCommand ( ChatHandler handler)
inlinestatic
115 {
116 uint16 worldPort = uint16(sWorld->getIntConfig(CONFIG_PORT_WORLD));
117 std::string dbPortOutput;
118
119 {
120 uint16 dbPort = 0;
121 if (QueryResult res = LoginDatabase.Query("SELECT port FROM realmlist WHERE id = {}", realm.Id.Realm))
122 dbPort = (*res)[0].Get<uint16>();
123
124 if (dbPort)
125 dbPortOutput = Acore::StringFormat("Realmlist (Realm Id: {}) configured in port {}", realm.Id.Realm, dbPort);
126 else
127 dbPortOutput = Acore::StringFormat("Realm Id: {} not found in `realmlist` table. Please check your setup", realm.Id.Realm);
128 }
129
131
132 handler->PSendSysMessage("Using SSL version: {} (library: {})", OPENSSL_VERSION_TEXT, OpenSSL_version(OPENSSL_VERSION));
133 handler->PSendSysMessage("Using Boost version: {}.{}.{}", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100);
134 handler->PSendSysMessage("Using CMake version: {}", GitRevision::GetCMakeVersion());
135
136 handler->PSendSysMessage("Using MySQL version: {}", MySQL::GetLibraryVersion());
137 handler->PSendSysMessage("Found MySQL Executable: {}", GitRevision::GetMySQLExecutable());
138
139 handler->PSendSysMessage("Compiled on: {}", GitRevision::GetHostOSVersion());
140
141 handler->PSendSysMessage("Worldserver listening connections on port {}", worldPort);
142 handler->PSendSysMessage("{}", dbPortOutput);
143
144 bool vmapIndoorCheck = sWorld->getBoolConfig(CONFIG_VMAP_INDOOR_CHECK);
147
148 bool mmapEnabled = sWorld->getBoolConfig(CONFIG_ENABLE_MMAPS);
149
150 std::string dataDir = sWorld->GetDataPath();
151 std::vector<std::string> subDirs;
152 subDirs.emplace_back("maps");
153 if (vmapIndoorCheck || vmapLOSCheck || vmapHeightCheck)
154 {
155 handler->PSendSysMessage("VMAPs status: Enabled. LineOfSight: {}, getHeight: {}, indoorCheck: {}", vmapLOSCheck, vmapHeightCheck, vmapIndoorCheck);
156 subDirs.emplace_back("vmaps");
157 }
158 else
159 handler->SendSysMessage("VMAPs status: Disabled");
160
161 if (mmapEnabled)
162 {
163 handler->SendSysMessage("MMAPs status: Enabled");
164 subDirs.emplace_back("mmaps");
165 }
166 else
167 handler->SendSysMessage("MMAPs status: Disabled");
168
169 for (std::string const& subDir : subDirs)
170 {
171 std::filesystem::path mapPath(dataDir);
172 mapPath /= subDir;
173
174 if (!std::filesystem::exists(mapPath))
175 {
176 handler->PSendSysMessage("{} directory doesn't exist!. Using path: {}", subDir, mapPath.generic_string());
177 continue;
178 }
179
180 auto end = std::filesystem::directory_iterator();
181 std::size_t folderSize = std::accumulate(std::filesystem::directory_iterator(mapPath), end, std::size_t(0), [](std::size_t val, std::filesystem::path const& mapFile)
182 {
183 if (std::filesystem::is_regular_file(mapFile))
184 val += std::filesystem::file_size(mapFile);
185 return val;
186 });
187
188 handler->PSendSysMessage("{} directory located in {}. Total size: {} bytes", subDir, mapPath.generic_string(), folderSize);
189 }
190
191 LocaleConstant defaultLocale = sWorld->GetDefaultDbcLocale();
192 uint32 availableLocalesMask = (1 << defaultLocale);
193
194 for (uint8 i = 0; i < TOTAL_LOCALES; ++i)
195 {
196 LocaleConstant locale = static_cast<LocaleConstant>(i);
197 if (locale == defaultLocale)
198 continue;
199
200 if (sWorld->GetAvailableDbcLocale(locale) != defaultLocale)
201 availableLocalesMask |= (1 << locale);
202 }
203
204 std::string availableLocales;
205 for (uint8 i = 0; i < TOTAL_LOCALES; ++i)
206 {
207 if (!(availableLocalesMask & (1 << i)))
208 continue;
209
210 availableLocales += localeNames[i];
211 if (i != TOTAL_LOCALES - 1)
212 availableLocales += " ";
213 }
214
215 handler->PSendSysMessage("Default DBC locale: {}.\nAll available DBC locales: {}", localeNames[defaultLocale], availableLocales);
216
217 handler->PSendSysMessage("Using World DB: {}", sWorld->GetDBVersion());
218
219 std::string lldb = "No updates found!";
220 if (QueryResult resL = LoginDatabase.Query("SELECT name FROM updates ORDER BY name DESC LIMIT 1"))
221 {
222 Field* fields = resL->Fetch();
223 lldb = fields[0].Get<std::string>();
224 }
225 std::string lcdb = "No updates found!";
226 if (QueryResult resC = CharacterDatabase.Query("SELECT name FROM updates ORDER BY name DESC LIMIT 1"))
227 {
228 Field* fields = resC->Fetch();
229 lcdb = fields[0].Get<std::string>();
230 }
231 std::string lwdb = "No updates found!";
232 if (QueryResult resW = WorldDatabase.Query("SELECT name FROM updates ORDER BY name DESC LIMIT 1"))
233 {
234 Field* fields = resW->Fetch();
235 lwdb = fields[0].Get<std::string>();
236 }
237
238 handler->PSendSysMessage("Latest LoginDatabase update: {}", lldb);
239 handler->PSendSysMessage("Latest CharacterDatabase update: {}", lcdb);
240 handler->PSendSysMessage("Latest WorldDatabase update: {}", lwdb);
241
242 handler->PSendSysMessage("LoginDatabase queue size: {}", LoginDatabase.QueueSize());
243 handler->PSendSysMessage("CharacterDatabase queue size: {}", CharacterDatabase.QueueSize());
244 handler->PSendSysMessage("WorldDatabase queue size: {}", WorldDatabase.QueueSize());
245
247 handler->PSendSysMessage("No modules are enabled");
248 else
249 handler->PSendSysMessage("List of enabled modules:");
250
251 for (auto const& modName : Acore::Module::GetEnableModulesList())
252 {
253 handler->PSendSysMessage("|- {}", modName);
254 }
255
256 return true;
257 }
LocaleConstant
Definition: Common.h:65
@ TOTAL_LOCALES
Definition: Common.h:76
char const * localeNames[TOTAL_LOCALES]
Definition: Common.cpp:20
std::uint8_t uint8
Definition: Define.h:109
std::uint32_t uint32
Definition: Define.h:107
std::uint16_t uint16
Definition: Define.h:108
@ CONFIG_PORT_WORLD
Definition: IWorld.h:215
@ CONFIG_ENABLE_MMAPS
Definition: IWorld.h:142
@ CONFIG_VMAP_INDOOR_CHECK
Definition: IWorld.h:123
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
Realm realm
Definition: World.cpp:112
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:34
AC_COMMON_API char const * GetMySQLExecutable()
Definition: GitRevision.cpp:61
AC_COMMON_API char const * GetCMakeVersion()
Definition: GitRevision.cpp:41
AC_COMMON_API char const * GetHostOSVersion()
Definition: GitRevision.cpp:46
AC_DATABASE_API uint32 GetLibraryVersion()
Definition: MySQLThreading.cpp:31
AC_COMMON_API std::vector< std::string_view > GetEnableModulesList()
Definition: ModuleMgr.cpp:31
bool isHeightCalcEnabled() const
Definition: IVMapMgr.h:119
bool isLineOfSightCalcEnabled() const
Definition: IVMapMgr.h:118
static VMapMgr2 * createOrGetVMapMgr()
Definition: VMapFactory.cpp:27
Class used to access individual fields of database query result.
Definition: Field.h:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:112
void PSendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:210
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
Definition: Chat.cpp:159
uint32 Realm
Definition: Realm.h:43
RealmHandle Id
Definition: Realm.h:69

References CharacterDatabase, CONFIG_ENABLE_MMAPS, CONFIG_PORT_WORLD, CONFIG_VMAP_INDOOR_CHECK, VMAP::VMapFactory::createOrGetVMapMgr(), Field::Get(), GitRevision::GetCMakeVersion(), Acore::Module::GetEnableModulesList(), GitRevision::GetHostOSVersion(), MySQL::GetLibraryVersion(), GitRevision::GetMySQLExecutable(), HandleServerInfoCommand(), Realm::Id, VMAP::IVMapMgr::isHeightCalcEnabled(), VMAP::IVMapMgr::isLineOfSightCalcEnabled(), localeNames, LoginDatabase, ChatHandler::PSendSysMessage(), realm, RealmHandle::Realm, ChatHandler::SendSysMessage(), Acore::StringFormat(), sWorld, TOTAL_LOCALES, and WorldDatabase.

Referenced by GetCommands().

◆ HandleServerExitCommand()

static bool server_commandscript::HandleServerExitCommand ( ChatHandler handler)
inlinestatic
521 {
524 return true;
525 }
@ LANG_COMMAND_EXIT
Definition: Language.h:855
@ SHUTDOWN_EXIT_CODE
Definition: World.h:53
static void StopNow(uint8 exitcode)
Definition: World.h:253

References LANG_COMMAND_EXIT, ChatHandler::SendSysMessage(), SHUTDOWN_EXIT_CODE, and World::StopNow().

Referenced by GetCommands().

◆ HandleServerIdleRestartCommand()

static bool server_commandscript::HandleServerIdleRestartCommand ( ChatHandler handler,
std::string  time,
Optional< int32 exitCode,
Tail  reason 
)
inlinestatic
414 {
415 std::wstring wReason = std::wstring();
416 std::string strReason = std::string();
417
418 if (time.empty())
419 {
420 return false;
421 }
422
423 if (Acore::StringTo<int32>(time).value_or(0) < 0)
424 {
426 return false;
427 }
428
429 if (!reason.empty())
430 {
431 if (!Utf8toWStr(reason, wReason))
432 {
433 return false;
434 }
435
436 if (!WStrToUtf8(wReason, strReason))
437 {
438 return false;
439 }
440 }
441
442 int32 delay = TimeStringToSecs(time);
443 if (delay <= 0)
444 {
445 delay = Acore::StringTo<int32>(time).value_or(0);
446 }
447
448 if (delay <= 0)
449 {
451 return false;
452 }
453
454 if (exitCode && *exitCode >= 0 && *exitCode <= 125)
455 {
456 sWorld->ShutdownServ(delay, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, *exitCode);
457 }
458 else
459 {
460 sWorld->ShutdownServ(delay, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, RESTART_EXIT_CODE, strReason);
461 }
462
463 return true;
464 }
bool Utf8toWStr(char const *utf8str, std::size_t csize, wchar_t *wstr, std::size_t &wsize)
Definition: Util.cpp:281
bool WStrToUtf8(wchar_t const *wstr, std::size_t size, std::string &utf8str)
Definition: Util.cpp:333
uint32 TimeStringToSecs(const std::string &timestring)
Definition: Util.cpp:163
std::int32_t int32
Definition: Define.h:103
@ LANG_BAD_VALUE
Definition: Language.h:147
@ RESTART_EXIT_CODE
Definition: World.h:55
@ SHUTDOWN_MASK_RESTART
Definition: World.h:47
@ SHUTDOWN_MASK_IDLE
Definition: World.h:48
void SendErrorMessage(uint32 entry)
Definition: Chat.cpp:215

References LANG_BAD_VALUE, RESTART_EXIT_CODE, ChatHandler::SendErrorMessage(), SHUTDOWN_MASK_IDLE, SHUTDOWN_MASK_RESTART, sWorld, TimeStringToSecs(), Utf8toWStr(), and WStrToUtf8().

Referenced by GetCommands().

◆ HandleServerIdleShutDownCommand()

static bool server_commandscript::HandleServerIdleShutDownCommand ( ChatHandler handler,
std::string  time,
Optional< int32 exitCode,
Tail  reason 
)
inlinestatic
467 {
468 std::wstring wReason = std::wstring();
469 std::string strReason = std::string();
470
471 if (time.empty())
472 {
473 return false;
474 }
475
476 if (Acore::StringTo<int32>(time).value_or(0) < 0)
477 {
479 return false;
480 }
481
482 if (!reason.empty())
483 {
484 if (!Utf8toWStr(reason, wReason))
485 {
486 return false;
487 }
488
489 if (!WStrToUtf8(wReason, strReason))
490 {
491 return false;
492 }
493 }
494
495 int32 delay = TimeStringToSecs(time);
496 if (delay <= 0)
497 {
498 delay = Acore::StringTo<int32>(time).value_or(0);
499 }
500
501 if (delay <= 0)
502 {
504 return false;
505 }
506
507 if (exitCode && *exitCode >= 0 && *exitCode <= 125)
508 {
509 sWorld->ShutdownServ(delay, SHUTDOWN_MASK_IDLE, *exitCode);
510 }
511 else
512 {
513 sWorld->ShutdownServ(delay, SHUTDOWN_MASK_IDLE, SHUTDOWN_EXIT_CODE, strReason);
514 }
515
516 return true;
517 }

References LANG_BAD_VALUE, ChatHandler::SendErrorMessage(), SHUTDOWN_EXIT_CODE, SHUTDOWN_MASK_IDLE, sWorld, TimeStringToSecs(), Utf8toWStr(), and WStrToUtf8().

Referenced by GetCommands().

◆ HandleServerInfoCommand()

static bool server_commandscript::HandleServerInfoCommand ( ChatHandler handler)
inlinestatic

Can't use sWorld->ShutdownMsg here in case of console command

260 {
261 std::string realmName = sWorld->GetRealmName();
262 uint32 playerCount = sWorld->GetPlayerCount();
263 uint32 activeSessionCount = sWorld->GetActiveSessionCount();
264 uint32 queuedSessionCount = sWorld->GetQueuedSessionCount();
265 uint32 connPeak = sWorld->GetMaxActiveSessionCount();
266
268 if (!queuedSessionCount)
269 handler->PSendSysMessage("Connected players: {}. Characters in world: {}.", activeSessionCount, playerCount);
270 else
271 handler->PSendSysMessage("Connected players: {}. Characters in world: {}. Queue: {}.", activeSessionCount, playerCount, queuedSessionCount);
272
273 handler->PSendSysMessage("Connection peak: {}.", connPeak);
275 handler->PSendSysMessage("Update time diff: {}ms. Last {} diffs summary:", sWorldUpdateTime.GetLastUpdateTime(), sWorldUpdateTime.GetDatasetSize());
276 handler->PSendSysMessage("|- Mean: {}ms", sWorldUpdateTime.GetAverageUpdateTime());
277 handler->PSendSysMessage("|- Median: {}ms", sWorldUpdateTime.GetPercentile(50));
278 handler->PSendSysMessage("|- Percentiles (95, 99, max): {}ms, {}ms, {}ms",
282
284 if (sWorld->IsShuttingDown())
285 handler->PSendSysMessage(LANG_SHUTDOWN_TIMELEFT, secsToTimeString(sWorld->GetShutDownTimeLeft()).append("."));
286
287 return true;
288 }
std::string secsToTimeString(uint64 timeInSecs, bool shortText)
Definition: Util.cpp:73
@ LANG_UPTIME
Definition: Language.h:45
@ LANG_SHUTDOWN_TIMELEFT
Definition: Language.h:52
WorldUpdateTime sWorldUpdateTime
Definition: UpdateTime.cpp:27
AC_COMMON_API char const * GetFullVersion()
Definition: GitRevision.cpp:82
Seconds GetUptime()
Uptime.
Definition: GameTime.cpp:58
uint32 GetAverageUpdateTime() const
Definition: UpdateTime.cpp:41
uint32 GetDatasetSize() const
Definition: UpdateTime.cpp:77
uint32 GetLastUpdateTime() const
Definition: UpdateTime.cpp:72
uint32 GetPercentile(uint8 p)
Definition: UpdateTime.cpp:82

References UpdateTime::GetAverageUpdateTime(), UpdateTime::GetDatasetSize(), GitRevision::GetFullVersion(), UpdateTime::GetLastUpdateTime(), UpdateTime::GetPercentile(), GameTime::GetUptime(), LANG_SHUTDOWN_TIMELEFT, LANG_UPTIME, ChatHandler::PSendSysMessage(), secsToTimeString(), sWorld, and sWorldUpdateTime.

Referenced by GetCommands(), and HandleServerDebugCommand().

◆ HandleServerMotdCommand()

static bool server_commandscript::HandleServerMotdCommand ( ChatHandler handler)
inlinestatic
291 {
292 LocaleConstant localeConstant = DEFAULT_LOCALE;
293 if (Player* player = handler->GetPlayer())
294 localeConstant = player->GetSession()->GetSessionDbLocaleIndex();
295
296 handler->PSendSysMessage(LANG_MOTD_CURRENT, sMotdMgr->GetMotd(localeConstant));
297 return true;
298 }
#define DEFAULT_LOCALE
Definition: Common.h:79
@ LANG_MOTD_CURRENT
Definition: Language.h:88
#define sMotdMgr
Definition: MotdMgr.h:61
Player * GetPlayer() const
Definition: Chat.cpp:35
Definition: Player.h:1081

References DEFAULT_LOCALE, ChatHandler::GetPlayer(), LANG_MOTD_CURRENT, ChatHandler::PSendSysMessage(), and sMotdMgr.

Referenced by GetCommands().

◆ HandleServerRestartCommand()

static bool server_commandscript::HandleServerRestartCommand ( ChatHandler handler,
std::string  time,
Optional< int32 exitCode,
Tail  reason 
)
inlinestatic
361 {
362 std::wstring wReason = std::wstring();
363 std::string strReason = std::string();
364
365 if (time.empty())
366 {
367 return false;
368 }
369
370 if (Acore::StringTo<int32>(time).value_or(0) < 0)
371 {
373 return false;
374 }
375
376 if (!reason.empty())
377 {
378 if (!Utf8toWStr(reason, wReason))
379 {
380 return false;
381 }
382
383 if (!WStrToUtf8(wReason, strReason))
384 {
385 return false;
386 }
387 }
388
389 int32 delay = TimeStringToSecs(time);
390 if (delay <= 0)
391 {
392 delay = Acore::StringTo<int32>(time).value_or(0);
393 }
394
395 if (delay <= 0)
396 {
398 return false;
399 }
400
401 if (exitCode && *exitCode >= 0 && *exitCode <= 125)
402 {
403 sWorld->ShutdownServ(delay, SHUTDOWN_MASK_RESTART, *exitCode);
404 }
405 else
406 {
407 sWorld->ShutdownServ(delay, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE, strReason);
408 }
409
410 return true;
411 }

References LANG_BAD_VALUE, RESTART_EXIT_CODE, ChatHandler::SendErrorMessage(), SHUTDOWN_MASK_RESTART, sWorld, TimeStringToSecs(), Utf8toWStr(), and WStrToUtf8().

Referenced by GetCommands().

◆ HandleServerSetClosedCommand()

static bool server_commandscript::HandleServerSetClosedCommand ( ChatHandler handler,
Optional< std::string >  args 
)
inlinestatic
611 {
612 if (StringStartsWith("on", *args))
613 {
615 sWorld->SetClosed(true);
616 return true;
617 }
618 else if (StringStartsWith("off", *args))
619 {
621 sWorld->SetClosed(false);
622 return true;
623 }
624
626 return false;
627 }
bool StringStartsWith(std::string_view haystack, std::string_view needle)
Definition: Util.h:401
@ LANG_USE_BOL
Definition: Language.h:303
@ LANG_WORLD_CLOSED
Definition: Language.h:1171
@ LANG_WORLD_OPENED
Definition: Language.h:1172

References LANG_USE_BOL, LANG_WORLD_CLOSED, LANG_WORLD_OPENED, ChatHandler::SendErrorMessage(), ChatHandler::SendSysMessage(), StringStartsWith(), and sWorld.

Referenced by GetCommands().

◆ HandleServerSetLogLevelCommand()

static bool server_commandscript::HandleServerSetLogLevelCommand ( ChatHandler ,
bool  isLogger,
std::string const &  name,
int32  level 
)
inlinestatic
631 {
632 sLog->SetLogLevel(name, level, isLogger);
633 return true;
634 }
#define sLog
Definition: Log.h:126

References sLog.

Referenced by GetCommands().

◆ HandleServerSetMotdCommand()

static bool server_commandscript::HandleServerSetMotdCommand ( ChatHandler handler,
Optional< int32 realmId,
Optional< std::string >  locale,
Tail  motd 
)
inlinestatic
529 {
530 std::wstring wMotd = std::wstring();
531 std::string strMotd = std::string();
532
533 // Default realmId to the current realm if not provided
534 if (!realmId)
535 realmId = static_cast<int32>(realm.Id.Realm);
536
537 if (motd.empty())
538 return false;
539
540 // Convert Tail (motd) to std::string
541 std::ostringstream motdStream;
542 motdStream << motd;
543 std::string motdString = motdStream.str(); // Convert Tail to std::string
544 // Determine the locale; default to "enUS" if not provided
545 LocaleConstant localeConstant = DEFAULT_LOCALE;
546 if (locale.has_value())
547 {
548 if (sMotdMgr->IsValidLocale(locale.value()))
549 {
550 localeConstant = GetLocaleByName(locale.value());
551 }
552 else
553 {
554 motdStream.str("");
555 motdStream << locale.value() << " " << motd;
556 motdString = motdStream.str();
557 localeConstant = DEFAULT_LOCALE;
558 locale = GetNameByLocaleConstant(localeConstant);
559 }
560 }
561 else
562 {
563 // Set to default locale string
564 localeConstant = DEFAULT_LOCALE;
565 locale = GetNameByLocaleConstant(localeConstant);
566 }
567
568 // Convert the concatenated motdString to UTF-8 and ensure encoding consistency
569 if (!Utf8toWStr(motdString, wMotd))
570 return false;
571
572 if (!WStrToUtf8(wMotd, strMotd))
573 return false;
574
575 // Start a transaction for the database operations
576 LoginDatabaseTransaction trans = LoginDatabase.BeginTransaction();
577
578 if (localeConstant == DEFAULT_LOCALE)
579 {
580 // Insert or update in the main motd table for enUS
581 LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_MOTD);
582 stmt->SetData(0, realmId.value()); // realmId for insertion
583 stmt->SetData(1, strMotd); // motd text for insertion
584 stmt->SetData(2, strMotd); // motd text for ON DUPLICATE KEY UPDATE
585 trans->Append(stmt);
586 }
587 else
588 {
589 // Insert or update in the motd_localized table for other locales
591 stmt->SetData(0, realmId.value()); // realmId for insertion
592 stmt->SetData(1, locale.value()); // locale for insertion
593 stmt->SetData(2, strMotd); // motd text for insertion
594 stmt->SetData(3, strMotd); // motd text for ON DUPLICATE KEY UPDATE
595 trans->Append(stmt);
596 }
597
598 // Commit the transaction & update db
599 LoginDatabase.CommitTransaction(trans);
600
601 // Update the in-memory maps for the current realm. Otherwise, do not update
602 if (realmId == -1 || realmId == static_cast<int32>(realm.Id.Realm))
603 sMotdMgr->SetMotd(strMotd, localeConstant);
604
605 handler->PSendSysMessage(LANG_MOTD_NEW, realmId.value(), locale.value(), strMotd);
606 return true;
607 }
const std::string GetNameByLocaleConstant(LocaleConstant localeConstant)
Definition: Common.cpp:44
LocaleConstant GetLocaleByName(const std::string &name)
Definition: Common.cpp:33
@ LANG_MOTD_NEW
Definition: Language.h:890
@ LOGIN_INS_MOTD_LOCALE
Definition: LoginDatabase.h:103
@ LOGIN_INS_MOTD
Definition: LoginDatabase.h:102
SQLTransaction< LoginDatabaseConnection > LoginDatabaseTransaction
Definition: DatabaseEnvFwd.h:70
Definition: PreparedStatement.h:157
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition: PreparedStatement.h:77

References DEFAULT_LOCALE, GetLocaleByName(), GetNameByLocaleConstant(), Realm::Id, LANG_MOTD_NEW, LOGIN_INS_MOTD, LOGIN_INS_MOTD_LOCALE, LoginDatabase, ChatHandler::PSendSysMessage(), realm, RealmHandle::Realm, PreparedStatementBase::SetData(), sMotdMgr, Utf8toWStr(), and WStrToUtf8().

Referenced by GetCommands().

◆ HandleServerShutDownCancelCommand()

static bool server_commandscript::HandleServerShutDownCancelCommand ( ChatHandler )
inlinestatic
301 {
302 sWorld->ShutdownCancel();
303
304 return true;
305 }

References sWorld.

Referenced by GetCommands().

◆ HandleServerShutDownCommand()

static bool server_commandscript::HandleServerShutDownCommand ( ChatHandler handler,
std::string  time,
Optional< int32 exitCode,
Tail  reason 
)
inlinestatic
308 {
309 std::wstring wReason = std::wstring();
310 std::string strReason = std::string();
311
312 if (time.empty())
313 {
314 return false;
315 }
316
317 if (Acore::StringTo<int32>(time).value_or(0) < 0)
318 {
320 return false;
321 }
322
323 if (!reason.empty())
324 {
325 if (!Utf8toWStr(reason, wReason))
326 {
327 return false;
328 }
329
330 if (!WStrToUtf8(wReason, strReason))
331 {
332 return false;
333 }
334 }
335
336 int32 delay = TimeStringToSecs(time);
337 if (delay <= 0)
338 {
339 delay = Acore::StringTo<int32>(time).value_or(0);
340 }
341
342 if (delay <= 0)
343 {
345 return false;
346 }
347
348 if (exitCode && *exitCode >= 0 && *exitCode <= 125)
349 {
350 sWorld->ShutdownServ(delay, 0, *exitCode);
351 }
352 else
353 {
354 sWorld->ShutdownServ(delay, 0, SHUTDOWN_EXIT_CODE, strReason);
355 }
356
357 return true;
358 }

References LANG_BAD_VALUE, ChatHandler::SendErrorMessage(), SHUTDOWN_EXIT_CODE, sWorld, TimeStringToSecs(), Utf8toWStr(), and WStrToUtf8().

Referenced by GetCommands().