Addons/AddonMgr: converted from singleton to namespace with free functions
This commit is contained in:
@@ -16,27 +16,31 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "DatabaseEnv.h"
|
||||
#include "AddonMgr.h"
|
||||
#include "ObjectAccessor.h"
|
||||
#include "Player.h"
|
||||
#include "Util.h"
|
||||
#include "SHA1.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "Log.h"
|
||||
#include "Timer.h"
|
||||
|
||||
AddonMgr::AddonMgr()
|
||||
#include <list>
|
||||
|
||||
namespace AddonMgr
|
||||
{
|
||||
|
||||
// Anonymous namespace ensures file scope of all the stuff inside it, even
|
||||
// if you add something more to this namespace somewhere else.
|
||||
namespace
|
||||
{
|
||||
// List of saved addons (in DB).
|
||||
typedef std::list<SavedAddon> SavedAddonsList;
|
||||
|
||||
SavedAddonsList m_knownAddons;
|
||||
}
|
||||
|
||||
AddonMgr::~AddonMgr()
|
||||
{
|
||||
}
|
||||
|
||||
void AddonMgr::LoadFromDB()
|
||||
void LoadFromDB()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
QueryResult result = CharacterDatabase.Query("SELECT name, crc FROM addons");
|
||||
|
||||
if (!result)
|
||||
{
|
||||
sLog->outString(">> Loaded 0 known addons. DB table `addons` is empty!");
|
||||
@@ -53,8 +57,7 @@ void AddonMgr::LoadFromDB()
|
||||
std::string name = fields[0].GetString();
|
||||
uint32 crc = fields[1].GetUInt32();
|
||||
|
||||
SavedAddon addon(name, crc);
|
||||
m_knownAddons.push_back(addon);
|
||||
m_knownAddons.push_back(SavedAddon(name, crc));
|
||||
|
||||
++count;
|
||||
}
|
||||
@@ -64,17 +67,16 @@ void AddonMgr::LoadFromDB()
|
||||
sLog->outString();
|
||||
}
|
||||
|
||||
void AddonMgr::SaveAddon(AddonInfo const& addon)
|
||||
void SaveAddon(AddonInfo const& addon)
|
||||
{
|
||||
std::string name = addon.Name;
|
||||
CharacterDatabase.EscapeString(name);
|
||||
CharacterDatabase.PExecute("INSERT INTO addons (name, crc) VALUES ('%s', %u)", name.c_str(), addon.CRC);
|
||||
|
||||
SavedAddon newAddon(addon.Name, addon.CRC);
|
||||
m_knownAddons.push_back(newAddon);
|
||||
m_knownAddons.push_back(SavedAddon(addon.Name, addon.CRC));
|
||||
}
|
||||
|
||||
SavedAddon const* AddonMgr::GetAddonInfo(const std::string& name) const
|
||||
SavedAddon const* GetAddonInfo(const std::string& name)
|
||||
{
|
||||
for (SavedAddonsList::const_iterator it = m_knownAddons.begin(); it != m_knownAddons.end(); ++it)
|
||||
{
|
||||
@@ -85,3 +87,5 @@ SavedAddon const* AddonMgr::GetAddonInfo(const std::string& name) const
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} // Namespace
|
||||
|
||||
@@ -19,13 +19,9 @@
|
||||
#ifndef _ADDONMGR_H
|
||||
#define _ADDONMGR_H
|
||||
|
||||
#include "Common.h"
|
||||
#include <ace/Singleton.h>
|
||||
|
||||
#include "Define.h"
|
||||
#include <string>
|
||||
|
||||
class WorldSession;
|
||||
|
||||
struct AddonInfo
|
||||
{
|
||||
AddonInfo(const std::string& name, uint8 enabled, uint32 crc, uint8 state, bool crcOrPubKey)
|
||||
@@ -56,33 +52,14 @@ struct SavedAddon
|
||||
uint32 CRC;
|
||||
};
|
||||
|
||||
// List of client addons (for WorldSession).
|
||||
typedef std::list<AddonInfo> AddonsList;
|
||||
|
||||
// List of saved addons (in DB).
|
||||
typedef std::list<SavedAddon> SavedAddonsList;
|
||||
|
||||
#define STANDARD_ADDON_CRC 0x4c1c776d
|
||||
|
||||
class AddonMgr
|
||||
namespace AddonMgr
|
||||
{
|
||||
friend class ACE_Singleton<AddonMgr, ACE_Null_Mutex>;
|
||||
AddonMgr();
|
||||
~AddonMgr();
|
||||
|
||||
public:
|
||||
|
||||
void LoadFromDB();
|
||||
void SaveAddon(AddonInfo const& addon);
|
||||
|
||||
SavedAddon const* GetAddonInfo(const std::string& name) const;
|
||||
|
||||
private:
|
||||
|
||||
SavedAddonsList m_knownAddons; // Known addons.
|
||||
};
|
||||
|
||||
#define sAddonMgr ACE_Singleton<AddonMgr, ACE_Null_Mutex>::instance()
|
||||
SavedAddon const* GetAddonInfo(const std::string& name);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -124,6 +124,8 @@ class AuctionHouseObject
|
||||
class AuctionHouseMgr
|
||||
{
|
||||
friend class ACE_Singleton<AuctionHouseMgr, ACE_Null_Mutex>;
|
||||
|
||||
private:
|
||||
AuctionHouseMgr();
|
||||
~AuctionHouseMgr();
|
||||
|
||||
|
||||
@@ -868,7 +868,7 @@ void WorldSession::ReadAddonsInfo(WorldPacket &data)
|
||||
|
||||
AddonInfo addon(addonName, enabled, crc, 2, true);
|
||||
|
||||
SavedAddon const* savedAddon = sAddonMgr->GetAddonInfo(addonName);
|
||||
SavedAddon const* savedAddon = AddonMgr::GetAddonInfo(addonName);
|
||||
if (savedAddon)
|
||||
{
|
||||
bool match = true;
|
||||
@@ -883,7 +883,7 @@ void WorldSession::ReadAddonsInfo(WorldPacket &data)
|
||||
}
|
||||
else
|
||||
{
|
||||
sAddonMgr->SaveAddon(addon);
|
||||
AddonMgr::SaveAddon(addon);
|
||||
|
||||
sLog->outDetail("ADDON: %s (0x%x) was not known, saving...", addon.Name.c_str(), addon.CRC);
|
||||
}
|
||||
|
||||
@@ -939,6 +939,8 @@ class WorldSession
|
||||
uint32 _accountId;
|
||||
uint8 m_expansion;
|
||||
|
||||
typedef std::list<AddonInfo> AddonsList;
|
||||
|
||||
time_t _logoutTime;
|
||||
bool m_inQueue; // session wait in auth.queue
|
||||
bool m_playerLoading; // code processed in LoginPlayer
|
||||
|
||||
@@ -1586,7 +1586,7 @@ void World::SetInitialWorldSettings()
|
||||
sTicketMgr->LoadSurveys();
|
||||
|
||||
sLog->outString("Loading client addons...");
|
||||
sAddonMgr->LoadFromDB();
|
||||
AddonMgr::LoadFromDB();
|
||||
|
||||
///- Handle outdated emails (delete/return)
|
||||
sLog->outString("Returning old mails...");
|
||||
|
||||
Reference in New Issue
Block a user