OregonCore  revision fb2a440-git
Your Favourite TBC server
WardenBase Class Reference

#include <WardenBase.h>

+ Inheritance diagram for WardenBase:

Public Member Functions

 WardenBase ()
 
virtual ~WardenBase ()
 
virtual void Init (WorldSession *pClient, BigNumber *K)
 
virtual ClientWardenModuleGetModuleForClient (WorldSession *session)
 
virtual void InitializeModule ()
 
virtual void RequestHash ()
 
virtual void HandleHashResult (ByteBuffer &buff)
 
virtual void RequestData ()
 
virtual void HandleData (ByteBuffer &buff)
 
void SendModuleToClient ()
 
void RequestModule ()
 
void Update ()
 
void DecryptData (uint8 *Buffer, uint32 Len)
 
void EncryptData (uint8 *Buffer, uint32 Len)
 

Static Public Member Functions

static void PrintHexArray (const char *Before, const uint8 *Buffer, uint32 Len, bool BreakWithNewline)
 
static bool IsValidCheckSum (uint32 checksum, const uint8 *Data, const uint16 Length)
 
static uint32 BuildChecksum (const uint8 *data, uint32 dataLen)
 

Private Attributes

WorldSessionClient
 
uint8 InputKey [16]
 
uint8 OutputKey [16]
 
uint8 Seed [16]
 
SARC4 iCrypto
 
SARC4 oCrypto
 
uint32 m_WardenCheckTimer
 
uint32 m_WardenKickTimer
 
bool m_WardenDataSent
 
uint32 m_WardenTimer
 
ClientWardenModuleModule
 
bool m_initialized
 

Friends

class WardenWin
 
class WardenMac
 

Detailed Description

Definition at line 88 of file WardenBase.h.

Constructor & Destructor Documentation

WardenBase::WardenBase ( )

Definition at line 30 of file WardenBase.cpp.

30  : iCrypto(16), oCrypto(16), m_WardenCheckTimer(10000/*10 sec*/), m_WardenKickTimer(0), m_WardenDataSent(false), m_initialized(false)
31 {
32 }
bool m_WardenDataSent
Definition: WardenBase.h:124
uint32 m_WardenKickTimer
Definition: WardenBase.h:123
SARC4 oCrypto
Definition: WardenBase.h:121
SARC4 iCrypto
Definition: WardenBase.h:120
uint32 m_WardenCheckTimer
Definition: WardenBase.h:122
bool m_initialized
Definition: WardenBase.h:127
WardenBase::~WardenBase ( )
virtual

Definition at line 34 of file WardenBase.cpp.

References ClientWardenModule::CompressedData, and Module.

35 {
36  delete[] Module->CompressedData;
37  delete Module;
38  Module = NULL;
39 }
ClientWardenModule * Module
Definition: WardenBase.h:126
uint8 * CompressedData
Definition: WardenBase.h:83

Member Function Documentation

uint32 WardenBase::BuildChecksum ( const uint8 data,
uint32  dataLen 
)
static

Definition at line 179 of file WardenBase.cpp.

Referenced by WardenWin::InitializeModule(), and IsValidCheckSum().

180 {
181  uint8 hash[20];
182  SHA1(data, dataLen, hash);
183  uint32 checkSum = 0;
184  for (uint8 i = 0; i < 5; ++i)
185  checkSum = checkSum ^ *(uint32*)(&hash[0] + i * 4);
186  return checkSum;
187 }
ACE_UINT8 uint8
Definition: Define.h:73
ACE_UINT32 uint32
Definition: Define.h:71
void WardenBase::DecryptData ( uint8 Buffer,
uint32  Len 
)

Definition at line 153 of file WardenBase.cpp.

References iCrypto, and SARC4::UpdateData().

154 {
155  iCrypto.UpdateData(Len, Buffer);
156 }
SARC4 iCrypto
Definition: WardenBase.h:120
void UpdateData(int len, uint8 *data)
Definition: SARC4.cpp:46
void WardenBase::EncryptData ( uint8 Buffer,
uint32  Len 
)

Definition at line 158 of file WardenBase.cpp.

References oCrypto, and SARC4::UpdateData().

Referenced by WardenWin::InitializeModule(), WardenMac::RequestData(), WardenWin::RequestData(), WardenMac::RequestHash(), WardenWin::RequestHash(), RequestModule(), and SendModuleToClient().

159 {
160  oCrypto.UpdateData(Len, Buffer);
161 }
SARC4 oCrypto
Definition: WardenBase.h:121
void UpdateData(int len, uint8 *data)
Definition: SARC4.cpp:46
ClientWardenModule * WardenBase::GetModuleForClient ( WorldSession session)
virtual

Reimplemented in WardenWin, and WardenMac.

Definition at line 46 of file WardenBase.cpp.

References ASSERT.

47 {
48  ASSERT(false);
49  return NULL;
50 }
#define ASSERT
Definition: Errors.h:29
void WardenBase::HandleData ( ByteBuffer buff)
virtual

Reimplemented in WardenWin, and WardenMac.

Definition at line 72 of file WardenBase.cpp.

References ASSERT.

73 {
74  ASSERT(false);
75 }
#define ASSERT
Definition: Errors.h:29
void WardenBase::HandleHashResult ( ByteBuffer buff)
virtual

Reimplemented in WardenWin, and WardenMac.

Definition at line 62 of file WardenBase.cpp.

References ASSERT.

63 {
64  ASSERT(false);
65 }
#define ASSERT
Definition: Errors.h:29
void WardenBase::Init ( WorldSession pClient,
BigNumber K 
)
virtual

Reimplemented in WardenWin, and WardenMac.

Definition at line 41 of file WardenBase.cpp.

References ASSERT.

Referenced by WorldSession::InitWarden().

42 {
43  ASSERT(false);
44 }
#define ASSERT
Definition: Errors.h:29
void WardenBase::InitializeModule ( )
virtual

Reimplemented in WardenWin, and WardenMac.

Definition at line 52 of file WardenBase.cpp.

References ASSERT.

53 {
54  ASSERT(false);
55 }
#define ASSERT
Definition: Errors.h:29
bool WardenBase::IsValidCheckSum ( uint32  checksum,
const uint8 Data,
const uint16  Length 
)
static

Definition at line 163 of file WardenBase.cpp.

References BuildChecksum(), and sLog.

Referenced by WardenWin::HandleData().

164 {
165  uint32 newchecksum = BuildChecksum(Data, Length);
166 
167  if (checksum != newchecksum)
168  {
169  sLog.outWarden("CHECKSUM IS NOT VALID");
170  return false;
171  }
172  else
173  {
174  sLog.outDebug("CHECKSUM IS VALID");
175  return true;
176  }
177 }
static uint32 BuildChecksum(const uint8 *data, uint32 dataLen)
Definition: WardenBase.cpp:179
#define sLog
Log class singleton.
Definition: Log.h:187
ACE_UINT32 uint32
Definition: Define.h:71
static void WardenBase::PrintHexArray ( const char *  Before,
const uint8 Buffer,
uint32  Len,
bool  BreakWithNewline 
)
static
void WardenBase::RequestData ( )
virtual

Reimplemented in WardenWin, and WardenMac.

Definition at line 67 of file WardenBase.cpp.

References ASSERT.

Referenced by Update().

68 {
69  ASSERT(false);
70 }
#define ASSERT
Definition: Errors.h:29
void WardenBase::RequestHash ( )
virtual

Reimplemented in WardenWin, and WardenMac.

Definition at line 57 of file WardenBase.cpp.

References ASSERT.

58 {
59  ASSERT(false);
60 }
#define ASSERT
Definition: Errors.h:29
void WardenBase::RequestModule ( )

Definition at line 103 of file WardenBase.cpp.

References ByteBuffer::append(), Client, WardenModuleUse::Command, ClientWardenModule::CompressedSize, EncryptData(), ClientWardenModule::ID, ClientWardenModule::Key, Module, WardenModuleUse::Module_Id, WardenModuleUse::Module_Key, WorldSession::SendPacket(), WardenModuleUse::Size, sLog, SMSG_WARDEN_DATA, and WARDEN_SMSG_MODULE_USE.

Referenced by WardenMac::Init(), and WardenWin::Init().

104 {
105  sLog.outDebug("Request module");
106 
107  // Create packet structure
108  WardenModuleUse Request;
110 
111  memcpy(Request.Module_Id, Module->ID, 16);
112  memcpy(Request.Module_Key, Module->Key, 16);
113  Request.Size = Module->CompressedSize;
114 
115  // Encrypt with warden RC4 key.
116  EncryptData((uint8*)&Request, sizeof(WardenModuleUse));
117 
119  pkt.append((uint8*)&Request, sizeof(WardenModuleUse));
120  Client->SendPacket(&pkt);
121 }
ClientWardenModule * Module
Definition: WardenBase.h:126
uint8 Module_Key[16]
Definition: WardenBase.h:55
uint32 CompressedSize
Definition: WardenBase.h:82
#define sLog
Log class singleton.
Definition: Log.h:187
void SendPacket(WorldPacket const *packet)
ACE_UINT8 uint8
Definition: Define.h:73
uint8 Module_Id[16]
Definition: WardenBase.h:54
WorldSession * Client
Definition: WardenBase.h:116
void EncryptData(uint8 *Buffer, uint32 Len)
Definition: WardenBase.cpp:158
void WardenBase::SendModuleToClient ( )

Definition at line 77 of file WardenBase.cpp.

References ByteBuffer::append(), Client, WardenModuleTransfer::Command, ClientWardenModule::CompressedData, ClientWardenModule::CompressedSize, WardenModuleTransfer::Data, WardenModuleTransfer::DataSize, EncryptData(), Module, WorldSession::SendPacket(), sLog, SMSG_WARDEN_DATA, and WARDEN_SMSG_MODULE_CACHE.

78 {
79  sLog.outDebug("Send module to client");
80 
81  // Create packet structure
83 
84  uint32 size_left = Module->CompressedSize;
85  uint32 pos = 0;
86  uint16 burst_size;
87  while (size_left > 0)
88  {
89  burst_size = size_left < 500 ? size_left : 500;
91  pkt.DataSize = burst_size;
92  memcpy(pkt.Data, &Module->CompressedData[pos], burst_size);
93  size_left -= burst_size;
94  pos += burst_size;
95 
96  EncryptData((uint8*)&pkt, burst_size + 3);
97  WorldPacket pkt1(SMSG_WARDEN_DATA, burst_size + 3);
98  pkt1.append((uint8*)&pkt, burst_size + 3);
99  Client->SendPacket(&pkt1);
100  }
101 }
ClientWardenModule * Module
Definition: WardenBase.h:126
uint32 CompressedSize
Definition: WardenBase.h:82
#define sLog
Log class singleton.
Definition: Log.h:187
void SendPacket(WorldPacket const *packet)
uint8 * CompressedData
Definition: WardenBase.h:83
ACE_UINT8 uint8
Definition: Define.h:73
WorldSession * Client
Definition: WardenBase.h:116
void EncryptData(uint8 *Buffer, uint32 Len)
Definition: WardenBase.cpp:158
ACE_UINT16 uint16
Definition: Define.h:72
ACE_UINT32 uint32
Definition: Define.h:71
void WardenBase::Update ( )

Definition at line 123 of file WardenBase.cpp.

References Client, CONFIG_WARDEN_CLIENT_CHECK_HOLDOFF, CONFIG_WARDEN_CLIENT_RESPONSE_DELAY, CONFIG_WARDEN_KICK, getMSTime(), IN_MILLISECONDS, WorldSession::KickPlayer(), m_initialized, m_WardenCheckTimer, m_WardenDataSent, m_WardenKickTimer, m_WardenTimer, RequestData(), and sWorld.

Referenced by WorldSession::Update().

124 {
125  if (m_initialized)
126  {
127  uint32 ticks = getMSTime();
128  uint32 diff = ticks - m_WardenTimer;
129  m_WardenTimer = ticks;
130 
131  if (m_WardenDataSent)
132  {
133  // 1.5 minutes after send packet
134  uint32 maxClientResponseDelay = sWorld.getConfig(CONFIG_WARDEN_CLIENT_RESPONSE_DELAY);
135  if ((m_WardenKickTimer > maxClientResponseDelay * IN_MILLISECONDS) && sWorld.getConfig(CONFIG_WARDEN_KICK))
136  Client->KickPlayer();
137  else
138  m_WardenKickTimer += diff;
139  }
140  else if (m_WardenCheckTimer > 0)
141  {
142  if (diff >= m_WardenCheckTimer)
143  {
144  RequestData();
146  }
147  else
148  m_WardenCheckTimer -= diff;
149  }
150  }
151 }
bool m_WardenDataSent
Definition: WardenBase.h:124
uint32 getMSTime()
Definition: Timer.h:32
uint32 m_WardenKickTimer
Definition: WardenBase.h:123
uint32 m_WardenTimer
Definition: WardenBase.h:125
WorldSession * Client
Definition: WardenBase.h:116
uint32 m_WardenCheckTimer
Definition: WardenBase.h:122
#define sWorld
Definition: World.h:860
ACE_UINT32 uint32
Definition: Define.h:71
bool m_initialized
Definition: WardenBase.h:127
virtual void RequestData()
Definition: WardenBase.cpp:67

Friends And Related Function Documentation

friend class WardenMac
friend

Definition at line 91 of file WardenBase.h.

friend class WardenWin
friend

Definition at line 90 of file WardenBase.h.

Member Data Documentation

SARC4 WardenBase::iCrypto
private
uint8 WardenBase::InputKey[16]
private
bool WardenBase::m_initialized
private

Definition at line 127 of file WardenBase.h.

Referenced by WardenMac::HandleHashResult(), WardenWin::HandleHashResult(), and Update().

uint32 WardenBase::m_WardenCheckTimer
private

Definition at line 122 of file WardenBase.h.

Referenced by Update().

bool WardenBase::m_WardenDataSent
private
uint32 WardenBase::m_WardenKickTimer
private

Definition at line 123 of file WardenBase.h.

Referenced by WardenMac::HandleData(), WardenWin::HandleData(), and Update().

uint32 WardenBase::m_WardenTimer
private

Definition at line 125 of file WardenBase.h.

Referenced by WardenMac::HandleHashResult(), WardenWin::HandleHashResult(), and Update().

ClientWardenModule* WardenBase::Module
private
SARC4 WardenBase::oCrypto
private
uint8 WardenBase::OutputKey[16]
private
uint8 WardenBase::Seed[16]
private

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