Replaced ACE_INET_Addr with boost::asio::ip::address

This commit is contained in:
leak committed 2014-05-31 18:31:53 +02:00
1 parent bf6e58b8d4
commit 35aa142f6a
4 files changed
+48 -33

No files matched your search

+14 -11
View File
@@ -16,10 +16,13 @@
* with this program. If not, see <http://www.gnu.org/licenses/>. * with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <boost/asio.hpp>
#include "Common.h" #include "Common.h"
#include "RealmList.h" #include "RealmList.h"
#include "Database/DatabaseEnv.h" #include "Database/DatabaseEnv.h"
namespace boost { namespace asio { namespace ip { class address; } } }
RealmList::RealmList() : m_UpdateInterval(0), m_NextUpdateTime(time(NULL)) { } RealmList::RealmList() : m_UpdateInterval(0), m_NextUpdateTime(time(NULL)) { }
// Load the realm list from the database // Load the realm list from the database
@@ -31,7 +34,8 @@ void RealmList::Initialize(uint32 updateInterval)
UpdateRealms(true); UpdateRealms(true);
} }
void RealmList::UpdateRealm(uint32 id, const std::string& name, ACE_INET_Addr const& address, ACE_INET_Addr const& localAddr, ACE_INET_Addr const& localSubmask, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, uint32 build) 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)
{ {
// Create new if not exist or update existed // Create new if not exist or update existed
Realm& realm = m_realms[name]; Realm& realm = m_realms[name];
@@ -42,12 +46,14 @@ void RealmList::UpdateRealm(uint32 id, const std::string& name, ACE_INET_Addr co
realm.flag = flag; realm.flag = flag;
realm.timezone = timezone; realm.timezone = timezone;
realm.allowedSecurityLevel = allowedSecurityLevel; realm.allowedSecurityLevel = allowedSecurityLevel;
realm.populationLevel = popu; realm.populationLevel = population;
// Append port to IP address. // Append port to IP address.
realm.ExternalAddress = address; realm.ExternalAddress = address;
realm.LocalAddress = localAddr; realm.LocalAddress = localAddr;
realm.LocalSubnetMask = localSubmask; realm.LocalSubnetMask = localSubmask;
realm.port = port;
realm.gamebuild = build; realm.gamebuild = build;
} }
@@ -81,9 +87,9 @@ void RealmList::UpdateRealms(bool init)
Field* fields = result->Fetch(); Field* fields = result->Fetch();
uint32 realmId = fields[0].GetUInt32(); uint32 realmId = fields[0].GetUInt32();
std::string name = fields[1].GetString(); std::string name = fields[1].GetString();
std::string externalAddress = fields[2].GetString(); ip::address externalAddress = ip::address::from_string(fields[2].GetString());
std::string localAddress = fields[3].GetString(); ip::address localAddress = ip::address::from_string(fields[3].GetString());
std::string localSubmask = fields[4].GetString(); ip::address localSubmask = ip::address::from_string(fields[4].GetString());
uint16 port = fields[5].GetUInt16(); uint16 port = fields[5].GetUInt16();
uint8 icon = fields[6].GetUInt8(); uint8 icon = fields[6].GetUInt8();
RealmFlags flag = RealmFlags(fields[7].GetUInt8()); RealmFlags flag = RealmFlags(fields[7].GetUInt8());
@@ -92,14 +98,11 @@ void RealmList::UpdateRealms(bool init)
float pop = fields[10].GetFloat(); float pop = fields[10].GetFloat();
uint32 build = fields[11].GetUInt32(); uint32 build = fields[11].GetUInt32();
ACE_INET_Addr externalAddr(port, externalAddress.c_str(), AF_INET); UpdateRealm(realmId, name, externalAddress, localAddress, localSubmask, port, icon, flag, timezone,
ACE_INET_Addr localAddr(port, localAddress.c_str(), AF_INET); (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop, build);
ACE_INET_Addr submask(0, localSubmask.c_str(), AF_INET);
UpdateRealm(realmId, name, externalAddr, localAddr, submask, icon, flag, timezone, (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop, build);
if (init) if (init)
TC_LOG_INFO("server.authserver", "Added realm \"%s\" at %s:%u.", name.c_str(), m_realms[name].ExternalAddress.get_host_addr(), port); TC_LOG_INFO("server.authserver", "Added realm \"%s\" at %s:%u.", name.c_str(), m_realms[name].ExternalAddress.to_string(), port);
} }
while (result->NextRow()); while (result->NextRow());
} }
+9 -6
View File
@@ -19,9 +19,11 @@
#ifndef _REALMLIST_H #ifndef _REALMLIST_H
#define _REALMLIST_H #define _REALMLIST_H
#include <ace/INET_Addr.h> #include <boost/asio.hpp>
#include "Common.h" #include "Common.h"
using namespace boost::asio;
enum RealmFlags enum RealmFlags
{ {
REALM_FLAG_NONE = 0x00, REALM_FLAG_NONE = 0x00,
@@ -38,9 +40,10 @@ enum RealmFlags
// Storage object for a realm // Storage object for a realm
struct Realm struct Realm
{ {
ACE_INET_Addr ExternalAddress; ip::address ExternalAddress;
ACE_INET_Addr LocalAddress; ip::address LocalAddress;
ACE_INET_Addr LocalSubnetMask; ip::address LocalSubnetMask;
uint16 port;
std::string name; std::string name;
uint8 icon; uint8 icon;
RealmFlags flag; RealmFlags flag;
@@ -77,8 +80,8 @@ private:
RealmList(); RealmList();
void UpdateRealms(bool init = false); void UpdateRealms(bool init = false);
void UpdateRealm(uint32 id, const std::string& name, ACE_INET_Addr const& address, ACE_INET_Addr const& localAddr, ACE_INET_Addr const& localSubmask, void UpdateRealm(uint32 id, const std::string& name, ip::address const& address, ip::address const& localAddr,
uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, uint32 build); ip::address const& localSubmask, uint16 port, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float population, uint32 build);
RealmMap m_realms; RealmMap m_realms;
uint32 m_UpdateInterval; uint32 m_UpdateInterval;
+25 -15
View File
@@ -18,6 +18,7 @@
#include <memory> #include <memory>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <boost/lexical_cast.hpp>
#include <AuthSession.h> #include <AuthSession.h>
#include <Log.h> #include <Log.h>
#include "ByteBuffer.h" #include "ByteBuffer.h"
@@ -729,29 +730,41 @@ bool AuthSession::_HandleReconnectProof()
} }
} }
ACE_INET_Addr const& GetAddressForClient(Realm const& realm, ACE_INET_Addr const& clientAddr) tcp::endpoint const GetAddressForClient(Realm const& realm, ip::address const& clientAddr)
{ {
ip::address realmIp;
// Attempt to send best address for client // Attempt to send best address for client
if (clientAddr.is_loopback()) if (clientAddr.is_loopback())
{ {
// Try guessing if realm is also connected locally // Try guessing if realm is also connected locally
if (realm.LocalAddress.is_loopback() || realm.ExternalAddress.is_loopback()) if (realm.LocalAddress.is_loopback() || realm.ExternalAddress.is_loopback())
return clientAddr; realmIp = clientAddr;
else
// Assume that user connecting from the machine that authserver is located on {
// has all realms available in his local network // Assume that user connecting from the machine that authserver is located on
return realm.LocalAddress; // has all realms available in his local network
realmIp = realm.LocalAddress;
}
}
else
{
if (clientAddr.is_v4() &&
(clientAddr.to_v4().to_ulong() & realm.LocalSubnetMask.to_v4().to_ulong()) ==
(realm.LocalAddress.to_v4().to_ulong() & realm.LocalSubnetMask.to_v4().to_ulong()))
{
realmIp = realm.LocalAddress;
}
else
realmIp = realm.ExternalAddress;
} }
// Check if connecting client is in the same network tcp::endpoint endpoint(realmIp, realm.port);
if (IsIPAddrInNetwork(realm.LocalAddress, clientAddr, realm.LocalSubnetMask))
return realm.LocalAddress;
// Return external IP // Return external IP
return realm.ExternalAddress; return endpoint;
} }
bool AuthSession::_HandleRealmList() bool AuthSession::_HandleRealmList()
{ {
TC_LOG_DEBUG("server.authserver", "Entering _HandleRealmList"); TC_LOG_DEBUG("server.authserver", "Entering _HandleRealmList");
@@ -806,9 +819,6 @@ bool AuthSession::_HandleRealmList()
name = ss.str(); name = ss.str();
} }
// We don't need the port number from which client connects with but the realm's port
ACE_INET_Addr clientAddr(realm.ExternalAddress.get_port_number(), GetRemoteIpAddress().c_str(), AF_INET);
uint8 lock = (realm.allowedSecurityLevel > _accountSecurityLevel) ? 1 : 0; uint8 lock = (realm.allowedSecurityLevel > _accountSecurityLevel) ? 1 : 0;
uint8 AmountOfCharacters = 0; uint8 AmountOfCharacters = 0;
@@ -824,7 +834,7 @@ bool AuthSession::_HandleRealmList()
pkt << lock; // if 1, then realm locked pkt << lock; // if 1, then realm locked
pkt << uint8(flag); // RealmFlags pkt << uint8(flag); // RealmFlags
pkt << name; pkt << name;
pkt << GetAddressString(GetAddressForClient(realm, clientAddr)); pkt << boost::lexical_cast<std::string>(GetAddressForClient(realm, _socket.remote_endpoint().address()));
pkt << realm.populationLevel; pkt << realm.populationLevel;
pkt << AmountOfCharacters; pkt << AmountOfCharacters;
pkt << realm.timezone; // realm category pkt << realm.timezone; // realm category
@@ -21,7 +21,6 @@
#include <memory> #include <memory>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include "Common.h" #include "Common.h"
#include "BigNumber.h" #include "BigNumber.h"