Implement banned_addons (#647)

This commit is contained in:
barncastle
2017-09-17 16:13:43 +01:00
committed by Francesco Borzì
parent cf627d8327
commit 2c9b2542d6
5 changed files with 108 additions and 2 deletions

View File

@@ -10,6 +10,7 @@
#include "Timer.h"
#include <list>
#include <openssl/md5.h>
namespace AddonMgr
{
@@ -22,6 +23,7 @@ namespace
typedef std::list<SavedAddon> SavedAddonsList;
SavedAddonsList m_knownAddons;
BannedAddonList m_bannedAddons;
}
void LoadFromDB()
@@ -52,7 +54,36 @@ void LoadFromDB()
while (result->NextRow());
sLog->outString(">> Loaded %u known addons in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
sLog->outString();
oldMSTime = getMSTime();
result = CharacterDatabase.Query("SELECT id, name, version, UNIX_TIMESTAMP(timestamp) FROM banned_addons");
if (result)
{
uint32 count = 0;
uint32 offset = 102;
do
{
Field* fields = result->Fetch();
BannedAddon addon;
addon.Id = fields[0].GetUInt32() + offset;
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());
sLog->outString(">> Loaded %u banned addons in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
sLog->outString();
}
}
void SaveAddon(AddonInfo const& addon)
@@ -81,4 +112,9 @@ SavedAddon const* GetAddonInfo(const std::string& name)
return NULL;
}
BannedAddonList const* GetBannedAddons()
{
return &m_bannedAddons;
}
} // Namespace

View File

@@ -9,6 +9,7 @@
#include "Define.h"
#include <string>
#include <list>
struct AddonInfo
{
@@ -33,6 +34,14 @@ struct SavedAddon
uint32 CRC;
};
struct BannedAddon
{
uint32 Id;
uint8 NameMD5[16];
uint8 VersionMD5[16];
uint32 Timestamp;
};
#define STANDARD_ADDON_CRC 0x4c1c776d
namespace AddonMgr
@@ -40,6 +49,9 @@ 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