45#include <boost/filesystem/directory.hpp>
46#include <boost/filesystem/operations.hpp>
47#include <openssl/crypto.h>
48#include <openssl/opensslv.h>
51#if TRINITY_COMPILER == TRINITY_COMPILER_GNU
52#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
62 static std::vector<ChatCommand> serverIdleRestartCommandTable =
68 static std::vector<ChatCommand> serverIdleShutdownCommandTable =
74 static std::vector<ChatCommand> serverRestartCommandTable =
81 static std::vector<ChatCommand> serverShutdownCommandTable =
88 static std::vector<ChatCommand> serverSetCommandTable =
95 static std::vector<ChatCommand> serverCommandTable =
110 static std::vector<ChatCommand> commandTable =
120 sWorld->RemoveOldCorpses();
127 std::string dbPortOutput;
132 dbPort = (*res)[0].GetUInt16();
141 handler->
PSendSysMessage(
"Using SSL version: %s (library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
142 handler->
PSendSysMessage(
"Using Boost version: %i.%i.%i", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100);
150 handler->
SendSysMessage(
"Automatic database updates are disabled for all databases!");
153 static char const*
const databaseNames[3 ] =
160 std::string availableUpdateDatabases;
161 for (
uint32 i = 0; i < 3 ; ++i)
163 if (!(updateFlags & (1 << i)))
166 availableUpdateDatabases += databaseNames[i];
168 availableUpdateDatabases +=
", ";
171 handler->
PSendSysMessage(
"Automatic database updates are enabled for the following databases: %s", availableUpdateDatabases.c_str());
174 handler->
PSendSysMessage(
"Worldserver listening connections on port {}", worldPort);
183 std::string dataDir =
sWorld->GetDataPath();
184 std::vector<std::string> subDirs;
185 subDirs.emplace_back(
"maps");
186 if (vmapIndoorCheck || vmapLOSCheck || vmapHeightCheck)
188 handler->
PSendSysMessage(
"VMAPs status: Enabled. LineOfSight: %i, getHeight: %i, indoorCheck: %i", vmapLOSCheck, vmapHeightCheck, vmapIndoorCheck);
189 subDirs.emplace_back(
"vmaps");
197 subDirs.emplace_back(
"mmaps");
202 for (std::string
const& subDir : subDirs)
204 boost::filesystem::path mapPath(dataDir);
207 if (!boost::filesystem::exists(mapPath))
209 handler->
PSendSysMessage(
"%s directory doesn't exist!. Using path: %s", subDir.c_str(), mapPath.generic_string().c_str());
213 auto end = boost::filesystem::directory_iterator();
214 std::size_t folderSize = std::accumulate(boost::filesystem::directory_iterator(mapPath), end, std::size_t(0), [](std::size_t val, boost::filesystem::path
const& mapFile)
216 boost::system::error_code ec;
217 if (boost::filesystem::is_regular_file(mapFile, ec))
218 val += boost::filesystem::file_size(mapFile);
222 handler->
PSendSysMessage(
"%s directory located in %s. Total size: " SZFMTD " bytes", subDir.c_str(), mapPath.generic_string().c_str(), folderSize);
226 uint32 availableLocalesMask = (1 << defaultLocale);
231 if (locale == defaultLocale)
234 if (
sWorld->GetAvailableDbcLocale(locale) != defaultLocale)
235 availableLocalesMask |= (1 << locale);
238 std::string availableLocales;
241 if (!(availableLocalesMask & (1 << i)))
246 availableLocales +=
" ";
249 handler->
PSendSysMessage(
"Using %s DBC Locale as default. All available DBC locales: %s",
localeNames[defaultLocale], availableLocales.c_str());
263 uint32 activeClientsNum =
sWorld->GetActiveSessionCount();
264 uint32 queuedClientsNum =
sWorld->GetQueuedSessionCount();
265 uint32 maxActiveClientsNum =
sWorld->GetMaxActiveSessionCount();
266 uint32 maxQueuedClientsNum =
sWorld->GetMaxQueuedSessionCount();
276 if (
sWorld->IsShuttingDown())
285 for (std::string
const& line :
sWorld->GetMotd())
295 char* paramStr = strtok((
char*)args,
" ");
299 int32 limit = strlen(paramStr);
301 if (strncmp(paramStr,
"player", limit) == 0)
303 else if (strncmp(paramStr,
"moderator", limit) == 0)
305 else if (strncmp(paramStr,
"gamemaster", limit) == 0)
307 else if (strncmp(paramStr,
"administrator", limit) == 0)
309 else if (strncmp(paramStr,
"reset", limit) == 0)
311 sWorld->SetPlayerAmountLimit(
sConfigMgr->GetIntDefault(
"PlayerLimit", 100));
312 sWorld->LoadDBAllowedSecurityLevel();
316 int32 value = atoi(paramStr);
324 uint32 playerAmountLimit =
sWorld->GetPlayerAmountLimit();
326 char const* secName =
"";
327 switch (allowedAccountType)
333 secName =
"Moderator";
336 secName =
"Gamemaster";
339 secName =
"Administrator";
342 secName =
"<unknown>";
345 handler->
PSendSysMessage(
"Player limits: amount %u, min. security level %s.", playerAmountLimit, secName);
363 for (SessionMap::value_type
const& session : sessions)
364 if (session.second && myAddr != session.second->GetRemoteAddress())
417 if (strncmp(args,
"on", 3) == 0)
423 else if (strncmp(args,
"off", 4) == 0)
438 if (name.empty() || level < 0 || (type !=
"a" && type !=
"l"))
441 sLog->SetLogLevel(name, level, type ==
"l");
448 exitCode = atoi(exitCodeStr);
451 if (exitCode == 0 && (exitCodeStr[0] !=
'0' || exitCodeStr[1] !=
'\0'))
457 if (exitCode < 0 || exitCode > 125)
468 if (strlen(args) > 255)
473 char* delayStr = strtok((
char*)args,
" ");
479 delay = atoi(delayStr);
481 if ((delay == 0 && (delayStr[0] !=
'0' || delayStr[1] !=
'\0')) || delay < 0)
492 char* exitCodeStr =
nullptr;
494 char reason[256] = { 0 };
496 while (
char* nextToken = strtok(
nullptr,
" "))
499 exitCodeStr = nextToken;
502 strcat(reason, nextToken);
503 if (
char* remainingTokens = strtok(
nullptr,
"\0"))
506 strcat(reason, remainingTokens);
512 int32 exitCode = defaultExitCode;
524 sWorld->ShutdownServ(delay, shutdownMask,
static_cast<uint8>(exitCode), std::string(reason));
char const * localeNames[TOTAL_LOCALES]
std::shared_ptr< ResultSet > QueryResult
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
@ LANG_SHUTDOWN_CANCELLED
Role Based Access Control related classes definition.
WorldUpdateTime sWorldUpdateTime
std::string secsToTimeString(uint64 timeInSecs, TimeFormat timeFormat, bool hoursOnly)
uint32 TimeStringToSecs(std::string const ×tring)
bool isNumeric(wchar_t wchar)
WorldSession * GetSession()
void SetSentErrorMessage(bool val)
void PSendSysMessage(char const *fmt, Args &&... args)
virtual void SendSysMessage(std::string_view str, bool escapeCharacters=false)
uint32 GetLastUpdateTime() const
bool isHeightCalcEnabled() const
bool isLineOfSightCalcEnabled() const
static VMapManager2 * createOrGetVMapManager()
Player session in the World.
std::string const & GetRemoteAddress() const
static void StopNow(uint8 exitcode)
static bool ShutdownServer(ChatHandler *handler, char const *args, uint32 shutdownMask, int32 defaultExitCode)
static bool HandleServerForceShutDownCommand(ChatHandler *handler, char const *args)
static bool HandleServerDebugCommand(ChatHandler *handler, char const *)
static bool HandleServerSetMotdCommand(ChatHandler *handler, char const *args)
static bool HandleServerExitCommand(ChatHandler *handler, char const *)
static bool HandleServerCorpsesCommand(ChatHandler *, char const *)
static bool HandleServerShutDownCommand(ChatHandler *handler, char const *args)
static bool HandleServerForceRestartCommand(ChatHandler *handler, char const *args)
static bool HandleServerPLimitCommand(ChatHandler *handler, char const *args)
static bool HandleServerIdleShutDownCommand(ChatHandler *handler, char const *args)
static bool HandleServerSetLogLevelCommand(ChatHandler *, std::string const &type, std::string const &name, int32 level)
std::vector< ChatCommand > GetCommands() const override
static bool HandleServerMotdCommand(ChatHandler *handler, char const *)
static bool IsOnlyUser(WorldSession *mySession)
static bool HandleServerRestartCommand(ChatHandler *handler, char const *args)
static bool HandleServerIdleRestartCommand(ChatHandler *handler, char const *args)
static bool HandleServerSetClosedCommand(ChatHandler *handler, char const *args)
static bool ParseExitCode(char const *exitCodeStr, int32 &exitCode)
static bool HandleServerInfoCommand(ChatHandler *handler, char const *)
static bool HandleServerShutDownCancelCommand(ChatHandler *handler, char const *)
void AddSC_server_commandscript()
std::unordered_map< uint32, WorldSession * > SessionMap
@ CONFIG_FORCE_SHUTDOWN_THRESHOLD
@ CONFIG_VMAP_INDOOR_CHECK
uint32 GetUptime()
Uptime (in secs)
TC_COMMON_API char const * GetCMakeVersion()
TC_COMMON_API char const * GetHostOSVersion()
TC_COMMON_API char const * GetFullVersion()
TC_DATABASE_API uint32 GetLibraryVersion()
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default TC string format function.
@ RBAC_PERM_COMMAND_SERVER_SHUTDOWN_FORCE
@ RBAC_PERM_COMMAND_SERVER_SHUTDOWN
@ RBAC_PERM_COMMAND_SERVER_SET_LOGLEVEL
@ RBAC_PERM_COMMAND_SERVER_RESTART_CANCEL
@ RBAC_PERM_COMMAND_SERVER_SET
@ RBAC_PERM_COMMAND_SERVER_EXIT
@ RBAC_PERM_COMMAND_SERVER_RESTART
@ RBAC_PERM_COMMAND_SERVER_PLIMIT
@ RBAC_PERM_COMMAND_SERVER_IDLESHUTDOWN_CANCEL
@ RBAC_PERM_COMMAND_SERVER_SHUTDOWN_CANCEL
@ RBAC_PERM_COMMAND_SERVER_IDLERESTART_CANCEL
@ RBAC_PERM_COMMAND_SERVER
@ RBAC_PERM_COMMAND_SERVER_MOTD
@ RBAC_PERM_COMMAND_SERVER_SET_CLOSED
@ RBAC_PERM_COMMAND_SERVER_SET_MOTD
@ RBAC_PERM_COMMAND_SERVER_INFO
@ RBAC_PERM_COMMAND_SERVER_IDLERESTART
@ RBAC_PERM_COMMAND_SERVER_RESTART_FORCE
@ RBAC_PERM_COMMAND_SERVER_IDLESHUTDOWN
@ RBAC_PERM_COMMAND_SERVER_DEBUG
@ RBAC_PERM_COMMAND_SERVER_CORPSES