92 std::map<Battlenet::RealmHandle, std::string> existingRealms;
94 existingRealms[p.first] = p.second.Name;
105 boost::asio::ip::tcp::resolver::iterator end;
107 Field* fields = result->Fetch();
109 std::string name = fields[1].
GetString();
112 boost::system::error_code ec;
113 boost::asio::ip::tcp::resolver::iterator endPoint =
_resolver->resolve(externalAddressQuery, ec);
114 if (endPoint == end || ec)
116 TC_LOG_ERROR(
"realmlist",
"Could not resolve address %s for realm \"%s\" id %u", fields[2].GetString().c_str(), name.c_str(), realmId);
120 ip::address externalAddress = (*endPoint).endpoint().address();
123 endPoint =
_resolver->resolve(localAddressQuery, ec);
124 if (endPoint == end || ec)
126 TC_LOG_ERROR(
"realmlist",
"Could not resolve localAddress %s for realm \"%s\" id %u", fields[3].GetString().c_str(), name.c_str(), realmId);
130 ip::address localAddress = (*endPoint).endpoint().address();
133 endPoint =
_resolver->resolve(localSubmaskQuery, ec);
134 if (endPoint == end || ec)
136 TC_LOG_ERROR(
"realmlist",
"Could not resolve localSubnetMask %s for realm \"%s\" id %u", fields[4].GetString().c_str(), name.c_str(), realmId);
140 ip::address localSubmask = (*endPoint).endpoint().address();
158 UpdateRealm(
id, build, name, externalAddress, localAddress, localSubmask, port, icon, flag,
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);
166 TC_LOG_DEBUG(
"realmlist",
"Updating realm \"%s\" at %s:%u.", name.c_str(), externalAddress.to_string().c_str(), port);
168 existingRealms.erase(
id);
170 catch (std::exception& ex)
172 TC_LOG_ERROR(
"realmlist",
"Realmlist::UpdateRealms has thrown an exception: %s", ex.what());
176 while (result->NextRow());
179 for (
auto itr = existingRealms.begin(); itr != existingRealms.end(); ++itr)
180 TC_LOG_INFO(
"realmlist",
"Removed realm \"%s\".", itr->second.c_str());
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
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
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
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