TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Warden Class Referenceabstract

#include <Warden.h>

Public Member Functions

 Warden ()
 
virtual ~Warden ()
 
virtual void Init (WorldSession *session, BigNumber *k)=0
 
virtual ClientWardenModuleGetModuleForClient ()=0
 
virtual void InitializeModule ()=0
 
virtual void RequestHash ()=0
 
virtual void HandleHashResult (ByteBuffer &buff)=0
 
virtual void RequestData ()=0
 
virtual void HandleData (ByteBuffer &buff)=0
 
void SendModuleToClient ()
 
void RequestModule ()
 
void Update ()
 
void DecryptData (uint8 *buffer, uint32 length)
 
void EncryptData (uint8 *buffer, uint32 length)
 
std::string Penalty (WardenCheck *check=NULL)
 

Static Public Member Functions

static bool IsValidCheckSum (uint32 checksum, const uint8 *data, const uint16 length)
 
static uint32 BuildChecksum (const uint8 *data, uint32 length)
 

Private Attributes

WorldSession_session
 
uint8 _inputKey [16]
 
uint8 _outputKey [16]
 
uint8 _seed [16]
 
ARC4 _inputCrypto
 
ARC4 _outputCrypto
 
uint32 _checkTimer
 
uint32 _clientResponseTimer
 
bool _dataSent
 
uint32 _previousTimestamp
 
ClientWardenModule_module
 
bool _initialized
 

Friends

class WardenWin
 
class WardenMac
 

Constructor & Destructor Documentation

Warden::Warden ( )
33  : _session(NULL), _inputCrypto(16), _outputCrypto(16), _checkTimer(10000/*10 sec*/), _clientResponseTimer(0),
35 {
36  memset(_inputKey, 0, sizeof(_inputKey));
37  memset(_outputKey, 0, sizeof(_outputKey));
38  memset(_seed, 0, sizeof(_seed));
39 }
uint32 _clientResponseTimer
Definition: Warden.h:132
uint32 _previousTimestamp
Definition: Warden.h:134
ClientWardenModule * _module
Definition: Warden.h:135
arena_t NULL
Definition: jemalloc_internal.h:624
bool _dataSent
Definition: Warden.h:133
uint8 _seed[16]
Definition: Warden.h:128
WorldSession * _session
Definition: Warden.h:125
uint8 _outputKey[16]
Definition: Warden.h:127
ARC4 _outputCrypto
Definition: Warden.h:130
ARC4 _inputCrypto
Definition: Warden.h:129
uint8 _inputKey[16]
Definition: Warden.h:126
bool _initialized
Definition: Warden.h:136
uint32 _checkTimer
Definition: Warden.h:131
Warden::~Warden ( )
virtual
42 {
43  delete[] _module->CompressedData;
44  delete _module;
45  _module = NULL;
46  _initialized = false;
47 }
ClientWardenModule * _module
Definition: Warden.h:135
arena_t NULL
Definition: jemalloc_internal.h:624
uint8 * CompressedData
Definition: Warden.h:90
bool _initialized
Definition: Warden.h:136

Member Function Documentation

uint32 Warden::BuildChecksum ( const uint8 data,
uint32  length 
)
static
174 {
175  keyData hash;
176  SHA1(data, length, hash.bytes.bytes);
177  uint32 checkSum = 0;
178  for (uint8 i = 0; i < 5; ++i)
179  checkSum = checkSum ^ hash.ints.ints[i];
180 
181  return checkSum;
182 }
uint32 ints[5]
Definition: Warden.cpp:168
Definition: Warden.cpp:158
uint8 bytes[20]
Definition: Warden.cpp:163
#define hash
Definition: private_namespace.h:186
uint32_t uint32
Definition: Define.h:150
float length(float v)
Definition: vectorMath.h:208
uint8_t uint8
Definition: Define.h:152

+ Here is the caller graph for this function:

void Warden::DecryptData ( uint8 buffer,
uint32  length 
)
133 {
134  _inputCrypto.UpdateData(length, buffer);
135 }
float length(float v)
Definition: vectorMath.h:208
ARC4 _inputCrypto
Definition: Warden.h:129
void UpdateData(int len, uint8 *data)
Definition: ARC4.cpp:47

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Warden::EncryptData ( uint8 buffer,
uint32  length 
)
138 {
140 }
float length(float v)
Definition: vectorMath.h:208
ARC4 _outputCrypto
Definition: Warden.h:130
void UpdateData(int len, uint8 *data)
Definition: ARC4.cpp:47

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual ClientWardenModule* Warden::GetModuleForClient ( )
pure virtual

Implemented in WardenWin, and WardenMac.

virtual void Warden::HandleData ( ByteBuffer buff)
pure virtual

Implemented in WardenWin, and WardenMac.

+ Here is the caller graph for this function:

virtual void Warden::HandleHashResult ( ByteBuffer buff)
pure virtual

Implemented in WardenWin, and WardenMac.

+ Here is the caller graph for this function:

virtual void Warden::Init ( WorldSession session,
BigNumber k 
)
pure virtual

Implemented in WardenWin, and WardenMac.

+ Here is the caller graph for this function:

virtual void Warden::InitializeModule ( )
pure virtual

Implemented in WardenWin, and WardenMac.

+ Here is the caller graph for this function:

bool Warden::IsValidCheckSum ( uint32  checksum,
const uint8 data,
const uint16  length 
)
static
143 {
144  uint32 newChecksum = BuildChecksum(data, length);
145 
146  if (checksum != newChecksum)
147  {
148  TC_LOG_DEBUG("warden", "CHECKSUM IS NOT VALID");
149  return false;
150  }
151  else
152  {
153  TC_LOG_DEBUG("warden", "CHECKSUM IS VALID");
154  return true;
155  }
156 }
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
static uint32 BuildChecksum(const uint8 *data, uint32 length)
Definition: Warden.cpp:173
uint32_t uint32
Definition: Define.h:150
float length(float v)
Definition: vectorMath.h:208

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string Warden::Penalty ( WardenCheck check = NULL)
185 {
186  WardenActions action;
187 
188  if (check)
189  action = check->Action;
190  else
191  action = WardenActions(sWorld->getIntConfig(CONFIG_WARDEN_CLIENT_FAIL_ACTION));
192 
193  switch (action)
194  {
195  case WARDEN_ACTION_LOG:
196  return "None";
197  break;
198  case WARDEN_ACTION_KICK:
199  _session->KickPlayer();
200  return "Kick";
201  break;
202  case WARDEN_ACTION_BAN:
203  {
204  std::stringstream duration;
205  duration << sWorld->getIntConfig(CONFIG_WARDEN_CLIENT_BAN_DURATION) << "s";
206  std::string accountName;
207  AccountMgr::GetName(_session->GetAccountId(), accountName);
208  std::stringstream banReason;
209  banReason << "Warden Anticheat Violation";
210  // Check can be NULL, for example if the client sent a wrong signature in the warden packet (CHECKSUM FAIL)
211  if (check)
212  banReason << ": " << check->Comment << " (CheckId: " << check->CheckId << ")";
213 
214  sWorld->BanAccount(BAN_ACCOUNT, accountName, duration.str(), banReason.str(),"Server");
215 
216  return "Ban";
217  }
218  default:
219  break;
220  }
221  return "Undefined";
222 }
Definition: WardenCheckMgr.h:29
Definition: WardenCheckMgr.h:31
Definition: World.h:346
enum WardenActions Action
Definition: WardenCheckMgr.h:43
uint32 GetAccountId() const
Definition: WorldSession.h:922
#define sWorld
Definition: World.h:887
void KickPlayer()
Kick a player out of the World.
Definition: WorldSession.cpp:646
static bool GetName(uint32 accountId, std::string &name)
Definition: AccountMgr.cpp:303
Definition: SharedDefines.h:4535
std::string Comment
Definition: WardenCheckMgr.h:41
uint16 CheckId
Definition: WardenCheckMgr.h:42
WardenActions
Definition: WardenCheckMgr.h:27
WorldSession * _session
Definition: Warden.h:125
Definition: World.h:347
Definition: WardenCheckMgr.h:30

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

virtual void Warden::RequestData ( )
pure virtual

Implemented in WardenWin, and WardenMac.

+ Here is the caller graph for this function:

virtual void Warden::RequestHash ( )
pure virtual

Implemented in WardenWin, and WardenMac.

+ Here is the caller graph for this function:

void Warden::RequestModule ( )
76 {
77  TC_LOG_DEBUG("warden", "Request module");
78 
79  // Create packet structure
80  WardenModuleUse request;
82 
83  memcpy(request.ModuleId, _module->Id, 16);
84  memcpy(request.ModuleKey, _module->Key, 16);
85  request.Size = _module->CompressedSize;
86 
87  // Encrypt with warden RC4 key.
88  EncryptData((uint8*)&request, sizeof(WardenModuleUse));
89 
91  pkt.append((uint8*)&request, sizeof(WardenModuleUse));
92  _session->SendPacket(&pkt);
93 }
uint8 ModuleId[16]
Definition: Warden.h:65
Definition: Warden.h:39
ClientWardenModule * _module
Definition: Warden.h:135
uint8 Id[16]
Definition: Warden.h:87
Definition: Warden.h:62
uint32 CompressedSize
Definition: Warden.h:89
uint8 Key[16]
Definition: Warden.h:88
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
uint8 ModuleKey[16]
Definition: Warden.h:66
uint8 Command
Definition: Warden.h:64
uint32 Size
Definition: Warden.h:67
void EncryptData(uint8 *buffer, uint32 length)
Definition: Warden.cpp:137
WorldSession * _session
Definition: Warden.h:125
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition: WorldSession.cpp:211
uint8_t uint8
Definition: Define.h:152
Definition: Opcodes.h:1623
Definition: WorldPacket.h:26

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Warden::SendModuleToClient ( )
50 {
51  TC_LOG_DEBUG("warden", "Send module to client");
52 
53  // Create packet structure
54  WardenModuleTransfer packet;
55 
56  uint32 sizeLeft = _module->CompressedSize;
57  uint32 pos = 0;
58  uint16 burstSize;
59  while (sizeLeft > 0)
60  {
61  burstSize = sizeLeft < 500 ? sizeLeft : 500;
63  packet.DataSize = burstSize;
64  memcpy(packet.Data, &_module->CompressedData[pos], burstSize);
65  sizeLeft -= burstSize;
66  pos += burstSize;
67 
68  EncryptData((uint8*)&packet, burstSize + 3);
69  WorldPacket pkt1(SMSG_WARDEN_DATA, burstSize + 3);
70  pkt1.append((uint8*)&packet, burstSize + 3);
71  _session->SendPacket(&pkt1);
72  }
73 }
ClientWardenModule * _module
Definition: Warden.h:135
uint32 CompressedSize
Definition: Warden.h:89
#define TC_LOG_DEBUG(filterType__,...)
Definition: Log.h:198
uint8 Command
Definition: Warden.h:72
uint8 * CompressedData
Definition: Warden.h:90
Definition: Warden.h:70
Definition: Warden.h:40
uint32_t uint32
Definition: Define.h:150
uint16_t uint16
Definition: Define.h:151
void EncryptData(uint8 *buffer, uint32 length)
Definition: Warden.cpp:137
WorldSession * _session
Definition: Warden.h:125
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition: WorldSession.cpp:211
uint8_t uint8
Definition: Define.h:152
uint16 DataSize
Definition: Warden.h:73
uint8 Data[500]
Definition: Warden.h:74
Definition: Opcodes.h:1623
Definition: WorldPacket.h:26

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Warden::Update ( )
96 {
97  if (_initialized)
98  {
99  uint32 currentTimestamp = getMSTime();
100  uint32 diff = currentTimestamp - _previousTimestamp;
101  _previousTimestamp = currentTimestamp;
102 
103  if (_dataSent)
104  {
105  uint32 maxClientResponseDelay = sWorld->getIntConfig(CONFIG_WARDEN_CLIENT_RESPONSE_DELAY);
106 
107  if (maxClientResponseDelay > 0)
108  {
109  // Kick player if client response delays more than set in config
110  if (_clientResponseTimer > maxClientResponseDelay * IN_MILLISECONDS)
111  {
112  TC_LOG_WARN("warden", "%s (latency: %u, IP: %s) exceeded Warden module response delay for more than %s - disconnecting client",
113  _session->GetPlayerInfo().c_str(), _session->GetLatency(), _session->GetRemoteAddress().c_str(), secsToTimeString(maxClientResponseDelay, true).c_str());
114  _session->KickPlayer();
115  }
116  else
117  _clientResponseTimer += diff;
118  }
119  }
120  else
121  {
122  if (diff >= _checkTimer)
123  {
124  RequestData();
125  }
126  else
127  _checkTimer -= diff;
128  }
129  }
130 }
uint32 _clientResponseTimer
Definition: Warden.h:132
uint32 _previousTimestamp
Definition: Warden.h:134
std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
Definition: Util.cpp:109
uint32 getMSTime()
Definition: Timer.h:24
bool _dataSent
Definition: Warden.h:133
#define sWorld
Definition: World.h:887
virtual void RequestData()=0
void KickPlayer()
Kick a player out of the World.
Definition: WorldSession.cpp:646
std::string const & GetRemoteAddress() const
Definition: WorldSession.h:932
uint32_t uint32
Definition: Define.h:150
WorldSession * _session
Definition: Warden.h:125
uint32 GetLatency() const
Definition: WorldSession.h:1063
bool _initialized
Definition: Warden.h:136
Definition: Common.h:103
std::string GetPlayerInfo() const
Definition: WorldSession.cpp:195
#define TC_LOG_WARN(filterType__,...)
Definition: Log.h:204
uint32 _checkTimer
Definition: Warden.h:131

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class WardenMac
friend
friend class WardenWin
friend

Member Data Documentation

uint32 Warden::_checkTimer
private
uint32 Warden::_clientResponseTimer
private
bool Warden::_dataSent
private
bool Warden::_initialized
private
ARC4 Warden::_inputCrypto
private
uint8 Warden::_inputKey[16]
private
ClientWardenModule* Warden::_module
private
ARC4 Warden::_outputCrypto
private
uint8 Warden::_outputKey[16]
private
uint32 Warden::_previousTimestamp
private
uint8 Warden::_seed[16]
private
WorldSession* Warden::_session
private

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