aboutsummaryrefslogtreecommitdiff
path: root/src/server/bnetserver
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/bnetserver')
-rw-r--r--src/server/bnetserver/Main.cpp40
-rw-r--r--src/server/bnetserver/REST/LoginRESTService.cpp39
-rw-r--r--src/server/bnetserver/REST/LoginRESTService.h11
-rw-r--r--src/server/bnetserver/Server/SessionManager.cpp4
-rw-r--r--src/server/bnetserver/Server/SessionManager.h2
5 files changed, 48 insertions, 48 deletions
diff --git a/src/server/bnetserver/Main.cpp b/src/server/bnetserver/Main.cpp
index caf9326fbd6..05fef45f918 100644
--- a/src/server/bnetserver/Main.cpp
+++ b/src/server/bnetserver/Main.cpp
@@ -64,12 +64,12 @@ char serviceDescription[] = "TrinityCore Battle.net emulator authentication serv
*/
int m_ServiceStatus = -1;
-void ServiceStatusWatcher(std::weak_ptr<boost::asio::deadline_timer> serviceStatusWatchTimerRef, std::weak_ptr<boost::asio::io_service> ioServiceRef, 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(std::weak_ptr<boost::asio::io_service> ioServiceRef, boost::system::error_code const& error, int signalNumber);
+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);
void BanExpiryHandler(std::weak_ptr<boost::asio::deadline_timer> banExpiryCheckTimerRef, int32 banExpiryCheckInterval, boost::system::error_code const& error);
variables_map GetConsoleArguments(int argc, char** argv, fs::path& configFile, std::string& configService);
@@ -153,7 +153,7 @@ int main(int argc, char** argv)
std::shared_ptr<void> dbHandle(nullptr, [](void*) { StopDB(); });
- 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>();
// Start the listening port (acceptor) for auth connections
int32 bnport = sConfigMgr->GetIntDefault("BattlenetPort", 1119);
@@ -163,7 +163,7 @@ int main(int argc, char** argv)
return 1;
}
- if (!sLoginService.Start(ioService.get()))
+ if (!sLoginService.Start(ioContext.get()))
{
TC_LOG_ERROR("server.bnetserver", "Failed to initialize login service");
return 1;
@@ -172,13 +172,13 @@ int main(int argc, char** argv)
std::shared_ptr<void> sLoginServiceHandle(nullptr, [](void*) { sLoginService.Stop(); });
// Get the list of realms for the server
- sRealmList->Initialize(*ioService, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 10));
+ sRealmList->Initialize(*ioContext, sConfigMgr->GetIntDefault("RealmsStateUpdateDelay", 10));
std::shared_ptr<void> sRealmListHandle(nullptr, [](void*) { sRealmList->Close(); });
std::string bindIp = sConfigMgr->GetStringDefault("BindIP", "0.0.0.0");
- if (!sSessionMgr.StartNetwork(*ioService, bindIp, bnport))
+ if (!sSessionMgr.StartNetwork(*ioContext, bindIp, bnport))
{
TC_LOG_ERROR("server.bnetserver", "Failed to initialize network");
return 1;
@@ -187,23 +187,23 @@ int main(int argc, char** argv)
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(std::bind(&SignalHandler, std::weak_ptr<boost::asio::io_service>(ioService), std::placeholders::_1, std::placeholders::_2));
+ 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", sConfigMgr->GetIntDefault(CONFIG_PROCESSOR_AFFINITY, 0), sConfigMgr->GetBoolDefault(CONFIG_HIGH_PRIORITY, false));
// Enabled a timed callback for handling the database keep alive ping
int32 dbPingInterval = sConfigMgr->GetIntDefault("MaxPingTime", 30);
- std::shared_ptr<boost::asio::deadline_timer> dbPingTimer = std::make_shared<boost::asio::deadline_timer>(*ioService);
+ 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));
int32 banExpiryCheckInterval = sConfigMgr->GetIntDefault("BanExpiryCheckInterval", 60);
- std::shared_ptr<boost::asio::deadline_timer> banExpiryCheckTimer = std::make_shared<boost::asio::deadline_timer>(*ioService);
+ std::shared_ptr<boost::asio::deadline_timer> banExpiryCheckTimer = std::make_shared<boost::asio::deadline_timer>(*ioContext);
banExpiryCheckTimer->expires_from_now(boost::posix_time::seconds(banExpiryCheckInterval));
banExpiryCheckTimer->async_wait(std::bind(&BanExpiryHandler, std::weak_ptr<boost::asio::deadline_timer>(banExpiryCheckTimer), banExpiryCheckInterval, std::placeholders::_1));
@@ -211,17 +211,17 @@ int main(int argc, char** argv)
std::shared_ptr<boost::asio::deadline_timer> serviceStatusWatchTimer;
if (m_ServiceStatus != -1)
{
- serviceStatusWatchTimer = std::make_shared<boost::asio::deadline_timer>(*ioService);
+ 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<boost::asio::io_service>(ioService),
+ std::weak_ptr<Trinity::Asio::IoContext>(ioContext),
std::placeholders::_1));
}
#endif
// Start the io service worker loop
- ioService->run();
+ ioContext->run();
banExpiryCheckTimer->cancel();
dbPingTimer->cancel();
@@ -258,11 +258,11 @@ void StopDB()
MySQL::Library_End();
}
-void SignalHandler(std::weak_ptr<boost::asio::io_service> ioServiceRef, boost::system::error_code const& error, int /*signalNumber*/)
+void SignalHandler(std::weak_ptr<Trinity::Asio::IoContext> ioContextRef, boost::system::error_code const& error, int /*signalNumber*/)
{
if (!error)
- if (std::shared_ptr<boost::asio::io_service> ioService = ioServiceRef.lock())
- ioService->stop();
+ if (std::shared_ptr<Trinity::Asio::IoContext> ioContext = ioContextRef.lock())
+ ioContext->stop();
}
void KeepDatabaseAliveHandler(std::weak_ptr<boost::asio::deadline_timer> dbPingTimerRef, int32 dbPingInterval, boost::system::error_code const& error)
@@ -297,20 +297,20 @@ void BanExpiryHandler(std::weak_ptr<boost::asio::deadline_timer> banExpiryCheckT
}
#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
-void ServiceStatusWatcher(std::weak_ptr<boost::asio::deadline_timer> serviceStatusWatchTimerRef, std::weak_ptr<boost::asio::io_service> ioServiceRef, 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)
{
if (!error)
{
- if (std::shared_ptr<boost::asio::io_service> ioService = ioServiceRef.lock())
+ if (std::shared_ptr<Trinity::Asio::IoContext> ioContext = ioContextRef.lock())
{
if (m_ServiceStatus == 0)
{
- ioService->stop();
+ 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, ioService, std::placeholders::_1));
+ serviceStatusWatchTimer->async_wait(std::bind(&ServiceStatusWatcher, serviceStatusWatchTimerRef, ioContext, std::placeholders::_1));
}
}
}
diff --git a/src/server/bnetserver/REST/LoginRESTService.cpp b/src/server/bnetserver/REST/LoginRESTService.cpp
index 20ca3f1431d..e256c9f10a5 100644
--- a/src/server/bnetserver/REST/LoginRESTService.cpp
+++ b/src/server/bnetserver/REST/LoginRESTService.cpp
@@ -19,8 +19,10 @@
#include "Configuration/Config.h"
#include "DatabaseEnv.h"
#include "Errors.h"
+#include "IpNetwork.h"
#include "ProtobufJSON.h"
#include "Realm.h"
+#include "Resolver.h"
#include "SessionManager.h"
#include "SHA1.h"
#include "SHA256.h"
@@ -69,9 +71,9 @@ int32 handle_post_plugin(soap* soapClient)
return sLoginService.HandleHttpRequest(soapClient, "POST", sLoginService._postHandlers);
}
-bool LoginRESTService::Start(boost::asio::io_service* ioService)
+bool LoginRESTService::Start(Trinity::Asio::IoContext* ioContext)
{
- _ioService = ioService;
+ _ioContext = ioContext;
_bindIP = sConfigMgr->GetStringDefault("BindIP", "0.0.0.0");
_port = sConfigMgr->GetIntDefault("LoginREST.Port", 8081);
if (_port < 0 || _port > 0xFFFF)
@@ -81,30 +83,28 @@ bool LoginRESTService::Start(boost::asio::io_service* ioService)
}
boost::system::error_code ec;
- boost::asio::ip::tcp::resolver resolver(*ioService);
- boost::asio::ip::tcp::resolver::iterator end;
+ boost::asio::ip::tcp::resolver resolver(*ioContext);
std::string configuredAddress = sConfigMgr->GetStringDefault("LoginREST.ExternalAddress", "127.0.0.1");
- boost::asio::ip::tcp::resolver::query externalAddressQuery(boost::asio::ip::tcp::v4(), configuredAddress, std::to_string(_port));
- 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(), configuredAddress, std::to_string(_port));
+ if (!externalAddress)
{
TC_LOG_ERROR("server.rest", "Could not resolve LoginREST.ExternalAddress %s", configuredAddress.c_str());
return false;
}
- _externalAddress = endPoint->endpoint();
+ _externalAddress = *externalAddress;
configuredAddress = sConfigMgr->GetStringDefault("LoginREST.LocalAddress", "127.0.0.1");
- boost::asio::ip::tcp::resolver::query localAddressQuery(boost::asio::ip::tcp::v4(), configuredAddress, std::to_string(_port));
- 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(), configuredAddress, std::to_string(_port));
+ if (!localAddress)
{
- TC_LOG_ERROR("server.rest", "Could not resolve LoginREST.ExternalAddress %s", configuredAddress.c_str());
+ TC_LOG_ERROR("server.rest", "Could not resolve LoginREST.LocalAddress %s", configuredAddress.c_str());
return false;
}
- _localAddress = endPoint->endpoint();
+ _localAddress = *localAddress;
+ _localNetmask = Trinity::Net::GetDefaultNetmaskV4(_localAddress.address().to_v4());
// set up form inputs
Battlenet::JSON::Login::FormInput* input;
@@ -145,8 +145,7 @@ boost::asio::ip::tcp::endpoint const& LoginRESTService::GetAddressForClient(boos
else if (_localAddress.address().is_loopback())
return _externalAddress;
- boost::asio::ip::address_v4 netmask = boost::asio::ip::address_v4::netmask(_localAddress.address().to_v4());
- if ((netmask.to_ulong() & address.to_v4().to_ulong()) == (netmask.to_ulong() & _localAddress.address().to_v4().to_ulong()))
+ if (Trinity::Net::IsInNetwork(_localAddress.address().to_v4(), _localNetmask, address.to_v4()))
return _localAddress;
return _externalAddress;
@@ -205,7 +204,7 @@ void LoginRESTService::Run()
TC_LOG_DEBUG("server.rest", "Accepted connection from IP=%s", boost::asio::ip::address_v4(soapClient->GetClient()->ip).to_string().c_str());
- _ioService->post([soapClient]()
+ Trinity::Asio::post(*_ioContext, [soapClient]()
{
soapClient->GetClient()->user = (void*)&soapClient; // this allows us to make a copy of pointer inside GET/POST handlers to increment reference count
soap_begin(soapClient->GetClient());
@@ -295,7 +294,7 @@ int32 LoginRESTService::HandleGetGameAccounts(std::shared_ptr<AsyncRequest> requ
SendResponse(request->GetClient(), response);
})));
- _ioService->post([this, request]() { HandleAsyncRequest(request); });
+ Trinity::Asio::post(*_ioContext, [this, request]() { HandleAsyncRequest(request); });
return SOAP_OK;
}
@@ -436,7 +435,7 @@ int32 LoginRESTService::HandlePostLogin(std::shared_ptr<AsyncRequest> request)
sLoginService.SendResponse(request->GetClient(), loginResult);
})));
- _ioService->post([this, request]() { HandleAsyncRequest(request); });
+ Trinity::Asio::post(*_ioContext, [this, request]() { HandleAsyncRequest(request); });
return SOAP_OK;
}
@@ -476,7 +475,7 @@ int32 LoginRESTService::HandlePostRefreshLoginTicket(std::shared_ptr<AsyncReques
SendResponse(request->GetClient(), loginRefreshResult);
})));
- _ioService->post([this, request]() { HandleAsyncRequest(request); });
+ Trinity::Asio::post(*_ioContext, [this, request]() { HandleAsyncRequest(request); });
return SOAP_OK;
}
@@ -494,7 +493,7 @@ void LoginRESTService::HandleAsyncRequest(std::shared_ptr<AsyncRequest> request)
{
if (!request->InvokeIfReady())
{
- _ioService->post([this, request]() { HandleAsyncRequest(request); });
+ Trinity::Asio::post(*_ioContext, [this, request]() { HandleAsyncRequest(request); });
}
else if (request->GetResponseStatus())
{
diff --git a/src/server/bnetserver/REST/LoginRESTService.h b/src/server/bnetserver/REST/LoginRESTService.h
index 78253732264..6cc0e60b3c3 100644
--- a/src/server/bnetserver/REST/LoginRESTService.h
+++ b/src/server/bnetserver/REST/LoginRESTService.h
@@ -19,11 +19,11 @@
#define LoginRESTService_h__
#include "Define.h"
+#include "IoContext.h"
+#include "IpAddress.h"
#include "Login.pb.h"
#include "Session.h"
-#include <boost/asio/io_service.hpp>
#include <boost/asio/ip/tcp.hpp>
-#include <boost/asio/ip/address.hpp>
#include <atomic>
#include <thread>
@@ -40,11 +40,11 @@ enum class BanMode
class LoginRESTService
{
public:
- LoginRESTService() : _ioService(nullptr), _stopped(false), _port(0), _loginTicketDuration(0) { }
+ LoginRESTService() : _ioContext(nullptr), _stopped(false), _port(0), _loginTicketDuration(0) { }
static LoginRESTService& Instance();
- bool Start(boost::asio::io_service* ioService);
+ bool Start(Trinity::Asio::IoContext* ioContext);
void Stop();
boost::asio::ip::tcp::endpoint const& GetAddressForClient(boost::asio::ip::address const& address) const;
@@ -96,7 +96,7 @@ private:
char const* ContentType;
};
- boost::asio::io_service* _ioService;
+ Trinity::Asio::IoContext* _ioContext;
std::thread _thread;
std::atomic<bool> _stopped;
Battlenet::JSON::Login::FormInputs _formInputs;
@@ -104,6 +104,7 @@ private:
int32 _port;
boost::asio::ip::tcp::endpoint _externalAddress;
boost::asio::ip::tcp::endpoint _localAddress;
+ boost::asio::ip::address_v4 _localNetmask;
uint32 _loginTicketDuration;
HttpMethodHandlerMap _getHandlers;
diff --git a/src/server/bnetserver/Server/SessionManager.cpp b/src/server/bnetserver/Server/SessionManager.cpp
index 92b4e9f7735..25abb0c5d6f 100644
--- a/src/server/bnetserver/Server/SessionManager.cpp
+++ b/src/server/bnetserver/Server/SessionManager.cpp
@@ -17,9 +17,9 @@
#include "SessionManager.h"
-bool Battlenet::SessionManager::StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port, int threadCount)
+bool Battlenet::SessionManager::StartNetwork(Trinity::Asio::IoContext& ioContext, std::string const& bindIp, uint16 port, int threadCount)
{
- if (!BaseSocketMgr::StartNetwork(service, bindIp, port, threadCount))
+ if (!BaseSocketMgr::StartNetwork(ioContext, bindIp, port, threadCount))
return false;
_acceptor->SetSocketFactory(std::bind(&BaseSocketMgr::GetSocketForAccept, this));
diff --git a/src/server/bnetserver/Server/SessionManager.h b/src/server/bnetserver/Server/SessionManager.h
index 7d4f35cb65c..3dcd3386f56 100644
--- a/src/server/bnetserver/Server/SessionManager.h
+++ b/src/server/bnetserver/Server/SessionManager.h
@@ -30,7 +30,7 @@ namespace Battlenet
public:
static SessionManager& Instance();
- bool StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port, int threadCount = 1) override;
+ bool StartNetwork(Trinity::Asio::IoContext& ioContext, std::string const& bindIp, uint16 port, int threadCount = 1) override;
protected:
NetworkThread<Session>* CreateThreads() const override;