* Add basic AddonMgr.

* All this really does at the moment is save addon names + CRCs to DB for use for.. whatever, later.

--HG--
branch : trunk
This commit is contained in:
XTZGZoReX
2010-01-20 16:24:52 +01:00
parent 593cbe4639
commit 48b085124e
9 changed files with 258 additions and 26 deletions
+104
View File
@@ -0,0 +1,104 @@
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* Copyright (C) 2008-2009 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
*/
#include "Database/DatabaseEnv.h"
#include "Policies/SingletonImp.h"
#include "AddonMgr.h"
#include "ObjectAccessor.h"
#include "Player.h"
#include "Util.h"
#include "Auth/Sha1.h"
#include "ProgressBar.h"
extern DatabaseType loginDatabase;
INSTANTIATE_SINGLETON_1(AddonMgr);
AddonMgr::AddonMgr()
{
}
AddonMgr::~AddonMgr()
{
}
void AddonMgr::LoadFromDB()
{
QueryResult *result = CharacterDatabase.PQuery("SELECT COUNT(name) FROM addons");
if (!result)
{
sLog.outError("an error occured while loading the table `addons`");
exit(1);
}
result = CharacterDatabase.PQuery("SELECT name, crc FROM addons");
if(!result)
{
sLog.outErrorDb("The table `addons` is empty");
return;
}
uint32 total_records = result->GetRowCount();
barGoLink bar(total_records);
uint32 count = 0;
Field *fields;
do
{
fields = result->Fetch();
bar.step();
count++;
std::string name = fields[0].GetString();
uint32 crc = fields[1].GetUInt32();
SavedAddon addon(name, crc);
m_knownAddons.push_back(addon);
} while(result->NextRow());
delete result;
sLog.outString();
sLog.outString(">> Loaded %u known addons", count);
}
void AddonMgr::SaveAddon(AddonInfo const& addon)
{
std::string name = addon.Name;
CharacterDatabase.escape_string(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);
}
SavedAddon const* AddonMgr::GetAddonInfo(const std::string& name) const
{
for (SavedAddonsList::const_iterator it = m_knownAddons.begin(); it != m_knownAddons.end(); ++it)
{
SavedAddon const& addon = (*it);
if (addon.Name == name)
return &addon;
}
return NULL;
}
+89
View File
@@ -0,0 +1,89 @@
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* Copyright (C) 2008-2009 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
*/
#ifndef _ADDONMGR_H
#define _ADDONMGR_H
#include "Common.h"
#include "Policies/Singleton.h"
#include <string>
class WorldSession;
struct AddonInfo
{
AddonInfo(const std::string& name, uint8 enabled, uint32 crc, uint8 state, bool crcOrPubKey)
{
Name = name;
Enabled = enabled;
CRC = crc;
State = state;
UsePublicKeyOrCRC = crcOrPubKey;
}
std::string Name;
uint8 Enabled;
uint32 CRC;
uint8 State;
bool UsePublicKeyOrCRC;
};
struct SavedAddon
{
SavedAddon(const std::string& name, uint32 crc)
{
Name = name;
CRC = crc;
}
std::string Name;
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
{
public:
AddonMgr();
~AddonMgr();
void LoadFromDB();
void SaveAddon(AddonInfo const& addon);
SavedAddon const* GetAddonInfo(const std::string& name) const;
private:
SavedAddonsList m_knownAddons; // Known addons.
};
#define sAddonMgr Trinity::Singleton<AddonMgr>::Instance()
#endif
+2
View File
@@ -4,6 +4,8 @@
SET(game_STAT_SRCS
AccountMgr.cpp
AccountMgr.h
AddonMgr.cpp
AddonMgr.h
AchievementMgr.h
AchievementMgr.cpp
AddonHandler.cpp
+1
View File
@@ -69,6 +69,7 @@
#include "Transports.h"
#include "ProgressBar.h"
#include "ScriptMgr.h"
#include "AddonMgr.h"
INSTANTIATE_SINGLETON_1(World);
+27 -4
View File
@@ -833,10 +833,32 @@ void WorldSession::ReadAddonsInfo(WorldPacket &data)
addonInfo >> enabled >> crc >> unk1;
sLog.outDebug("ADDON: Name: %s, Enabled: 0x%x, CRC: 0x%x, Unknown2: 0x%x", addonName.c_str(), enabled, crc, unk1);
sLog.outDetail("ADDON: Name: %s, Enabled: 0x%x, CRC: 0x%x, Unknown2: 0x%x", addonName.c_str(), enabled, crc, unk1);
AddonInfo addon(addonName, enabled, crc, 2, true);
SavedAddon const* savedAddon = sAddonMgr.GetAddonInfo(addonName);
if (savedAddon)
{
bool match = true;
if (addon.CRC != savedAddon->CRC)
match = false;
if (!match)
sLog.outDetail("ADDON: %s was known, but didn't match known CRC (0x%x)!", addon.Name.c_str(), savedAddon->CRC);
else
sLog.outDetail("ADDON: %s was known, CRC is correct (0x%x)", addon.Name.c_str(), savedAddon->CRC);
}
else
{
sAddonMgr.SaveAddon(addon);
sLog.outDetail("ADDON: %s (0x%x) was not known, saving...", addon.Name.c_str(), addon.CRC);
}
// TODO: Find out when to not use CRC/pubkey, and other possible states.
m_addonsList.push_back(AddonInfo(addonName, enabled, crc, 2, true));
m_addonsList.push_back(addon);
}
uint32 currentTime;
@@ -844,7 +866,7 @@ void WorldSession::ReadAddonsInfo(WorldPacket &data)
sLog.outDebug("ADDON: CurrentTime: %u", currentTime);
if(addonInfo.rpos() != addonInfo.size())
sLog.outDebug("packet under read!");
sLog.outDebug("packet under-read!");
}
else
sLog.outError("Addon packet uncompress error!");
@@ -886,7 +908,7 @@ void WorldSession::SendAddonsInfo()
data << uint8(usepk);
if (usepk) // if CRC is wrong, add public key (client need it)
{
sLog.outError("ADDON: CRC (0x%x) for addon %s is wrong (does not match expected 0x%x), sending pubkey",
sLog.outDetail("ADDON: CRC (0x%x) for addon %s is wrong (does not match expected 0x%x), sending pubkey",
itr->CRC, itr->Name.c_str(), STANDARD_ADDON_CRC);
data.append(addonPublicKey, sizeof(addonPublicKey));
@@ -914,6 +936,7 @@ void WorldSession::SendAddonsInfo()
string (16 bytes)
string (16 bytes)
uint32
uint32
}*/
SendPacket(&data);
+1 -22
View File
@@ -27,6 +27,7 @@
#include "Common.h"
#include "SharedDefines.h"
#include "AddonMgr.h"
struct ItemPrototype;
struct AuctionEntry;
@@ -71,28 +72,6 @@ struct AccountData
std::string Data;
};
struct AddonInfo
{
AddonInfo(const std::string& name, uint8 enabled, uint32 crc, uint8 state, bool crcOrPubKey)
{
Name = name;
Enabled = enabled;
CRC = crc;
State = state;
UsePublicKeyOrCRC = crcOrPubKey;
}
std::string Name;
uint8 Enabled;
uint32 CRC;
uint8 State;
bool UsePublicKeyOrCRC;
};
typedef std::list<AddonInfo> AddonsList;
#define STANDARD_ADDON_CRC 0x4c1c776d
enum PartyOperation
{
PARTY_OP_INVITE = 0,