aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXTZGZoReX <none@none>2010-01-20 16:24:52 +0100
committerXTZGZoReX <none@none>2010-01-20 16:24:52 +0100
commit48b085124e84610082c61a626c5773aeca5b4cfd (patch)
tree3508da3970c8c75cd5726fa5ae4f729ad3fea49f /src
parent593cbe46397a31796ab7bbe99c484cde74e6e361 (diff)
* 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
Diffstat (limited to 'src')
-rw-r--r--src/game/AddonMgr.cpp104
-rw-r--r--src/game/AddonMgr.h89
-rw-r--r--src/game/CMakeLists.txt2
-rw-r--r--src/game/World.cpp1
-rw-r--r--src/game/WorldSession.cpp31
-rw-r--r--src/game/WorldSession.h23
6 files changed, 224 insertions, 26 deletions
diff --git a/src/game/AddonMgr.cpp b/src/game/AddonMgr.cpp
new file mode 100644
index 00000000000..da6603e883e
--- /dev/null
+++ b/src/game/AddonMgr.cpp
@@ -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;
+}
diff --git a/src/game/AddonMgr.h b/src/game/AddonMgr.h
new file mode 100644
index 00000000000..8f5eed4918f
--- /dev/null
+++ b/src/game/AddonMgr.h
@@ -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
+
diff --git a/src/game/CMakeLists.txt b/src/game/CMakeLists.txt
index 3d31cf4a99d..1b02b4d93b3 100644
--- a/src/game/CMakeLists.txt
+++ b/src/game/CMakeLists.txt
@@ -4,6 +4,8 @@
SET(game_STAT_SRCS
AccountMgr.cpp
AccountMgr.h
+ AddonMgr.cpp
+ AddonMgr.h
AchievementMgr.h
AchievementMgr.cpp
AddonHandler.cpp
diff --git a/src/game/World.cpp b/src/game/World.cpp
index fc512e40da2..570d4b5573c 100644
--- a/src/game/World.cpp
+++ b/src/game/World.cpp
@@ -69,6 +69,7 @@
#include "Transports.h"
#include "ProgressBar.h"
#include "ScriptMgr.h"
+#include "AddonMgr.h"
INSTANTIATE_SINGLETON_1(World);
diff --git a/src/game/WorldSession.cpp b/src/game/WorldSession.cpp
index 3dfbdf7994d..7b7dac2c31b 100644
--- a/src/game/WorldSession.cpp
+++ b/src/game/WorldSession.cpp
@@ -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);
diff --git a/src/game/WorldSession.h b/src/game/WorldSession.h
index dd48a6f9533..6a6121385b7 100644
--- a/src/game/WorldSession.h
+++ b/src/game/WorldSession.h
@@ -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,