Merge pull request #16 from Olion17/develop21

[Warden] Support of several client builds
This commit is contained in:
Antz 2015-05-20 12:21:58 +01:00
commit 39efe8c4af
14 changed files with 148 additions and 29 deletions

View File

@ -307,7 +307,7 @@ enum SpellAttributes
SPELL_ATTR_CASTABLE_WHILE_SITTING = 0x08000000, // 27 castable while sitting
SPELL_ATTR_CANT_USED_IN_COMBAT = 0x10000000, // 28 Can not be used in combat
SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY = 0x20000000, // 29 unaffected by invulnerability (hmm possible not...)
SPELL_ATTR_UNK30 = 0x40000000, // 30 breakable by damage?
SPELL_ATTR_HEARTBEAT_RESIST_CHECK = 0x40000000, // 30 TC 335: random chance the effect will end (subjected to the hearbeat resist)
SPELL_ATTR_CANT_CANCEL = 0x80000000 // 31 positive aura can't be canceled
};

View File

@ -97,7 +97,7 @@ bool WorldSessionFilter::Process(WorldPacket* packet)
/// WorldSession constructor
WorldSession::WorldSession(uint32 id, WorldSocket* sock, AccountTypes sec, time_t mute_time, LocaleConstant locale) :
m_muteTime(mute_time),
_player(NULL), m_Socket(sock), _security(sec), _accountId(id), _warden(NULL), _logoutTime(0),
_player(NULL), m_Socket(sock), _security(sec), _accountId(id), _warden(NULL), _build(0), _logoutTime(0),
m_inQueue(false), m_playerLoading(false), m_playerLogout(false), m_playerRecentlyLogout(false), m_playerSave(false),
m_sessionDbcLocale(sWorld.GetAvailableDbcLocale(locale)), m_sessionDbLocaleIndex(sObjectMgr.GetIndexForLocale(locale)),
m_latency(0), m_tutorialState(TUTORIALDATA_UNCHANGED)
@ -823,8 +823,10 @@ void WorldSession::SendPlaySpellVisual(ObjectGuid guid, uint32 spellArtKit)
SendPacket(&data);
}
void WorldSession::InitWarden(BigNumber* k, std::string const& os)
void WorldSession::InitWarden(uint16 build, BigNumber* k, std::string const& os)
{
_build = build;
if (os == "Win" && sWorld.getConfig(CONFIG_BOOL_WARDEN_WIN_ENABLED))
{
_warden = new WardenWin();

View File

@ -194,7 +194,7 @@ class WorldSession
}
// Warden
void InitWarden(BigNumber* k, std::string const& os);
void InitWarden(uint16 build, BigNumber* k, std::string const& os);
/// Session in auth.queue currently
void SetInQueue(bool state)
@ -737,6 +737,9 @@ class WorldSession
void HandleBotPackets();
#endif
// for Warden
uint16 GetClientBuild() const { return _build; }
private:
// private trade methods
void moveItems(Item* myItems[], Item* hisItems[]);
@ -759,6 +762,7 @@ class WorldSession
// Warden
Warden* _warden; // Remains NULL if Warden system is not enabled by config
uint16 _build; // connected client build
time_t _logoutTime;
bool m_inQueue; // session wait in auth.queue

View File

@ -864,7 +864,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
// Initialize Warden system only if it is enabled by config
if (wardenActive)
m_Session->InitWarden(&K, os);
m_Session->InitWarden(uint16(BuiltNumberClient), &K, os);
sWorld.AddSession(m_Session);

View File

@ -230,7 +230,7 @@ std::string Warden::Penalty(WardenCheck* check /*= NULL*/)
banReason << "Warden Anticheat Violation";
// Check can be NULL, for example if the client sent a wrong signature in the warden packet (CHECKSUM FAIL)
if (check)
banReason << ": " << check->Comment << " (CheckId: " << check->CheckId << ")";
banReason << ": " << (check->Comment.empty() ? std::string("Undocumented Check") : check->Comment) << " (CheckId: " << check->CheckId << ")";
sWorld.BanAccount(BAN_ACCOUNT, accountName, sWorld.getConfig(CONFIG_UINT32_WARDEN_CLIENT_BAN_DURATION), banReason.str(), "Warden");

View File

@ -33,6 +33,9 @@
#include "WardenCheckMgr.h"
#include "Database/DatabaseEnv.h"
// the default client version with info in warden_checks; for other version checks, see warden_build_specific
#define DEFAULT_CLIENT_BUILD 5875
enum WardenOpcodes
{
// Client->Server

View File

@ -66,6 +66,7 @@ void WardenCheckMgr::LoadWardenChecks()
CheckStore.resize(maxCheckId + 1);
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");
@ -147,7 +148,7 @@ void WardenCheckMgr::LoadWardenChecks()
}
if (comment.empty())
wardenCheck->Comment = "Undocumented Check";
wardenCheck->Comment = "";
else
wardenCheck->Comment = comment;
@ -155,6 +156,81 @@ void WardenCheckMgr::LoadWardenChecks()
} while (result->NextRow());
sLog.outWarden(">> Loaded %u warden checks.", count);
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()
@ -203,18 +279,34 @@ void WardenCheckMgr::LoadWardenOverrides()
sLog.outWarden(">> Loaded %u warden action overrides.", count);
}
WardenCheck* WardenCheckMgr::GetWardenDataById(uint16 Id)
WardenCheck* WardenCheckMgr::GetWardenDataById(uint16 build, uint16 Id)
{
if (Id < CheckStore.size())
{
if (build != DEFAULT_CLIENT_BUILD)
{
MultiCheckContainer::const_iterator it = MCheckStore.find(ComposeMultiCheckKey(build, Id));
if (it != MCheckStore.end())
return it->second;
}
return CheckStore[Id];
}
return NULL;
}
WardenCheckResult* WardenCheckMgr::GetWardenResultById(uint16 Id)
WardenCheckResult* WardenCheckMgr::GetWardenResultById(uint16 build, uint16 Id)
{
if (build != DEFAULT_CLIENT_BUILD)
{
MultiResultContainer::const_iterator it = MCheckResultStore.find(ComposeMultiCheckKey(build, Id));
if (it != MCheckResultStore.end())
return it->second;
}
CheckResultContainer::const_iterator itr = CheckResultStore.find(Id);
if (itr != CheckResultStore.end())
return itr->second;
return NULL;
}

View File

@ -66,12 +66,8 @@ class WardenCheckMgr
return &instance;
}
// We have a linear key without any gaps, so we use vector for fast access
typedef std::vector<WardenCheck*> CheckContainer;
typedef std::map<uint32, WardenCheckResult*> CheckResultContainer;
WardenCheck* GetWardenDataById(uint16 Id);
WardenCheckResult* GetWardenResultById(uint16 Id);
WardenCheck* GetWardenDataById(uint16 build, uint16 Id);
WardenCheckResult* GetWardenResultById(uint16 build, uint16 Id);
std::vector<uint16> MemChecksIdPool;
std::vector<uint16> OtherChecksIdPool;
@ -82,8 +78,21 @@ class WardenCheckMgr
ACE_RW_Mutex _checkStoreLock;
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
typedef std::vector<WardenCheck*> CheckContainer;
typedef std::map<uint32, WardenCheckResult*> CheckResultContainer;
CheckContainer CheckStore;
CheckResultContainer CheckResultStore;
// here we have just few checks, vector is not appropriate; key is from ComposeMultiCheckKey
typedef std::map<uint32 /*MultiCheckKey*/, WardenCheck*> MultiCheckContainer;
typedef std::map<uint32 /*MultiCheckKey*/, WardenCheckResult*> MultiResultContainer;
MultiCheckContainer MCheckStore;
MultiResultContainer MCheckResultStore;
};
#define sWardenCheckMgr WardenCheckMgr::instance()

View File

@ -61,7 +61,7 @@ void WardenMac::Init(WorldSession* pClient, BigNumber* K)
_inputCrypto.Init(_inputKey);
_outputCrypto.Init(_outputKey);
sLog.outWarden("Server side warden for client %u initializing...", pClient->GetAccountId());
sLog.outWarden("Server side Mac warden for client %u (build %u) initializing...", pClient->GetAccountId(), _session->GetClientBuild());
sLog.outWarden("C->S Key: %s", ByteArrayToHexStr(_inputKey, 16).c_str());
sLog.outWarden("S->C Key: %s", ByteArrayToHexStr(_outputKey, 16).c_str());
sLog.outWarden(" Seed: %s", ByteArrayToHexStr(_seed, 16).c_str());

View File

@ -56,7 +56,7 @@ void WardenWin::Init(WorldSession* session, BigNumber* k)
_inputCrypto.Init(_inputKey);
_outputCrypto.Init(_outputKey);
sLog.outWarden("Server side warden for client %u initializing...", session->GetAccountId());
sLog.outWarden("Server side warden for client %u (build %u) initializing...", session->GetAccountId(), _session->GetClientBuild());
sLog.outWarden("C->S Key: %s", ByteArrayToHexStr(_inputKey, 16).c_str());
sLog.outWarden("S->C Key: %s", ByteArrayToHexStr(_outputKey, 16).c_str());
sLog.outWarden(" Seed: %s", ByteArrayToHexStr(_seed, 16).c_str());
@ -210,7 +210,7 @@ void WardenWin::RequestData()
// Add the id to the list sent in this cycle
_currentChecks.push_back(id);
wd = sWardenCheckMgr->GetWardenDataById(id);
wd = sWardenCheckMgr->GetWardenDataById(_session->GetClientBuild(), id);
switch (wd->Type)
{
@ -235,7 +235,7 @@ void WardenWin::RequestData()
for (std::list<uint16>::iterator itr = _currentChecks.begin(); itr != _currentChecks.end(); ++itr)
{
wd = sWardenCheckMgr->GetWardenDataById(*itr);
wd = sWardenCheckMgr->GetWardenDataById(_session->GetClientBuild(), *itr);
type = wd->Type;
buff << uint8(type ^ xorByte);
@ -360,8 +360,8 @@ void WardenWin::HandleData(ByteBuffer &buff)
for (std::list<uint16>::iterator itr = _currentChecks.begin(); itr != _currentChecks.end(); ++itr)
{
rd = sWardenCheckMgr->GetWardenDataById(*itr);
rs = sWardenCheckMgr->GetWardenResultById(*itr);
rd = sWardenCheckMgr->GetWardenDataById(_session->GetClientBuild(), *itr);
rs = sWardenCheckMgr->GetWardenResultById(_session->GetClientBuild(), *itr);
type = rd->Type;
switch (type)
@ -475,7 +475,7 @@ void WardenWin::HandleData(ByteBuffer &buff)
if (checkFailed > 0)
{
WardenCheck* check = sWardenCheckMgr->GetWardenDataById(checkFailed); //note it IS NOT NULL here
WardenCheck* check = sWardenCheckMgr->GetWardenDataById(_session->GetClientBuild(), checkFailed); //note it IS NOT NULL here
sLog.outWarden("%s failed Warden check %u. Action: %s", _session->GetPlayerName(), checkFailed, Penalty(check).c_str());
LogPositiveToDB(check);
}

View File

@ -71,7 +71,7 @@ struct WardenInitModuleRequest
#endif
class WorldSession;
class Warden;
//class Warden;
class WardenWin : public Warden
{

View File

@ -4928,8 +4928,11 @@ SpellAuraHolder::SpellAuraHolder(SpellEntry const* spellproto, Unit* target, Wor
break;
}
m_isHeartbeatSubject = (GetSpellMechanicMask(m_spellProto, (1 << MAX_EFFECT_INDEX) - 1) & HEARTBEAT_AURA_MECHANIC_MASK)
&& caster->GetTypeId() == TYPEID_PLAYER && target->GetTypeId() == TYPEID_PLAYER && !IsChanneledSpell(m_spellProto);
//m_isHeartbeatSubject = (GetSpellMechanicMask(m_spellProto, (1 << MAX_EFFECT_INDEX) - 1) & HEARTBEAT_AURA_MECHANIC_MASK) && caster != target
// && caster->GetTypeId() == TYPEID_PLAYER && target->GetTypeId() == TYPEID_PLAYER && !IsChanneledSpell(m_spellProto);
//TODO consider removing the m_isHeartbeatSubject variable due to simplified condition check
m_isHeartbeatSubject = bool(m_spellProto->Attributes & SPELL_ATTR_HEARTBEAT_RESIST_CHECK);
for (int32 i = 0; i < MAX_EFFECT_INDEX; ++i)
{ m_auras[i] = NULL; }

View File

@ -570,7 +570,7 @@ void Master::clearOnlineAccounts()
{
// Cleanup online status for characters hosted at current realm
/// \todo Only accounts with characters logged on *this* realm should have online status reset. Move the online column from 'account' to 'realmcharacters'?
LoginDatabase.PExecute("UPDATE account SET active_realm_id = 0 WHERE active_realm_id = '%u'", realmID);
LoginDatabase.PExecute("UPDATE account SET active_realm_id = 0, os = '' WHERE active_realm_id = '%u'", realmID);
CharacterDatabase.Execute("UPDATE characters SET online = 0 WHERE online<>0");

View File

@ -272,7 +272,12 @@ struct npc_doctor : public CreatureScript
m_uiPatientSavedCount = 0;
m_lPatientGuids.clear();
if (!m_vPatientSummonCoordinates.empty())
{
for (std::vector<Location*>::iterator itr = m_vPatientSummonCoordinates.begin(); itr != m_vPatientSummonCoordinates.end(); ++itr)
delete (*itr);
m_vPatientSummonCoordinates.clear();
}
m_bIsEventInProgress = false;
@ -293,13 +298,13 @@ struct npc_doctor : public CreatureScript
case DOCTOR_ALLIANCE:
for (uint8 i = 0; i < ALLIANCE_COORDS; ++i)
{
m_vPatientSummonCoordinates.push_back(&AllianceCoords[i]);
m_vPatientSummonCoordinates.push_back(new Location(AllianceCoords[i]));
}
break;
case DOCTOR_HORDE:
for (uint8 i = 0; i < HORDE_COORDS; ++i)
{
m_vPatientSummonCoordinates.push_back(&HordeCoords[i]);
m_vPatientSummonCoordinates.push_back(new Location(HordeCoords[i]));
}
break;
}
@ -433,6 +438,7 @@ struct npc_doctor : public CreatureScript
SendAIEvent(AI_EVENT_CUSTOM_A, m_creature, Patient);
//pPatientAI->m_doctorGuid = m_creature->GetObjectGuid();
//pPatientAI->m_pCoord = *itr;
delete (*itr);
m_vPatientSummonCoordinates.erase(itr);
}
}