[6914] Fixed missing comma.
[getmangos.git] / src / realmd / RealmList.cpp
bloba25e495b0cd0afc3a0e69190c67eba98b94b8288
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 /** \file
20 \ingroup realmd
23 #include "Common.h"
24 #include "RealmList.h"
25 #include "Policies/SingletonImp.h"
26 #include "Database/DatabaseEnv.h"
28 INSTANTIATE_SINGLETON_1( RealmList );
30 extern DatabaseType dbRealmServer;
32 RealmList::RealmList( ) : m_UpdateInterval(0), m_NextUpdateTime(time(NULL))
36 /// Load the realm list from the database
37 void RealmList::Initialize(uint32 updateInterval)
39 m_UpdateInterval = updateInterval;
41 ///- Get the content of the realmlist table in the database
42 UpdateRealms(true);
45 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)
47 ///- Create new if not exist or update existed
48 Realm& realm = m_realms[name];
50 realm.m_ID = ID;
51 realm.name = name;
52 realm.icon = icon;
53 realm.color = color;
54 realm.timezone = timezone;
55 realm.allowedSecurityLevel = allowedSecurityLevel;
56 realm.populationLevel = popu;
58 ///- Append port to IP address.
59 std::ostringstream ss;
60 ss << address << ":" << port;
61 realm.address = ss.str();
64 void RealmList::UpdateIfNeed()
66 // maybe disabled or updated recently
67 if(!m_UpdateInterval || m_NextUpdateTime > time(NULL))
68 return;
70 m_NextUpdateTime = time(NULL) + m_UpdateInterval;
72 // Clears Realm list
73 m_realms.clear();
75 // Get the content of the realmlist table in the database
76 UpdateRealms(false);
79 void RealmList::UpdateRealms(bool init)
81 sLog.outDetail("Updating Realm List...");
83 QueryResult *result = dbRealmServer.Query( "SELECT id, name, address, port, icon, color, timezone, allowedSecurityLevel, population FROM realmlist WHERE color <> 3 ORDER BY name" );
85 ///- Circle through results and add them to the realm map
86 if(result)
90 Field *fields = result->Fetch();
92 uint8 allowedSecurityLevel = fields[7].GetUInt8();
94 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() );
95 if(init)
96 sLog.outString("Added realm \"%s\".", fields[1].GetString());
97 } while( result->NextRow() );
98 delete result;