aboutsummaryrefslogtreecommitdiff
path: root/src/server/authserver/Realms
diff options
context:
space:
mode:
authorDDuarte <dnpd.dd@gmail.com>2014-11-10 20:57:39 +0000
committerDDuarte <dnpd.dd@gmail.com>2014-11-10 20:57:39 +0000
commit90c53e8c84b6a7b4346bda8087be8d14d0902d1a (patch)
tree440106833555d60ebf7a3a042449fd80250c2e2f /src/server/authserver/Realms
parente90ef4fa24a1da7f4d7433a1522e5cb43ef68d29 (diff)
Core: Nuke authserver
It has been replaced by bnetserver since grunt was deprecated
Diffstat (limited to 'src/server/authserver/Realms')
-rw-r--r--src/server/authserver/Realms/RealmList.cpp188
-rw-r--r--src/server/authserver/Realms/RealmList.h99
2 files changed, 0 insertions, 287 deletions
diff --git a/src/server/authserver/Realms/RealmList.cpp b/src/server/authserver/Realms/RealmList.cpp
deleted file mode 100644
index 15302c74ac6..00000000000
--- a/src/server/authserver/Realms/RealmList.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <boost/asio/ip/tcp.hpp>
-#include "Common.h"
-#include "RealmList.h"
-#include "Database/DatabaseEnv.h"
-#include "Util.h"
-
-ip::tcp::endpoint Realm::GetAddressForClient(ip::address const& clientAddr) const
-{
- ip::address realmIp;
-
- // Attempt to send best address for client
- if (clientAddr.is_loopback())
- {
- // 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;
- }
-
- ip::tcp::endpoint endpoint(realmIp, port);
-
- // Return external IP
- return endpoint;
-}
-
-RealmList::RealmList() : m_UpdateInterval(0), m_NextUpdateTime(time(NULL)), _resolver(nullptr)
-{
-}
-
-RealmList::~RealmList()
-{
- delete _resolver;
-}
-
-// Load the realm list from the database
-void RealmList::Initialize(boost::asio::io_service& ioService, uint32 updateInterval)
-{
- _resolver = new boost::asio::ip::tcp::resolver(ioService);
- m_UpdateInterval = updateInterval;
-
- // Get the content of the realmlist table in the database
- UpdateRealms(true);
-}
-
-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];
-
- realm.m_ID = id;
- realm.name = name;
- realm.icon = icon;
- realm.flag = flag;
- realm.timezone = timezone;
- realm.allowedSecurityLevel = allowedSecurityLevel;
- realm.populationLevel = population;
-
- realm.ExternalAddress = address;
- realm.LocalAddress = localAddr;
- realm.LocalSubnetMask = localSubmask;
- realm.port = port;
- realm.gamebuild = build;
-}
-
-void RealmList::UpdateIfNeed()
-{
- // maybe disabled or updated recently
- if (!m_UpdateInterval || m_NextUpdateTime > time(NULL))
- return;
-
- m_NextUpdateTime = time(NULL) + m_UpdateInterval;
-
- // Clears Realm list
- m_realms.clear();
-
- // Get the content of the realmlist table in the database
- UpdateRealms();
-}
-
-void RealmList::UpdateRealms(bool init)
-{
- TC_LOG_INFO("server.authserver", "Updating Realm List...");
-
- PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_REALMLIST);
- PreparedQueryResult result = LoginDatabase.Query(stmt);
-
- // Circle through results and add them to the realm map
- if (result)
- {
- do
- {
- 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(ip::tcp::v4(), fields[2].GetString(), "");
-
- boost::system::error_code ec;
- boost::asio::ip::tcp::resolver::iterator endPoint = _resolver->resolve(externalAddressQuery, ec);
- if (endPoint == end || ec)
- {
- TC_LOG_ERROR("server.authserver", "Could not resolve address %s", fields[2].GetString().c_str());
- return;
- }
-
- ip::address externalAddress = (*endPoint).endpoint().address();
-
- boost::asio::ip::tcp::resolver::query localAddressQuery(ip::tcp::v4(), fields[3].GetString(), "");
- endPoint = _resolver->resolve(localAddressQuery, ec);
- if (endPoint == end || ec)
- {
- TC_LOG_ERROR("server.authserver", "Could not resolve address %s", fields[3].GetString().c_str());
- return;
- }
-
- ip::address localAddress = (*endPoint).endpoint().address();
-
- boost::asio::ip::tcp::resolver::query localSubmaskQuery(ip::tcp::v4(), fields[4].GetString(), "");
- endPoint = _resolver->resolve(localSubmaskQuery, ec);
- if (endPoint == end || ec)
- {
- TC_LOG_ERROR("server.authserver", "Could not resolve address %s", fields[4].GetString().c_str());
- return;
- }
-
- ip::address localSubmask = (*endPoint).endpoint().address();
-
- uint16 port = fields[5].GetUInt16();
- uint8 icon = fields[6].GetUInt8();
- RealmFlags flag = RealmFlags(fields[7].GetUInt8());
- uint8 timezone = fields[8].GetUInt8();
- uint8 allowedSecurityLevel = fields[9].GetUInt8();
- float pop = fields[10].GetFloat();
- uint32 build = fields[11].GetUInt32();
-
- 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.to_string().c_str(), port);
- }
- catch (std::exception& ex)
- {
- TC_LOG_ERROR("server.authserver", "Realmlist::UpdateRealms has thrown an exception: %s", ex.what());
- ASSERT(false);
- }
- }
- while (result->NextRow());
- }
-}
diff --git a/src/server/authserver/Realms/RealmList.h b/src/server/authserver/Realms/RealmList.h
deleted file mode 100644
index 9d5771144a9..00000000000
--- a/src/server/authserver/Realms/RealmList.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef _REALMLIST_H
-#define _REALMLIST_H
-
-#include <boost/asio/ip/address.hpp>
-#include <boost/asio/ip/tcp.hpp>
-#include <boost/asio/io_service.hpp>
-#include "Common.h"
-
-using namespace boost::asio;
-
-enum RealmFlags
-{
- REALM_FLAG_NONE = 0x00,
- REALM_FLAG_INVALID = 0x01,
- REALM_FLAG_OFFLINE = 0x02,
- REALM_FLAG_SPECIFYBUILD = 0x04,
- REALM_FLAG_UNK1 = 0x08,
- REALM_FLAG_UNK2 = 0x10,
- REALM_FLAG_RECOMMENDED = 0x20,
- REALM_FLAG_NEW = 0x40,
- REALM_FLAG_FULL = 0x80
-};
-
-// Storage object for a realm
-struct Realm
-{
- ip::address ExternalAddress;
- ip::address LocalAddress;
- ip::address LocalSubnetMask;
- uint16 port;
- std::string name;
- uint8 icon;
- RealmFlags flag;
- uint8 timezone;
- uint32 m_ID;
- AccountTypes allowedSecurityLevel;
- float populationLevel;
- uint32 gamebuild;
-
- ip::tcp::endpoint GetAddressForClient(ip::address const& clientAddr) const;
-};
-
-/// Storage object for the list of realms on the server
-class RealmList
-{
-public:
- typedef std::map<std::string, Realm> RealmMap;
-
- static RealmList* instance()
- {
- static RealmList instance;
- return &instance;
- }
-
- ~RealmList();
-
- void Initialize(boost::asio::io_service& ioService, uint32 updateInterval);
-
- void UpdateIfNeed();
-
- void AddRealm(const Realm& NewRealm) { m_realms[NewRealm.name] = NewRealm; }
-
- RealmMap::const_iterator begin() const { return m_realms.begin(); }
- RealmMap::const_iterator end() const { return m_realms.end(); }
- uint32 size() const { return m_realms.size(); }
-
-private:
- RealmList();
-
- void UpdateRealms(bool init = false);
- 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;
- time_t m_NextUpdateTime;
- boost::asio::ip::tcp::resolver* _resolver;
-};
-
-#define sRealmList RealmList::instance()
-#endif