aboutsummaryrefslogtreecommitdiff
path: root/src/trinityrealm/RealmList.cpp
diff options
context:
space:
mode:
authorNeo2003 <none@none>2008-10-02 16:23:55 -0500
committerNeo2003 <none@none>2008-10-02 16:23:55 -0500
commit9b1c0e006f20091f28f3f468cfcab1feb51286bd (patch)
treeb5d1ba94a656e6679f8737f9ea6bed1239b73b14 /src/trinityrealm/RealmList.cpp
[svn] * Proper SVN structureinit
--HG-- branch : trunk
Diffstat (limited to 'src/trinityrealm/RealmList.cpp')
-rw-r--r--src/trinityrealm/RealmList.cpp100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/trinityrealm/RealmList.cpp b/src/trinityrealm/RealmList.cpp
new file mode 100644
index 00000000000..091b8f95d88
--- /dev/null
+++ b/src/trinityrealm/RealmList.cpp
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * 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 dbRealmServer;
+
+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, std::string name, std::string address, uint32 port, uint8 icon, uint8 color, uint8 timezone, AccountTypes allowedSecurityLevel, float popu)
+{
+ ///- Create new if not exist or update existed
+ Realm& realm = m_realms[name];
+
+ realm.m_ID = ID;
+ realm.name = name;
+ realm.icon = icon;
+ realm.color = color;
+ realm.timezone = timezone;
+ realm.allowedSecurityLevel = allowedSecurityLevel;
+ realm.populationLevel = popu;
+
+ ///- Append port to IP address.
+ std::ostringstream ss;
+ ss << address << ":" << port;
+ realm.address = ss.str();
+}
+
+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 = dbRealmServer.Query( "SELECT id, name, address, port, icon, color, timezone, allowedSecurityLevel, population 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() );
+ if(init)
+ sLog.outString("Added realm \"%s\".", fields[1].GetString());
+ } while( result->NextRow() );
+ delete result;
+ }
+}