mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-23 18:36:31 +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:
@@ -24,26 +24,29 @@
|
||||
* authentication server
|
||||
*/
|
||||
|
||||
#include "AppenderDB.h"
|
||||
#include "Banner.h"
|
||||
#include "BNetRealmList.h"
|
||||
#include "ComponentManager.h"
|
||||
#include "ModuleManager.h"
|
||||
#include "SessionManager.h"
|
||||
#include "Common.h"
|
||||
#include "Config.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "Log.h"
|
||||
#include "DatabaseLoader.h"
|
||||
#include "IoContext.h"
|
||||
#include "MySQLThreading.h"
|
||||
#include "ModuleManager.h"
|
||||
#include "ProcessPriority.h"
|
||||
#include "RealmList.h"
|
||||
#include "GitRevision.h"
|
||||
#include "SessionManager.h"
|
||||
#include "Util.h"
|
||||
#include "ZmqContext.h"
|
||||
#include "DatabaseLoader.h"
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/asio/signal_set.hpp>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <openssl/opensslv.h>
|
||||
#include <openssl/crypto.h>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <csignal>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef _WIN32 // ugly as hell
|
||||
#pragma comment(lib, "iphlpapi.lib")
|
||||
#endif
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
using namespace boost::program_options;
|
||||
@@ -66,28 +69,35 @@ char serviceDescription[] = "TrinityCore Battle.net emulator authentication serv
|
||||
*/
|
||||
int m_ServiceStatus = -1;
|
||||
|
||||
static boost::asio::deadline_timer* _serviceStatusWatchTimer;
|
||||
void ServiceStatusWatcher(boost::system::error_code const& error);
|
||||
void ServiceStatusWatcher(std::weak_ptr<boost::asio::deadline_timer> serviceStatusWatchTimerRef, std::weak_ptr<Trinity::Asio::IoContext> ioContextRef, boost::system::error_code const& error);
|
||||
#endif
|
||||
|
||||
bool StartDB();
|
||||
void StopDB();
|
||||
void SignalHandler(const boost::system::error_code& error, int signalNumber);
|
||||
void KeepDatabaseAliveHandler(const boost::system::error_code& error);
|
||||
variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile);
|
||||
|
||||
boost::asio::io_service _ioService;
|
||||
boost::asio::deadline_timer _dbPingTimer(_ioService);
|
||||
uint32 _dbPingInterval;
|
||||
void SignalHandler(std::weak_ptr<Trinity::Asio::IoContext> ioContextRef, boost::system::error_code const& error, int signalNumber);
|
||||
void KeepDatabaseAliveHandler(std::weak_ptr<boost::asio::deadline_timer> dbPingTimerRef, int32 dbPingInterval, boost::system::error_code const& error);
|
||||
variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, std::string& configService);
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
signal(SIGABRT, &Trinity::AbortHandler);
|
||||
|
||||
auto configFile = fs::absolute(_TRINITY_BNET_CONFIG);
|
||||
auto vm = GetConsoleArguments(argc, argv, configFile);
|
||||
std::string configService;
|
||||
auto vm = GetConsoleArguments(argc, argv, configFile, configService);
|
||||
// exit if help is enabled
|
||||
if (vm.count("help"))
|
||||
return 0;
|
||||
|
||||
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
|
||||
if (configService.compare("install") == 0)
|
||||
return WinServiceInstall() ? 0 : 1;
|
||||
else if (configService.compare("uninstall") == 0)
|
||||
return WinServiceUninstall() ? 0 : 1;
|
||||
else if (configService.compare("run") == 0)
|
||||
return WinServiceRun() ? 0 : 1;
|
||||
#endif
|
||||
|
||||
std::string configError;
|
||||
if (!sConfigMgr->LoadInitial(configFile.generic_string(),
|
||||
std::vector<std::string>(argv, argv + argc),
|
||||
@@ -97,11 +107,26 @@ int main(int argc, char** argv)
|
||||
return 1;
|
||||
}
|
||||
|
||||
TC_LOG_INFO("server.bnetserver", "%s (bnetserver)", GitRevision::GetFullVersion());
|
||||
TC_LOG_INFO("server.bnetserver", "<Ctrl-C> to stop.\n");
|
||||
TC_LOG_INFO("server.bnetserver", "Using configuration file %s.", sConfigMgr->GetFilename().c_str());
|
||||
TC_LOG_INFO("server.bnetserver", "Using SSL version: %s (library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
|
||||
TC_LOG_INFO("server.bnetserver", "Using Boost version: %i.%i.%i", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100);
|
||||
sLog->RegisterAppender<AppenderDB>();
|
||||
sLog->Initialize(nullptr);
|
||||
|
||||
Trinity::Banner::Show("bnetserver",
|
||||
[](char const* text)
|
||||
{
|
||||
TC_LOG_INFO("server.bnetserver", "%s", text);
|
||||
},
|
||||
[]()
|
||||
{
|
||||
TC_LOG_INFO("server.bnetserver", "Using configuration file %s.", sConfigMgr->GetFilename().c_str());
|
||||
TC_LOG_INFO("server.bnetserver", "Using SSL version: %s (library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));
|
||||
TC_LOG_INFO("server.bnetserver", "Using Boost version: %i.%i.%i", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100);
|
||||
}
|
||||
);
|
||||
|
||||
// Seed the OpenSSL's PRNG here.
|
||||
// That way it won't auto-seed when calling BigNumber::SetRand and slow down the first world login
|
||||
BigNumber seed;
|
||||
seed.SetRand(16 * 8);
|
||||
|
||||
// bnetserver PID file creation
|
||||
std::string pidFile = sConfigMgr->GetStringDefault("PidFile", "");
|
||||
@@ -127,53 +152,77 @@ int main(int argc, char** argv)
|
||||
if (!StartDB())
|
||||
return 1;
|
||||
|
||||
sIpcContext->Initialize();
|
||||
std::shared_ptr<void> dbHandle(nullptr, [](void*) { StopDB(); });
|
||||
|
||||
// Get the list of realms for the server
|
||||
sRealmList->Initialize(_ioService, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 10), worldListenPort);
|
||||
sIpcContext->Initialize();
|
||||
std::shared_ptr<void> ipcHandle(nullptr, [](void*) { sIpcContext->Close(); });
|
||||
|
||||
std::shared_ptr<Trinity::Asio::IoContext> ioContext = std::make_unique<Trinity::Asio::IoContext>();
|
||||
|
||||
// Start the listening port (acceptor) for auth connections
|
||||
int32 bnport = sConfigMgr->GetIntDefault("BattlenetPort", 1119);
|
||||
if (bnport < 0 || bnport > 0xFFFF)
|
||||
{
|
||||
TC_LOG_ERROR("server.bnetserver", "Specified battle.net port (%d) out of allowed range (1-65535)", bnport);
|
||||
StopDB();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get the list of realms for the server
|
||||
sBNetRealmList->Initialize(*ioContext, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 10), worldListenPort);
|
||||
|
||||
std::shared_ptr<void> sBNetRealmListHandle(nullptr, [](void*) { sBNetRealmList->Close(); });
|
||||
|
||||
std::string bindIp = sConfigMgr->GetStringDefault("BindIP", "0.0.0.0");
|
||||
|
||||
sSessionMgr.StartNetwork(_ioService, bindIp, bnport);
|
||||
if (!sSessionMgr.StartNetwork(*ioContext, bindIp, bnport))
|
||||
{
|
||||
TC_LOG_ERROR("server.bnetserver", "Failed to initialize network");
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::shared_ptr<void> sSessionMgrHandle(nullptr, [](void*) { sSessionMgr.StopNetwork(); });
|
||||
|
||||
// Set signal handlers
|
||||
boost::asio::signal_set signals(_ioService, SIGINT, SIGTERM);
|
||||
boost::asio::signal_set signals(*ioContext, SIGINT, SIGTERM);
|
||||
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
|
||||
signals.add(SIGBREAK);
|
||||
#endif
|
||||
signals.async_wait(SignalHandler);
|
||||
signals.async_wait(std::bind(&SignalHandler, std::weak_ptr<Trinity::Asio::IoContext>(ioContext), std::placeholders::_1, std::placeholders::_2));
|
||||
|
||||
// Set process priority according to configuration settings
|
||||
SetProcessPriority("server.bnetserver");
|
||||
SetProcessPriority("server.bnetserver", sConfigMgr->GetIntDefault(CONFIG_PROCESSOR_AFFINITY, 0), sConfigMgr->GetBoolDefault(CONFIG_HIGH_PRIORITY, false));
|
||||
|
||||
// Enabled a timed callback for handling the database keep alive ping
|
||||
_dbPingInterval = sConfigMgr->GetIntDefault("MaxPingTime", 30);
|
||||
_dbPingTimer.expires_from_now(boost::posix_time::minutes(_dbPingInterval));
|
||||
_dbPingTimer.async_wait(KeepDatabaseAliveHandler);
|
||||
int32 dbPingInterval = sConfigMgr->GetIntDefault("MaxPingTime", 30);
|
||||
std::shared_ptr<boost::asio::deadline_timer> dbPingTimer = std::make_shared<boost::asio::deadline_timer>(*ioContext);
|
||||
dbPingTimer->expires_from_now(boost::posix_time::minutes(dbPingInterval));
|
||||
dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, std::weak_ptr<boost::asio::deadline_timer>(dbPingTimer), dbPingInterval, std::placeholders::_1));
|
||||
|
||||
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
|
||||
std::shared_ptr<boost::asio::deadline_timer> serviceStatusWatchTimer;
|
||||
if (m_ServiceStatus != -1)
|
||||
{
|
||||
serviceStatusWatchTimer = std::make_shared<boost::asio::deadline_timer>(*ioContext);
|
||||
serviceStatusWatchTimer->expires_from_now(boost::posix_time::seconds(1));
|
||||
serviceStatusWatchTimer->async_wait(std::bind(&ServiceStatusWatcher,
|
||||
std::weak_ptr<boost::asio::deadline_timer>(serviceStatusWatchTimer),
|
||||
std::weak_ptr<Trinity::Asio::IoContext>(ioContext),
|
||||
std::placeholders::_1));
|
||||
}
|
||||
#endif
|
||||
|
||||
sComponentMgr->Load();
|
||||
sModuleMgr->Load();
|
||||
|
||||
// Start the io service worker loop
|
||||
_ioService.run();
|
||||
ioContext->run();
|
||||
|
||||
sIpcContext->Close();
|
||||
|
||||
sRealmList->Close();
|
||||
|
||||
// Close the Database Pool and library
|
||||
StopDB();
|
||||
dbPingTimer->cancel();
|
||||
|
||||
TC_LOG_INFO("server.bnetserver", "Halting process...");
|
||||
|
||||
signals.cancel();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -203,32 +252,67 @@ void StopDB()
|
||||
MySQL::Library_End();
|
||||
}
|
||||
|
||||
void SignalHandler(const boost::system::error_code& error, int /*signalNumber*/)
|
||||
void SignalHandler(std::weak_ptr<Trinity::Asio::IoContext> ioContextRef, boost::system::error_code const& error, int /*signalNumber*/)
|
||||
{
|
||||
if (!error)
|
||||
_ioService.stop();
|
||||
if (std::shared_ptr<Trinity::Asio::IoContext> ioContext = ioContextRef.lock())
|
||||
ioContext->stop();
|
||||
}
|
||||
|
||||
void KeepDatabaseAliveHandler(const boost::system::error_code& error)
|
||||
void KeepDatabaseAliveHandler(std::weak_ptr<boost::asio::deadline_timer> dbPingTimerRef, int32 dbPingInterval, boost::system::error_code const& error)
|
||||
{
|
||||
if (!error)
|
||||
{
|
||||
TC_LOG_INFO("server.bnetserver", "Ping MySQL to keep connection alive");
|
||||
LoginDatabase.KeepAlive();
|
||||
if (std::shared_ptr<boost::asio::deadline_timer> dbPingTimer = dbPingTimerRef.lock())
|
||||
{
|
||||
TC_LOG_INFO("server.bnetserver", "Ping MySQL to keep connection alive");
|
||||
LoginDatabase.KeepAlive();
|
||||
|
||||
_dbPingTimer.expires_from_now(boost::posix_time::minutes(_dbPingInterval));
|
||||
_dbPingTimer.async_wait(KeepDatabaseAliveHandler);
|
||||
dbPingTimer->expires_from_now(boost::posix_time::minutes(dbPingInterval));
|
||||
dbPingTimer->async_wait(std::bind(&KeepDatabaseAliveHandler, dbPingTimerRef, dbPingInterval, std::placeholders::_1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile)
|
||||
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
|
||||
void ServiceStatusWatcher(std::weak_ptr<boost::asio::deadline_timer> serviceStatusWatchTimerRef, std::weak_ptr<Trinity::Asio::IoContext> ioContextRef, boost::system::error_code const& error)
|
||||
{
|
||||
if (!error)
|
||||
{
|
||||
if (std::shared_ptr<Trinity::Asio::IoContext> ioContext = ioContextRef.lock())
|
||||
{
|
||||
if (m_ServiceStatus == 0)
|
||||
{
|
||||
ioContext->stop();
|
||||
}
|
||||
else if (std::shared_ptr<boost::asio::deadline_timer> serviceStatusWatchTimer = serviceStatusWatchTimerRef.lock())
|
||||
{
|
||||
serviceStatusWatchTimer->expires_from_now(boost::posix_time::seconds(1));
|
||||
serviceStatusWatchTimer->async_wait(std::bind(&ServiceStatusWatcher, serviceStatusWatchTimerRef, ioContext, std::placeholders::_1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, std::string& configService)
|
||||
{
|
||||
(void)configService;
|
||||
|
||||
options_description all("Allowed options");
|
||||
all.add_options()
|
||||
("help,h", "print usage message")
|
||||
("config,c", value<fs::path>(&configFile)->default_value(fs::absolute(_TRINITY_BNET_CONFIG)),
|
||||
"use <arg> as configuration file")
|
||||
;
|
||||
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
|
||||
options_description win("Windows platform specific options");
|
||||
win.add_options()
|
||||
("service,s", value<std::string>(&configService)->default_value(""), "Windows service options: [install | uninstall]")
|
||||
;
|
||||
|
||||
all.add(win);
|
||||
#endif
|
||||
variables_map variablesMap;
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user