aboutsummaryrefslogtreecommitdiff
path: root/src/server/authserver/Realms
diff options
context:
space:
mode:
authorXTZGZoReX <none@none>2010-06-06 23:08:23 +0200
committerXTZGZoReX <none@none>2010-06-06 23:08:23 +0200
commitf27daddd1b95616b7e68bc384eeffb3c62e9bdd2 (patch)
treef8400e56656071b309127e23580e94f5bc99f978 /src/server/authserver/Realms
parent2225a6bcf7af401a780d93dae43b903dba68c463 (diff)
* Restructuring authserver and worldserver.
--HG-- branch : trunk
Diffstat (limited to 'src/server/authserver/Realms')
-rw-r--r--src/server/authserver/Realms/RealmList.cpp100
-rw-r--r--src/server/authserver/Realms/RealmList.h79
2 files changed, 179 insertions, 0 deletions
diff --git a/src/server/authserver/Realms/RealmList.cpp b/src/server/authserver/Realms/RealmList.cpp
new file mode 100644
index 00000000000..1e989c36c5d
--- /dev/null
+++ b/src/server/authserver/Realms/RealmList.cpp
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
+ *
+ * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.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 "Database/DatabaseEnv.h"
+
+
+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;
+ 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();
+ 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_AutoPtr 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());
+ } while(result->NextRow());
+ }
+}
diff --git a/src/server/authserver/Realms/RealmList.h b/src/server/authserver/Realms/RealmList.h
new file mode 100644
index 00000000000..b29b561c797
--- /dev/null
+++ b/src/server/authserver/Realms/RealmList.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
+ *
+ * Copyright (C) 2008-2010 Trinity <http://www.trinitycore.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
+ */
+
+/// \addtogroup realmd
+/// @{
+/// \file
+
+#ifndef _REALMLIST_H
+#define _REALMLIST_H
+
+#include <ace/Singleton.h>
+#include <ace/Null_Mutex.h>
+#include "Common.h"
+
+/// Storage object for a realm
+struct Realm
+{
+ std::string address;
+ std::string name;
+ uint8 icon;
+ uint8 color;
+ uint8 timezone;
+ uint32 m_ID;
+ AccountTypes allowedSecurityLevel;
+ float populationLevel;
+ uint32 gamebuild;
+};
+
+/// Storage object for the list of realms on the server
+class RealmList
+{
+ public:
+ // Null_Mutex is safe because the singleton initialized before the acceptor initialized(another place where the singleton called)
+ static RealmList* instance() { return ACE_Singleton<RealmList, ACE_Null_Mutex>::instance(); }
+
+ typedef std::map<std::string, Realm> RealmMap;
+
+ RealmList();
+ ~RealmList() {}
+
+ void Initialize(uint32 updateInterval);
+
+ void UpdateIfNeed();
+
+ void AddRealm(Realm NewRealm) {m_realms[NewRealm.name] = NewRealm;}
+
+ RealmMap::const_iterator begin() const { return m_realms.begin(); }
+ RealmMap::const_iterator end() const { return m_realms.end(); }
+ uint32 size() const { return m_realms.size(); }
+ private:
+ void UpdateRealms(bool init);
+ void 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);
+ private:
+ RealmMap m_realms; ///< Internal map of realms
+ uint32 m_UpdateInterval;
+ time_t m_NextUpdateTime;
+};
+
+#define sRealmList RealmList::instance()
+
+#endif
+/// @}