AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
WardenCheckMgr Class Reference

#include "WardenCheckMgr.h"

Public Types

typedef std::vector< WardenCheckCheckContainer
 
typedef std::map< uint32, WardenCheckResultCheckResultContainer
 

Public Member Functions

uint16 GetMaxValidCheckId () const
 
WardenCheck const * GetWardenDataById (uint16 Id)
 
WardenCheckResult const * GetWardenResultById (uint16 Id)
 
void LoadWardenChecks ()
 
void LoadWardenOverrides ()
 

Static Public Member Functions

static WardenCheckMgrinstance ()
 

Public Attributes

std::vector< uint16CheckIdPool [MAX_WARDEN_CHECK_TYPES]
 

Private Member Functions

 WardenCheckMgr ()
 
 ~WardenCheckMgr ()
 

Private Attributes

std::vector< WardenCheckCheckStore
 
std::map< uint32, WardenCheckResultCheckResultStore
 

Detailed Description

Member Typedef Documentation

◆ CheckContainer

◆ CheckResultContainer

Constructor & Destructor Documentation

◆ WardenCheckMgr()

WardenCheckMgr::WardenCheckMgr ( )
private
26{
27}

◆ ~WardenCheckMgr()

WardenCheckMgr::~WardenCheckMgr ( )
private
30{
31}

Member Function Documentation

◆ GetMaxValidCheckId()

uint16 WardenCheckMgr::GetMaxValidCheckId ( ) const
inline
75{ return static_cast<uint16>(CheckStore.size()); }
std::uint16_t uint16
Definition: Define.h:108
std::vector< WardenCheck > CheckStore
Definition: WardenCheckMgr.h:85

References CheckStore.

◆ GetWardenDataById()

WardenCheck const * WardenCheckMgr::GetWardenDataById ( uint16  Id)
211{
212 if (Id < CheckStore.size())
213 return &CheckStore.at(Id);
214
215 return nullptr;
216}

References CheckStore.

◆ GetWardenResultById()

WardenCheckResult const * WardenCheckMgr::GetWardenResultById ( uint16  Id)
219{
220 CheckResultContainer::const_iterator itr = CheckResultStore.find(Id);
221 if (itr != CheckResultStore.end())
222 {
223 return &itr->second;
224 }
225
226 return nullptr;
227}
std::map< uint32, WardenCheckResult > CheckResultStore
Definition: WardenCheckMgr.h:86

References CheckResultStore.

◆ instance()

WardenCheckMgr * WardenCheckMgr::instance ( )
static
34{
36 return &instance;
37}
Definition: WardenCheckMgr.h:64
static WardenCheckMgr * instance()
Definition: WardenCheckMgr.cpp:33

References instance().

Referenced by instance().

◆ LoadWardenChecks()

void WardenCheckMgr::LoadWardenChecks ( )
40{
41 // Check if Warden is enabled by config before loading anything
42 if (!sWorld->getBoolConfig(CONFIG_WARDEN_ENABLED))
43 {
44 LOG_INFO("server.loading", ">> Warden disabled, loading checks skipped.");
45 LOG_INFO("server.loading", " ");
46 return;
47 }
48
49 QueryResult result = WorldDatabase.Query("SELECT MAX(id) FROM warden_checks");
50
51 if (!result)
52 {
53 LOG_WARN("server.loading", ">> Loaded 0 Warden checks. DB table `warden_checks` is empty!");
54 LOG_INFO("server.loading", " ");
55 return;
56 }
57
58 Field* fields = result->Fetch();
59
60 uint16 maxCheckId = fields[0].Get<uint16>();
61
62 CheckStore.resize(maxCheckId + 1);
63
64 // 0 1 2 3 4 5 6 7
65 result = WorldDatabase.Query("SELECT id, type, data, result, address, length, str, comment FROM warden_checks ORDER BY id ASC");
66
67 uint32 count = 0;
68 do
69 {
70 fields = result->Fetch();
71
72 uint16 id = fields[0].Get<uint16>();
73 uint8 checkType = fields[1].Get<uint8>();
74
75 if (checkType == LUA_EVAL_CHECK && id > 9999)
76 {
77 LOG_ERROR("warden", "sql.sql: Warden Lua check with id {} found in `warden_checks`. Lua checks may have four-digit IDs at most. Skipped.", id);
78 continue;
79 }
80
81 std::string data = fields[2].Get<std::string>();
82 std::string checkResult = fields[3].Get<std::string>();
83 uint32 address = fields[4].Get<uint32>();
84 uint8 length = fields[5].Get<uint8>();
85 std::string str = fields[6].Get<std::string>();
86 std::string comment = fields[7].Get<std::string>();
87
88 WardenCheck &wardenCheck = CheckStore.at(id);
89 wardenCheck.Type = checkType;
90 wardenCheck.CheckId = id;
91
92 // Initialize action with default action from config
93 wardenCheck.Action = sWorld->getIntConfig(CONFIG_WARDEN_CLIENT_FAIL_ACTION);
94 if (wardenCheck.Action > MAX_WARDEN_ACTION)
95 {
96 wardenCheck.Action = WARDEN_ACTION_BAN;
97 }
98
99 if (checkType == MEM_CHECK || checkType == PAGE_CHECK_A || checkType == PAGE_CHECK_B || checkType == PROC_CHECK)
100 {
101 wardenCheck.Address = address;
102 wardenCheck.Length = length;
103 }
104
105 // PROC_CHECK support missing
106 if (checkType == MEM_CHECK || checkType == MPQ_CHECK || checkType == LUA_EVAL_CHECK || checkType == DRIVER_CHECK || checkType == MODULE_CHECK)
107 {
108 wardenCheck.Str = str;
109 }
110
111 if (checkType == MPQ_CHECK || checkType == MEM_CHECK)
112 {
114 wr.Result.SetHexStr(checkResult.c_str());
115 CheckResultStore[id] = wr;
116 }
117
118 if (comment.empty())
119 wardenCheck.Comment = "Undocumented Check";
120 else
121 wardenCheck.Comment = comment;
122
123 // Prepare check pools
124 switch (checkType)
125 {
126 case MEM_CHECK:
127 case MODULE_CHECK:
128 {
129 CheckIdPool[WARDEN_CHECK_MEM_TYPE].push_back(id);
130 break;
131 }
132 case LUA_EVAL_CHECK:
133 {
134 if (wardenCheck.Length > WARDEN_MAX_LUA_CHECK_LENGTH)
135 {
136 LOG_ERROR("warden", "sql.sql: Found over-long Lua check for Warden check with id {} in `warden_checks`. Max length is {}. Skipped.", id, WARDEN_MAX_LUA_CHECK_LENGTH);
137 continue;
138 }
139
140 std::string str2 = Acore::StringFormat("{:04}", id);
141 ASSERT(str2.size() == 4);
142 std::copy(str2.begin(), str2.end(), wardenCheck.IdStr.begin());
143
144 CheckIdPool[WARDEN_CHECK_LUA_TYPE].push_back(id);
145 break;
146 }
147 default:
148 {
149 if (checkType == PAGE_CHECK_A || checkType == PAGE_CHECK_B || checkType == DRIVER_CHECK)
150 wardenCheck.Data.SetHexStr(data.c_str());
151
153 break;
154 }
155 }
156
157 ++count;
158 } while (result->NextRow());
159
160 LOG_INFO("server.loading", ">> Loaded {} warden checks.", count);
161 LOG_INFO("server.loading", " ");
162}
#define LOG_INFO(filterType__,...)
Definition: Log.h:164
#define LOG_ERROR(filterType__,...)
Definition: Log.h:156
#define LOG_WARN(filterType__,...)
Definition: Log.h:160
std::uint8_t uint8
Definition: Define.h:109
std::uint32_t uint32
Definition: Define.h:107
#define ASSERT
Definition: Errors.h:68
@ CONFIG_WARDEN_CLIENT_FAIL_ACTION
Definition: IWorld.h:379
@ CONFIG_WARDEN_ENABLED
Definition: IWorld.h:153
constexpr uint8 WARDEN_MAX_LUA_CHECK_LENGTH
Definition: WardenCheckMgr.h:56
@ WARDEN_ACTION_BAN
Definition: WardenCheckMgr.h:29
@ WARDEN_CHECK_MEM_TYPE
Definition: WardenCheckMgr.h:36
@ WARDEN_CHECK_LUA_TYPE
Definition: WardenCheckMgr.h:37
@ WARDEN_CHECK_OTHER_TYPE
Definition: WardenCheckMgr.h:38
constexpr uint8 MAX_WARDEN_ACTION
Definition: WardenCheckMgr.h:32
@ PROC_CHECK
Definition: Warden.h:56
@ DRIVER_CHECK
Definition: Warden.h:54
@ PAGE_CHECK_A
Definition: Warden.h:50
@ PAGE_CHECK_B
Definition: Warden.h:51
@ LUA_EVAL_CHECK
Definition: Warden.h:53
@ MPQ_CHECK
Definition: Warden.h:52
@ MEM_CHECK
Definition: Warden.h:49
@ MODULE_CHECK
Definition: Warden.h:57
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:28
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
#define sWorld
Definition: World.h:444
std::string StringFormat(FormatString< Args... > fmt, Args &&... args)
Default AC string format function.
Definition: StringFormat.h:34
bool SetHexStr(char const *str)
Definition: BigNumber.cpp:65
Class used to access individual fields of database query result.
Definition: Field.h:99
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:113
Definition: WardenCheckMgr.h:44
Definition: WardenCheckMgr.h:59
BigNumber Result
Definition: WardenCheckMgr.h:60
std::vector< uint16 > CheckIdPool[MAX_WARDEN_CHECK_TYPES]
Definition: WardenCheckMgr.h:79

References ASSERT, CheckIdPool, CheckResultStore, CheckStore, CONFIG_WARDEN_CLIENT_FAIL_ACTION, CONFIG_WARDEN_ENABLED, DRIVER_CHECK, Field::Get(), LOG_ERROR, LOG_INFO, LOG_WARN, LUA_EVAL_CHECK, MAX_WARDEN_ACTION, MEM_CHECK, MODULE_CHECK, MPQ_CHECK, PAGE_CHECK_A, PAGE_CHECK_B, PROC_CHECK, WardenCheckResult::Result, BigNumber::SetHexStr(), Acore::StringFormat(), sWorld, WARDEN_ACTION_BAN, WARDEN_CHECK_LUA_TYPE, WARDEN_CHECK_MEM_TYPE, WARDEN_CHECK_OTHER_TYPE, WARDEN_MAX_LUA_CHECK_LENGTH, and WorldDatabase.

◆ LoadWardenOverrides()

void WardenCheckMgr::LoadWardenOverrides ( )
165{
166 // Check if Warden is enabled by config before loading anything
167 if (!sWorld->getBoolConfig(CONFIG_WARDEN_ENABLED))
168 {
169 LOG_INFO("server.loading", ">> Warden disabled, loading check overrides skipped.");
170 LOG_INFO("server.loading", " ");
171 return;
172 }
173
174 // 0 1
175 QueryResult result = CharacterDatabase.Query("SELECT wardenId, action FROM warden_action");
176
177 if (!result)
178 {
179 LOG_WARN("server.loading", ">> Loaded 0 Warden action overrides. DB table `warden_action` is empty!");
180 LOG_INFO("server.loading", " ");
181 return;
182 }
183
184 uint32 count = 0;
185
186 do
187 {
188 Field* fields = result->Fetch();
189
190 uint16 checkId = fields[0].Get<uint16>();
191 uint8 action = fields[1].Get<uint8>();
192
193 // Check if action value is in range (0-2, see WardenActions enum)
194 if (action > WARDEN_ACTION_BAN)
195 LOG_ERROR("warden", "Warden check override action out of range (ID: {}, action: {})", checkId, action);
196 // Check if check actually exists before accessing the CheckStore vector
197 else if (checkId > CheckStore.size())
198 LOG_ERROR("warden", "Warden check action override for non-existing check (ID: {}, action: {}), skipped", checkId, action);
199 else
200 {
201 CheckStore.at(checkId).Action = WardenActions(action);
202 ++count;
203 }
204 } while (result->NextRow());
205
206 LOG_INFO("server.loading", ">> Loaded {} warden action overrides.", count);
207 LOG_INFO("server.loading", " ");
208}
WardenActions
Definition: WardenCheckMgr.h:26
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21

References CharacterDatabase, CheckStore, CONFIG_WARDEN_ENABLED, Field::Get(), LOG_ERROR, LOG_INFO, LOG_WARN, sWorld, and WARDEN_ACTION_BAN.

Member Data Documentation

◆ CheckIdPool

std::vector<uint16> WardenCheckMgr::CheckIdPool[MAX_WARDEN_CHECK_TYPES]

Referenced by LoadWardenChecks().

◆ CheckResultStore

std::map<uint32, WardenCheckResult> WardenCheckMgr::CheckResultStore
private

◆ CheckStore

std::vector<WardenCheck> WardenCheckMgr::CheckStore
private