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
 
- Public Member Functions inherited from ScriptObject
virtual bool IsDatabaseBound () const
 
virtual bool isAfterLoadScript () const
 
virtual void checkValidity ()
 
std::string const & GetName () const
 
uint16 GetTotalAvailableHooks ()
 

Static Public Member Functions

static bool HandleServerCorpsesCommand (ChatHandler *)
 
static bool HandleServerDebugCommand (ChatHandler *handler)
 
static bool HandleServerInfoCommand (ChatHandler *handler)
 
static void SendPreviousSessionInfo (ChatHandler *handler)
 
static AcoreStrings GetShutdownTypeString (SessionShutdownType type)
 
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, std::string locale, Tail motd)
 
static bool HandleServerSetClosedCommand (ChatHandler *handler, Optional< std::string > args)
 
static bool HandleServerSetSecurityCommand (ChatHandler *handler, uint8 level)
 
static bool HandleServerSetLogLevelCommand (ChatHandler *, bool isLogger, std::string const &name, int32 level)
 

Additional Inherited Members

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

Detailed Description

Constructor & Destructor Documentation

◆ server_commandscript()

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

Member Function Documentation

◆ GetCommands()

ChatCommandTable server_commandscript::GetCommands ( ) const
inlineoverridevirtual

Implements CommandScript.

52 {
53 static ChatCommandTable serverIdleRestartCommandTable =
54 {
57 };
58
59 static ChatCommandTable serverIdleShutdownCommandTable =
60 {
63 };
64
65 static ChatCommandTable serverRestartCommandTable =
66 {
69 };
70
71 static ChatCommandTable serverShutdownCommandTable =
72 {
75 };
76
77 static ChatCommandTable serverSetCommandTable =
78 {
83 };
84
85 static ChatCommandTable serverCommandTable =
86 {
90 { "idlerestart", serverIdleRestartCommandTable },
91 { "idleshutdown", serverIdleShutdownCommandTable },
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 }
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:684
static bool HandleServerSetClosedCommand(ChatHandler *handler, Optional< std::string > args)
Definition cs_server.cpp:643
static bool HandleServerRestartCommand(ChatHandler *handler, std::string time, Optional< int32 > exitCode, Tail reason)
Definition cs_server.cpp:416
static bool HandleServerShutDownCommand(ChatHandler *handler, std::string time, Optional< int32 > exitCode, Tail reason)
Definition cs_server.cpp:363
static bool HandleServerInfoCommand(ChatHandler *handler)
Definition cs_server.cpp:267
static bool HandleServerSetMotdCommand(ChatHandler *handler, Optional< int32 > realmId, std::string locale, Tail motd)
Definition cs_server.cpp:584
static bool HandleServerMotdCommand(ChatHandler *handler)
Definition cs_server.cpp:342
static bool HandleServerSetSecurityCommand(ChatHandler *handler, uint8 level)
Definition cs_server.cpp:663
static bool HandleServerIdleShutDownCommand(ChatHandler *handler, std::string time, Optional< int32 > exitCode, Tail reason)
Definition cs_server.cpp:522
static bool HandleServerExitCommand(ChatHandler *handler)
Definition cs_server.cpp:576
static bool HandleServerDebugCommand(ChatHandler *handler)
Definition cs_server.cpp:117
static bool HandleServerIdleRestartCommand(ChatHandler *handler, std::string time, Optional< int32 > exitCode, Tail reason)
Definition cs_server.cpp:469
static bool HandleServerShutDownCancelCommand(ChatHandler *)
Definition cs_server.cpp:356
std::vector< ChatCommandBuilder > ChatCommandTable
Definition ChatCommand.h:46
@ RBAC_PERM_COMMAND_SERVER_SHUTDOWN
Definition RBAC.h:561
@ RBAC_PERM_COMMAND_SERVER_SET_LOGLEVEL
Definition RBAC.h:559
@ RBAC_PERM_COMMAND_SERVER_RESTART_CANCEL
Definition RBAC.h:555
@ RBAC_PERM_COMMAND_SERVER_EXIT
Definition RBAC.h:547
@ RBAC_PERM_COMMAND_SERVER_RESTART
Definition RBAC.h:554
@ RBAC_PERM_COMMAND_SERVER_IDLESHUTDOWN_CANCEL
Definition RBAC.h:551
@ RBAC_PERM_COMMAND_SERVER_SET_SECURITY
Definition RBAC.h:703
@ RBAC_PERM_COMMAND_SERVER_SHUTDOWN_CANCEL
Definition RBAC.h:562
@ RBAC_PERM_COMMAND_SERVER_IDLERESTART_CANCEL
Definition RBAC.h:549
@ RBAC_PERM_COMMAND_SERVER_MOTD
Definition RBAC.h:563
@ RBAC_PERM_COMMAND_SERVER_SET_CLOSED
Definition RBAC.h:557
@ RBAC_PERM_COMMAND_SERVER_SET_MOTD
Definition RBAC.h:560
@ RBAC_PERM_COMMAND_SERVER_INFO
Definition RBAC.h:552
@ RBAC_PERM_COMMAND_SERVER_IDLERESTART
Definition RBAC.h:548
@ RBAC_PERM_COMMAND_SERVER_IDLESHUTDOWN
Definition RBAC.h:550
@ RBAC_PERM_COMMAND_SERVER_DEBUG
Definition RBAC.h:640
@ RBAC_PERM_COMMAND_SERVER_CORPSES
Definition RBAC.h:546

References HandleServerCorpsesCommand(), HandleServerDebugCommand(), HandleServerExitCommand(), HandleServerIdleRestartCommand(), HandleServerIdleShutDownCommand(), HandleServerInfoCommand(), HandleServerMotdCommand(), HandleServerRestartCommand(), HandleServerSetClosedCommand(), HandleServerSetLogLevelCommand(), HandleServerSetMotdCommand(), HandleServerSetSecurityCommand(), HandleServerShutDownCancelCommand(), HandleServerShutDownCommand(), rbac::RBAC_PERM_COMMAND_SERVER_CORPSES, rbac::RBAC_PERM_COMMAND_SERVER_DEBUG, rbac::RBAC_PERM_COMMAND_SERVER_EXIT, rbac::RBAC_PERM_COMMAND_SERVER_IDLERESTART, rbac::RBAC_PERM_COMMAND_SERVER_IDLERESTART_CANCEL, rbac::RBAC_PERM_COMMAND_SERVER_IDLESHUTDOWN, rbac::RBAC_PERM_COMMAND_SERVER_IDLESHUTDOWN_CANCEL, rbac::RBAC_PERM_COMMAND_SERVER_INFO, rbac::RBAC_PERM_COMMAND_SERVER_MOTD, rbac::RBAC_PERM_COMMAND_SERVER_RESTART, rbac::RBAC_PERM_COMMAND_SERVER_RESTART_CANCEL, rbac::RBAC_PERM_COMMAND_SERVER_SET_CLOSED, rbac::RBAC_PERM_COMMAND_SERVER_SET_LOGLEVEL, rbac::RBAC_PERM_COMMAND_SERVER_SET_MOTD, rbac::RBAC_PERM_COMMAND_SERVER_SET_SECURITY, rbac::RBAC_PERM_COMMAND_SERVER_SHUTDOWN, and rbac::RBAC_PERM_COMMAND_SERVER_SHUTDOWN_CANCEL.

◆ GetShutdownTypeString()

static AcoreStrings server_commandscript::GetShutdownTypeString ( SessionShutdownType  type)
inlinestatic
329 {
330 switch (type)
331 {
336 default:
338 }
339 }
@ SHUTDOWN_TYPE_ERROR
Definition IWorld.h:69
@ SHUTDOWN_TYPE_RESTART
Definition IWorld.h:68
@ LANG_COMMAND_SERVER_INFO_TYPE_SHUTDOWN
Definition Language.h:1412
@ LANG_COMMAND_SERVER_INFO_TYPE_RESTART
Definition Language.h:1413
@ LANG_COMMAND_SERVER_INFO_TYPE_ERROR
Definition Language.h:1414

References LANG_COMMAND_SERVER_INFO_TYPE_ERROR, LANG_COMMAND_SERVER_INFO_TYPE_RESTART, LANG_COMMAND_SERVER_INFO_TYPE_SHUTDOWN, SHUTDOWN_TYPE_ERROR, and SHUTDOWN_TYPE_RESTART.

Referenced by SendPreviousSessionInfo().

◆ HandleServerCorpsesCommand()

static bool server_commandscript::HandleServerCorpsesCommand ( ChatHandler *  )
inlinestatic
109 {
110 sMapMgr->DoForAllMaps([](Map* map)
111 {
112 map->RemoveOldCorpses();
113 });
114 return true;
115 }
#define sMapMgr
Definition MapMgr.h:220
Definition Map.h:168
void RemoveOldCorpses()
Definition Map.cpp:3179

References Map::RemoveOldCorpses(), and sMapMgr.

Referenced by GetCommands().

◆ HandleServerDebugCommand()

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

Referenced by GetCommands().

◆ HandleServerExitCommand()

static bool server_commandscript::HandleServerExitCommand ( ChatHandler *  handler)
inlinestatic
577 {
580 return true;
581 }
@ LANG_COMMAND_EXIT
Definition Language.h:867
static void StopNow(uint8 exitcode)
Definition World.h:195
@ SHUTDOWN_EXIT_CODE
Definition World.h:53

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
470 {
471 std::wstring wReason = std::wstring();
472 std::string strReason = std::string();
473
474 if (time.empty())
475 {
476 return false;
477 }
478
479 if (Acore::StringTo<int32>(time).value_or(0) < 0)
480 {
482 return false;
483 }
484
485 if (!reason.empty())
486 {
487 if (!Utf8toWStr(reason, wReason))
488 {
489 return false;
490 }
491
492 if (!WStrToUtf8(wReason, strReason))
493 {
494 return false;
495 }
496 }
497
498 int32 delay = TimeStringToSecs(time);
499 if (delay <= 0)
500 {
501 delay = Acore::StringTo<int32>(time).value_or(0);
502 }
503
504 if (delay <= 0)
505 {
507 return false;
508 }
509
510 if (exitCode && *exitCode >= 0 && *exitCode <= 125)
511 {
512 sWorld->ShutdownServ(delay, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, *exitCode, strReason);
513 }
514 else
515 {
516 sWorld->ShutdownServ(delay, SHUTDOWN_MASK_RESTART | SHUTDOWN_MASK_IDLE, RESTART_EXIT_CODE, strReason);
517 }
518
519 return true;
520 }
std::int32_t int32
Definition Define.h:103
@ LANG_BAD_VALUE
Definition Language.h:151
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(std::string const &timestring)
Definition Util.cpp:163
void SendErrorMessage(uint32 entry)
Definition Chat.cpp:224
@ RESTART_EXIT_CODE
Definition World.h:55
@ SHUTDOWN_MASK_RESTART
Definition World.h:47
@ SHUTDOWN_MASK_IDLE
Definition World.h:48

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
523 {
524 std::wstring wReason = std::wstring();
525 std::string strReason = std::string();
526
527 if (time.empty())
528 {
529 return false;
530 }
531
532 if (Acore::StringTo<int32>(time).value_or(0) < 0)
533 {
535 return false;
536 }
537
538 if (!reason.empty())
539 {
540 if (!Utf8toWStr(reason, wReason))
541 {
542 return false;
543 }
544
545 if (!WStrToUtf8(wReason, strReason))
546 {
547 return false;
548 }
549 }
550
551 int32 delay = TimeStringToSecs(time);
552 if (delay <= 0)
553 {
554 delay = Acore::StringTo<int32>(time).value_or(0);
555 }
556
557 if (delay <= 0)
558 {
560 return false;
561 }
562
563 if (exitCode && *exitCode >= 0 && *exitCode <= 125)
564 {
565 sWorld->ShutdownServ(delay, SHUTDOWN_MASK_IDLE, *exitCode, strReason);
566 }
567 else
568 {
569 sWorld->ShutdownServ(delay, SHUTDOWN_MASK_IDLE, SHUTDOWN_EXIT_CODE, strReason);
570 }
571
572 return true;
573 }

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

268 {
269 std::string realmName = sWorld->GetRealmName();
270 uint32 playerCount = sWorldSessionMgr->GetPlayerCount();
271 uint32 activeSessionCount = sWorldSessionMgr->GetActiveSessionCount();
272 uint32 queuedSessionCount = sWorldSessionMgr->GetQueuedSessionCount();
273 uint32 connPeak = sWorldSessionMgr->GetMaxActiveSessionCount();
274
276 if (!queuedSessionCount)
277 handler->PSendSysMessage(LANG_COMMAND_SERVER_INFO_CONNECTED, activeSessionCount, connPeak);
278 else
279 handler->PSendSysMessage(LANG_COMMAND_SERVER_INFO_CONNECTED_QUEUE, activeSessionCount, connPeak, queuedSessionCount);
280
281 handler->PSendSysMessage(LANG_COMMAND_SERVER_INFO_CHARACTERS_IN_WORLD, playerCount, sWorldSessionMgr->GetMaxPlayerCount(), sWorld->GetLifetimeMaxPlayerCount());
282 handler->PSendSysMessage(LANG_COMMAND_SERVER_INFO_SECURITY, uint32(sWorld->GetPlayerSecurityLimit()));
291
293 if (sWorld->IsShuttingDown())
294 handler->PSendSysMessage(LANG_SHUTDOWN_TIMELEFT, secsToTimeString(sWorld->GetShutDownTimeLeft()).append("."));
295
297
298 return true;
299 }
@ LANG_COMMAND_SERVER_INFO_CONNECTED_QUEUE
Definition Language.h:1416
@ LANG_COMMAND_SERVER_INFO_CONNECTED
Definition Language.h:1415
@ LANG_COMMAND_SERVER_INFO_UPDATE_MEDIAN
Definition Language.h:1419
@ LANG_COMMAND_SERVER_INFO_SECURITY
Definition Language.h:1405
@ LANG_COMMAND_SERVER_INFO_UPDATE_PERCENTILES
Definition Language.h:1420
@ LANG_UPTIME
Definition Language.h:45
@ LANG_COMMAND_SERVER_INFO_CHARACTERS_IN_WORLD
Definition Language.h:1406
@ LANG_COMMAND_SERVER_INFO_UPDATE_DIFF
Definition Language.h:1417
@ LANG_COMMAND_SERVER_INFO_UPDATE_MEAN
Definition Language.h:1418
@ LANG_SHUTDOWN_TIMELEFT
Definition Language.h:52
WorldUpdateTime sWorldUpdateTime
Definition UpdateTime.cpp:27
std::string secsToTimeString(uint64 timeInSecs, bool shortText)
Definition Util.cpp:73
#define sWorldSessionMgr
Definition WorldSessionMgr.h:118
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
static void SendPreviousSessionInfo(ChatHandler *handler)
Definition cs_server.cpp:301
Seconds GetUptime()
Time since server start, unaffected by wall clock changes.
Definition GameTime.cpp:59
AC_COMMON_API char const * GetFullVersion()
Definition GitRevision.cpp:82

References UpdateTime::GetAverageUpdateTime(), UpdateTime::GetDatasetSize(), GitRevision::GetFullVersion(), UpdateTime::GetLastUpdateTime(), UpdateTime::GetPercentile(), GameTime::GetUptime(), LANG_COMMAND_SERVER_INFO_CHARACTERS_IN_WORLD, LANG_COMMAND_SERVER_INFO_CONNECTED, LANG_COMMAND_SERVER_INFO_CONNECTED_QUEUE, LANG_COMMAND_SERVER_INFO_SECURITY, LANG_COMMAND_SERVER_INFO_UPDATE_DIFF, LANG_COMMAND_SERVER_INFO_UPDATE_MEAN, LANG_COMMAND_SERVER_INFO_UPDATE_MEDIAN, LANG_COMMAND_SERVER_INFO_UPDATE_PERCENTILES, LANG_SHUTDOWN_TIMELEFT, LANG_UPTIME, ChatHandler::PSendSysMessage(), secsToTimeString(), SendPreviousSessionInfo(), sWorld, sWorldSessionMgr, and sWorldUpdateTime.

Referenced by GetCommands(), and HandleServerDebugCommand().

◆ HandleServerMotdCommand()

static bool server_commandscript::HandleServerMotdCommand ( ChatHandler *  handler)
inlinestatic
343 {
345 for (uint32 i = 0; i < TOTAL_LOCALES; ++i)
346 {
348 continue;
349
351 }
352
353 return true;
354 }
const std::string GetNameByLocaleConstant(LocaleConstant localeConstant)
Definition Common.cpp:87
bool IsLocaleRegistered(LocaleConstant locale)
Definition Common.h:147
@ LANG_MOTD_CURRENT
Definition Language.h:88
@ LANG_GENERIC_TWO_CURLIES_WITH_COLON
Definition Language.h:114
#define sMotdMgr
Definition MotdMgr.h:52

References GetNameByLocaleConstant(), IsLocaleRegistered(), LANG_GENERIC_TWO_CURLIES_WITH_COLON, LANG_MOTD_CURRENT, ChatHandler::PSendSysMessage(), sMotdMgr, and TOTAL_LOCALES.

Referenced by GetCommands().

◆ HandleServerRestartCommand()

static bool server_commandscript::HandleServerRestartCommand ( ChatHandler *  handler,
std::string  time,
Optional< int32 >  exitCode,
Tail  reason 
)
inlinestatic
417 {
418 std::wstring wReason = std::wstring();
419 std::string strReason = std::string();
420
421 if (time.empty())
422 {
423 return false;
424 }
425
426 if (Acore::StringTo<int32>(time).value_or(0) < 0)
427 {
429 return false;
430 }
431
432 if (!reason.empty())
433 {
434 if (!Utf8toWStr(reason, wReason))
435 {
436 return false;
437 }
438
439 if (!WStrToUtf8(wReason, strReason))
440 {
441 return false;
442 }
443 }
444
445 int32 delay = TimeStringToSecs(time);
446 if (delay <= 0)
447 {
448 delay = Acore::StringTo<int32>(time).value_or(0);
449 }
450
451 if (delay <= 0)
452 {
454 return false;
455 }
456
457 if (exitCode && *exitCode >= 0 && *exitCode <= 125)
458 {
459 sWorld->ShutdownServ(delay, SHUTDOWN_MASK_RESTART, *exitCode, strReason);
460 }
461 else
462 {
463 sWorld->ShutdownServ(delay, SHUTDOWN_MASK_RESTART, RESTART_EXIT_CODE, strReason);
464 }
465
466 return true;
467 }

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
644 {
645 if (StringStartsWith("on", *args))
646 {
648 sWorld->SetClosed(true);
649 return true;
650 }
651 else if (StringStartsWith("off", *args))
652 {
654 sWorld->SetClosed(false);
655 return true;
656 }
657
659 return false;
660 }
@ LANG_USE_BOL
Definition Language.h:311
@ LANG_WORLD_CLOSED
Definition Language.h:1261
@ LANG_WORLD_OPENED
Definition Language.h:1262
bool StringStartsWith(std::string_view haystack, std::string_view needle)
Definition Util.h:392

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
685 {
686 sLog->SetLogLevel(name, level, isLogger);
687 return true;
688 }
#define sLog
Definition Log.h:127

References sLog.

Referenced by GetCommands().

◆ HandleServerSetMotdCommand()

static bool server_commandscript::HandleServerSetMotdCommand ( ChatHandler *  handler,
Optional< int32 >  realmId,
std::string  locale,
Tail  motd 
)
inlinestatic
585 {
586 std::wstring wMotd = std::wstring();
587 std::string strMotd = std::string();
588
589 // Default realmId to the current realm if not provided
590 if (!realmId)
591 realmId = static_cast<int32>(realm.Id.Realm);
592
593 // Determine the locale; default to "enUS" if not provided
594 LocaleConstant localeConstant;
595 if (IsLocaleValid(locale))
596 localeConstant = GetLocaleByName(locale);
597 else
598 {
599 handler->SendErrorMessage("locale ({}) is not valid. Valid locales: enUS, koKR, frFR, deDE, zhCN, zhTW, esES, esMX, ruRU.", locale);
600 return false;
601 }
602
603 if (motd.empty())
604 return false;
605
606 // Convert the concatenated motdString to UTF-8 and ensure encoding consistency
607 if (!Utf8toWStr(motd, wMotd))
608 return false;
609
610 if (!WStrToUtf8(wMotd, strMotd))
611 return false;
612
613 // Start a transaction for the database operations
614 LoginDatabaseTransaction trans = LoginDatabase.BeginTransaction();
615
616 if (localeConstant == LOCALE_enUS)
617 {
618 // Insert or update in the main motd table for enUS
619 LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_REP_MOTD);
620 stmt->SetData(0, realmId.value()); // realmId for insertion
621 stmt->SetData(1, strMotd); // motd text for insertion
622 trans->Append(stmt);
623 }
624 else
625 {
626 // Insert or update in the motd_localized table for other locales
628 stmt->SetData(0, realmId.value()); // realmId for insertion
629 stmt->SetData(1, locale); // locale for insertion
630 stmt->SetData(2, strMotd); // motd text for insertion
631 trans->Append(stmt);
632 }
633
634 // Commit the transaction & update db
635 LoginDatabase.CommitTransaction(trans);
636
637 sMotdMgr->SetMotd(strMotd, localeConstant);
638 handler->PSendSysMessage(LANG_MOTD_NEW, realmId.value(), locale, strMotd);
639 return true;
640 }
LocaleConstant GetLocaleByName(std::string const &name)
Definition Common.cpp:78
bool IsLocaleValid(std::string const &locale)
Definition Common.cpp:69
@ LOCALE_enUS
Definition Common.h:126
SQLTransaction< LoginDatabaseConnection > LoginDatabaseTransaction
Definition DatabaseEnvFwd.h:70
@ LANG_MOTD_NEW
Definition Language.h:902
@ LOGIN_REP_MOTD
Definition LoginDatabase.h:115
@ LOGIN_REP_MOTD_LOCALE
Definition LoginDatabase.h:116
Acore::Types::is_default< T > SetData(const uint8 index, T value)
Definition PreparedStatement.h:77
Definition PreparedStatement.h:157

References GetLocaleByName(), Realm::Id, IsLocaleValid(), LANG_MOTD_NEW, LOCALE_enUS, LOGIN_REP_MOTD, LOGIN_REP_MOTD_LOCALE, LoginDatabase, ChatHandler::PSendSysMessage(), realm, RealmHandle::Realm, ChatHandler::SendErrorMessage(), PreparedStatementBase::SetData(), sMotdMgr, Utf8toWStr(), and WStrToUtf8().

Referenced by GetCommands().

◆ HandleServerSetSecurityCommand()

static bool server_commandscript::HandleServerSetSecurityCommand ( ChatHandler *  handler,
uint8  level 
)
inlinestatic
664 {
665 if (level > SEC_ADMINISTRATOR)
666 {
668 return false;
669 }
670
672 stmt->SetData(0, level);
673 stmt->SetData(1, realm.Id.Realm);
674 LoginDatabase.Execute(stmt);
675
676 // Apply live; raising the limit kicks any now-disallowed sessions.
677 sWorld->SetPlayerSecurityLimit(AccountTypes(level));
678
680 return true;
681 }
AccountTypes
Definition Common.h:56
@ SEC_PLAYER
Definition Common.h:57
@ SEC_ADMINISTRATOR
Definition Common.h:60
@ LANG_COMMAND_SERVER_SET_SECURITY_ERROR
Definition Language.h:1404
@ LANG_COMMAND_SERVER_SET_SECURITY
Definition Language.h:1403
@ LOGIN_UPD_REALMLIST_SECURITY_LEVEL
Definition LoginDatabase.h:102

References Realm::Id, LANG_COMMAND_SERVER_SET_SECURITY, LANG_COMMAND_SERVER_SET_SECURITY_ERROR, LOGIN_UPD_REALMLIST_SECURITY_LEVEL, LoginDatabase, ChatHandler::PSendSysMessage(), realm, RealmHandle::Realm, SEC_ADMINISTRATOR, SEC_PLAYER, ChatHandler::SendErrorMessage(), PreparedStatementBase::SetData(), and sWorld.

Referenced by GetCommands().

◆ HandleServerShutDownCancelCommand()

static bool server_commandscript::HandleServerShutDownCancelCommand ( ChatHandler *  )
inlinestatic
357 {
358 sWorld->ShutdownCancel();
359
360 return true;
361 }

References sWorld.

Referenced by GetCommands().

◆ HandleServerShutDownCommand()

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

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

Referenced by GetCommands().

◆ SendPreviousSessionInfo()

static void server_commandscript::SendPreviousSessionInfo ( ChatHandler *  handler)
inlinestatic
302 {
303 Optional<PreviousSessionInfo> const& previous = sWorld->GetPreviousSessionInfo();
304 if (!previous)
305 return;
306
307 std::string uptime = secsToTimeString(previous->Uptime.count());
308
309 if (previous->Crashed)
310 {
311 std::string lastSeen = Acore::Time::TimeToTimestampStr(previous->StartTime + previous->Uptime);
312
313 // A crash with a type set happened after the world loop had already stopped
314 if (previous->Type == SHUTDOWN_TYPE_UNKNOWN)
316 else
317 handler->PSendSysMessage(LANG_COMMAND_SERVER_INFO_CRASH_DURING, handler->GetAcoreString(GetShutdownTypeString(previous->Type)), uptime, lastSeen);
318 }
319 else if (previous->Type == SHUTDOWN_TYPE_UNKNOWN)
321 else
323
324 if (!previous->Reason.empty())
326 }
@ SHUTDOWN_TYPE_UNKNOWN
Definition IWorld.h:66
@ LANG_COMMAND_SERVER_INFO_PREVIOUS_RAN
Definition Language.h:1408
@ LANG_COMMAND_SERVER_INFO_CRASH_RECOVERED
Definition Language.h:1409
@ LANG_COMMAND_SERVER_INFO_SHUTDOWN_REASON
Definition Language.h:1411
@ LANG_COMMAND_SERVER_INFO_CRASH_DURING
Definition Language.h:1410
@ LANG_COMMAND_SERVER_INFO_PREVIOUS_ENDED
Definition Language.h:1407
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:24
virtual std::string GetAcoreString(uint32 entry) const
Definition Chat.cpp:42
static AcoreStrings GetShutdownTypeString(SessionShutdownType type)
Definition cs_server.cpp:328
AC_COMMON_API std::string TimeToTimestampStr(Seconds time=0s, std::string_view fmt={})
Definition Timer.cpp:272

References ChatHandler::GetAcoreString(), GetShutdownTypeString(), LANG_COMMAND_SERVER_INFO_CRASH_DURING, LANG_COMMAND_SERVER_INFO_CRASH_RECOVERED, LANG_COMMAND_SERVER_INFO_PREVIOUS_ENDED, LANG_COMMAND_SERVER_INFO_PREVIOUS_RAN, LANG_COMMAND_SERVER_INFO_SHUTDOWN_REASON, ChatHandler::PSendSysMessage(), secsToTimeString(), SHUTDOWN_TYPE_UNKNOWN, sWorld, and Acore::Time::TimeToTimestampStr().

Referenced by HandleServerInfoCommand().


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