aboutsummaryrefslogtreecommitdiff
path: root/src/server/authserver/Realms
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2014-07-19 13:40:14 +0200
committerShauren <shauren.trinity@gmail.com>2014-07-19 13:40:14 +0200
commit3e56a4b8d7340ff75ecdd596516370076419ce2f (patch)
treef661438cac15ad70b35da09b40da2fe6c3c06283 /src/server/authserver/Realms
parent909acdbac3223d8c788b1b5dc42b6dfab8b604ab (diff)
Part 1: Merge branch 'master' into 4.3.4
Diffstat (limited to 'src/server/authserver/Realms')
-rw-r--r--src/server/authserver/Realms/RealmList.cpp46
-rw-r--r--src/server/authserver/Realms/RealmList.h4
2 files changed, 33 insertions, 17 deletions
diff --git a/src/server/authserver/Realms/RealmList.cpp b/src/server/authserver/Realms/RealmList.cpp
index 181bee31185..519d54c1c59 100644
--- a/src/server/authserver/Realms/RealmList.cpp
+++ b/src/server/authserver/Realms/RealmList.cpp
@@ -16,35 +16,51 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <boost/asio/ip/tcp.hpp>
#include "Common.h"
#include "RealmList.h"
#include "BattlenetManager.h"
#include "Database/DatabaseEnv.h"
#include "Util.h"
-namespace boost { namespace asio { namespace ip { class address; } } }
-ACE_INET_Addr const& Realm::GetAddressForClient(ACE_INET_Addr const& clientAddr) const
+tcp::endpoint Realm::GetAddressForClient(ip::address const& clientAddr) const
{
+ ip::address realmIp;
+
// Attempt to send best address for client
if (clientAddr.is_loopback())
- // Assume that user connecting from the machine that authserver is located on
- // has all realms available in his local network
- return LocalAddress;
+ {
+ // Try guessing if realm is also connected locally
+ if (LocalAddress.is_loopback() || ExternalAddress.is_loopback())
+ realmIp = clientAddr;
+ else
+ {
+ // Assume that user connecting from the machine that authserver is located on
+ // has all realms available in his local network
+ realmIp = LocalAddress;
+ }
+ }
+ 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()))
+ {
+ realmIp = LocalAddress;
+ }
+ else
+ realmIp = ExternalAddress;
+ }
- // Check if connecting client is in the same network
- if (IsIPAddrInNetwork(LocalAddress, clientAddr, LocalSubnetMask))
- return LocalAddress;
+ tcp::endpoint endpoint(realmIp, port);
// Return external IP
- return ExternalAddress;
+ return endpoint;
}
-RealmList::RealmList() : m_UpdateInterval(0), m_NextUpdateTime(time(NULL))
+RealmList::RealmList() : m_UpdateInterval(0), m_NextUpdateTime(time(NULL)), _resolver(nullptr)
{
}
-RealmList::RealmList() : m_UpdateInterval(0), m_NextUpdateTime(time(NULL)), _resolver(nullptr) { }
RealmList::~RealmList()
{
delete _resolver;
@@ -60,7 +76,7 @@ void RealmList::Initialize(boost::asio::io_service& ioService, uint32 updateInte
UpdateRealms(true);
}
-void RealmList::UpdateRealm(uint32 id, const std::string& name, ip::address const& address, ip::address const& localAddr,
+void RealmList::UpdateRealm(uint32 id, const std::string& name, ip::address const& address, ip::address const& localAddr,
ip::address const& localSubmask, uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population, uint32 build, uint8 region, uint8 battlegroup)
{
// Create new if not exist or update existed
@@ -156,8 +172,8 @@ void RealmList::UpdateRealms(bool init)
uint8 allowedSecurityLevel = fields[9].GetUInt8();
float pop = fields[10].GetFloat();
uint32 build = fields[11].GetUInt32();
- uint8 region = fields[12].GetUInt8();
- uint8 battlegroup = fields[13].GetUInt8();
+ uint8 region = fields[12].GetUInt8();
+ uint8 battlegroup = fields[13].GetUInt8();
UpdateRealm(realmId, name, externalAddress, localAddress, localSubmask, port, icon, flag, timezone,
(allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop, build, region, battlegroup);
diff --git a/src/server/authserver/Realms/RealmList.h b/src/server/authserver/Realms/RealmList.h
index 7426d5b3f32..beb520df25a 100644
--- a/src/server/authserver/Realms/RealmList.h
+++ b/src/server/authserver/Realms/RealmList.h
@@ -57,7 +57,7 @@ struct Realm
uint8 Region;
uint8 Battlegroup;
- ACE_INET_Addr const& GetAddressForClient(ACE_INET_Addr const& clientAddr) const;
+ ip::tcp::endpoint GetAddressForClient(ip::address const& clientAddr) const;
};
namespace Battlenet
@@ -76,7 +76,7 @@ public:
static RealmList *instance = new RealmList();
return *instance;
}
-
+
~RealmList();
void Initialize(boost::asio::io_service& ioService, uint32 updateInterval);