diff options
| author | DDuarte <dnpd.dd@gmail.com> | 2016-02-28 03:48:28 +0000 |
|---|---|---|
| committer | DDuarte <dnpd.dd@gmail.com> | 2016-03-06 19:46:59 +0000 |
| commit | 2ea31027e5d5155fa88839aac38b175ec402e4ac (patch) | |
| tree | 265befd07d5f8f977aebeb9b45927ad073150c0f /src/server/authserver/Realms | |
| parent | 510bb30b2ca44f082354504b7092eee67a994ecf (diff) | |
Core: Backport 6.x realm changes
Make acessible all the info about current realm (e.g name) anywhere, not only realm id
Reduce the number of differences between the two branches
Original changes by Shauren
Partial port of bacc90b6baa34e6a194c93e5a7860d4041f08af7 and 63def8aa3291d0a6e5f83b289ad12c4c8a3cebd9
Diffstat (limited to 'src/server/authserver/Realms')
| -rw-r--r-- | src/server/authserver/Realms/RealmList.cpp | 65 | ||||
| -rw-r--r-- | src/server/authserver/Realms/RealmList.h | 52 |
2 files changed, 50 insertions, 67 deletions
diff --git a/src/server/authserver/Realms/RealmList.cpp b/src/server/authserver/Realms/RealmList.cpp index 53aeff6133b..b64ff0974f9 100644 --- a/src/server/authserver/Realms/RealmList.cpp +++ b/src/server/authserver/Realms/RealmList.cpp @@ -16,14 +16,14 @@ * 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 "RealmList.h" +#include <boost/asio/ip/tcp.hpp> namespace boost { namespace asio { namespace ip { class address; } } } -RealmList::RealmList() : m_UpdateInterval(0), m_NextUpdateTime(time(NULL)), _resolver(nullptr) { } +RealmList::RealmList() : _updateInterval(0), _nextUpdateTime(time(NULL)), _resolver(nullptr) { } RealmList::~RealmList() { delete _resolver; @@ -33,45 +33,43 @@ RealmList::~RealmList() void RealmList::Initialize(boost::asio::io_service& ioService, uint32 updateInterval) { _resolver = new boost::asio::ip::tcp::resolver(ioService); - m_UpdateInterval = updateInterval; + _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) +void RealmList::UpdateRealm(RealmHandle const& id, uint32 build, 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) { // 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; - - // Append port to IP address. - + Realm& realm = _realms[id]; + + realm.Id = id; + realm.Build = build; + realm.Name = name; + realm.Type = icon; + realm.Flags = 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; + realm.Port = port; } void RealmList::UpdateIfNeed() { // maybe disabled or updated recently - if (!m_UpdateInterval || m_NextUpdateTime > time(NULL)) + if (!_updateInterval || _nextUpdateTime > time(NULL)) return; - m_NextUpdateTime = time(NULL) + m_UpdateInterval; + _nextUpdateTime = time(NULL) + _updateInterval; // Clears Realm list - m_realms.clear(); + _realms.clear(); // Get the content of the realmlist table in the database UpdateRealms(); @@ -130,17 +128,23 @@ void RealmList::UpdateRealms(bool init) uint16 port = fields[5].GetUInt16(); uint8 icon = fields[6].GetUInt8(); + if (icon == REALM_TYPE_FFA_PVP) + icon = REALM_TYPE_PVP; + if (icon >= MAX_CLIENT_REALM_TYPE) + icon = REALM_TYPE_NORMAL; 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); + RealmHandle id{ realmId }; + + UpdateRealm(id, build, name, externalAddress, localAddress, localSubmask, port, icon, flag, + timezone, (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop); 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); + TC_LOG_INFO("server.authserver", "Added realm \"%s\" at %s:%u.", name.c_str(), externalAddress.to_string().c_str(), port); } catch (std::exception& ex) { @@ -151,3 +155,12 @@ void RealmList::UpdateRealms(bool init) while (result->NextRow()); } } + +Realm const* RealmList::GetRealm(RealmHandle const& id) const +{ + auto itr = _realms.find(id); + if (itr != _realms.end()) + return &itr->second; + + return NULL; +} diff --git a/src/server/authserver/Realms/RealmList.h b/src/server/authserver/Realms/RealmList.h index cc5c88c01f2..e8b2c8337fa 100644 --- a/src/server/authserver/Realms/RealmList.h +++ b/src/server/authserver/Realms/RealmList.h @@ -19,48 +19,19 @@ #ifndef _REALMLIST_H #define _REALMLIST_H +#include "Common.h" +#include "Realm/Realm.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; -}; - /// Storage object for the list of realms on the server class RealmList { public: - typedef std::map<std::string, Realm> RealmMap; + typedef std::map<RealmHandle, Realm> RealmMap; static RealmList* instance() { @@ -74,22 +45,21 @@ public: void UpdateIfNeed(); - void AddRealm(const Realm& NewRealm) { m_realms[NewRealm.name] = NewRealm; } + void AddRealm(const Realm& NewRealm) { _realms[NewRealm.Id] = 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(); } + RealmMap const& GetRealms() const { return _realms; } + Realm const* GetRealm(RealmHandle const& id) const; 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); + void UpdateRealm(RealmHandle const& id, uint32 build, 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); - RealmMap m_realms; - uint32 m_UpdateInterval; - time_t m_NextUpdateTime; + RealmMap _realms; + uint32 _updateInterval; + time_t _nextUpdateTime; boost::asio::ip::tcp::resolver* _resolver; }; |
