commit
9f31d12914
@ -36,11 +36,19 @@ WardenCheckMgr::WardenCheckMgr() { }
|
|||||||
|
|
||||||
WardenCheckMgr::~WardenCheckMgr()
|
WardenCheckMgr::~WardenCheckMgr()
|
||||||
{
|
{
|
||||||
for (uint16 i = 0; i < CheckStore.size(); ++i)
|
for (CheckMap::iterator it = CheckStore.begin(); it != CheckStore.end(); ++it)
|
||||||
delete CheckStore[i];
|
{
|
||||||
|
for (CheckContainer::iterator itr = it->second->begin(); itr != it->second->end(); ++itr)
|
||||||
for (CheckResultContainer::iterator itr = CheckResultStore.begin(); itr != CheckResultStore.end(); ++itr)
|
|
||||||
delete itr->second;
|
delete itr->second;
|
||||||
|
delete it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (CheckResultMap::iterator it = CheckResultStore.begin(); it != CheckResultStore.end(); ++it)
|
||||||
|
{
|
||||||
|
for (CheckResultContainer::iterator itr = it->second->begin(); itr != it->second->end(); ++itr)
|
||||||
|
delete itr->second;
|
||||||
|
delete it->second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WardenCheckMgr::LoadWardenChecks()
|
void WardenCheckMgr::LoadWardenChecks()
|
||||||
@ -52,44 +60,48 @@ void WardenCheckMgr::LoadWardenChecks()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueryResult *result = WorldDatabase.Query("SELECT MAX(id) FROM warden_checks");
|
QueryResult *result = WorldDatabase.Query("SELECT DISTINCT build FROM warden");
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
sLog.outWarden(">> Loaded 0 Warden checks. DB table `warden_checks` is empty!");
|
sLog.outString("[Warden]: >> Loaded 0 warden data and results");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Field* fields = result->Fetch();
|
Field* fields;
|
||||||
|
|
||||||
uint16 maxCheckId = fields[0].GetUInt16();
|
do
|
||||||
|
{
|
||||||
|
fields = result->Fetch();
|
||||||
|
uint16 build = fields[0].GetUInt16();
|
||||||
|
CheckContainer* ck = new CheckContainer();
|
||||||
|
CheckResultContainer* ckr = new CheckResultContainer();
|
||||||
|
CheckStore[build] = ck;
|
||||||
|
CheckResultStore[build] = ckr;
|
||||||
|
|
||||||
CheckStore.resize(maxCheckId + 1);
|
} while (result->NextRow());
|
||||||
|
|
||||||
delete result;
|
delete result;
|
||||||
// 0 1 2 3 4 5 6 7
|
|
||||||
result = WorldDatabase.Query("SELECT id, type, data, result, address, length, str, comment FROM warden_checks ORDER BY id ASC");
|
// 0 1 2 3 4 5 6 7 8
|
||||||
|
result = WorldDatabase.Query("SELECT id, build, type, data, result, address, length, str, comment FROM warden ORDER BY build ASC, id ASC");
|
||||||
|
// no need to check. done in SELECT DISTINCT before
|
||||||
|
|
||||||
uint32 count = 0;
|
uint32 count = 0;
|
||||||
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
sLog.outString("[Warden]: >> Loaded %u warden data and results", count);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
fields = result->Fetch();
|
fields = result->Fetch();
|
||||||
|
|
||||||
uint16 id = fields[0].GetUInt16();
|
uint16 id = fields[0].GetUInt16();
|
||||||
uint8 checkType = fields[1].GetUInt8();
|
uint16 build = fields[1].GetUInt16();
|
||||||
std::string data = fields[2].GetString();
|
uint8 checkType = fields[2].GetUInt8();
|
||||||
std::string checkResult = fields[3].GetString();
|
std::string data = fields[3].GetString();
|
||||||
uint32 address = fields[4].GetUInt32();
|
std::string checkResult = fields[4].GetString();
|
||||||
uint8 length = fields[5].GetUInt8();
|
uint32 address = fields[5].GetUInt32();
|
||||||
std::string str = fields[6].GetString();
|
uint8 length = fields[6].GetUInt8();
|
||||||
std::string comment = fields[7].GetString();
|
std::string str = fields[7].GetString();
|
||||||
|
std::string comment = fields[8].GetString();
|
||||||
|
|
||||||
WardenCheck* wardenCheck = new WardenCheck();
|
WardenCheck* wardenCheck = new WardenCheck();
|
||||||
wardenCheck->Type = checkType;
|
wardenCheck->Type = checkType;
|
||||||
@ -128,7 +140,7 @@ void WardenCheckMgr::LoadWardenChecks()
|
|||||||
if (checkType == MEM_CHECK || checkType == MPQ_CHECK || checkType == LUA_STR_CHECK || checkType == DRIVER_CHECK || checkType == MODULE_CHECK)
|
if (checkType == MEM_CHECK || checkType == MPQ_CHECK || checkType == LUA_STR_CHECK || checkType == DRIVER_CHECK || checkType == MODULE_CHECK)
|
||||||
wardenCheck->Str = str;
|
wardenCheck->Str = str;
|
||||||
|
|
||||||
CheckStore[id] = wardenCheck;
|
CheckStore[build]->insert(std::pair<uint16,WardenCheck*>(id, wardenCheck));
|
||||||
|
|
||||||
if (checkType == MPQ_CHECK || checkType == MEM_CHECK)
|
if (checkType == MPQ_CHECK || checkType == MEM_CHECK)
|
||||||
{
|
{
|
||||||
@ -144,7 +156,7 @@ void WardenCheckMgr::LoadWardenChecks()
|
|||||||
wr->Result.SetBinary((uint8*)temp, len);
|
wr->Result.SetBinary((uint8*)temp, len);
|
||||||
delete[] temp;
|
delete[] temp;
|
||||||
}
|
}
|
||||||
CheckResultStore[id] = wr;
|
CheckResultStore[build]->insert(std::pair<uint16, WardenCheckResult*>(id,wr));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (comment.empty())
|
if (comment.empty())
|
||||||
@ -158,79 +170,6 @@ void WardenCheckMgr::LoadWardenChecks()
|
|||||||
sLog.outWarden(">> Loaded %u warden checks.", count);
|
sLog.outWarden(">> Loaded %u warden checks.", count);
|
||||||
|
|
||||||
delete result;
|
delete result;
|
||||||
// 0 1 2 3 4 5 6
|
|
||||||
result = WorldDatabase.Query("SELECT id, build, data, result, address, length, str FROM warden_build_specific ORDER BY id ASC");
|
|
||||||
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
sLog.outString("[Warden]: >> Loaded 0 warden client build-specific data.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
count = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
fields = result->Fetch();
|
|
||||||
|
|
||||||
uint16 id = fields[0].GetUInt16();
|
|
||||||
if (id >= CheckStore.size())
|
|
||||||
{
|
|
||||||
sLog.outWarden("ERROR: Build-specific, check is missing in warden_checks, skipping id %u.", id);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16 build = fields[1].GetUInt16();
|
|
||||||
if (build == DEFAULT_CLIENT_BUILD)
|
|
||||||
{
|
|
||||||
sLog.outWarden("ERROR: Build-specific table may not contain checks for default %u build, skipping id %u.", DEFAULT_CLIENT_BUILD, id);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//std::string data = fields[2].GetString(); //unused for now
|
|
||||||
std::string checkResult = fields[3].GetString();
|
|
||||||
uint32 address = fields[4].GetUInt32();
|
|
||||||
uint8 length = fields[5].GetUInt8();
|
|
||||||
std::string str = fields[6].GetString();
|
|
||||||
|
|
||||||
WardenCheck* wardenCheck = new WardenCheck();
|
|
||||||
wardenCheck->CheckId = id;
|
|
||||||
wardenCheck->Type = CheckStore[id]->Type;
|
|
||||||
|
|
||||||
WardenCheckResult* wr = new WardenCheckResult();
|
|
||||||
switch (wardenCheck->Type)
|
|
||||||
{
|
|
||||||
case MEM_CHECK:
|
|
||||||
wardenCheck->Address = address;
|
|
||||||
wardenCheck->Length = length;
|
|
||||||
wardenCheck->Str = str;
|
|
||||||
wr->Result.SetHexStr(checkResult.c_str());
|
|
||||||
{
|
|
||||||
int len = checkResult.size() / 2;
|
|
||||||
if (wr->Result.GetNumBytes() < len)
|
|
||||||
{
|
|
||||||
uint8 *temp = new uint8[len];
|
|
||||||
memset(temp, 0, len);
|
|
||||||
memcpy(temp, wr->Result.AsByteArray(), wr->Result.GetNumBytes());
|
|
||||||
std::reverse(temp, temp + len);
|
|
||||||
wr->Result.SetBinary((uint8*)temp, len);
|
|
||||||
delete[] temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
sLog.outWarden("The check type %u is considered as build-independent, skipping id %u.", wardenCheck->Type, id);
|
|
||||||
delete wr;
|
|
||||||
delete wardenCheck;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
MCheckStore[ComposeMultiCheckKey(build, id)] = wardenCheck;
|
|
||||||
MCheckResultStore[ComposeMultiCheckKey(build, id)] = wr;
|
|
||||||
++count;
|
|
||||||
|
|
||||||
} while (result->NextRow());
|
|
||||||
|
|
||||||
sLog.outString(">> Loaded %u warden client build-specific check overrides.", count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WardenCheckMgr::LoadWardenOverrides()
|
void WardenCheckMgr::LoadWardenOverrides()
|
||||||
@ -265,48 +204,52 @@ void WardenCheckMgr::LoadWardenOverrides()
|
|||||||
// Check if action value is in range (0-2, see WardenActions enum)
|
// Check if action value is in range (0-2, see WardenActions enum)
|
||||||
if (action > WARDEN_ACTION_BAN)
|
if (action > WARDEN_ACTION_BAN)
|
||||||
sLog.outWarden("Warden check override action out of range (ID: %u, action: %u)", checkId, action);
|
sLog.outWarden("Warden check override action out of range (ID: %u, action: %u)", checkId, action);
|
||||||
|
|
||||||
// Check if check actually exists before accessing the CheckStore vector
|
// Check if check actually exists before accessing the CheckStore vector
|
||||||
else if (checkId > CheckStore.size())
|
else
|
||||||
|
{
|
||||||
|
for (CheckMap::iterator it = CheckStore.begin(); it != CheckStore.end(); ++it)
|
||||||
|
{
|
||||||
|
CheckContainer::iterator ir = it->second->find(checkId);
|
||||||
|
if (ir == it->second->end())
|
||||||
sLog.outWarden("Warden check action override for non-existing check (ID: %u, action: %u), skipped", checkId, action);
|
sLog.outWarden("Warden check action override for non-existing check (ID: %u, action: %u), skipped", checkId, action);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CheckStore[checkId]->Action = WardenActions(action);
|
ir->second->Action = WardenActions(action);
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
while (result->NextRow());
|
while (result->NextRow());
|
||||||
|
|
||||||
sLog.outWarden(">> Loaded %u warden action overrides.", count);
|
sLog.outWarden(">> Loaded %u warden action overrides.", count);
|
||||||
}
|
}
|
||||||
|
|
||||||
WardenCheck* WardenCheckMgr::GetWardenDataById(uint16 build, uint16 Id)
|
WardenCheck* WardenCheckMgr::GetWardenDataById(uint16 build, uint16 id)
|
||||||
{
|
{
|
||||||
if (Id < CheckStore.size())
|
WardenCheck* result = NULL;
|
||||||
|
CheckMap::iterator it = CheckStore.find(build);
|
||||||
|
if (it != CheckStore.end())
|
||||||
{
|
{
|
||||||
if (build != DEFAULT_CLIENT_BUILD)
|
CheckContainer::iterator ir = it->second->find(id);
|
||||||
{
|
if (ir != it->second->end())
|
||||||
MultiCheckContainer::const_iterator it = MCheckStore.find(ComposeMultiCheckKey(build, Id));
|
result = ir->second;
|
||||||
if (it != MCheckStore.end())
|
|
||||||
return it->second;
|
|
||||||
}
|
|
||||||
return CheckStore[Id];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
WardenCheckResult* WardenCheckMgr::GetWardenResultById(uint16 build, uint16 Id)
|
WardenCheckResult* WardenCheckMgr::GetWardenResultById(uint16 build, uint16 id)
|
||||||
{
|
{
|
||||||
if (build != DEFAULT_CLIENT_BUILD)
|
WardenCheckResult* result = NULL;
|
||||||
|
CheckResultMap::iterator it = CheckResultStore.find(build);
|
||||||
|
if (it != CheckResultStore.end())
|
||||||
{
|
{
|
||||||
MultiResultContainer::const_iterator it = MCheckResultStore.find(ComposeMultiCheckKey(build, Id));
|
CheckResultContainer::iterator ir = it->second->find(id);
|
||||||
if (it != MCheckResultStore.end())
|
if (ir != it->second->end())
|
||||||
return it->second;
|
result = ir->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckResultContainer::const_iterator itr = CheckResultStore.find(Id);
|
return result;
|
||||||
if (itr != CheckResultStore.end())
|
|
||||||
return itr->second;
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,8 @@ class WardenCheckMgr
|
|||||||
return &instance;
|
return &instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
WardenCheck* GetWardenDataById(uint16 build, uint16 Id);
|
WardenCheck* GetWardenDataById(uint16 /*build*/, uint16 /*id*/);
|
||||||
WardenCheckResult* GetWardenResultById(uint16 build, uint16 Id);
|
WardenCheckResult* GetWardenResultById(uint16 /*build*/, uint16 /*id*/);
|
||||||
|
|
||||||
std::vector<uint16> MemChecksIdPool;
|
std::vector<uint16> MemChecksIdPool;
|
||||||
std::vector<uint16> OtherChecksIdPool;
|
std::vector<uint16> OtherChecksIdPool;
|
||||||
@ -78,21 +78,16 @@ class WardenCheckMgr
|
|||||||
ACE_RW_Mutex _checkStoreLock;
|
ACE_RW_Mutex _checkStoreLock;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32 inline ComposeMultiCheckKey(uint16 clientBuild, uint16 checkID) { return (uint32(checkID) << 16) | clientBuild; }
|
|
||||||
|
|
||||||
// We have a linear key without any gaps, so we use vector for fast access
|
// We have a linear key without any gaps, so we use vector for fast access
|
||||||
typedef std::vector<WardenCheck*> CheckContainer;
|
typedef std::map< uint16, WardenCheck* > CheckContainer;
|
||||||
typedef std::map<uint32, WardenCheckResult*> CheckResultContainer;
|
typedef std::map< uint16, WardenCheckResult* > CheckResultContainer;
|
||||||
|
|
||||||
CheckContainer CheckStore;
|
typedef std::map< uint16 /*build*/, CheckContainer* > CheckMap;
|
||||||
CheckResultContainer CheckResultStore;
|
typedef std::map< uint16 /*build*/, CheckResultContainer* > CheckResultMap;
|
||||||
|
|
||||||
// here we have just few checks, vector is not appropriate; key is from ComposeMultiCheckKey
|
CheckMap CheckStore;
|
||||||
typedef std::map<uint32 /*MultiCheckKey*/, WardenCheck*> MultiCheckContainer;
|
CheckResultMap CheckResultStore;
|
||||||
typedef std::map<uint32 /*MultiCheckKey*/, WardenCheckResult*> MultiResultContainer;
|
|
||||||
|
|
||||||
MultiCheckContainer MCheckStore;
|
|
||||||
MultiResultContainer MCheckResultStore;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define sWardenCheckMgr WardenCheckMgr::instance()
|
#define sWardenCheckMgr WardenCheckMgr::instance()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user