Scripts/Commands: implemented command .server debug

- Shows detailed information about server setup, useful when reporting a bug:
 * rev. hash
 * versions of mysql, openssl, boost, cmake
 * info about autoupdater
 * info about ports (realmlist and current)
 * vmap/map/mmap status and folder sizes
 * available DBC locales
 * TDB version

Closes #19957
This commit is contained in:
ariel-
2018-03-06 18:48:57 -03:00
parent 272e000e89
commit d18f8b94b0
8 changed files with 171 additions and 3 deletions

View File

@@ -38,6 +38,16 @@ char const* GitRevision::GetCMakeCommand()
return _CMAKE_COMMAND;
}
char const* GitRevision::GetCMakeVersion()
{
return _CMAKE_VERSION;
}
char const* GitRevision::GetHostOSVersion()
{
return _CMAKE_HOST_SYSTEM;
}
char const* GitRevision::GetBuildDirectory()
{
return _BUILD_DIRECTORY;

View File

@@ -26,6 +26,8 @@ namespace GitRevision
TC_COMMON_API char const* GetDate();
TC_COMMON_API char const* GetBranch();
TC_COMMON_API char const* GetCMakeCommand();
TC_COMMON_API char const* GetCMakeVersion();
TC_COMMON_API char const* GetHostOSVersion();
TC_COMMON_API char const* GetBuildDirectory();
TC_COMMON_API char const* GetSourceDirectory();
TC_COMMON_API char const* GetMySQLExecutable();

View File

@@ -777,6 +777,7 @@ enum RBACPermissions
RBAC_PERM_COMMAND_DEBUG_SEND_PLAYER_CHOICE = 869, // reserved
RBAC_PERM_COMMAND_DEBUG_THREATINFO = 870,
RBAC_PERM_COMMAND_DEBUG_INSTANCESPAWN = 871,
RBAC_PERM_COMMAND_SERVER_DEBUG = 872,
//
// IF YOU ADD NEW PERMISSIONS, ADD THEM IN MASTER BRANCH AS WELL!
//

View File

@@ -25,6 +25,8 @@ EndScriptData */
#include "ScriptMgr.h"
#include "Chat.h"
#include "Config.h"
#include "DatabaseEnv.h"
#include "DatabaseLoader.h"
#include "GameTime.h"
#include "GitRevision.h"
#include "Language.h"
@@ -32,12 +34,21 @@ EndScriptData */
#include "ObjectAccessor.h"
#include "Player.h"
#include "RBAC.h"
#include "Realm.h"
#include "ServerMotd.h"
#include "UpdateTime.h"
#include "Util.h"
#include "VMapFactory.h"
#include "World.h"
#include "WorldSession.h"
#include <numeric>
#include <boost/filesystem.hpp>
#include <mysql_version.h>
#include <openssl/crypto.h>
#include <openssl/opensslv.h>
class server_commandscript : public CommandScript
{
public:
@@ -82,6 +93,7 @@ public:
static std::vector<ChatCommand> serverCommandTable =
{
{ "corpses", rbac::RBAC_PERM_COMMAND_SERVER_CORPSES, true, &HandleServerCorpsesCommand, "" },
{ "debug", rbac::RBAC_PERM_COMMAND_SERVER_DEBUG, true, &HandleServerDebugCommand, "" },
{ "exit", rbac::RBAC_PERM_COMMAND_SERVER_EXIT, true, &HandleServerExitCommand, "" },
{ "idlerestart", rbac::RBAC_PERM_COMMAND_SERVER_IDLERESTART, true, nullptr, "", serverIdleRestartCommandTable },
{ "idleshutdown", rbac::RBAC_PERM_COMMAND_SERVER_IDLESHUTDOWN, true, nullptr, "", serverIdleShutdownCommandTable },
@@ -107,6 +119,136 @@ public:
return true;
}
static bool HandleServerDebugCommand(ChatHandler* handler, char const* /*args*/)
{
uint16 worldPort = uint16(sWorld->getIntConfig(CONFIG_PORT_WORLD));
std::string dbPortOutput;
{
uint16 dbPort = 0;
if (QueryResult res = LoginDatabase.PQuery("SELECT port FROM realmlist WHERE id = %u", realm.Id.Realm))
dbPort = (*res)[0].GetUInt16();
if (dbPort)
dbPortOutput = Trinity::StringFormat("Realmlist (Realm Id: %u) configured in port %" PRIu16, realm.Id.Realm, dbPort);
else
dbPortOutput = Trinity::StringFormat("Realm Id: %u not found in `realmlist` table. Please check your setup", realm.Id.Realm);
}
handler->PSendSysMessage("%s", GitRevision::GetFullVersion());
handler->PSendSysMessage("Using SSL version: %s (library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
handler->PSendSysMessage("Using Boost version: %i.%i.%i", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100);
handler->PSendSysMessage("Using MySQL version: %s", MYSQL_SERVER_VERSION);
handler->PSendSysMessage("Using CMake version: %s", GitRevision::GetCMakeVersion());
handler->PSendSysMessage("Compiled on: %s", GitRevision::GetHostOSVersion());
uint32 updateFlags = sConfigMgr->GetIntDefault("Updates.EnableDatabases", DatabaseLoader::DATABASE_NONE);
if (!updateFlags)
handler->SendSysMessage("Automatic database updates are disabled for all databases!");
else
{
static char const* const databaseNames[3 /*TOTAL_DATABASES*/] =
{
"Auth",
"Characters",
"World"
};
std::string availableUpdateDatabases;
for (uint32 i = 0; i < 3 /* TOTAL_DATABASES*/; ++i)
{
if (!(updateFlags & (1 << i)))
continue;
availableUpdateDatabases += databaseNames[i];
if (i != 3 /*TOTAL_DATABASES*/ - 1)
availableUpdateDatabases += ", ";
}
handler->PSendSysMessage("Automatic database updates are enabled for the following databases: %s", availableUpdateDatabases.c_str());
}
handler->PSendSysMessage("Worldserver listening connections on port %" PRIu16, worldPort);
handler->PSendSysMessage("%s", dbPortOutput.c_str());
bool vmapIndoorCheck = sWorld->getBoolConfig(CONFIG_VMAP_INDOOR_CHECK);
bool vmapLOSCheck = VMAP::VMapFactory::createOrGetVMapManager()->isLineOfSightCalcEnabled();
bool vmapHeightCheck = VMAP::VMapFactory::createOrGetVMapManager()->isHeightCalcEnabled();
bool mmapEnabled = sWorld->getBoolConfig(CONFIG_ENABLE_MMAPS);
std::string dataDir = sWorld->GetDataPath();
std::vector<std::string> subDirs;
subDirs.emplace_back("maps");
if (vmapIndoorCheck || vmapLOSCheck || vmapHeightCheck)
{
handler->PSendSysMessage("VMAPs status: Enabled. LineOfSight: %i, getHeight: %i, indoorCheck: %i", vmapLOSCheck, vmapHeightCheck, vmapIndoorCheck);
subDirs.emplace_back("vmaps");
}
else
handler->SendSysMessage("VMAPs status: Disabled");
if (mmapEnabled)
{
handler->SendSysMessage("MMAPs status: Enabled");
subDirs.emplace_back("mmaps");
}
else
handler->SendSysMessage("MMAPs status: Disabled");
for (std::string const& subDir : subDirs)
{
boost::filesystem::path mapPath(dataDir);
mapPath.append(subDir);
if (!boost::filesystem::exists(mapPath))
{
handler->PSendSysMessage("%s directory doesn't exist!. Using path: %s", subDir.c_str(), mapPath.generic_string().c_str());
continue;
}
auto end = boost::filesystem::directory_iterator();
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)
{
if (boost::filesystem::is_regular_file(mapFile))
val += boost::filesystem::file_size(mapFile);
return val;
});
handler->PSendSysMessage("%s directory located in %s. Total size: " SZFMTD " bytes", subDir.c_str(), mapPath.generic_string().c_str(), folderSize);
}
LocaleConstant defaultLocale = sWorld->GetDefaultDbcLocale();
uint32 availableLocalesMask = (1 << defaultLocale);
for (uint8 i = 0; i < TOTAL_LOCALES; ++i)
{
LocaleConstant locale = static_cast<LocaleConstant>(i);
if (locale == defaultLocale)
continue;
if (sWorld->GetAvailableDbcLocale(locale) != defaultLocale)
availableLocalesMask |= (1 << locale);
}
std::string availableLocales;
for (uint8 i = 0; i < TOTAL_LOCALES; ++i)
{
if (!(availableLocalesMask & (1 << i)))
continue;
availableLocales += localeNames[i];
if (i != TOTAL_LOCALES - 1)
availableLocales += " ";
}
handler->PSendSysMessage("Using %s DBC Locale as default. All available DBC locales: %s", localeNames[defaultLocale], availableLocales.c_str());
handler->PSendSysMessage("Using World DB: %s", sWorld->GetDBVersion());
return true;
}
static bool HandleServerInfoCommand(ChatHandler* handler, char const* /*args*/)
{
uint32 playersNum = sWorld->GetPlayerCount();
@@ -118,7 +260,7 @@ public:
std::string uptime = secsToTimeString(GameTime::GetUptime());
uint32 updateTime = sWorldUpdateTime.GetLastUpdateTime();
handler->SendSysMessage(GitRevision::GetFullVersion());
handler->PSendSysMessage("%s", GitRevision::GetFullVersion());
handler->PSendSysMessage(LANG_CONNECTED_PLAYERS, playersNum, maxPlayersNum);
handler->PSendSysMessage(LANG_CONNECTED_USERS, activeClientsNum, maxActiveClientsNum, queuedClientsNum, maxQueuedClientsNum);
handler->PSendSysMessage(LANG_UPTIME, uptime.c_str());