Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
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
"
7
#include "
Database/DatabaseEnv.h
"
8
#include "
RealmList.h
"
9
10
RealmList::RealmList
() :
m_UpdateInterval
(0),
m_NextUpdateTime
(time(NULL)) { }
11
12
// Load the realm list from the database
13
void
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
21
void
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
44
void
RealmList::UpdateIfNeed
()
45
{
46
// maybe disabled or updated recently
47
if
(!
m_UpdateInterval
||
m_NextUpdateTime
> time(NULL))
48
return
;
49
50
m_NextUpdateTime
= time(NULL) +
m_UpdateInterval
;
51
52
// Clears Realm list
53
m_realms
.clear();
54
55
// Get the content of the realmlist table in the database
56
UpdateRealms
();
57
}
58
59
void
RealmList::UpdateRealms
(
bool
init)
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
}
Common.h
AccountTypes
AccountTypes
Definition
Common.h:129
AccountTypes::SEC_ADMINISTRATOR
@ SEC_ADMINISTRATOR
Definition
Common.h:133
DatabaseEnv.h
uint8
std::uint8_t uint8
Definition
Define.h:79
uint32
std::uint32_t uint32
Definition
Define.h:77
uint16
std::uint16_t uint16
Definition
Define.h:78
SF_LOG_INFO
#define SF_LOG_INFO(filterType__,...)
Definition
Log.h:137
LOGIN_SEL_AUTH_REALMLIST
@ LOGIN_SEL_AUTH_REALMLIST
Definition
LoginDatabase.h:33
PreparedQueryResult
Skyfire::AutoPtr< PreparedResultSet, Skyfire::Mutex > PreparedQueryResult
Definition
QueryResult.h:94
RealmList.h
RealmFlags
RealmFlags
Definition
RealmList.h:14
Field
Definition
Field.h:16
Field::GetUInt8
uint8 GetUInt8() const
Definition
Field.h:26
Field::GetString
std::string GetString() const
Definition
Field.h:228
Field::GetUInt16
uint16 GetUInt16() const
Definition
Field.h:69
Field::GetFloat
float GetFloat() const
Definition
Field.h:177
Field::GetUInt32
uint32 GetUInt32() const
Definition
Field.h:105
PreparedStatement
Definition
PreparedStatement.h:63
RealmList::m_NextUpdateTime
time_t m_NextUpdateTime
Definition
RealmList.h:72
RealmList::m_UpdateInterval
uint32 m_UpdateInterval
Definition
RealmList.h:71
RealmList::UpdateRealm
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
RealmList::Initialize
void Initialize(uint32 updateInterval)
Definition
RealmList.cpp:13
RealmList::UpdateIfNeed
void UpdateIfNeed()
Definition
RealmList.cpp:44
RealmList::m_realms
RealmMap m_realms
Definition
RealmList.h:70
RealmList::RealmList
RealmList()
Definition
RealmList.cpp:10
RealmList::UpdateRealms
void UpdateRealms(bool init=false)
Definition
RealmList.cpp:59
Skyfire::Net::Address
Definition
NetworkAddress.h:18
LoginDatabase
LoginDatabaseWorkerPool LoginDatabase
Definition
Main.cpp:54
Realm
Definition
RealmList.h:28
Realm::LocalAddress
Skyfire::Net::Address LocalAddress
Definition
RealmList.h:32
Realm::name
std::string name
Definition
RealmList.h:34
Realm::flag
RealmFlags flag
Definition
RealmList.h:36
Realm::allowedSecurityLevel
AccountTypes allowedSecurityLevel
Definition
RealmList.h:39
Realm::icon
uint8 icon
Definition
RealmList.h:35
Realm::timezone
uint8 timezone
Definition
RealmList.h:37
Realm::m_ID
uint32 m_ID
Definition
RealmList.h:38
Realm::populationLevel
float populationLevel
Definition
RealmList.h:40
Realm::ExternalAddress
Skyfire::Net::Address ExternalAddress
Definition
RealmList.h:31
Realm::gamebuild
uint32 gamebuild
Definition
RealmList.h:41
Realm::LocalSubnetMask
Skyfire::Net::Address LocalSubnetMask
Definition
RealmList.h:33
src
server
authserver
Realms
RealmList.cpp
Generated on
for Project SkyFire Core by
1.17.0