2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "RealmList.h"
25 #include "AuthCodes.h"
26 #include "Util.h" // for Tokens typedef
27 #include "Policies/SingletonImp.h"
28 #include "Database/DatabaseEnv.h"
30 INSTANTIATE_SINGLETON_1( RealmList
);
32 extern DatabaseType LoginDatabase
;
34 // will only support WoW 1.12.1/1.12.2 , WoW:TBC 2.4.3 and official release for WoW:WotLK and later, client builds 10505, 8606, 6005, 5875
35 // if you need more from old build then add it in cases in realmd sources code
36 // list sorted from high to low build and first build used as low bound for accepted by default range (any > it will accepted by realmd at least)
38 static RealmBuildInfo ExpectedRealmdClientBuilds
[] = {
39 {11723, 3, 3, 3, 'a'}, // highest supported build, also auto accept all above for simplify future supported builds testing
40 {11403, 3, 3, 2, ' '},
41 {11159, 3, 3, 0, 'a'},
42 {10505, 3, 2, 2, 'a'},
46 {0, 0, 0, 0, ' '} // terminator
49 RealmBuildInfo
const* FindBuildInfo(uint16 _build
)
51 // first build is low bound of always accepted range
52 if (_build
>= ExpectedRealmdClientBuilds
[0].build
)
53 return &ExpectedRealmdClientBuilds
[0];
55 // continue from 1 with explicit equal check
56 for(int i
= 1; ExpectedRealmdClientBuilds
[i
].build
; ++i
)
57 if(_build
== ExpectedRealmdClientBuilds
[i
].build
)
58 return &ExpectedRealmdClientBuilds
[i
];
60 // none appropriate build
64 RealmList::RealmList( ) : m_UpdateInterval(0), m_NextUpdateTime(time(NULL
))
70 static RealmList realmlist
;
74 /// Load the realm list from the database
75 void RealmList::Initialize(uint32 updateInterval
)
77 m_UpdateInterval
= updateInterval
;
79 ///- Get the content of the realmlist table in the database
83 void RealmList::UpdateRealm( uint32 ID
, const std::string
& name
, const std::string
& address
, uint32 port
, uint8 icon
, RealmFlags realmflags
, uint8 timezone
, AccountTypes allowedSecurityLevel
, float popu
, const char* builds
)
85 ///- Create new if not exist or update existed
86 Realm
& realm
= m_realms
[name
];
90 realm
.realmflags
= realmflags
;
91 realm
.timezone
= timezone
;
92 realm
.allowedSecurityLevel
= allowedSecurityLevel
;
93 realm
.populationLevel
= popu
;
95 Tokens tokens
= StrSplit(builds
, " ");
96 Tokens::iterator iter
;
98 for (iter
= tokens
.begin(); iter
!= tokens
.end(); ++iter
)
100 uint32 build
= atol((*iter
).c_str());
101 realm
.realmbuilds
.insert(build
);
104 uint16 first_build
= !realm
.realmbuilds
.empty() ? *realm
.realmbuilds
.begin() : 0;
106 realm
.realmBuildInfo
.build
= first_build
;
107 realm
.realmBuildInfo
.major_version
= 0;
108 realm
.realmBuildInfo
.minor_version
= 0;
109 realm
.realmBuildInfo
.bugfix_version
= 0;
110 realm
.realmBuildInfo
.hotfix_version
= ' ';
113 if (RealmBuildInfo
const* bInfo
= FindBuildInfo(first_build
))
114 if (bInfo
->build
== first_build
)
115 realm
.realmBuildInfo
= *bInfo
;
117 ///- Append port to IP address.
118 std::ostringstream ss
;
119 ss
<< address
<< ":" << port
;
120 realm
.address
= ss
.str();
123 void RealmList::UpdateIfNeed()
125 // maybe disabled or updated recently
126 if(!m_UpdateInterval
|| m_NextUpdateTime
> time(NULL
))
129 m_NextUpdateTime
= time(NULL
) + m_UpdateInterval
;
134 // Get the content of the realmlist table in the database
138 void RealmList::UpdateRealms(bool init
)
140 DETAIL_LOG("Updating Realm List...");
142 //// 0 1 2 3 4 5 6 7 8 9
143 QueryResult
*result
= LoginDatabase
.Query( "SELECT id, name, address, port, icon, realmflags, timezone, allowedSecurityLevel, population, realmbuilds FROM realmlist WHERE (realmflags & 1) = 0 ORDER BY name" );
145 ///- Circle through results and add them to the realm map
150 Field
*fields
= result
->Fetch();
152 uint8 allowedSecurityLevel
= fields
[7].GetUInt8();
154 uint8 realmflags
= fields
[5].GetUInt8();
156 if (realmflags
& ~(REALM_FLAG_OFFLINE
|REALM_FLAG_NEW_PLAYERS
|REALM_FLAG_RECOMMENDED
|REALM_FLAG_SPECIFYBUILD
))
158 sLog
.outError("Realm allowed have only OFFLINE Mask 0x2), or NEWPLAYERS (mask 0x20), or RECOMENDED (mask 0x40), or SPECIFICBUILD (mask 0x04) flags in DB");
159 realmflags
&= (REALM_FLAG_OFFLINE
|REALM_FLAG_NEW_PLAYERS
|REALM_FLAG_RECOMMENDED
|REALM_FLAG_SPECIFYBUILD
);
163 fields
[0].GetUInt32(), fields
[1].GetCppString(),fields
[2].GetCppString(),fields
[3].GetUInt32(),
164 fields
[4].GetUInt8(), RealmFlags(realmflags
), fields
[6].GetUInt8(),
165 (allowedSecurityLevel
<= SEC_ADMINISTRATOR
? AccountTypes(allowedSecurityLevel
) : SEC_ADMINISTRATOR
),
166 fields
[8].GetFloat(), fields
[9].GetString());
169 sLog
.outString("Added realm \"%s\"", fields
[1].GetString());
170 } while( result
->NextRow() );