Make RealmList a Singleton.

Patch by Anubiss

--HG--
branch : trunk
This commit is contained in:
Spp
2010-05-02 00:06:08 +02:00
parent a0e1357e2b
commit 274457a7fb
5 changed files with 18 additions and 16 deletions
+1 -1
View File
@@ -1711,7 +1711,7 @@ void World::SetInitialWorldSettings()
void World::DetectDBCLang() void World::DetectDBCLang()
{ {
uint8 m_lang_confid = sConfig.GetIntDefault("DBC.Locale", 255); uint16 m_lang_confid = sConfig.GetIntDefault("DBC.Locale", 255);
if (m_lang_confid != 255 && m_lang_confid >= MAX_LOCALE) if (m_lang_confid != 255 && m_lang_confid >= MAX_LOCALE)
{ {
+7 -10
View File
@@ -34,8 +34,6 @@
#include "Auth/Sha1.h" #include "Auth/Sha1.h"
//#include "Util.h" -- for commented utf8ToUpperOnlyLatin //#include "Util.h" -- for commented utf8ToUpperOnlyLatin
extern RealmList m_realmList;
extern DatabaseType loginDatabase; extern DatabaseType loginDatabase;
#define ChunkSize 2048 #define ChunkSize 2048
@@ -816,21 +814,20 @@ bool AuthSocket::_HandleRealmList()
std::string rI = (*result)[1].GetCppString(); std::string rI = (*result)[1].GetCppString();
///- Update realm list if need ///- Update realm list if need
m_realmList.UpdateIfNeed(); sRealmList->UpdateIfNeed();
RealmList::RealmMap::const_iterator rlm; RealmList::RealmMap::const_iterator rlm;
RealmList built_realmList; for (rlm = sRealmList->begin(); rlm != sRealmList->end(); ++rlm)
for (rlm = m_realmList.begin(); rlm != m_realmList.end(); ++rlm)
{ {
if ( _expversion & POST_BC_EXP_FLAG )//2.4.3 and 3.1.3 cliens if ( _expversion & POST_BC_EXP_FLAG )//2.4.3 and 3.1.3 cliens
{ {
if (rlm->second.gamebuild == _build) if (rlm->second.gamebuild == _build)
built_realmList.AddRealm(rlm->second); sRealmList->AddRealm(rlm->second);
} }
else if ( _expversion & PRE_BC_EXP_FLAG )//1.12.1 and 1.12.2 clients are compatible with eachother else if ( _expversion & PRE_BC_EXP_FLAG )//1.12.1 and 1.12.2 clients are compatible with eachother
{ {
if ( AuthHelper::IsPreBCAcceptedClientBuild ( rlm->second.gamebuild ) ) if ( AuthHelper::IsPreBCAcceptedClientBuild ( rlm->second.gamebuild ) )
built_realmList.AddRealm(rlm->second); sRealmList->AddRealm(rlm->second);
} }
} }
@@ -839,12 +836,12 @@ bool AuthSocket::_HandleRealmList()
ByteBuffer pkt; ByteBuffer pkt;
pkt << (uint32) 0; pkt << (uint32) 0;
if ( _expversion & POST_BC_EXP_FLAG )//only 2.4.3 and 3.1.3 cliens if ( _expversion & POST_BC_EXP_FLAG )//only 2.4.3 and 3.1.3 cliens
pkt << (uint16) built_realmList.size(); pkt << (uint16) sRealmList->size();
else else
pkt << (uint32) built_realmList.size(); pkt << (uint32) sRealmList->size();
RealmList::RealmMap::const_iterator i; RealmList::RealmMap::const_iterator i;
for (i = built_realmList.begin(); i != built_realmList.end(); ++i) for (i = sRealmList->begin(); i != sRealmList->end(); ++i)
{ {
uint8 AmountOfCharacters; uint8 AmountOfCharacters;
+2 -3
View File
@@ -61,7 +61,6 @@ void UnhookSignals();
void HookSignals(); void HookSignals();
bool stopEvent = false; ///< Setting it to true stops the server bool stopEvent = false; ///< Setting it to true stops the server
RealmList m_realmList; ///< Holds the list of realms for this server
DatabaseType loginDatabase; ///< Accessor to the realm server database DatabaseType loginDatabase; ///< Accessor to the realm server database
@@ -194,8 +193,8 @@ extern int main(int argc, char **argv)
} }
///- Get the list of realms for the server ///- Get the list of realms for the server
m_realmList.Initialize(sConfig.GetIntDefault("RealmsStateUpdateDelay", 20)); sRealmList->Initialize(sConfig.GetIntDefault("RealmsStateUpdateDelay", 20));
if (m_realmList.size() == 0) if (sRealmList->size() == 0)
{ {
sLog.outError("No valid realms specified."); sLog.outError("No valid realms specified.");
return 1; return 1;
-2
View File
@@ -24,10 +24,8 @@
#include "Common.h" #include "Common.h"
#include "RealmList.h" #include "RealmList.h"
#include "Policies/SingletonImp.h"
#include "Database/DatabaseEnv.h" #include "Database/DatabaseEnv.h"
INSTANTIATE_SINGLETON_1(RealmList);
extern DatabaseType loginDatabase; extern DatabaseType loginDatabase;
+8
View File
@@ -25,6 +25,8 @@
#ifndef _REALMLIST_H #ifndef _REALMLIST_H
#define _REALMLIST_H #define _REALMLIST_H
#include <ace/Singleton.h>
#include <ace/Null_Mutex.h>
#include "Common.h" #include "Common.h"
/// Storage object for a realm /// Storage object for a realm
@@ -45,6 +47,9 @@ struct Realm
class RealmList class RealmList
{ {
public: 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; typedef std::map<std::string, Realm> RealmMap;
RealmList(); RealmList();
@@ -67,5 +72,8 @@ class RealmList
uint32 m_UpdateInterval; uint32 m_UpdateInterval;
time_t m_NextUpdateTime; time_t m_NextUpdateTime;
}; };
#define sRealmList RealmList::instance()
#endif #endif
/// @} /// @}