AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
WorldSession::DosProtection Class Reference

#include "WorldSession.h"

Public Types

enum class  Policy {
  Process ,
  Kick ,
  Ban ,
  Log ,
  BlockingThrottle ,
  DropPacket
}
 

Public Member Functions

 DosProtection (WorldSession *s)
 
Policy EvaluateOpcode (WorldPacket const &p, time_t const time) const
 

Protected Attributes

WorldSession * Session
 

Private Types

typedef std::unordered_map< uint16, PacketCounter > PacketThrottlingMap
 

Private Member Functions

 DosProtection (DosProtection const &right)=delete
 
DosProtection & operator= (DosProtection const &right)=delete
 

Private Attributes

PacketThrottlingMap _PacketThrottlingMap
 

Friends

class World
 

Detailed Description

Member Typedef Documentation

◆ PacketThrottlingMap

Member Enumeration Documentation

◆ Policy

Constructor & Destructor Documentation

◆ DosProtection() [1/2]

WorldSession::DosProtection::DosProtection ( WorldSession *  s)
1513 :
1514 Session(s) { }
WorldSession * Session
Definition WorldSession.h:1260

◆ DosProtection() [2/2]

WorldSession::DosProtection::DosProtection ( DosProtection const &  right)
privatedelete

Member Function Documentation

◆ EvaluateOpcode()

WorldSession::DosProtection::Policy WorldSession::DosProtection::EvaluateOpcode ( WorldPacket const &  p,
time_t const  time 
) const
1445{
1446 AntiDosOpcodePolicy const* policy = sWorldGlobals->GetAntiDosPolicyForOpcode(p.GetOpcode());
1447 if (!policy)
1448 return WorldSession::DosProtection::Policy::Process; // Return true if there is no policy for the opcode
1449
1450 uint32 const maxPacketCounterAllowed = policy->MaxAllowedCount;
1451 if (!maxPacketCounterAllowed)
1452 return WorldSession::DosProtection::Policy::Process; // Return true if there no limit for the opcode
1453
1454 // packetCounter is opcodes handled in the same world second, so MaxAllowedCount is per second
1455 PacketCounter& packetCounter = _PacketThrottlingMap[p.GetOpcode()];
1456 if (packetCounter.lastReceiveTime != time)
1457 {
1458 packetCounter.lastReceiveTime = time;
1459 packetCounter.amountCounter = 0;
1460 }
1461
1462 // Check if player is flooding some packets
1463 if (++packetCounter.amountCounter <= maxPacketCounterAllowed)
1465
1467 {
1468 LOG_WARN("network", "AntiDOS: Account {}, IP: {}, Ping: {}, Character: {}, flooding packet (opc: {} (0x{:X}), count: {})",
1470 opcodeTable[static_cast<OpcodeClient>(p.GetOpcode())]->Name, p.GetOpcode(), packetCounter.amountCounter);
1471 }
1472
1474 {
1476 {
1477 LOG_INFO("network", "AntiDOS: Player {} kicked!", Session->GetPlayerName());
1479 break;
1480 }
1482 {
1483 uint32 bm = sWorld->getIntConfig(CONFIG_PACKET_SPOOF_BANMODE);
1484 uint32 duration = sWorld->getIntConfig(CONFIG_PACKET_SPOOF_BANDURATION); // in seconds
1485 std::string nameOrIp = "";
1486 switch (bm)
1487 {
1488 case 0: // Ban account
1489 (void)AccountMgr::GetName(Session->GetAccountId(), nameOrIp);
1490 sBan->BanAccount(nameOrIp, std::to_string(duration), "DOS (Packet Flooding/Spoofing", "Server: AutoDOS");
1491 break;
1492 case 1: // Ban ip
1493 nameOrIp = Session->GetRemoteAddress();
1494 sBan->BanIP(nameOrIp, std::to_string(duration), "DOS (Packet Flooding/Spoofing", "Server: AutoDOS");
1495 break;
1496 }
1497
1498 LOG_INFO("network", "AntiDOS: Player automatically banned for {} seconds.", duration);
1499 break;
1500 }
1502 {
1503 LOG_INFO("network", "AntiDOS: Opcode packet {} from player {} will be dropped.", p.GetOpcode(), Session->GetPlayerName());
1504 break;
1505 }
1506 default: // invalid policy
1507 break;
1508 }
1509
1511}
#define sBan
Definition BanMgr.h:48
std::uint32_t uint32
Definition Define.h:107
#define LOG_INFO(filterType__,...)
Definition Log.h:153
#define LOG_WARN(filterType__,...)
Definition Log.h:149
@ CONFIG_PACKET_SPOOF_BANDURATION
Definition WorldConfig.h:344
@ CONFIG_PACKET_SPOOF_BANMODE
Definition WorldConfig.h:343
#define sWorldGlobals
Definition WorldGlobals.h:42
static bool GetName(uint32 accountId, std::string &name)
Definition AccountMgr.cpp:276
PacketThrottlingMap _PacketThrottlingMap
Definition WorldSession.h:1264
Policy
Definition WorldSession.h:1248
uint32 GetAccountId() const
Definition WorldSession.h:502
uint32 GetLatency() const
Definition WorldSession.h:651
std::string const & GetRemoteAddress()
Definition WorldSession.h:512
void KickPlayer(bool setKicked=true)
Definition WorldSession.h:551
std::string const & GetPlayerName() const
Definition WorldSession.cpp:267
Opcodes
List of Opcodes.
Definition Opcodes.h:30
OpcodeTable opcodeTable
Definition Opcodes.cpp:51
#define sWorld
Definition World.h:318
Definition WorldGlobals.h:25
uint8 Policy
Definition WorldGlobals.h:26
uint16 MaxAllowedCount
Definition WorldGlobals.h:27
Definition WorldSession.h:423
time_t lastReceiveTime
Definition WorldSession.h:424
uint16 amountCounter
Definition WorldSession.h:425

References _PacketThrottlingMap, PacketCounter::amountCounter, Ban, BlockingThrottle, CONFIG_PACKET_SPOOF_BANDURATION, CONFIG_PACKET_SPOOF_BANMODE, DropPacket, WorldSession::GetAccountId(), WorldSession::GetLatency(), AccountMgr::GetName(), WorldPacket::GetOpcode(), WorldSession::GetPlayerName(), WorldSession::GetRemoteAddress(), Kick, WorldSession::KickPlayer(), PacketCounter::lastReceiveTime, LOG_INFO, LOG_WARN, AntiDosOpcodePolicy::MaxAllowedCount, opcodeTable, AntiDosOpcodePolicy::Policy, Process, sBan, Session, sWorld, and sWorldGlobals.

Referenced by WorldSession::Update().

◆ operator=()

DosProtection & WorldSession::DosProtection::operator= ( DosProtection const &  right)
privatedelete

Friends And Related Symbol Documentation

◆ World

friend class World
friend

Member Data Documentation

◆ _PacketThrottlingMap

PacketThrottlingMap WorldSession::DosProtection::_PacketThrottlingMap
mutableprivate

Referenced by EvaluateOpcode().

◆ Session

WorldSession* WorldSession::DosProtection::Session
protected

Referenced by EvaluateOpcode().


The documentation for this class was generated from the following files: