Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
RealmList.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "Common.h"
8#include "RealmList.h"
9
11
12// Load the realm list from the database
13void RealmList::Initialize(uint32 updateInterval)
14{
15 m_UpdateInterval = updateInterval;
16
17 // Get the content of the realmlist table in the database
18 UpdateRealms(true);
19}
20
21void RealmList::UpdateRealm(uint32 id, const std::string& name, Skyfire::Net::Address const& address,
22 Skyfire::Net::Address const& localAddr, Skyfire::Net::Address const& localSubmask,
23 uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel,
24 float popu, uint32 build)
25{
26 // Create new if not exist or update existed
27 Realm& realm = m_realms[name];
28
29 realm.m_ID = id;
30 realm.name = name;
31 realm.icon = icon;
32 realm.flag = flag;
33 realm.timezone = timezone;
34 realm.allowedSecurityLevel = allowedSecurityLevel;
35 realm.populationLevel = popu;
36
37 // Append port to IP address.
38 realm.ExternalAddress = address;
39 realm.LocalAddress = localAddr;
40 realm.LocalSubnetMask = localSubmask;
41 realm.gamebuild = build;
42}
43
45{
46 // maybe disabled or updated recently
47 if (!m_UpdateInterval || m_NextUpdateTime > time(NULL))
48 return;
49
51
52 // Clears Realm list
53 m_realms.clear();
54
55 // Get the content of the realmlist table in the database
57}
58
60{
61 SF_LOG_INFO("server.authserver", "Updating Realm List...");
62
63 PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_AUTH_REALMLIST);
64 PreparedQueryResult result = LoginDatabase.Query(stmt);
65
66 // Circle through results and add them to the realm map
67 if (result)
68 {
69 do
70 {
71 Field* fields = result->Fetch();
72 uint32 realmId = fields[0].GetUInt32();
73 std::string name = fields[1].GetString();
74 std::string externalAddress = fields[2].GetString();
75 std::string localAddress = fields[3].GetString();
76 std::string localSubmask = fields[4].GetString();
77 uint16 port = fields[5].GetUInt16();
78 uint8 icon = fields[6].GetUInt8();
79 RealmFlags flag = RealmFlags(fields[7].GetUInt8());
80 uint8 timezone = fields[8].GetUInt8();
81 AccountTypes allowedSecurityLevel = AccountTypes(fields[9].GetUInt8());
82 float pop = fields[10].GetFloat();
83 uint32 build = fields[11].GetUInt32();
84
85 Skyfire::Net::Address externalAddr(externalAddress, port);
86 Skyfire::Net::Address localAddr(localAddress, port);
87 Skyfire::Net::Address submask(localSubmask);
88
89 AccountTypes securityLevel = allowedSecurityLevel <= AccountTypes::SEC_ADMINISTRATOR ?
90 AccountTypes(allowedSecurityLevel) : AccountTypes::SEC_ADMINISTRATOR;
91 UpdateRealm(realmId, name, externalAddr, localAddr, submask, icon, flag, timezone,
92 securityLevel, pop, build);
93
94 if (init)
95 SF_LOG_INFO("server.authserver", "Added realm \"%s\" at %s:%u.", name.c_str(),
96 m_realms[name].ExternalAddress.GetHost().c_str(), port);
97 } while (result->NextRow());
98 }
99}
AccountTypes
Definition Common.h:129
@ SEC_ADMINISTRATOR
Definition Common.h:133
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
std::uint16_t uint16
Definition Define.h:78
#define SF_LOG_INFO(filterType__,...)
Definition Log.h:137
@ LOGIN_SEL_AUTH_REALMLIST
Skyfire::AutoPtr< PreparedResultSet, Skyfire::Mutex > PreparedQueryResult
Definition QueryResult.h:94
RealmFlags
Definition RealmList.h:14
Definition Field.h:16
uint8 GetUInt8() const
Definition Field.h:26
std::string GetString() const
Definition Field.h:228
uint16 GetUInt16() const
Definition Field.h:69
float GetFloat() const
Definition Field.h:177
uint32 GetUInt32() const
Definition Field.h:105
time_t m_NextUpdateTime
Definition RealmList.h:72
uint32 m_UpdateInterval
Definition RealmList.h:71
void UpdateRealm(uint32 id, const std::string &name, Skyfire::Net::Address const &address, Skyfire::Net::Address const &localAddr, Skyfire::Net::Address const &localSubmask, uint8 icon, RealmFlags flag, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, uint32 build)
Definition RealmList.cpp:21
void Initialize(uint32 updateInterval)
Definition RealmList.cpp:13
void UpdateIfNeed()
Definition RealmList.cpp:44
RealmMap m_realms
Definition RealmList.h:70
void UpdateRealms(bool init=false)
Definition RealmList.cpp:59
LoginDatabaseWorkerPool LoginDatabase
Definition Main.cpp:54
Skyfire::Net::Address LocalAddress
Definition RealmList.h:32
std::string name
Definition RealmList.h:34
RealmFlags flag
Definition RealmList.h:36
AccountTypes allowedSecurityLevel
Definition RealmList.h:39
uint8 icon
Definition RealmList.h:35
uint8 timezone
Definition RealmList.h:37
uint32 m_ID
Definition RealmList.h:38
float populationLevel
Definition RealmList.h:40
Skyfire::Net::Address ExternalAddress
Definition RealmList.h:31
uint32 gamebuild
Definition RealmList.h:41
Skyfire::Net::Address LocalSubnetMask
Definition RealmList.h:33