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
27{
28}

◆ ~WardenCheckMgr()

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

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)
212{
213 if (Id < CheckStore.size())
214 return &CheckStore.at(Id);
215
216 return nullptr;
217}

References CheckStore.

◆ GetWardenResultById()

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

References CheckResultStore.

◆ instance()

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

References instance().

Referenced by instance().

◆ LoadWardenChecks()

void WardenCheckMgr::LoadWardenChecks ( )
41{
42 // Check if Warden is enabled by config before loading anything
43 if (!sWorld->getBoolConfig(CONFIG_WARDEN_ENABLED))
44 {
45 LOG_INFO("server.loading", ">> Warden disabled, loading checks skipped.");
46 LOG_INFO("server.loading", " ");
47 return;
48 }
49
50 QueryResult result = WorldDatabase.Query("SELECT MAX(id) FROM warden_checks");
51
52 if (!result)
53 {
54 LOG_WARN("server.loading", ">> Loaded 0 Warden checks. DB table `warden_checks` is empty!");
55 LOG_INFO("server.loading", " ");
56 return;
57 }
58
59 Field* fields = result->Fetch();
60
61 uint16 maxCheckId = fields[0].Get<uint16>();
62
63 CheckStore.resize(maxCheckId + 1);
64
65 // 0 1 2 3 4 5 6 7
66 result = WorldDatabase.Query("SELECT id, type, data, result, address, length, str, comment FROM warden_checks ORDER BY id ASC");
67
68 uint32 count = 0;
69 do
70 {
71 fields = result->Fetch();
72
73 uint16 id = fields[0].Get<uint16>();
74 uint8 checkType = fields[1].Get<uint8>();
75
76 if (checkType == LUA_EVAL_CHECK && id > 9999)
77 {
78 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);
79 continue;
80 }
81
82 std::string data = fields[2].Get<std::string>();
83 std::string checkResult = fields[3].Get<std::string>();
84 uint32 address = fields[4].Get<uint32>();
85 uint8 length = fields[5].Get<uint8>();
86 std::string str = fields[6].Get<std::string>();
87 std::string comment = fields[7].Get<std::string>();
88
89 WardenCheck &wardenCheck = CheckStore.at(id);
90 wardenCheck.Type = checkType;
91 wardenCheck.CheckId = id;
92
93 // Initialize action with default action from config
94 wardenCheck.Action = sWorld->getIntConfig(CONFIG_WARDEN_CLIENT_FAIL_ACTION);
95 if (wardenCheck.Action > MAX_WARDEN_ACTION)
96 {
97 wardenCheck.Action = WARDEN_ACTION_BAN;
98 }
99
100 if (checkType == MEM_CHECK || checkType == PAGE_CHECK_A || checkType == PAGE_CHECK_B || checkType == PROC_CHECK)
101 {
102 wardenCheck.Address = address;
103 wardenCheck.Length = length;
104 }
105
106 // PROC_CHECK support missing
107 if (checkType == MEM_CHECK || checkType == MPQ_CHECK || checkType == LUA_EVAL_CHECK || checkType == DRIVER_CHECK || checkType == MODULE_CHECK)
108 {
109 wardenCheck.Str = str;
110 }
111
112 if (checkType == MPQ_CHECK || checkType == MEM_CHECK)
113 {
115 wr.Result.SetHexStr(checkResult.c_str());
116 CheckResultStore[id] = wr;
117 }
118
119 if (comment.empty())
120 wardenCheck.Comment = "Undocumented Check";
121 else
122 wardenCheck.Comment = comment;
123
124 // Prepare check pools
125 switch (checkType)
126 {
127 case MEM_CHECK:
128 case MODULE_CHECK:
129 {
130 CheckIdPool[WARDEN_CHECK_MEM_TYPE].push_back(id);
131 break;
132 }
133 case LUA_EVAL_CHECK:
134 {
135 if (wardenCheck.Length > WARDEN_MAX_LUA_CHECK_LENGTH)
136 {
137 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);
138 continue;
139 }
140
141 std::string str2 = Acore::StringFormat("{:04}", id);
142 ASSERT(str2.size() == 4);
143 std::copy(str2.begin(), str2.end(), wardenCheck.IdStr.begin());
144
145 CheckIdPool[WARDEN_CHECK_LUA_TYPE].push_back(id);
146 break;
147 }
148 default:
149 {
150 if (checkType == PAGE_CHECK_A || checkType == PAGE_CHECK_B || checkType == DRIVER_CHECK)
151 wardenCheck.Data.SetHexStr(data.c_str());
152
154 break;
155 }
156 }
157
158 ++count;
159 } while (result->NextRow());
160
161 LOG_INFO("server.loading", ">> Loaded {} warden checks.", count);
162 LOG_INFO("server.loading", " ");
163}
#define ASSERT
Definition: Errors.h:68
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
#define LOG_WARN(filterType__,...)
Definition: Log.h:161
std::uint8_t uint8
Definition: Define.h:109
std::uint32_t uint32
Definition: Define.h:107
@ CONFIG_WARDEN_CLIENT_FAIL_ACTION
Definition: IWorld.h:376
@ CONFIG_WARDEN_ENABLED
Definition: IWorld.h:148
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:55
@ DRIVER_CHECK
Definition: Warden.h:53
@ PAGE_CHECK_A
Definition: Warden.h:49
@ PAGE_CHECK_B
Definition: Warden.h:50
@ LUA_EVAL_CHECK
Definition: Warden.h:52
@ MPQ_CHECK
Definition: Warden.h:51
@ MEM_CHECK
Definition: Warden.h:48
@ MODULE_CHECK
Definition: Warden.h:56
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:27
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
#define sWorld
Definition: World.h:443
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:98
std::enable_if_t< std::is_arithmetic_v< T >, T > Get() const
Definition: Field.h:112
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 ( )
166{
167 // Check if Warden is enabled by config before loading anything
168 if (!sWorld->getBoolConfig(CONFIG_WARDEN_ENABLED))
169 {
170 LOG_INFO("server.loading", ">> Warden disabled, loading check overrides skipped.");
171 LOG_INFO("server.loading", " ");
172 return;
173 }
174
175 // 0 1
176 QueryResult result = CharacterDatabase.Query("SELECT wardenId, action FROM warden_action");
177
178 if (!result)
179 {
180 LOG_WARN("server.loading", ">> Loaded 0 Warden action overrides. DB table `warden_action` is empty!");
181 LOG_INFO("server.loading", " ");
182 return;
183 }
184
185 uint32 count = 0;
186
187 do
188 {
189 Field* fields = result->Fetch();
190
191 uint16 checkId = fields[0].Get<uint16>();
192 uint8 action = fields[1].Get<uint8>();
193
194 // Check if action value is in range (0-2, see WardenActions enum)
195 if (action > WARDEN_ACTION_BAN)
196 LOG_ERROR("warden", "Warden check override action out of range (ID: {}, action: {})", checkId, action);
197 // Check if check actually exists before accessing the CheckStore vector
198 else if (checkId > CheckStore.size())
199 LOG_ERROR("warden", "Warden check action override for non-existing check (ID: {}, action: {}), skipped", checkId, action);
200 else
201 {
202 CheckStore.at(checkId).Action = WardenActions(action);
203 ++count;
204 }
205 } while (result->NextRow());
206
207 LOG_INFO("server.loading", ">> Loaded {} warden action overrides.", count);
208 LOG_INFO("server.loading", " ");
209}
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