TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RealmList Class Reference

Storage object for the list of realms on the server. More...

#include <RealmList.h>

Public Types

typedef std::map
< Battlenet::RealmHandle,
Realm
RealmMap
 

Public Member Functions

 ~RealmList ()
 
void Initialize (boost::asio::io_service &ioService, uint32 updateInterval)
 
void Close ()
 
RealmMap constGetRealms () const
 
Realm constGetRealm (Battlenet::RealmHandle const &id) const
 
RealmBuildInfo constGetBuildInfo (uint32 build) const
 
std::unordered_set
< std::string > const
GetSubRegions () const
 
void WriteSubRegions (bgs::protocol::game_utilities::v1::GetAllValuesForAttributeResponse *response) const
 
std::vector< uint8GetRealmEntryJSON (Battlenet::RealmHandle const &id, uint32 build) const
 
std::vector< uint8GetRealmList (uint32 build, std::string const &subRegion) const
 
uint32 JoinRealm (uint32 realmAddress, uint32 build, boost::asio::ip::address const &clientAddress, std::array< uint8, 32 > const &clientSecret, LocaleConstant locale, std::string const &os, std::string accountName, bgs::protocol::game_utilities::v1::ClientResponse *response) const
 

Static Public Member Functions

static RealmListInstance ()
 

Private Member Functions

 RealmList ()
 
void UpdateRealms (boost::system::error_code const &error)
 
void UpdateRealm (Battlenet::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)
 

Private Attributes

RealmMap _realms
 
std::unordered_set< std::string > _subRegions
 
uint32 _updateInterval
 
boost::asio::deadline_timer * _updateTimer
 
boost::asio::ip::tcp::resolver * _resolver
 

Detailed Description

Storage object for the list of realms on the server.

Member Typedef Documentation

Constructor & Destructor Documentation

RealmList::~RealmList ( )
35 {
36  delete _updateTimer;
37 }
boost::asio::deadline_timer * _updateTimer
Definition: RealmList.h:97
RealmList::RealmList ( )
private
30  : _updateInterval(0), _updateTimer(nullptr), _resolver(nullptr)
31 {
32 }
boost::asio::ip::tcp::resolver * _resolver
Definition: RealmList.h:98
boost::asio::deadline_timer * _updateTimer
Definition: RealmList.h:97
uint32 _updateInterval
Definition: RealmList.h:96

Member Function Documentation

void RealmList::Close ( )
57 {
58  _updateTimer->cancel();
59 }
boost::asio::deadline_timer * _updateTimer
Definition: RealmList.h:97
RealmBuildInfo const * RealmList::GetBuildInfo ( uint32  build) const
199 {
200  // List of client builds for verbose version info in realmlist packet
201  static std::vector<RealmBuildInfo> const ClientBuilds =
202  {
203  { 21355, 6, 2, 4, ' ' },
204  { 20726, 6, 2, 3, ' ' },
205  { 20574, 6, 2, 2, 'a' },
206  { 20490, 6, 2, 2, 'a' },
207  { 15595, 4, 3, 4, ' ' },
208  { 14545, 4, 2, 2, ' ' },
209  { 13623, 4, 0, 6, 'a' },
210  { 13930, 3, 3, 5, 'a' }, // 3.3.5a China Mainland build
211  { 12340, 3, 3, 5, 'a' },
212  { 11723, 3, 3, 3, 'a' },
213  { 11403, 3, 3, 2, ' ' },
214  { 11159, 3, 3, 0, 'a' },
215  { 10505, 3, 2, 2, 'a' },
216  { 9947, 3, 1, 3, ' ' },
217  { 8606, 2, 4, 3, ' ' },
218  { 6141, 1, 12, 3, ' ' },
219  { 6005, 1, 12, 2, ' ' },
220  { 5875, 1, 12, 1, ' ' },
221  };
222 
223  for (std::size_t i = 0; i < ClientBuilds.size(); ++i)
224  if (ClientBuilds[i].Build == build)
225  return &ClientBuilds[i];
226 
227  return nullptr;
228 }

+ Here is the caller graph for this function:

Realm const * RealmList::GetRealm ( Battlenet::RealmHandle const id) const
190 {
191  auto itr = _realms.find(id);
192  if (itr != _realms.end())
193  return &itr->second;
194 
195  return NULL;
196 }
arena_t NULL
Definition: jemalloc_internal.h:624
RealmMap _realms
Definition: RealmList.h:94

+ Here is the caller graph for this function:

std::vector< uint8 > RealmList::GetRealmEntryJSON ( Battlenet::RealmHandle const id,
uint32  build 
) const
237 {
238  std::vector<uint8> compressed;
239  if (Realm const* realm = GetRealm(id))
240  {
241  if (!(realm->Flags & REALM_FLAG_OFFLINE) && realm->Build == build)
242  {
243  JSON::RealmList::RealmEntry realmEntry;
244  realmEntry.set_wowrealmaddress(realm->Id.GetAddress());
245  realmEntry.set_cfgtimezonesid(1);
247  realmEntry.set_cfgcategoriesid(realm->Timezone);
248 
249  JSON::RealmList::ClientVersion* version = realmEntry.mutable_version();
250  if (RealmBuildInfo const* buildInfo = GetBuildInfo(realm->Build))
251  {
252  version->set_versionmajor(buildInfo->MajorVersion);
253  version->set_versionminor(buildInfo->MinorVersion);
254  version->set_versionrevision(buildInfo->BugfixVersion);
255  version->set_versionbuild(buildInfo->Build);
256  }
257  else
258  {
259  version->set_versionmajor(6);
260  version->set_versionminor(2);
261  version->set_versionrevision(4);
262  version->set_versionbuild(realm->Build);
263  }
264 
265  realmEntry.set_cfgrealmsid(realm->Id.Realm);
266  realmEntry.set_flags(realm->Flags);
267  realmEntry.set_name(realm->Name);
268  realmEntry.set_cfgconfigsid(realm->GetConfigId());
269  realmEntry.set_cfglanguagesid(1);
270 
271  std::string json = "JamJSONRealmEntry:" + JSON::Serialize(realmEntry);
272 
273  uLong compressedLength = compressBound(json.length());
274  compressed.resize(compressedLength + 4);
275  *reinterpret_cast<uint32*>(compressed.data()) = json.length() + 1;
276 
277  if (compress(compressed.data() + 4, &compressedLength, reinterpret_cast<uint8 const*>(json.c_str()), json.length() + 1) == Z_OK)
278  compressed.resize(compressedLength + 4);
279  else
280  compressed.clear();
281  }
282  }
283 
284  return compressed;
285 }
RealmBuildInfo const * GetBuildInfo(uint32 build) const
Definition: RealmList.cpp:198
Realm const * GetRealm(Battlenet::RealmHandle const &id) const
Definition: RealmList.cpp:189
uint32 Realm
Definition: Realm.h:53
void set_flags(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:2037
std::string Name
Definition: Realm.h:92
void set_cfgrealmsid(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:2013
Definition: RealmList.pb.h:129
Realm realm
Definition: World.cpp:3485
void set_versionminor(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:1252
void set_cfgconfigsid(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:2137
Definition: Realm.h:84
void set_name(const ::std::string &value)
Definition: RealmList.pb.h:2063
void set_versionrevision(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:1276
unsigned long uLong
Definition: zconf.h:371
uint32 GetAddress() const
Definition: Realm.h:60
void set_wowrealmaddress(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:1876
Definition: Realm.h:31
void set_cfgcategoriesid(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:1948
TC_SHARED_API std::string Serialize(google::protobuf::Message const &message)
Definition: ProtobufJSON.cpp:438
T max(const T &x, const T &y)
Definition: g3dmath.h:320
void set_cfglanguagesid(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:2161
Battlenet::RealmHandle Id
Definition: Realm.h:86
inline::JSON::RealmList::ClientVersion * mutable_version()
Definition: RealmList.pb.h:1972
uint32_t uint32
Definition: Define.h:150
void set_populationstate(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:1924
uint32 Build
Definition: Realm.h:87
void set_versionbuild(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:1300
uint8 Timezone
Definition: Realm.h:95
void set_cfgtimezonesid(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:1900
void set_versionmajor(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:1228
#define Z_OK
Definition: zlib.h:173
uint8_t uint8
Definition: Define.h:152
uint32 GetConfigId() const
Definition: Realm.cpp:56
uint32_t uint32
Definition: g3dmath.h:168
#define const
Definition: zconf.h:217
RealmFlags Flags
Definition: Realm.h:94
Definition: RealmList.h:31
Definition: RealmList.pb.h:611
float PopulationLevel
Definition: Realm.h:97

+ Here is the call graph for this function:

std::vector< uint8 > RealmList::GetRealmList ( uint32  build,
std::string const subRegion 
) const
288 {
290  for (auto const& realm : _realms)
291  {
292  if (realm.second.Id.GetSubRegionAddress() != subRegion)
293  continue;
294 
295  uint32 flag = realm.second.Flags;
296  if (realm.second.Build != build)
298 
299  JSON::RealmList::RealmState* state = realmList.add_updates();
300  state->mutable_update()->set_wowrealmaddress(realm.second.Id.GetAddress());
301  state->mutable_update()->set_cfgtimezonesid(1);
302  state->mutable_update()->set_populationstate((realm.second.Flags & REALM_FLAG_OFFLINE) ? 0u : std::max(uint32(realm.second.PopulationLevel), 1u));
303  state->mutable_update()->set_cfgcategoriesid(realm.second.Timezone);
304 
305  JSON::RealmList::ClientVersion* version = state->mutable_update()->mutable_version();
306  if (RealmBuildInfo const* buildInfo = GetBuildInfo(realm.second.Build))
307  {
308  version->set_versionmajor(buildInfo->MajorVersion);
309  version->set_versionminor(buildInfo->MinorVersion);
310  version->set_versionrevision(buildInfo->BugfixVersion);
311  version->set_versionbuild(buildInfo->Build);
312  }
313  else
314  {
315  version->set_versionmajor(6);
316  version->set_versionminor(2);
317  version->set_versionrevision(4);
318  version->set_versionbuild(realm.second.Build);
319  }
320 
321  state->mutable_update()->set_cfgrealmsid(realm.second.Id.Realm);
322  state->mutable_update()->set_flags(flag);
323  state->mutable_update()->set_name(realm.second.Name);
324  state->mutable_update()->set_cfgconfigsid(realm.second.GetConfigId());
325  state->mutable_update()->set_cfglanguagesid(1);
326 
327  state->set_deleting(false);
328  }
329 
330  std::string json = "JSONRealmListUpdates:" + JSON::Serialize(realmList);
331 
332  uLong compressedLength = compressBound(json.length());
333  std::vector<uint8> compressed;
334  compressed.resize(4 + compressedLength);
335  *reinterpret_cast<uint32*>(compressed.data()) = json.length() + 1;
336 
337  compress(compressed.data() + 4, &compressedLength, reinterpret_cast<uint8 const*>(json.c_str()), json.length() + 1);
338 
339  compressed.resize(compressedLength + 4);
340 
341  return compressed;
342 }
RealmBuildInfo const * GetBuildInfo(uint32 build) const
Definition: RealmList.cpp:198
uint32 Realm
Definition: Realm.h:53
std::string Name
Definition: Realm.h:92
Definition: RealmList.pb.h:129
Definition: Realm.h:30
Definition: RealmList.pb.h:774
Realm realm
Definition: World.cpp:3485
void set_versionminor(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:1252
void set_deleting(bool value)
Definition: RealmList.pb.h:2230
void set_versionrevision(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:1276
unsigned long uLong
Definition: zconf.h:371
uint32 GetAddress() const
Definition: Realm.h:60
Definition: Realm.h:31
TC_SHARED_API std::string Serialize(google::protobuf::Message const &message)
Definition: ProtobufJSON.cpp:438
T max(const T &x, const T &y)
Definition: g3dmath.h:320
std::string GetSubRegionAddress() const
Definition: Realm.cpp:71
Battlenet::RealmHandle Id
Definition: Realm.h:86
uint32_t uint32
Definition: Define.h:150
inline::JSON::RealmList::RealmEntry * mutable_update()
Definition: RealmList.pb.h:2189
inline::JSON::RealmList::RealmState * add_updates()
Definition: RealmList.pb.h:2255
Definition: RealmList.pb.h:852
uint32 Build
Definition: Realm.h:87
void set_versionbuild(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:1300
uint8 Timezone
Definition: Realm.h:95
void set_versionmajor(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:1228
uint8_t uint8
Definition: Define.h:152
RealmMap _realms
Definition: RealmList.h:94
uint32 GetConfigId() const
Definition: Realm.cpp:56
#define const
Definition: zconf.h:217
RealmFlags Flags
Definition: Realm.h:94
Definition: RealmList.h:31
float PopulationLevel
Definition: Realm.h:97

+ Here is the call graph for this function:

RealmMap const& RealmList::GetRealms ( ) const
inline
76 { return _realms; }
RealmMap _realms
Definition: RealmList.h:94
std::unordered_set<std::string> const& RealmList::GetSubRegions ( ) const
inline
80 { return _subRegions; }
std::unordered_set< std::string > _subRegions
Definition: RealmList.h:95

+ Here is the caller graph for this function:

void RealmList::Initialize ( boost::asio::io_service &  ioService,
uint32  updateInterval 
)
47 {
48  _updateInterval = updateInterval;
49  _updateTimer = new boost::asio::deadline_timer(ioService);
50  _resolver = new boost::asio::ip::tcp::resolver(ioService);
51 
52  // Get the content of the realmlist table in the database
53  UpdateRealms(boost::system::error_code());
54 }
boost::asio::ip::tcp::resolver * _resolver
Definition: RealmList.h:98
void UpdateRealms(boost::system::error_code const &error)
Definition: RealmList.cpp:82
boost::asio::deadline_timer * _updateTimer
Definition: RealmList.h:97
uint32 _updateInterval
Definition: RealmList.h:96

+ Here is the call graph for this function:

RealmList * RealmList::Instance ( )
static
40 {
41  static RealmList instance;
42  return &instance;
43 }
Storage object for the list of realms on the server.
Definition: RealmList.h:64
uint32 RealmList::JoinRealm ( uint32  realmAddress,
uint32  build,
boost::asio::ip::address const clientAddress,
std::array< uint8, 32 > const clientSecret,
LocaleConstant  locale,
std::string const os,
std::string  accountName,
bgs::protocol::game_utilities::v1::ClientResponse response 
) const
346 {
347  if (Realm const* realm = GetRealm(Battlenet::RealmHandle(realmAddress)))
348  {
349  if (realm->Flags & REALM_FLAG_OFFLINE || realm->Build != build)
351 
353  JSON::RealmList::RealmIPAddressFamily* addressFamily = serverAddresses.add_families();
354  addressFamily->set_family(1);
355 
356  JSON::RealmList::IPAddress* address = addressFamily->add_addresses();
357  address->set_ip(realm->GetAddressForClient(clientAddress).address().to_string());
358  address->set_port(realm->Port);
359 
360  std::string json = "JSONRealmListServerIPAddresses:" + JSON::Serialize(serverAddresses);
361 
362  uLong compressedLength = compressBound(json.length());
363  std::vector<uint8> compressed;
364  compressed.resize(4 + compressedLength);
365  *reinterpret_cast<uint32*>(compressed.data()) = json.length() + 1;
366 
367  if (compress(compressed.data() + 4, &compressedLength, reinterpret_cast<uint8 const*>(json.c_str()), json.length() + 1) != Z_OK)
369 
370  BigNumber serverSecret;
371  serverSecret.SetRand(8 * 32);
372 
373  SHA256Hash wowSessionKey;
374  wowSessionKey.UpdateData(clientSecret.data(), clientSecret.size());
375  wowSessionKey.UpdateData(serverSecret.AsByteArray(32).get(), 32);
376  wowSessionKey.Finalize();
377 
379  stmt->setString(0, ByteArrayToHexStr(wowSessionKey.GetDigest(), wowSessionKey.GetLength(), true));
380  stmt->setString(1, clientAddress.to_string());
381  stmt->setUInt8(2, locale);
382  stmt->setString(3, os);
383  stmt->setString(4, accountName);
385 
386  bgs::protocol::Attribute* attribute = response->add_attribute();
387  attribute->set_name("Param_RealmJoinTicket");
388  attribute->mutable_value()->set_blob_value(accountName);
389 
390  attribute = response->add_attribute();
391  attribute->set_name("Param_ServerAddresses");
392  attribute->mutable_value()->set_blob_value(compressed.data(), compressedLength + 4);
393 
394  attribute = response->add_attribute();
395  attribute->set_name("Param_JoinSecret");
396  attribute->mutable_value()->set_blob_value(serverSecret.AsByteArray(32).get(), 32);
397  return ERROR_OK;
398  }
399 
401 }
Definition: BigNumber.h:28
Realm const * GetRealm(Battlenet::RealmHandle const &id) const
Definition: RealmList.cpp:189
void set_name(const ::std::string &value)
Definition: attribute_types.pb.h:935
void set_port(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:2368
Realm realm
Definition: World.cpp:3485
Definition: Realm.h:84
void setUInt8(const uint8 index, const uint8 value)
Definition: PreparedStatement.cpp:97
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
Definition: RealmList.pb.h:1002
unsigned long uLong
Definition: zconf.h:371
uint16 Port
Definition: Realm.h:91
inline::bgs::protocol::Variant * mutable_value()
Definition: attribute_types.pb.h:1009
Definition: Realm.h:31
TC_SHARED_API std::string Serialize(google::protobuf::Message const &message)
Definition: ProtobufJSON.cpp:438
Definition: SHA256.h:28
Definition: PreparedStatement.h:74
uint8 * GetDigest(void)
Definition: SHA256.h:44
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
Definition: BattlenetRpcErrorCodes.h:594
Definition: RealmList.pb.h:1081
uint32_t uint32
Definition: Define.h:150
void set_family(::google::protobuf::uint32 value)
Definition: RealmList.pb.h:2396
Definition: RealmList.pb.h:921
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void SetRand(int32 numbits)
Definition: BigNumber.cpp:74
inline::JSON::RealmList::IPAddress * add_addresses()
Definition: RealmList.pb.h:2417
void set_ip(const ::std::string &value)
Definition: RealmList.pb.h:2294
uint32 Build
Definition: Realm.h:87
void UpdateData(const uint8 *dta, int len)
Definition: SHA256.cpp:34
Definition: LoginDatabase.h:115
inline::bgs::protocol::Attribute * add_attribute()
Definition: game_utilities_service.pb.h:1617
Definition: BattlenetRpcErrorCodes.h:25
std::string ByteArrayToHexStr(uint8 const *bytes, uint32 arrayLen, bool reverse)
Definition: Util.cpp:509
inline::JSON::RealmList::RealmIPAddressFamily * add_families()
Definition: RealmList.pb.h:2451
std::unique_ptr< uint8[]> AsByteArray(int32 minSize=0, bool littleEndian=true)
Definition: BigNumber.cpp:177
Definition: BattlenetRpcErrorCodes.h:604
Definition: Realm.h:44
#define Z_OK
Definition: zlib.h:173
uint8_t uint8
Definition: Define.h:152
void Finalize()
Definition: SHA256.cpp:64
#define const
Definition: zconf.h:217
ip::tcp::endpoint GetAddressForClient(ip::address const &clientAddr) const
Definition: Realm.cpp:21
RealmFlags Flags
Definition: Realm.h:94
void DirectExecute(const char *sql)
Definition: DatabaseWorkerPool.h:121
int GetLength(void) const
Definition: SHA256.h:45
Definition: attribute_types.pb.h:248
Definition: BattlenetRpcErrorCodes.h:638

+ Here is the call graph for this function:

void RealmList::UpdateRealm ( Battlenet::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 
)
private
64 {
65  // Create new if not exist or update existed
66  Realm& realm = _realms[id];
67 
68  realm.Id = id;
69  realm.Build = build;
70  realm.Name = name;
71  realm.Type = icon;
72  realm.Flags = flag;
73  realm.Timezone = timezone;
74  realm.AllowedSecurityLevel = allowedSecurityLevel;
75  realm.PopulationLevel = population;
76  realm.ExternalAddress = address;
77  realm.LocalAddress = localAddr;
78  realm.LocalSubnetMask = localSubmask;
79  realm.Port = port;
80 }
std::string Name
Definition: Realm.h:92
AccountTypes AllowedSecurityLevel
Definition: Realm.h:96
Realm realm
Definition: World.cpp:3485
Definition: Realm.h:84
uint16 Port
Definition: Realm.h:91
ip::address ExternalAddress
Definition: Realm.h:88
ip::address LocalSubnetMask
Definition: Realm.h:90
Battlenet::RealmHandle Id
Definition: Realm.h:86
ip::address LocalAddress
Definition: Realm.h:89
uint32 Build
Definition: Realm.h:87
uint8 Timezone
Definition: Realm.h:95
RealmMap _realms
Definition: RealmList.h:94
uint8 Type
Definition: Realm.h:93
RealmFlags Flags
Definition: Realm.h:94
float PopulationLevel
Definition: Realm.h:97

+ Here is the caller graph for this function:

void RealmList::UpdateRealms ( boost::system::error_code const error)
private
83 {
84  if (error)
85  return;
86 
87  TC_LOG_DEBUG("realmlist", "Updating Realm List...");
88 
91 
92  std::map<Battlenet::RealmHandle, std::string> existingRealms;
93  for (auto const& p : _realms)
94  existingRealms[p.first] = p.second.Name;
95 
96  _realms.clear();
97 
98  // Circle through results and add them to the realm map
99  if (result)
100  {
101  do
102  {
103  try
104  {
105  boost::asio::ip::tcp::resolver::iterator end;
106 
107  Field* fields = result->Fetch();
108  uint32 realmId = fields[0].GetUInt32();
109  std::string name = fields[1].GetString();
110  boost::asio::ip::tcp::resolver::query externalAddressQuery(ip::tcp::v4(), fields[2].GetString(), "");
111 
112  boost::system::error_code ec;
113  boost::asio::ip::tcp::resolver::iterator endPoint = _resolver->resolve(externalAddressQuery, ec);
114  if (endPoint == end || ec)
115  {
116  TC_LOG_ERROR("realmlist", "Could not resolve address %s for realm \"%s\" id %u", fields[2].GetString().c_str(), name.c_str(), realmId);
117  continue;
118  }
119 
120  ip::address externalAddress = (*endPoint).endpoint().address();
121 
122  boost::asio::ip::tcp::resolver::query localAddressQuery(ip::tcp::v4(), fields[3].GetString(), "");
123  endPoint = _resolver->resolve(localAddressQuery, ec);
124  if (endPoint == end || ec)
125  {
126  TC_LOG_ERROR("realmlist", "Could not resolve localAddress %s for realm \"%s\" id %u", fields[3].GetString().c_str(), name.c_str(), realmId);
127  continue;
128  }
129 
130  ip::address localAddress = (*endPoint).endpoint().address();
131 
132  boost::asio::ip::tcp::resolver::query localSubmaskQuery(ip::tcp::v4(), fields[4].GetString(), "");
133  endPoint = _resolver->resolve(localSubmaskQuery, ec);
134  if (endPoint == end || ec)
135  {
136  TC_LOG_ERROR("realmlist", "Could not resolve localSubnetMask %s for realm \"%s\" id %u", fields[4].GetString().c_str(), name.c_str(), realmId);
137  continue;
138  }
139 
140  ip::address localSubmask = (*endPoint).endpoint().address();
141 
142  uint16 port = fields[5].GetUInt16();
143  uint8 icon = fields[6].GetUInt8();
144  if (icon == REALM_TYPE_FFA_PVP)
145  icon = REALM_TYPE_PVP;
146  if (icon >= MAX_CLIENT_REALM_TYPE)
147  icon = REALM_TYPE_NORMAL;
148  RealmFlags flag = RealmFlags(fields[7].GetUInt8());
149  uint8 timezone = fields[8].GetUInt8();
150  uint8 allowedSecurityLevel = fields[9].GetUInt8();
151  float pop = fields[10].GetFloat();
152  uint32 build = fields[11].GetUInt32();
153  uint8 region = fields[12].GetUInt8();
154  uint8 battlegroup = fields[13].GetUInt8();
155 
156  Battlenet::RealmHandle id{ region, battlegroup, realmId };
157 
158  UpdateRealm(id, build, name, externalAddress, localAddress, localSubmask, port, icon, flag,
159  timezone, (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), pop);
160 
161  _subRegions.insert(Battlenet::RealmHandle{ region, battlegroup, 0 }.GetAddressString());
162 
163  if (!existingRealms.count(id))
164  TC_LOG_INFO("realmlist", "Added realm \"%s\" at %s:%u.", name.c_str(), externalAddress.to_string().c_str(), port);
165  else
166  TC_LOG_DEBUG("realmlist", "Updating realm \"%s\" at %s:%u.", name.c_str(), externalAddress.to_string().c_str(), port);
167 
168  existingRealms.erase(id);
169  }
170  catch (std::exception& ex)
171  {
172  TC_LOG_ERROR("realmlist", "Realmlist::UpdateRealms has thrown an exception: %s", ex.what());
173  ABORT();
174  }
175  }
176  while (result->NextRow());
177  }
178 
179  for (auto itr = existingRealms.begin(); itr != existingRealms.end(); ++itr)
180  TC_LOG_INFO("realmlist", "Removed realm \"%s\".", itr->second.c_str());
181 
182  if (_updateInterval)
183  {
185  _updateTimer->async_wait(std::bind(&RealmList::UpdateRealms, this, std::placeholders::_1));
186  }
187 }
Definition: Realm.h:71
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
boost::asio::ip::tcp::resolver * _resolver
Definition: RealmList.h:98
float GetFloat() const
Definition: Field.h:222
std::string GetAddressString() const
Definition: Realm.cpp:66
Definition: Realm.h:72
Definition: Common.h:111
Class used to access individual fields of database query result.
Definition: Field.h:56
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
char * query(struct soap *soap)
Definition: httpget.cpp:244
float seconds()
Definition: units.h:97
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
uint8 GetUInt8() const
Definition: Field.h:70
void UpdateRealm(Battlenet::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)
Definition: RealmList.cpp:61
uint32_t uint32
Definition: Define.h:150
AccountTypes
Definition: Common.h:106
uint16_t uint16
Definition: Define.h:151
uint16 GetUInt16() const
Definition: Field.h:108
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void UpdateRealms(boost::system::error_code const &error)
Definition: RealmList.cpp:82
Definition: Realm.h:77
boost::asio::deadline_timer * _updateTimer
Definition: RealmList.h:97
RealmFlags
Definition: Realm.h:27
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
#define ABORT
Definition: Errors.h:56
uint32 GetUInt32() const
Definition: Field.h:146
Definition: Realm.h:44
uint8_t uint8
Definition: Define.h:152
RealmMap _realms
Definition: RealmList.h:94
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
Definition: LoginDatabase.h:32
std::unordered_set< std::string > _subRegions
Definition: RealmList.h:95
std::string GetString() const
Definition: Field.h:276
uint32 _updateInterval
Definition: RealmList.h:96
Definition: Realm.h:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RealmList::WriteSubRegions ( bgs::protocol::game_utilities::v1::GetAllValuesForAttributeResponse response) const
231 {
232  for (std::string const& subRegion : GetSubRegions())
233  response->add_attribute_value()->set_string_value(subRegion);
234 }
inline::bgs::protocol::Variant * add_attribute_value()
Definition: game_utilities_service.pb.h:2620
std::unordered_set< std::string > const & GetSubRegions() const
Definition: RealmList.h:80

+ Here is the call graph for this function:

Member Data Documentation

RealmMap RealmList::_realms
private
boost::asio::ip::tcp::resolver* RealmList::_resolver
private
std::unordered_set<std::string> RealmList::_subRegions
private
uint32 RealmList::_updateInterval
private
boost::asio::deadline_timer* RealmList::_updateTimer
private

The documentation for this class was generated from the following files: