aboutsummaryrefslogtreecommitdiff
path: root/src/trinityrealm/RealmList.cpp
diff options
context:
space:
mode:
authormaximius <none@none>2009-10-17 15:51:44 -0700
committermaximius <none@none>2009-10-17 15:51:44 -0700
commite585187b248f48b3c6e9247b49fa07c6565d65e5 (patch)
tree637c5b7ddacf41040bef4ea4f75a97da64c6a9bc /src/trinityrealm/RealmList.cpp
parent26b5e033ffde3d161382fc9addbfa99738379641 (diff)
*Backed out changeset 3be01fb200a5
--HG-- branch : trunk
Diffstat (limited to 'src/trinityrealm/RealmList.cpp')
-rw-r--r--src/trinityrealm/RealmList.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/trinityrealm/RealmList.cpp b/src/trinityrealm/RealmList.cpp
index c4b78bfe482..be8a7738ef7 100644
--- a/src/trinityrealm/RealmList.cpp
+++ b/src/trinityrealm/RealmList.cpp
@@ -17,29 +17,38 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+
/** \file
\ingroup realmd
*/
+
#include "Common.h"
#include "RealmList.h"
#include "Policies/SingletonImp.h"
#include "Database/DatabaseEnv.h"
+
INSTANTIATE_SINGLETON_1(RealmList);
+
extern DatabaseType loginDatabase;
+
RealmList::RealmList() : m_UpdateInterval(0), m_NextUpdateTime(time(NULL))
{
}
+
/// Load the realm list from the database
void RealmList::Initialize(uint32 updateInterval)
{
m_UpdateInterval = updateInterval;
+
///- Get the content of the realmlist table in the database
UpdateRealms(true);
}
+
void RealmList::UpdateRealm(uint32 ID, const std::string& name, const std::string& address, uint32 port, uint8 icon, uint8 color, uint8 timezone, AccountTypes allowedSecurityLevel, float popu, uint32 build)
{
///- Create new if not exist or update existed
Realm& realm = m_realms[name];
+
realm.m_ID = ID;
realm.name = name;
realm.icon = icon;
@@ -47,34 +56,44 @@ void RealmList::UpdateRealm(uint32 ID, const std::string& name, const std::strin
realm.timezone = timezone;
realm.allowedSecurityLevel = allowedSecurityLevel;
realm.populationLevel = popu;
+
///- Append port to IP address.
std::ostringstream ss;
ss << address << ":" << port;
realm.address = ss.str();
realm.gamebuild = build;
}
+
void RealmList::UpdateIfNeed()
{
// maybe disabled or updated recently
if (!m_UpdateInterval || m_NextUpdateTime > time(NULL))
return;
+
m_NextUpdateTime = time(NULL) + m_UpdateInterval;
+
// Clears Realm list
m_realms.clear();
+
// Get the content of the realmlist table in the database
UpdateRealms(false);
}
+
void RealmList::UpdateRealms(bool init)
{
sLog.outDetail("Updating Realm List...");
+
QueryResult *result = loginDatabase.Query("SELECT id, name, address, port, icon, color, timezone, allowedSecurityLevel, population, gamebuild FROM realmlist WHERE color <> 3 ORDER BY name");
+
///- Circle through results and add them to the realm map
if (result)
{
do
{
Field *fields = result->Fetch();
+
uint8 allowedSecurityLevel = fields[7].GetUInt8();
+
UpdateRealm(fields[0].GetUInt32(), fields[1].GetCppString(),fields[2].GetCppString(),fields[3].GetUInt32(),fields[4].GetUInt8(), fields[5].GetUInt8(), fields[6].GetUInt8(), (allowedSecurityLevel <= SEC_ADMINISTRATOR ? AccountTypes(allowedSecurityLevel) : SEC_ADMINISTRATOR), fields[8].GetFloat(), fields[9].GetUInt32());
if (init)
sLog.outString("Added realm \"%s\".", fields[1].GetString());