diff options
| author | Shauren <shauren.trinity@gmail.com> | 2014-07-19 13:40:14 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2014-07-19 13:40:14 +0200 |
| commit | 3e56a4b8d7340ff75ecdd596516370076419ce2f (patch) | |
| tree | f661438cac15ad70b35da09b40da2fe6c3c06283 /src/server/authserver | |
| parent | 909acdbac3223d8c788b1b5dc42b6dfab8b604ab (diff) | |
Part 1: Merge branch 'master' into 4.3.4
Diffstat (limited to 'src/server/authserver')
| -rw-r--r-- | src/server/authserver/Realms/RealmList.cpp | 46 | ||||
| -rw-r--r-- | src/server/authserver/Realms/RealmList.h | 4 | ||||
| -rw-r--r-- | src/server/authserver/Server/AuthSession.cpp | 49 |
3 files changed, 36 insertions, 63 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); diff --git a/src/server/authserver/Server/AuthSession.cpp b/src/server/authserver/Server/AuthSession.cpp index b426b82e44d..3bc51ace67b 100644 --- a/src/server/authserver/Server/AuthSession.cpp +++ b/src/server/authserver/Server/AuthSession.cpp @@ -739,41 +739,6 @@ bool AuthSession::_HandleReconnectProof() } } -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()) - 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; - } - - tcp::endpoint endpoint(realmIp, realm.port); - - // Return external IP - return endpoint; -} - bool AuthSession::_HandleRealmList() { TC_LOG_DEBUG("server.authserver", "Entering _HandleRealmList"); @@ -843,7 +808,7 @@ bool AuthSession::_HandleRealmList() pkt << lock; // if 1, then realm locked pkt << uint8(flag); // RealmFlags pkt << name; - pkt << boost::lexical_cast<std::string>(GetAddressForClient(realm, _socket.remote_endpoint().address())); + pkt << boost::lexical_cast<std::string>(realm.GetAddressForClient(_socket.remote_endpoint().address())); pkt << realm.populationLevel; pkt << AmountOfCharacters; pkt << realm.timezone; // realm category @@ -918,17 +883,9 @@ void AuthSession::SetVSFields(const std::string& rI) x.SetBinary(sha.GetDigest(), sha.GetLength()); v = g.ModExp(x, N); - // No SQL injection (username escaped) - char *v_hex, *s_hex; - v_hex = v.AsHexStr(); - s_hex = s.AsHexStr(); - PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_VS); - stmt->setString(0, v_hex); - stmt->setString(1, s_hex); + stmt->setString(0, v.AsHexStr()); + stmt->setString(1, s.AsHexStr()); stmt->setString(2, _login); LoginDatabase.Execute(stmt); - - OPENSSL_free(v_hex); - OPENSSL_free(s_hex); } |
