Core/Addons: Removed AddonMgr

This commit is contained in:
Shauren
2016-05-30 23:42:09 +02:00
parent 634ec0061f
commit d62b52befb
9 changed files with 2 additions and 296 deletions

View File

@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS `addons`;
DROP TABLE IF EXISTS `banned_addons`;

View File

@@ -431,7 +431,6 @@ void CharacterDatabaseConnection::DoPrepareStatements()
PrepareStatement(CHAR_DEL_INVALID_ACHIEV_PROGRESS_CRITERIA, "DELETE FROM character_achievement_progress WHERE criteria = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_INVALID_ACHIEV_PROGRESS_CRITERIA_GUILD, "DELETE FROM guild_achievement_progress WHERE criteria = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_INVALID_ACHIEVMENT, "DELETE FROM character_achievement WHERE achievement = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_INS_ADDON, "INSERT INTO addons (name, crc) VALUES (?, ?)", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_INVALID_PET_SPELL, "DELETE FROM pet_spell WHERE spell = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_GROUP_INSTANCE_BY_INSTANCE, "DELETE FROM group_instance WHERE instance = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_DEL_GROUP_INSTANCE_BY_GUID, "DELETE FROM group_instance WHERE guid = ? AND instance = ?", CONNECTION_ASYNC);

View File

@@ -348,7 +348,6 @@ enum CharacterDatabaseStatements
CHAR_DEL_INVALID_ACHIEV_PROGRESS_CRITERIA,
CHAR_DEL_INVALID_ACHIEV_PROGRESS_CRITERIA_GUILD,
CHAR_DEL_INVALID_ACHIEVMENT,
CHAR_INS_ADDON,
CHAR_DEL_INVALID_PET_SPELL,
CHAR_DEL_GROUP_INSTANCE_BY_INSTANCE,
CHAR_DEL_GROUP_INSTANCE_BY_GUID,

View File

@@ -1,129 +0,0 @@
/*
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "AddonMgr.h"
#include "DatabaseEnv.h"
#include "DB2Stores.h"
#include "Log.h"
#include "Timer.h"
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;
BannedAddonList m_bannedAddons;
}
void LoadFromDB()
{
uint32 oldMSTime = getMSTime();
QueryResult result = CharacterDatabase.Query("SELECT name, crc FROM addons");
if (result)
{
uint32 count = 0;
do
{
Field* fields = result->Fetch();
std::string name = fields[0].GetString();
uint32 crc = fields[1].GetUInt32();
m_knownAddons.push_back(SavedAddon(name, crc));
++count;
}
while (result->NextRow());
TC_LOG_INFO("server.loading", ">> Loaded %u known addons in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
}
else
TC_LOG_INFO("server.loading", ">> Loaded 0 known addons. DB table `addons` is empty!");
oldMSTime = getMSTime();
result = CharacterDatabase.Query("SELECT id, name, version, UNIX_TIMESTAMP(timestamp) FROM banned_addons");
if (result)
{
uint32 count = 0;
uint32 dbcMaxBannedAddon = sBannedAddOnsStore.GetNumRows();
do
{
Field* fields = result->Fetch();
BannedAddon addon;
addon.Id = fields[0].GetUInt32() + dbcMaxBannedAddon;
addon.Timestamp = uint32(fields[3].GetUInt64());
std::string name = fields[1].GetString();
std::string version = fields[2].GetString();
MD5(reinterpret_cast<uint8 const*>(name.c_str()), name.length(), addon.NameMD5);
MD5(reinterpret_cast<uint8 const*>(version.c_str()), version.length(), addon.VersionMD5);
m_bannedAddons.push_back(addon);
++count;
}
while (result->NextRow());
TC_LOG_INFO("server.loading", ">> Loaded %u banned addons in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
}
}
void SaveAddon(AddonInfo const& addon)
{
std::string name = addon.Name;
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_ADDON);
stmt->setString(0, name);
stmt->setUInt32(1, addon.CRC);
CharacterDatabase.Execute(stmt);
m_knownAddons.push_back(SavedAddon(addon.Name, addon.CRC));
}
SavedAddon const* GetAddonInfo(const std::string& name)
{
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;
}
BannedAddonList const* GetBannedAddons()
{
return &m_bannedAddons;
}
} // Namespace

View File

@@ -1,71 +0,0 @@
/*
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef _ADDONMGR_H
#define _ADDONMGR_H
#include "Define.h"
#include <string>
#include <list>
#include <openssl/md5.h>
struct AddonInfo
{
AddonInfo(const std::string& name, uint8 enabled, uint32 crc, uint8 state, bool crcOrPubKey)
: Name(name), Enabled(enabled), CRC(crc), Status(state), UsePublicKeyOrCRC(crcOrPubKey)
{ }
std::string Name;
uint8 Enabled;
uint32 CRC;
uint8 Status;
bool UsePublicKeyOrCRC;
};
struct SavedAddon
{
SavedAddon(std::string const& name, uint32 crc) : Name(name)
{
CRC = crc;
}
std::string Name;
uint32 CRC;
};
struct BannedAddon
{
uint32 Id;
uint8 NameMD5[MD5_DIGEST_LENGTH];
uint8 VersionMD5[MD5_DIGEST_LENGTH];
uint32 Timestamp;
};
#define STANDARD_ADDON_CRC 0x4C1C776D
namespace AddonMgr
{
void LoadFromDB();
void SaveAddon(AddonInfo const& addon);
SavedAddon const* GetAddonInfo(const std::string& name);
typedef std::list<BannedAddon> BannedAddonList;
BannedAddonList const* GetBannedAddons();
}
#endif

View File

@@ -827,89 +827,6 @@ void WorldSession::SaveTutorialsData(SQLTransaction& trans)
_tutorialsChanged = false;
}
void WorldSession::ReadAddonsInfo(ByteBuffer& data)
{
if (data.rpos() + 4 > data.size())
return;
uint32 size;
data >> size;
if (!size)
return;
if (size > 0xFFFFF)
{
TC_LOG_DEBUG("addon", "WorldSession::ReadAddonsInfo: AddOnInfo too big, size %u", size);
return;
}
uLongf uSize = size;
uint32 pos = data.rpos();
ByteBuffer addonInfo;
addonInfo.resize(size);
m_addonsList.clear();
if (uncompress(addonInfo.contents(), &uSize, data.contents() + pos, data.size() - pos) == Z_OK)
{
uint32 addonsCount;
addonInfo >> addonsCount; // addons count
for (uint32 i = 0; i < addonsCount; ++i)
{
std::string addonName;
uint8 enabled;
uint32 crc, unk1;
// check next addon data format correctness
if (addonInfo.rpos() + 1 > addonInfo.size())
return;
addonInfo >> addonName;
addonInfo >> enabled >> crc >> unk1;
TC_LOG_DEBUG("addon", "AddOn: %s (CRC: 0x%x) - enabled: 0x%x - Unknown2: 0x%x", addonName.c_str(), crc, enabled, unk1);
AddonInfo addon(addonName, enabled, crc, 2, true);
SavedAddon const* savedAddon = AddonMgr::GetAddonInfo(addonName);
if (savedAddon)
{
if (addon.CRC != savedAddon->CRC)
TC_LOG_WARN("addon", " Addon: %s: modified (CRC: 0x%x) - accountID %d)", addon.Name.c_str(), savedAddon->CRC, GetAccountId());
else
TC_LOG_DEBUG("addon", "Addon: %s: validated (CRC: 0x%x) - accountID %d", addon.Name.c_str(), savedAddon->CRC, GetAccountId());
}
else
{
AddonMgr::SaveAddon(addon);
TC_LOG_WARN("addon", "Addon: %s: unknown (CRC: 0x%x) - accountId %d (storing addon name and checksum to database)", addon.Name.c_str(), addon.CRC, GetAccountId());
}
/// @todo Find out when to not use CRC/pubkey, and other possible states.
m_addonsList.push_back(addon);
}
uint32 currentTime;
addonInfo >> currentTime;
TC_LOG_DEBUG("addon", "AddOn: CurrentTime: %u", currentTime);
}
else
TC_LOG_DEBUG("addon", "AddOn: Addon packet uncompress error!");
}
void WorldSession::SendAddonsInfo()
{
WorldPackets::ClientConfig::AddonInfo addonInfo;
addonInfo.Addons = &m_addonsList;
addonInfo.BannedAddons = AddonMgr::GetBannedAddons();
SendPacket(addonInfo.Write());
}
bool WorldSession::IsAddonRegistered(const std::string& prefix) const
{
if (!_filterAddonMessages) // if we have hit the softcap (64) nothing should be filtered
@@ -1234,7 +1151,6 @@ void WorldSession::InitializeSessionCallback(SQLQueryHolder* realmHolder, SQLQue
SendSetTimeZoneInformation();
SendFeatureSystemStatusGlueScreen();
SendAddonsInfo();
SendClientCacheVersion(sWorld->getIntConfig(CONFIG_CLIENTCACHE_VERSION));
SendTutorialsData();

View File

@@ -25,7 +25,6 @@
#include "Common.h"
#include "SharedDefines.h"
#include "AddonMgr.h"
#include "DatabaseEnv.h"
#include "World.h"
#include "Packet.h"
@@ -896,8 +895,6 @@ class TC_GAME_API WorldSession
bool PlayerRecentlyLoggedOut() const { return m_playerRecentlyLogout; }
bool PlayerDisconnected() const;
void ReadAddonsInfo(ByteBuffer& data);
void SendAddonsInfo();
bool IsAddonRegistered(const std::string& prefix) const;
void SendPacket(WorldPacket const* packet, bool forced = false);
@@ -1815,8 +1812,6 @@ class TC_GAME_API WorldSession
std::unordered_map<uint32, std::function<void(MessageBuffer)>> _battlenetResponseCallbacks;
uint32 _battlenetRequestToken;
typedef std::list<AddonInfo> AddonsList;
// Warden
Warden* _warden; // Remains NULL if Warden system is not enabled by config
@@ -1833,7 +1828,6 @@ class TC_GAME_API WorldSession
AccountData _accountData[NUM_ACCOUNT_DATA_TYPES];
uint32 _tutorials[MAX_ACCOUNT_TUTORIAL_VALUES];
bool _tutorialsChanged;
AddonsList m_addonsList;
std::vector<std::string> _registeredAddonPrefixes;
bool _filterAddonMessages;
uint32 recruiterId;

View File

@@ -838,7 +838,6 @@ void WorldSocket::HandleAuthSessionCallback(std::shared_ptr<WorldPackets::Auth::
_authed = true;
_worldSession = new WorldSession(account.Game.Id, std::move(authSession->RealmJoinTicket), account.BattleNet.Id, shared_from_this(), account.Game.Security,
account.Game.Expansion, mutetime, account.Game.OS, account.BattleNet.Locale, account.Game.Recruiter, account.Game.IsRectuiter);
_worldSession->ReadAddonsInfo(authSession->AddonInfo);
// Initialize Warden system only if it is enabled by config
if (wardenActive)

View File

@@ -1941,9 +1941,6 @@ void World::SetInitialWorldSettings()
/*TC_LOG_INFO("server.loading", "Loading GM surveys...");
sSupportMgr->LoadSurveys();*/
TC_LOG_INFO("server.loading", "Loading client addons...");
AddonMgr::LoadFromDB();
TC_LOG_INFO("server.loading", "Loading garrison info...");
sGarrisonMgr.Initialize();