diff options
author | leak <leak@bitmx.net> | 2014-05-31 18:31:53 +0200 |
---|---|---|
committer | leak <leak@bitmx.net> | 2014-05-31 18:31:53 +0200 |
commit | 35aa142f6aa748db1febe901b2446fe53b9abbe0 (patch) | |
tree | 2c93f57822e4a38262dc658a0fcd8ef82c2ded7d /src/server | |
parent | bf6e58b8d44d3a4b78e9473df029caac74c68220 (diff) |
Replaced ACE_INET_Addr with boost::asio::ip::address
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/authserver/Realms/RealmList.cpp | 25 | ||||
-rw-r--r-- | src/server/authserver/Realms/RealmList.h | 15 | ||||
-rw-r--r-- | src/server/authserver/Server/AuthSession.cpp | 40 | ||||
-rw-r--r-- | src/server/authserver/Server/AuthSession.h | 1 |
4 files changed, 48 insertions, 33 deletions
diff --git a/src/server/authserver/Realms/RealmList.cpp b/src/server/authserver/Realms/RealmList.cpp index 4aeecfc0aaa..7ed9021dd21 100644 --- a/src/server/authserver/Realms/RealmList.cpp +++ b/src/server/authserver/Realms/RealmList.cpp @@ -16,10 +16,13 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <boost/asio.hpp> #include "Common.h" #include "RealmList.h" #include "Database/DatabaseEnv.h" +namespace boost { namespace asio { namespace ip { class address; } } } + RealmList::RealmList() : m_UpdateInterval(0), m_NextUpdateTime(time(NULL)) { } // Load the realm list from the database @@ -31,7 +34,8 @@ void RealmList::Initialize(uint32 updateInterval) 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 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.timezone = timezone; realm.allowedSecurityLevel = allowedSecurityLevel; - realm.populationLevel = popu; + realm.populationLevel = population; // Append port to IP address. + realm.ExternalAddress = address; realm.LocalAddress = localAddr; realm.LocalSubnetMask = localSubmask; + realm.port = port; realm.gamebuild = build; } @@ -81,9 +87,9 @@ void RealmList::UpdateRealms(bool init) Field* fields = result->Fetch(); uint32 realmId = fields[0].GetUInt32(); std::string name = fields[1].GetString(); - std::string externalAddress = fields[2].GetString(); - std::string localAddress = fields[3].GetString(); - std::string localSubmask = fields[4].GetString(); + ip::address externalAddress = ip::address::from_string(fields[2].GetString()); + ip::address localAddress = ip::address::from_string(fields[3].GetString()); + ip::address localSubmask = ip::address::from_string(fields[4].GetString()); uint16 port = fields[5].GetUInt16(); uint8 icon = fields[6].GetUInt8(); RealmFlags flag = RealmFlags(fields[7].GetUInt8()); @@ -92,14 +98,11 @@ void RealmList::UpdateRealms(bool init) float pop = fields[10].GetFloat(); uint32 build = fields[11].GetUInt32(); - ACE_INET_Addr externalAddr(port, externalAddress.c_str(), AF_INET); - ACE_INET_Addr localAddr(port, localAddress.c_str(), AF_INET); - 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); + UpdateRealm(realmId, name, externalAddress, localAddress, localSubmask, port, icon, flag, timezone, + (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop, build); 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()); } diff --git a/src/server/authserver/Realms/RealmList.h b/src/server/authserver/Realms/RealmList.h index 29b6aca07d3..b96d5523da9 100644 --- a/src/server/authserver/Realms/RealmList.h +++ b/src/server/authserver/Realms/RealmList.h @@ -19,9 +19,11 @@ #ifndef _REALMLIST_H #define _REALMLIST_H -#include <ace/INET_Addr.h> +#include <boost/asio.hpp> #include "Common.h" +using namespace boost::asio; + enum RealmFlags { REALM_FLAG_NONE = 0x00, @@ -38,9 +40,10 @@ enum RealmFlags // Storage object for a realm struct Realm { - ACE_INET_Addr ExternalAddress; - ACE_INET_Addr LocalAddress; - ACE_INET_Addr LocalSubnetMask; + ip::address ExternalAddress; + ip::address LocalAddress; + ip::address LocalSubnetMask; + uint16 port; std::string name; uint8 icon; RealmFlags flag; @@ -77,8 +80,8 @@ private: RealmList(); 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, - uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, uint32 build); + void 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); RealmMap m_realms; uint32 m_UpdateInterval; diff --git a/src/server/authserver/Server/AuthSession.cpp b/src/server/authserver/Server/AuthSession.cpp index 627e1fc470d..304d593fa3d 100644 --- a/src/server/authserver/Server/AuthSession.cpp +++ b/src/server/authserver/Server/AuthSession.cpp @@ -18,6 +18,7 @@ #include <memory> #include <boost/asio.hpp> +#include <boost/lexical_cast.hpp> #include <AuthSession.h> #include <Log.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 if (clientAddr.is_loopback()) { // Try guessing if realm is also connected locally if (realm.LocalAddress.is_loopback() || realm.ExternalAddress.is_loopback()) - return clientAddr; - - // Assume that user connecting from the machine that authserver is located on - // has all realms available in his local network - return realm.LocalAddress; + realmIp = clientAddr; + else + { + // Assume that user connecting from the machine that authserver is located on + // 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 - if (IsIPAddrInNetwork(realm.LocalAddress, clientAddr, realm.LocalSubnetMask)) - return realm.LocalAddress; + tcp::endpoint endpoint(realmIp, realm.port); // Return external IP - return realm.ExternalAddress; + return endpoint; } - bool AuthSession::_HandleRealmList() { TC_LOG_DEBUG("server.authserver", "Entering _HandleRealmList"); @@ -806,9 +819,6 @@ bool AuthSession::_HandleRealmList() 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 AmountOfCharacters = 0; @@ -824,7 +834,7 @@ bool AuthSession::_HandleRealmList() pkt << lock; // if 1, then realm locked pkt << uint8(flag); // RealmFlags pkt << name; - pkt << GetAddressString(GetAddressForClient(realm, clientAddr)); + pkt << boost::lexical_cast<std::string>(GetAddressForClient(realm, _socket.remote_endpoint().address())); pkt << realm.populationLevel; pkt << AmountOfCharacters; pkt << realm.timezone; // realm category diff --git a/src/server/authserver/Server/AuthSession.h b/src/server/authserver/Server/AuthSession.h index 79b1e568aa6..32e81d5240e 100644 --- a/src/server/authserver/Server/AuthSession.h +++ b/src/server/authserver/Server/AuthSession.h @@ -21,7 +21,6 @@ #include <memory> #include <boost/asio.hpp> - #include "Common.h" #include "BigNumber.h" |