aboutsummaryrefslogtreecommitdiff
path: root/src/server/shared/Realm
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2018-01-06 01:21:59 +0100
committerShauren <shauren.trinity@gmail.com>2018-01-06 01:21:59 +0100
commitdfd2660a85e4f0891c63009ee8425b2796586409 (patch)
tree26704dff3840402765ada5e6e4549a48b95ed82b /src/server/shared/Realm
parent76577ddc3ca4edd5943777443d9cf5a4c5314e10 (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
Diffstat (limited to 'src/server/shared/Realm')
-rw-r--r--src/server/shared/Realm/Realm.cpp9
-rw-r--r--src/server/shared/Realm/RealmList.cpp55
-rw-r--r--src/server/shared/Realm/RealmList.h17
3 files changed, 37 insertions, 44 deletions
diff --git a/src/server/shared/Realm/Realm.cpp b/src/server/shared/Realm/Realm.cpp
index 7b98f51bf35..6f9d216bcd4 100644
--- a/src/server/shared/Realm/Realm.cpp
+++ b/src/server/shared/Realm/Realm.cpp
@@ -16,8 +16,9 @@
*/
#include "Realm.h"
+#include "IpAddress.h"
+#include "IpNetwork.h"
#include "StringFormat.h"
-#include <boost/asio/ip/address.hpp>
#include <algorithm>
#include <cctype>
@@ -47,12 +48,8 @@ boost::asio::ip::address Realm::GetAddressForClient(boost::asio::ip::address con
}
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 84449fae116..d94be106ac5 100644
--- a/src/server/shared/Realm/RealmList.cpp
+++ b/src/server/shared/Realm/RealmList.cpp
@@ -21,8 +21,10 @@
#include "BigNumber.h"
#include "DatabaseEnv.h"
#include "Errors.h"
+#include "IoContext.h"
#include "Log.h"
#include "ProtobufJSON.h"
+#include "Resolver.h"
#include "Util.h"
#include "game_utilities_service.pb.h"
#include "RealmList.pb.h"
@@ -48,11 +50,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());
@@ -64,7 +66,7 @@ void RealmList::Close()
}
void RealmList::UpdateRealm(Realm& realm, Battlenet::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)
{
@@ -78,11 +80,11 @@ void RealmList::UpdateRealm(Realm& realm, Battlenet::RealmHandle const& id, uint
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;
}
@@ -110,43 +112,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("realmlist", "Could not resolve address %s for realm \"%s\" id %u", fields[2].GetString().c_str(), name.c_str(), realmId);
+ TC_LOG_ERROR("realmlist", "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("realmlist", "Could not resolve localAddress %s for realm \"%s\" id %u", fields[3].GetString().c_str(), name.c_str(), realmId);
+ TC_LOG_ERROR("realmlist", "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("realmlist", "Could not resolve localSubnetMask %s for realm \"%s\" id %u", fields[4].GetString().c_str(), name.c_str(), realmId);
+ TC_LOG_ERROR("realmlist", "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)
@@ -163,15 +156,15 @@ void RealmList::UpdateRealms(boost::system::error_code const& error)
Battlenet::RealmHandle id{ region, battlegroup, realmId };
- UpdateRealm(newRealms[id], id, build, name, externalAddress, localAddress, localSubmask, port, icon,
+ UpdateRealm(newRealms[id], id, build, name, externalAddress->address(), localAddress->address(), localSubmask->address(), port, icon,
flag, timezone, (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop);
newSubRegions.insert(Battlenet::RealmHandle{ region, battlegroup, 0 }.GetAddressString());
if (!existingRealms.count(id))
- TC_LOG_INFO("realmlist", "Added realm \"%s\" at %s:%u.", name.c_str(), externalAddress.to_string().c_str(), port);
+ TC_LOG_INFO("realmlist", "Added realm \"%s\" at %s:%u.", name.c_str(), externalAddressString.c_str(), port);
else
- TC_LOG_DEBUG("realmlist", "Updating realm \"%s\" at %s:%u.", name.c_str(), externalAddress.to_string().c_str(), port);
+ TC_LOG_DEBUG("realmlist", "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 9f3b93e3d08..ac8983c283a 100644
--- a/src/server/shared/Realm/RealmList.h
+++ b/src/server/shared/Realm/RealmList.h
@@ -38,11 +38,6 @@ namespace boost
{
class shared_mutex;
- namespace asio
- {
- class io_service;
- }
-
namespace system
{
class error_code;
@@ -72,6 +67,14 @@ namespace JSON
}
}
+namespace Trinity
+{
+ namespace Asio
+ {
+ class IoContext;
+ }
+}
+
/// Storage object for the list of realms on the server
class TC_SHARED_API RealmList
{
@@ -82,7 +85,7 @@ public:
~RealmList();
- void Initialize(boost::asio::io_service& ioService, uint32 updateInterval);
+ void Initialize(Trinity::Asio::IoContext& ioContext, uint32 updateInterval);
void Close();
Realm const* GetRealm(Battlenet::RealmHandle const& id) const;
@@ -99,7 +102,7 @@ private:
void UpdateRealms(boost::system::error_code const& error);
void UpdateRealm(Realm& realm, Battlenet::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);
std::unique_ptr<boost::shared_mutex> _realmsMutex;