TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
WardenCheckMgr Class Reference

#include <WardenCheckMgr.h>

Public Types

typedef std::vector
< WardenCheck * > 
CheckContainer
 
typedef std::map< uint32,
WardenCheckResult * > 
CheckResultContainer
 

Public Member Functions

WardenCheckGetWardenDataById (uint16 Id)
 
WardenCheckResultGetWardenResultById (uint16 Id)
 
void LoadWardenChecks ()
 
void LoadWardenOverrides ()
 

Static Public Member Functions

static WardenCheckMgrinstance ()
 

Public Attributes

std::vector< uint16MemChecksIdPool
 
std::vector< uint16OtherChecksIdPool
 
boost::shared_mutex _checkStoreLock
 

Private Member Functions

 WardenCheckMgr ()
 
 ~WardenCheckMgr ()
 

Private Attributes

CheckContainer CheckStore
 
CheckResultContainer CheckResultStore
 

Member Typedef Documentation

Constructor & Destructor Documentation

WardenCheckMgr::WardenCheckMgr ( )
private
27 { }
WardenCheckMgr::~WardenCheckMgr ( )
private
30 {
31  for (uint16 i = 0; i < CheckStore.size(); ++i)
32  delete CheckStore[i];
33 
34  for (CheckResultContainer::iterator itr = CheckResultStore.begin(); itr != CheckResultStore.end(); ++itr)
35  delete itr->second;
36 }
CheckContainer CheckStore
Definition: WardenCheckMgr.h:76
uint16_t uint16
Definition: Define.h:151
CheckResultContainer CheckResultStore
Definition: WardenCheckMgr.h:77

Member Function Documentation

WardenCheck * WardenCheckMgr::GetWardenDataById ( uint16  Id)
199 {
200  if (Id < CheckStore.size())
201  return CheckStore[Id];
202 
203  return NULL;
204 }
arena_t NULL
Definition: jemalloc_internal.h:624
CheckContainer CheckStore
Definition: WardenCheckMgr.h:76
WardenCheckResult * WardenCheckMgr::GetWardenResultById ( uint16  Id)
207 {
208  CheckResultContainer::const_iterator itr = CheckResultStore.find(Id);
209  if (itr != CheckResultStore.end())
210  return itr->second;
211  return NULL;
212 }
arena_t NULL
Definition: jemalloc_internal.h:624
CheckResultContainer CheckResultStore
Definition: WardenCheckMgr.h:77
WardenCheckMgr * WardenCheckMgr::instance ( )
static
193 {
194  static WardenCheckMgr instance;
195  return &instance;
196 }
static WardenCheckMgr * instance()
Definition: WardenCheckMgr.cpp:192
Definition: WardenCheckMgr.h:51
void WardenCheckMgr::LoadWardenChecks ( )
39 {
40  // Check if Warden is enabled by config before loading anything
41  if (!sWorld->getBoolConfig(CONFIG_WARDEN_ENABLED))
42  {
43  TC_LOG_INFO("warden", ">> Warden disabled, loading checks skipped.");
44  return;
45  }
46 
47  QueryResult result = WorldDatabase.Query("SELECT MAX(id) FROM warden_checks");
48 
49  if (!result)
50  {
51  TC_LOG_INFO("server.loading", ">> Loaded 0 Warden checks. DB table `warden_checks` is empty!");
52  return;
53  }
54 
55  Field* fields = result->Fetch();
56 
57  uint16 maxCheckId = fields[0].GetUInt16();
58 
59  CheckStore.resize(maxCheckId + 1);
60 
61  // 0 1 2 3 4 5 6 7
62  result = WorldDatabase.Query("SELECT id, type, data, result, address, length, str, comment FROM warden_checks ORDER BY id ASC");
63 
64  uint32 count = 0;
65  do
66  {
67  fields = result->Fetch();
68 
69  uint16 id = fields[0].GetUInt16();
70  uint8 checkType = fields[1].GetUInt8();
71  std::string data = fields[2].GetString();
72  std::string checkResult = fields[3].GetString();
73  uint32 address = fields[4].GetUInt32();
74  uint8 length = fields[5].GetUInt8();
75  std::string str = fields[6].GetString();
76  std::string comment = fields[7].GetString();
77 
78  WardenCheck* wardenCheck = new WardenCheck();
79  wardenCheck->Type = checkType;
80  wardenCheck->CheckId = id;
81 
82  // Initialize action with default action from config
83  wardenCheck->Action = WardenActions(sWorld->getIntConfig(CONFIG_WARDEN_CLIENT_FAIL_ACTION));
84 
85  if (checkType == PAGE_CHECK_A || checkType == PAGE_CHECK_B || checkType == DRIVER_CHECK)
86  {
87  wardenCheck->Data.SetHexStr(data.c_str());
88  int len = data.size() / 2;
89 
90  if (wardenCheck->Data.GetNumBytes() < len)
91  {
92  uint8 temp[24];
93  memset(temp, 0, len);
94  memcpy(temp, wardenCheck->Data.AsByteArray().get(), wardenCheck->Data.GetNumBytes());
95  std::reverse(temp, temp + len);
96  wardenCheck->Data.SetBinary((uint8*)temp, len);
97  }
98  }
99 
100  if (checkType == MEM_CHECK || checkType == MODULE_CHECK)
101  MemChecksIdPool.push_back(id);
102  else
103  OtherChecksIdPool.push_back(id);
104 
105  if (checkType == MEM_CHECK || checkType == PAGE_CHECK_A || checkType == PAGE_CHECK_B || checkType == PROC_CHECK)
106  {
107  wardenCheck->Address = address;
108  wardenCheck->Length = length;
109  }
110 
111  // PROC_CHECK support missing
112  if (checkType == MEM_CHECK || checkType == MPQ_CHECK || checkType == LUA_STR_CHECK || checkType == DRIVER_CHECK || checkType == MODULE_CHECK)
113  wardenCheck->Str = str;
114 
115  CheckStore[id] = wardenCheck;
116 
117  if (checkType == MPQ_CHECK || checkType == MEM_CHECK)
118  {
120  wr->Result.SetHexStr(checkResult.c_str());
121  int len = checkResult.size() / 2;
122  if (wr->Result.GetNumBytes() < len)
123  {
124  uint8 *temp = new uint8[len];
125  memset(temp, 0, len);
126  memcpy(temp, wr->Result.AsByteArray().get(), wr->Result.GetNumBytes());
127  std::reverse(temp, temp + len);
128  wr->Result.SetBinary((uint8*)temp, len);
129  delete [] temp;
130  }
131  CheckResultStore[id] = wr;
132  }
133 
134  if (comment.empty())
135  wardenCheck->Comment = "Undocumented Check";
136  else
137  wardenCheck->Comment = comment;
138 
139  ++count;
140  }
141  while (result->NextRow());
142 
143  TC_LOG_INFO("server.loading", ">> Loaded %u warden checks.", count);
144 }
Definition: World.h:166
void SetHexStr(char const *str)
Definition: BigNumber.cpp:69
uint8 Length
Definition: WardenCheckMgr.h:39
std::vector< uint16 > MemChecksIdPool
Definition: WardenCheckMgr.h:67
Definition: WardenCheckMgr.h:46
Definition: Warden.h:54
Definition: Warden.h:51
Class used to access individual fields of database query result.
Definition: Field.h:56
Definition: World.h:346
BigNumber Result
Definition: WardenCheckMgr.h:48
uint8 Type
Definition: WardenCheckMgr.h:36
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
CheckContainer CheckStore
Definition: WardenCheckMgr.h:76
enum WardenActions Action
Definition: WardenCheckMgr.h:43
Definition: Warden.h:53
void SetBinary(uint8 const *bytes, int32 len)
Definition: BigNumber.cpp:57
#define sWorld
Definition: World.h:887
Definition: Warden.h:56
Definition: Warden.h:57
std::vector< uint16 > OtherChecksIdPool
Definition: WardenCheckMgr.h:68
std::string Comment
Definition: WardenCheckMgr.h:41
int32 GetNumBytes(void)
Definition: BigNumber.cpp:157
uint8 GetUInt8() const
Definition: Field.h:70
BigNumber Data
Definition: WardenCheckMgr.h:37
uint16 CheckId
Definition: WardenCheckMgr.h:42
Definition: Warden.h:52
Definition: Warden.h:50
uint32_t uint32
Definition: Define.h:150
WardenActions
Definition: WardenCheckMgr.h:27
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
uint16_t uint16
Definition: Define.h:151
uint16 GetUInt16() const
Definition: Field.h:108
float length(float v)
Definition: vectorMath.h:208
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
std::unique_ptr< uint8[]> AsByteArray(int32 minSize=0, bool littleEndian=true)
Definition: BigNumber.cpp:177
uint32 GetUInt32() const
Definition: Field.h:146
uint8_t uint8
Definition: Define.h:152
CheckResultContainer CheckResultStore
Definition: WardenCheckMgr.h:77
std::string Str
Definition: WardenCheckMgr.h:40
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
Definition: WardenCheckMgr.h:34
uint32 Address
Definition: WardenCheckMgr.h:38
std::string GetString() const
Definition: Field.h:276
Definition: Warden.h:49

+ Here is the call graph for this function:

void WardenCheckMgr::LoadWardenOverrides ( )
147 {
148  // Check if Warden is enabled by config before loading anything
149  if (!sWorld->getBoolConfig(CONFIG_WARDEN_ENABLED))
150  {
151  TC_LOG_INFO("warden", ">> Warden disabled, loading check overrides skipped.");
152  return;
153  }
154 
155  // 0 1
156  QueryResult result = CharacterDatabase.Query("SELECT wardenId, action FROM warden_action");
157 
158  if (!result)
159  {
160  TC_LOG_INFO("server.loading", ">> Loaded 0 Warden action overrides. DB table `warden_action` is empty!");
161  return;
162  }
163 
164  uint32 count = 0;
165 
166  boost::unique_lock<boost::shared_mutex> lock(sWardenCheckMgr->_checkStoreLock);
167 
168  do
169  {
170  Field* fields = result->Fetch();
171 
172  uint16 checkId = fields[0].GetUInt16();
173  uint8 action = fields[1].GetUInt8();
174 
175  // Check if action value is in range (0-2, see WardenActions enum)
176  if (action > WARDEN_ACTION_BAN)
177  TC_LOG_ERROR("warden", "Warden check override action out of range (ID: %u, action: %u)", checkId, action);
178  // Check if check actually exists before accessing the CheckStore vector
179  else if (checkId > CheckStore.size())
180  TC_LOG_ERROR("warden", "Warden check action override for non-existing check (ID: %u, action: %u), skipped", checkId, action);
181  else
182  {
183  CheckStore[checkId]->Action = WardenActions(action);
184  ++count;
185  }
186  }
187  while (result->NextRow());
188 
189  TC_LOG_INFO("server.loading", ">> Loaded %u warden action overrides.", count);
190 }
Definition: World.h:166
Definition: WardenCheckMgr.h:31
Class used to access individual fields of database query result.
Definition: Field.h:56
CheckContainer CheckStore
Definition: WardenCheckMgr.h:76
#define sWorld
Definition: World.h:887
uint8 GetUInt8() const
Definition: Field.h:70
uint32_t uint32
Definition: Define.h:150
WardenActions
Definition: WardenCheckMgr.h:27
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
uint16_t uint16
Definition: Define.h:151
uint16 GetUInt16() const
Definition: Field.h:108
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
#define sWardenCheckMgr
Definition: WardenCheckMgr.h:80
uint8_t uint8
Definition: Define.h:152
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207

+ Here is the call graph for this function:

Member Data Documentation

boost::shared_mutex WardenCheckMgr::_checkStoreLock
CheckResultContainer WardenCheckMgr::CheckResultStore
private
CheckContainer WardenCheckMgr::CheckStore
private
std::vector<uint16> WardenCheckMgr::MemChecksIdPool
std::vector<uint16> WardenCheckMgr::OtherChecksIdPool

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