diff options
author | XTZGZoReX <none@none> | 2010-01-20 16:24:52 +0100 |
---|---|---|
committer | XTZGZoReX <none@none> | 2010-01-20 16:24:52 +0100 |
commit | 48b085124e84610082c61a626c5773aeca5b4cfd (patch) | |
tree | 3508da3970c8c75cd5726fa5ae4f729ad3fea49f | |
parent | 593cbe46397a31796ab7bbe99c484cde74e6e361 (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
-rw-r--r-- | sql/characters.sql | 20 | ||||
-rw-r--r-- | sql/updates/7118_characters_addons.sql | 6 | ||||
-rw-r--r-- | src/game/AddonMgr.cpp | 104 | ||||
-rw-r--r-- | src/game/AddonMgr.h | 89 | ||||
-rw-r--r-- | src/game/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/game/World.cpp | 1 | ||||
-rw-r--r-- | src/game/WorldSession.cpp | 31 | ||||
-rw-r--r-- | src/game/WorldSession.h | 23 | ||||
-rw-r--r-- | win/VC90/game.vcproj | 8 |
9 files changed, 258 insertions, 26 deletions
diff --git a/sql/characters.sql b/sql/characters.sql index cbcc9df3ec9..a7ff0ea9604 100644 --- a/sql/characters.sql +++ b/sql/characters.sql @@ -60,6 +60,26 @@ LOCK TABLES `account_data` WRITE; UNLOCK TABLES; -- +-- Table structure for table `addons` +-- + +DROP TABLE IF EXISTS `addons`; +CREATE TABLE `addons` ( + `name` varchar(120) NOT NULL default '', + `crc` mediumint(32) unsigned NOT NULL default '0', + PRIMARY KEY (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='Addons'; + +-- +-- Dumping data for table `addons` +-- + +LOCK TABLES `addons` WRITE; +/*!40000 ALTER TABLE `addons` DISABLE KEYS */; +/*!40000 ALTER TABLE `addons` ENABLE KEYS */; +UNLOCK TABLES; + +-- -- Table structure for table `arena_team` -- diff --git a/sql/updates/7118_characters_addons.sql b/sql/updates/7118_characters_addons.sql new file mode 100644 index 00000000000..ba857fda6d8 --- /dev/null +++ b/sql/updates/7118_characters_addons.sql @@ -0,0 +1,6 @@ +DROP TABLE IF EXISTS `addons`; +CREATE TABLE `addons` ( + `name` varchar(120) NOT NULL default '', + `crc` mediumint(32) unsigned NOT NULL default '0', + PRIMARY KEY (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='Addons'; 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, diff --git a/win/VC90/game.vcproj b/win/VC90/game.vcproj index a8c39f31680..b9adb49139c 100644 --- a/win/VC90/game.vcproj +++ b/win/VC90/game.vcproj @@ -537,6 +537,14 @@ > </File> <File + RelativePath="..\..\src\game\AddonMgr.cpp" + > + </File> + <File + RelativePath="..\..\src\game\AddonMgr.h" + > + </File> + <File RelativePath="..\..\src\game\ArenaTeamHandler.cpp" > </File> |