mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-21 17:54:48 +01:00
Core: header cleanup, split realmlist, boost compatibility, cotire, remove stormlib/zlib and stormlib/bzip2 and instead use dep sources
This commit is contained in:
@@ -21,39 +21,48 @@
|
||||
/// \file
|
||||
|
||||
#include "Common.h"
|
||||
#include "Commands.h"
|
||||
#include "ZmqContext.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "AppenderDB.h"
|
||||
#include "AsyncAcceptor.h"
|
||||
#include "RASession.h"
|
||||
#include "Configuration/Config.h"
|
||||
#include "OpenSSLCrypto.h"
|
||||
#include "ProcessPriority.h"
|
||||
#include "Banner.h"
|
||||
#include "BattlegroundMgr.h"
|
||||
#include "BattlenetServerManager.h"
|
||||
#include "BigNumber.h"
|
||||
#include "World.h"
|
||||
#include "MapManager.h"
|
||||
#include "CliRunnable.h"
|
||||
#include "Configuration/Config.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "DatabaseLoader.h"
|
||||
#include "GitRevision.h"
|
||||
#include "InstanceSaveMgr.h"
|
||||
#include "IoContext.h"
|
||||
#include "MapManager.h"
|
||||
#include "Metric.h"
|
||||
#include "MySQLThreading.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "OpenSSLCrypto.h"
|
||||
#include "OutdoorPvP/OutdoorPvPMgr.h"
|
||||
#include "ProcessPriority.h"
|
||||
#include "RASession.h"
|
||||
#include "Resolver.h"
|
||||
#include "ScriptLoader.h"
|
||||
#include "ScriptMgr.h"
|
||||
#include "ScriptReloadMgr.h"
|
||||
#include "ScriptLoader.h"
|
||||
#include "OutdoorPvP/OutdoorPvPMgr.h"
|
||||
#include "BattlegroundMgr.h"
|
||||
#include "TCSoap.h"
|
||||
#include "CliRunnable.h"
|
||||
#include "GitRevision.h"
|
||||
#include "World.h"
|
||||
#include "WorldSocket.h"
|
||||
#include "WorldSocketMgr.h"
|
||||
#include "BattlenetServerManager.h"
|
||||
#include "DatabaseLoader.h"
|
||||
#include "AppenderDB.h"
|
||||
#include "Metric.h"
|
||||
#include "ZmqContext.h"
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <boost/asio/deadline_timer.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/asio/signal_set.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <csignal>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef _WIN32 // ugly as hell
|
||||
#pragma comment(lib, "iphlpapi.lib")
|
||||
#endif
|
||||
|
||||
using namespace boost::program_options;
|
||||
namespace fs = boost::filesystem;
|
||||
@@ -81,8 +90,8 @@ int m_ServiceStatus = -1;
|
||||
class FreezeDetector
|
||||
{
|
||||
public:
|
||||
FreezeDetector(boost::asio::io_service& ioService, uint32 maxCoreStuckTime)
|
||||
: _timer(ioService), _worldLoopCounter(0), _lastChangeMsTime(0), _maxCoreStuckTimeInMs(maxCoreStuckTime) { }
|
||||
FreezeDetector(Trinity::Asio::IoContext& ioContext, uint32 maxCoreStuckTime)
|
||||
: _timer(ioContext), _worldLoopCounter(0), _lastChangeMsTime(0), _maxCoreStuckTimeInMs(maxCoreStuckTime) { }
|
||||
|
||||
static void Start(std::shared_ptr<FreezeDetector> const& freezeDetector)
|
||||
{
|
||||
@@ -101,13 +110,13 @@ class FreezeDetector
|
||||
|
||||
void SignalHandler(boost::system::error_code const& error, int signalNumber);
|
||||
|
||||
AsyncAcceptor* StartRaSocketAcceptor(boost::asio::io_service& ioService);
|
||||
AsyncAcceptor* StartRaSocketAcceptor(Trinity::Asio::IoContext& ioContext);
|
||||
bool StartDB();
|
||||
void StopDB();
|
||||
void WorldUpdateLoop();
|
||||
void ClearOnlineAccounts();
|
||||
void ShutdownCLIThread(std::thread* cliThread);
|
||||
bool LoadRealmInfo(boost::asio::io_service& ioService);
|
||||
bool LoadRealmInfo(Trinity::Asio::IoContext& ioContext);
|
||||
variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, std::string& cfg_service);
|
||||
|
||||
/// Launch the Trinity server
|
||||
@@ -141,26 +150,24 @@ extern int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::shared_ptr<boost::asio::io_service> ioService = std::make_shared<boost::asio::io_service>();
|
||||
std::shared_ptr<Trinity::Asio::IoContext> ioContext = std::make_shared<Trinity::Asio::IoContext>();
|
||||
|
||||
sLog->RegisterAppender<AppenderDB>();
|
||||
// If logs are supposed to be handled async then we need to pass the io_service into the Log singleton
|
||||
sLog->Initialize(sConfigMgr->GetBoolDefault("Log.Async.Enable", false) ? ioService.get() : nullptr);
|
||||
// If logs are supposed to be handled async then we need to pass the IoContext into the Log singleton
|
||||
sLog->Initialize(sConfigMgr->GetBoolDefault("Log.Async.Enable", false) ? ioContext.get() : nullptr);
|
||||
|
||||
TC_LOG_INFO("server.worldserver", "%s (worldserver-daemon)", GitRevision::GetFullVersion());
|
||||
TC_LOG_INFO("server.worldserver", "<Ctrl-C> to stop.\n");
|
||||
TC_LOG_INFO("server.worldserver", " ______ __");
|
||||
TC_LOG_INFO("server.worldserver", "/\\__ _\\ __ __/\\ \\__");
|
||||
TC_LOG_INFO("server.worldserver", "\\/_/\\ \\/ _ __ /\\_\\ ___ /\\_\\ \\, _\\ __ __");
|
||||
TC_LOG_INFO("server.worldserver", " \\ \\ \\/\\`'__\\/\\ \\ /' _ `\\/\\ \\ \\ \\/ /\\ \\/\\ \\");
|
||||
TC_LOG_INFO("server.worldserver", " \\ \\ \\ \\ \\/ \\ \\ \\/\\ \\/\\ \\ \\ \\ \\ \\_\\ \\ \\_\\ \\");
|
||||
TC_LOG_INFO("server.worldserver", " \\ \\_\\ \\_\\ \\ \\_\\ \\_\\ \\_\\ \\_\\ \\__\\\\/`____ \\");
|
||||
TC_LOG_INFO("server.worldserver", " \\/_/\\/_/ \\/_/\\/_/\\/_/\\/_/\\/__/ `/___/> \\");
|
||||
TC_LOG_INFO("server.worldserver", " C O R E /\\___/");
|
||||
TC_LOG_INFO("server.worldserver", "http://TrinityCore.org \\/__/\n");
|
||||
TC_LOG_INFO("server.worldserver", "Using configuration file %s.", sConfigMgr->GetFilename().c_str());
|
||||
TC_LOG_INFO("server.worldserver", "Using SSL version: %s (library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
|
||||
TC_LOG_INFO("server.worldserver", "Using Boost version: %i.%i.%i", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100);
|
||||
Trinity::Banner::Show("worldserver-daemon",
|
||||
[](char const* text)
|
||||
{
|
||||
TC_LOG_INFO("server.worldserver", "%s", text);
|
||||
},
|
||||
[]()
|
||||
{
|
||||
TC_LOG_INFO("server.worldserver", "Using configuration file %s.", sConfigMgr->GetFilename().c_str());
|
||||
TC_LOG_INFO("server.worldserver", "Using SSL version: %s (library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
|
||||
TC_LOG_INFO("server.worldserver", "Using Boost version: %i.%i.%i", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100);
|
||||
}
|
||||
);
|
||||
|
||||
OpenSSLCrypto::threadsSetup();
|
||||
|
||||
@@ -184,8 +191,8 @@ extern int main(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
|
||||
// Set signal handlers (this must be done before starting io_service threads, because otherwise they would unblock and exit)
|
||||
boost::asio::signal_set signals(*ioService, SIGINT, SIGTERM);
|
||||
// Set signal handlers (this must be done before starting IoContext threads, because otherwise they would unblock and exit)
|
||||
boost::asio::signal_set signals(*ioContext, SIGINT, SIGTERM);
|
||||
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
|
||||
signals.add(SIGBREAK);
|
||||
#endif
|
||||
@@ -193,9 +200,9 @@ extern int main(int argc, char** argv)
|
||||
|
||||
// Start the Boost based thread pool
|
||||
int numThreads = sConfigMgr->GetIntDefault("ThreadPool", 1);
|
||||
std::shared_ptr<std::vector<std::thread>> threadPool(new std::vector<std::thread>(), [ioService](std::vector<std::thread>* del)
|
||||
std::shared_ptr<std::vector<std::thread>> threadPool(new std::vector<std::thread>(), [ioContext](std::vector<std::thread>* del)
|
||||
{
|
||||
ioService->stop();
|
||||
ioContext->stop();
|
||||
for (std::thread& thr : *del)
|
||||
thr.join();
|
||||
|
||||
@@ -206,10 +213,10 @@ extern int main(int argc, char** argv)
|
||||
numThreads = 1;
|
||||
|
||||
for (int i = 0; i < numThreads; ++i)
|
||||
threadPool->push_back(std::thread([ioService]() { ioService->run(); }));
|
||||
threadPool->push_back(std::thread([ioContext]() { ioContext->run(); }));
|
||||
|
||||
// Set process priority according to configuration settings
|
||||
SetProcessPriority("server.worldserver");
|
||||
SetProcessPriority("server.worldserver", sConfigMgr->GetIntDefault(CONFIG_PROCESSOR_AFFINITY, 0), sConfigMgr->GetBoolDefault(CONFIG_HIGH_PRIORITY, false));
|
||||
|
||||
// Start the databases
|
||||
if (!StartDB())
|
||||
@@ -220,9 +227,9 @@ extern int main(int argc, char** argv)
|
||||
// Set server offline (not connectable)
|
||||
LoginDatabase.DirectPExecute("UPDATE realmlist SET flag = flag | %u WHERE id = '%d'", REALM_FLAG_OFFLINE, realm.Id.Realm);
|
||||
|
||||
LoadRealmInfo(*ioService);
|
||||
LoadRealmInfo(*ioContext);
|
||||
|
||||
sMetric->Initialize(realm.Name, *ioService, []()
|
||||
sMetric->Initialize(realm.Name, *ioContext, []()
|
||||
{
|
||||
TC_METRIC_VALUE("online_players", sWorld->GetPlayerCount());
|
||||
});
|
||||
@@ -258,7 +265,7 @@ extern int main(int argc, char** argv)
|
||||
// Start the Remote Access port (acceptor) if enabled
|
||||
std::unique_ptr<AsyncAcceptor> raAcceptor;
|
||||
if (sConfigMgr->GetBoolDefault("Ra.Enable", false))
|
||||
raAcceptor.reset(StartRaSocketAcceptor(*ioService));
|
||||
raAcceptor.reset(StartRaSocketAcceptor(*ioContext));
|
||||
|
||||
// Start soap serving thread if enabled
|
||||
std::shared_ptr<std::thread> soapThread;
|
||||
@@ -284,7 +291,7 @@ extern int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!sWorldSocketMgr.StartNetwork(*ioService, worldListener, worldPort, networkThreads))
|
||||
if (!sWorldSocketMgr.StartWorldNetwork(*ioContext, worldListener, worldPort, networkThreads))
|
||||
{
|
||||
TC_LOG_ERROR("server.worldserver", "Failed to initialize network");
|
||||
return 1;
|
||||
@@ -321,7 +328,7 @@ extern int main(int argc, char** argv)
|
||||
std::shared_ptr<FreezeDetector> freezeDetector;
|
||||
if (int coreStuckTime = sConfigMgr->GetIntDefault("MaxCoreStuckTime", 0))
|
||||
{
|
||||
freezeDetector = std::make_shared<FreezeDetector>(*ioService, coreStuckTime * 1000);
|
||||
freezeDetector = std::make_shared<FreezeDetector>(*ioContext, coreStuckTime * 1000);
|
||||
FreezeDetector::Start(freezeDetector);
|
||||
TC_LOG_INFO("server.worldserver", "Starting up anti-freeze thread (%u seconds max stuck time)...", coreStuckTime);
|
||||
}
|
||||
@@ -485,12 +492,12 @@ void FreezeDetector::Handler(std::weak_ptr<FreezeDetector> freezeDetectorRef, bo
|
||||
}
|
||||
}
|
||||
|
||||
AsyncAcceptor* StartRaSocketAcceptor(boost::asio::io_service& ioService)
|
||||
AsyncAcceptor* StartRaSocketAcceptor(Trinity::Asio::IoContext& ioContext)
|
||||
{
|
||||
uint16 raPort = uint16(sConfigMgr->GetIntDefault("Ra.Port", 3443));
|
||||
std::string raListener = sConfigMgr->GetStringDefault("Ra.IP", "0.0.0.0");
|
||||
|
||||
AsyncAcceptor* acceptor = new AsyncAcceptor(ioService, raListener, raPort);
|
||||
AsyncAcceptor* acceptor = new AsyncAcceptor(ioContext, raListener, raPort);
|
||||
if (!acceptor->Bind())
|
||||
{
|
||||
TC_LOG_ERROR("server.worldserver", "Failed to bind RA socket acceptor");
|
||||
@@ -502,48 +509,42 @@ AsyncAcceptor* StartRaSocketAcceptor(boost::asio::io_service& ioService)
|
||||
return acceptor;
|
||||
}
|
||||
|
||||
bool LoadRealmInfo(boost::asio::io_service& ioService)
|
||||
bool LoadRealmInfo(Trinity::Asio::IoContext& ioContext)
|
||||
{
|
||||
boost::asio::ip::tcp::resolver resolver(ioService);
|
||||
boost::asio::ip::tcp::resolver::iterator end;
|
||||
|
||||
QueryResult result = LoginDatabase.PQuery("SELECT id, name, address, localAddress, localSubnetMask, port, icon, flag, timezone, allowedSecurityLevel, population, gamebuild FROM realmlist WHERE id = %u", realm.Id.Realm);
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
boost::asio::ip::tcp::resolver resolver(ioContext);
|
||||
|
||||
Field* fields = result->Fetch();
|
||||
realm.Name = fields[1].GetString();
|
||||
boost::asio::ip::tcp::resolver::query externalAddressQuery(boost::asio::ip::tcp::v4(), fields[2].GetString(), "");
|
||||
|
||||
boost::system::error_code ec;
|
||||
boost::asio::ip::tcp::resolver::iterator endPoint = resolver.resolve(externalAddressQuery, ec);
|
||||
if (endPoint == end || ec)
|
||||
Optional<boost::asio::ip::tcp::endpoint> externalAddress = Trinity::Net::Resolve(resolver, boost::asio::ip::tcp::v4(), fields[2].GetString(), "");
|
||||
if (!externalAddress)
|
||||
{
|
||||
TC_LOG_ERROR("server.worldserver", "Could not resolve address %s", fields[2].GetString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
realm.ExternalAddress = (*endPoint).endpoint().address();
|
||||
realm.ExternalAddress = Trinity::make_unique<boost::asio::ip::address>(externalAddress->address());
|
||||
|
||||
boost::asio::ip::tcp::resolver::query localAddressQuery(boost::asio::ip::tcp::v4(), fields[3].GetString(), "");
|
||||
endPoint = resolver.resolve(localAddressQuery, ec);
|
||||
if (endPoint == end || ec)
|
||||
Optional<boost::asio::ip::tcp::endpoint> localAddress = Trinity::Net::Resolve(resolver, boost::asio::ip::tcp::v4(), fields[3].GetString(), "");
|
||||
if (!localAddress)
|
||||
{
|
||||
TC_LOG_ERROR("server.worldserver", "Could not resolve address %s", fields[3].GetString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
realm.LocalAddress = (*endPoint).endpoint().address();
|
||||
realm.LocalAddress = Trinity::make_unique<boost::asio::ip::address>(localAddress->address());
|
||||
|
||||
boost::asio::ip::tcp::resolver::query localSubmaskQuery(boost::asio::ip::tcp::v4(), fields[4].GetString(), "");
|
||||
endPoint = resolver.resolve(localSubmaskQuery, ec);
|
||||
if (endPoint == end || ec)
|
||||
Optional<boost::asio::ip::tcp::endpoint> localSubmask = Trinity::Net::Resolve(resolver, boost::asio::ip::tcp::v4(), fields[4].GetString(), "");
|
||||
if (!localSubmask)
|
||||
{
|
||||
TC_LOG_ERROR("server.worldserver", "Could not resolve address %s", fields[4].GetString().c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
realm.LocalSubnetMask = (*endPoint).endpoint().address();
|
||||
realm.LocalSubnetMask = Trinity::make_unique<boost::asio::ip::address>(localSubmask->address());
|
||||
|
||||
realm.Port = fields[5].GetUInt16();
|
||||
realm.Type = fields[6].GetUInt8();
|
||||
|
||||
Reference in New Issue
Block a user