feat(Core/Packet): Implement AntiDOS protection from Trinity (#2789)

* Implement AntiDOS protection from Trinity


Co-authored-by: jackpoz <giacomopoz@gmail.com>
Co-authored-by: Shauren <shauren.trinity@gmail.com>
Co-authored-by: Vincent-Michael <trinity.michael_vincent@gmx.eu>
This commit is contained in:
Nefertumm
2020-03-23 15:46:00 -03:00
committed by GitHub
parent c5a7497f4d
commit 846f7862d8
13 changed files with 473 additions and 80 deletions

View File

@@ -19,6 +19,9 @@
#include "WorldPacket.h"
#include "GossipDef.h"
#include "Cryptography/BigNumber.h"
#include "AccountMgr.h"
#include "BanManager.h"
#include "Opcodes.h"
class Creature;
class GameObject;
@@ -181,6 +184,12 @@ class CharacterCreateInfo
virtual ~CharacterCreateInfo(){};
};
struct PacketCounter
{
time_t lastReceiveTime;
uint32 amountCounter;
};
/// Player session in the World
class WorldSession
{
@@ -937,6 +946,36 @@ class WorldSession
QueryResultHolderFuture _loadPetFromDBSecondCallback;
QueryCallback_3<PreparedQueryResult, uint8, uint8, uint32> _openWrappedItemCallback;
friend class World;
protected:
class DosProtection
{
friend class World;
public:
DosProtection(WorldSession* s) : Session(s), _policy((Policy)sWorld->getIntConfig(CONFIG_PACKET_SPOOF_POLICY)) { }
bool EvaluateOpcode(WorldPacket& p, time_t time) const;
protected:
enum Policy
{
POLICY_LOG,
POLICY_KICK,
POLICY_BAN
};
uint32 GetMaxPacketCounterAllowed(uint16 opcode) const;
WorldSession* Session;
private:
Policy _policy;
typedef std::unordered_map<uint16, PacketCounter> PacketThrottlingMap;
// mark this member as "mutable" so it can be modified even in const functions
mutable PacketThrottlingMap _PacketThrottlingMap;
DosProtection(DosProtection const& right) = delete;
DosProtection& operator=(DosProtection const& right) = delete;
} AntiDOS;
public:
// xinef: those must be public, requires calls out of worldsession :(
QueryCallback_2<PreparedQueryResult, uint32, AsynchPetSummon*> _loadPetFromDBFirstCallback;