diff options
| author | Shauren <shauren.trinity@gmail.com> | 2018-01-06 12:28:38 +0100 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2018-01-06 12:30:28 +0100 |
| commit | b2b4f9d1e4562ec246efb5136c1c674ec78f50b7 (patch) | |
| tree | ba0d81ce1ba02528599030fde736f30c19d49d72 /src/server/shared/Realm | |
| parent | 6da6f1b415be2e7964c7c15c87b29a38052e76e4 (diff) | |
Core/Misc: Added compatibility layer for boost 1.66 and future std:: networking stuff
* Based on work done by @dimiandre in PR #21173
Closes #21171
Closes #21173
(cherry picked from commit dfd2660a85e4f0891c63009ee8425b2796586409)
Diffstat (limited to 'src/server/shared/Realm')
| -rw-r--r-- | src/server/shared/Realm/Realm.cpp | 9 | ||||
| -rw-r--r-- | src/server/shared/Realm/RealmList.cpp | 55 | ||||
| -rw-r--r-- | src/server/shared/Realm/RealmList.h | 15 |
3 files changed, 36 insertions, 43 deletions
diff --git a/src/server/shared/Realm/Realm.cpp b/src/server/shared/Realm/Realm.cpp index f99feaae96c..79d9891dfa2 100644 --- a/src/server/shared/Realm/Realm.cpp +++ b/src/server/shared/Realm/Realm.cpp @@ -16,7 +16,8 @@ */ #include "Realm.h" -#include <boost/asio/ip/basic_endpoint.hpp> +#include "IpAddress.h" +#include "IpNetwork.h" boost::asio::ip::tcp_endpoint Realm::GetAddressForClient(boost::asio::ip::address const& clientAddr) const { @@ -37,12 +38,8 @@ boost::asio::ip::tcp_endpoint Realm::GetAddressForClient(boost::asio::ip::addres } else { - if (clientAddr.is_v4() && - (clientAddr.to_v4().to_ulong() & LocalSubnetMask->to_v4().to_ulong()) == - (LocalAddress->to_v4().to_ulong() & LocalSubnetMask->to_v4().to_ulong())) - { + if (clientAddr.is_v4() && Trinity::Net::IsInNetwork(LocalAddress->to_v4(), LocalSubnetMask->to_v4(), clientAddr.to_v4())) realmIp = *LocalAddress; - } else realmIp = *ExternalAddress; } diff --git a/src/server/shared/Realm/RealmList.cpp b/src/server/shared/Realm/RealmList.cpp index aa8ab98da56..e0523f04af2 100644 --- a/src/server/shared/Realm/RealmList.cpp +++ b/src/server/shared/Realm/RealmList.cpp @@ -18,7 +18,9 @@ #include "RealmList.h" #include "DatabaseEnv.h" +#include "IoContext.h" #include "Log.h" +#include "Resolver.h" #include "Util.h" #include <boost/asio/deadline_timer.hpp> #include <boost/asio/ip/tcp.hpp> @@ -38,11 +40,11 @@ RealmList* RealmList::Instance() } // Load the realm list from the database -void RealmList::Initialize(boost::asio::io_service& ioService, uint32 updateInterval) +void RealmList::Initialize(Trinity::Asio::IoContext& ioContext, uint32 updateInterval) { _updateInterval = updateInterval; - _updateTimer = Trinity::make_unique<boost::asio::deadline_timer>(ioService); - _resolver = Trinity::make_unique<boost::asio::ip::tcp::resolver>(ioService); + _updateTimer = Trinity::make_unique<boost::asio::deadline_timer>(ioContext); + _resolver = Trinity::make_unique<boost::asio::ip::tcp::resolver>(ioContext); // Get the content of the realmlist table in the database UpdateRealms(boost::system::error_code()); @@ -54,7 +56,7 @@ void RealmList::Close() } void RealmList::UpdateRealm(RealmHandle const& id, uint32 build, std::string const& name, - boost::asio::ip::address const& address, boost::asio::ip::address const& localAddr, boost::asio::ip::address const& localSubmask, + boost::asio::ip::address&& address, boost::asio::ip::address&& localAddr, boost::asio::ip::address&& localSubmask, uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population) { // Create new if not exist or update existed @@ -69,11 +71,11 @@ void RealmList::UpdateRealm(RealmHandle const& id, uint32 build, std::string con realm.AllowedSecurityLevel = allowedSecurityLevel; realm.PopulationLevel = population; if (!realm.ExternalAddress || *realm.ExternalAddress != address) - realm.ExternalAddress = Trinity::make_unique<boost::asio::ip::address>(address); + realm.ExternalAddress = Trinity::make_unique<boost::asio::ip::address>(std::move(address)); if (!realm.LocalAddress || *realm.LocalAddress != localAddr) - realm.LocalAddress = Trinity::make_unique<boost::asio::ip::address>(localAddr); + realm.LocalAddress = Trinity::make_unique<boost::asio::ip::address>(std::move(localAddr)); if (!realm.LocalSubnetMask || *realm.LocalSubnetMask != localSubmask) - realm.LocalSubnetMask = Trinity::make_unique<boost::asio::ip::address>(localSubmask); + realm.LocalSubnetMask = Trinity::make_unique<boost::asio::ip::address>(std::move(localSubmask)); realm.Port = port; } @@ -100,43 +102,34 @@ void RealmList::UpdateRealms(boost::system::error_code const& error) { try { - boost::asio::ip::tcp::resolver::iterator end; - Field* fields = result->Fetch(); uint32 realmId = fields[0].GetUInt32(); std::string name = fields[1].GetString(); - boost::asio::ip::tcp::resolver::query externalAddressQuery(boost::asio::ip::tcp::v4(), fields[2].GetString(), ""); + std::string externalAddressString = fields[2].GetString(); + std::string localAddressString = fields[3].GetString(); + std::string localSubmaskString = fields[4].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(), externalAddressString, ""); + if (!externalAddress) { - TC_LOG_ERROR("server.authserver", "Could not resolve address %s for realm \"%s\" id %u", fields[2].GetString().c_str(), name.c_str(), realmId); + TC_LOG_ERROR("server.authserver", "Could not resolve address %s for realm \"%s\" id %u", externalAddressString.c_str(), name.c_str(), realmId); continue; } - boost::asio::ip::address externalAddress = endPoint->endpoint().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(), localAddressString, ""); + if (!localAddress) { - TC_LOG_ERROR("server.authserver", "Could not resolve localAddress %s for realm \"%s\" id %u", fields[3].GetString().c_str(), name.c_str(), realmId); + TC_LOG_ERROR("server.authserver", "Could not resolve localAddress %s for realm \"%s\" id %u", localAddressString.c_str(), name.c_str(), realmId); continue; } - boost::asio::ip::address localAddress = endPoint->endpoint().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(), localSubmaskString, ""); + if (!localSubmask) { - TC_LOG_ERROR("server.authserver", "Could not resolve localSubnetMask %s for realm \"%s\" id %u", fields[4].GetString().c_str(), name.c_str(), realmId); + TC_LOG_ERROR("server.authserver", "Could not resolve localSubnetMask %s for realm \"%s\" id %u", localSubmaskString.c_str(), name.c_str(), realmId); continue; } - boost::asio::ip::address localSubmask = endPoint->endpoint().address(); - uint16 port = fields[5].GetUInt16(); uint8 icon = fields[6].GetUInt8(); if (icon == REALM_TYPE_FFA_PVP) @@ -151,13 +144,13 @@ void RealmList::UpdateRealms(boost::system::error_code const& error) RealmHandle id{ realmId }; - UpdateRealm(id, build, name, externalAddress, localAddress, localSubmask, port, icon, flag, + UpdateRealm(id, build, name, externalAddress->address(), localAddress->address(), localSubmask->address(), port, icon, flag, timezone, (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop); if (!existingRealms.count(id)) - TC_LOG_INFO("server.authserver", "Added realm \"%s\" at %s:%u.", name.c_str(), externalAddress.to_string().c_str(), port); + TC_LOG_INFO("server.authserver", "Added realm \"%s\" at %s:%u.", name.c_str(), externalAddressString.c_str(), port); else - TC_LOG_DEBUG("server.authserver", "Updating realm \"%s\" at %s:%u.", name.c_str(), externalAddress.to_string().c_str(), port); + TC_LOG_DEBUG("server.authserver", "Updating realm \"%s\" at %s:%u.", name.c_str(), externalAddressString.c_str(), port); existingRealms.erase(id); } diff --git a/src/server/shared/Realm/RealmList.h b/src/server/shared/Realm/RealmList.h index c70243f82d8..7b18f6a99a0 100644 --- a/src/server/shared/Realm/RealmList.h +++ b/src/server/shared/Realm/RealmList.h @@ -27,14 +27,17 @@ namespace boost { - namespace asio + namespace system { - class io_service; + class error_code; } +} - namespace system +namespace Trinity +{ + namespace Asio { - class error_code; + class IoContext; } } @@ -48,7 +51,7 @@ public: ~RealmList(); - void Initialize(boost::asio::io_service& ioService, uint32 updateInterval); + void Initialize(Trinity::Asio::IoContext& ioContext, uint32 updateInterval); void Close(); RealmMap const& GetRealms() const { return _realms; } @@ -59,7 +62,7 @@ private: void UpdateRealms(boost::system::error_code const& error); void UpdateRealm(RealmHandle const& id, uint32 build, std::string const& name, - boost::asio::ip::address const& address, boost::asio::ip::address const& localAddr, boost::asio::ip::address const& localSubmask, + boost::asio::ip::address&& address, boost::asio::ip::address&& localAddr, boost::asio::ip::address&& localSubmask, uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population); RealmMap _realms; |
