Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
WardenCheckMgr.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of Project SkyFire https://www.projectskyfire.org.
3
* See LICENSE.md file for Copyright information
4
*/
5
6
#include "
Common.h
"
7
#include "
Database/DatabaseEnv.h
"
8
#include "
Log.h
"
9
#include "
Util.h
"
10
#include "
Warden.h
"
11
#include "
WardenCheckMgr.h
"
12
#include "
WorldPacket.h
"
13
#include "
WorldSession.h
"
14
#include <mutex>
15
16
WardenCheckMgr::WardenCheckMgr
() { }
17
18
WardenCheckMgr::~WardenCheckMgr
()
19
{
20
for
(
uint16
i = 0; i <
CheckStore
.size(); ++i)
21
delete
CheckStore
[i];
22
23
for
(CheckResultContainer::iterator itr =
CheckResultStore
.begin(); itr !=
CheckResultStore
.end(); ++itr)
24
delete
itr->second;
25
}
26
27
void
WardenCheckMgr::LoadWardenChecks
()
28
{
29
// Check if Warden is enabled by config before loading anything
30
if
(!
sWorld
->GetBoolConfig(
WorldBoolConfigs::CONFIG_WARDEN_ENABLED
))
31
{
32
SF_LOG_INFO
(
"warden"
,
">> Warden disabled, loading checks skipped."
);
33
return
;
34
}
35
36
QueryResult
result =
WorldDatabase
.Query(
"SELECT MAX(id) FROM warden_checks"
);
37
38
if
(!result)
39
{
40
SF_LOG_INFO
(
"server.loading"
,
">> Loaded 0 Warden checks. DB table `warden_checks` is empty!"
);
41
return
;
42
}
43
44
Field
* fields = result->Fetch();
45
46
uint16
maxCheckId = fields[0].
GetUInt16
();
47
48
CheckStore
.resize(maxCheckId + 1);
49
50
// 0 1 2 3 4 5 6 7
51
result =
WorldDatabase
.Query(
"SELECT id, type, data, result, address, length, str, comment FROM warden_checks ORDER BY id ASC"
);
52
53
uint32
count = 0;
54
do
55
{
56
fields = result->Fetch();
57
58
uint16
id
= fields[0].
GetUInt16
();
59
uint8
checkType = fields[1].
GetUInt8
();
60
std::string data = fields[2].
GetString
();
61
std::string checkResult = fields[3].
GetString
();
62
uint32
address = fields[4].
GetUInt32
();
63
uint8
length = fields[5].
GetUInt8
();
64
std::string str = fields[6].
GetString
();
65
std::string comment = fields[7].
GetString
();
66
67
WardenCheck
* wardenCheck =
new
WardenCheck
();
68
wardenCheck->
Type
= checkType;
69
wardenCheck->
CheckId
= id;
70
71
// Initialize action with default action from config
72
wardenCheck->
Action
=
WardenActions
(
sWorld
->getIntConfig(
WorldIntConfigs::CONFIG_WARDEN_CLIENT_FAIL_ACTION
));
73
74
if
(checkType ==
PAGE_CHECK_A
|| checkType ==
PAGE_CHECK_B
|| checkType ==
DRIVER_CHECK
)
75
wardenCheck->
Data
.
SetHexStr
(data.c_str());
76
77
if
(checkType ==
MEM_CHECK
|| checkType ==
MODULE_CHECK
)
78
MemChecksIdPool
.push_back(
id
);
79
else
80
OtherChecksIdPool
.push_back(
id
);
81
82
if
(checkType ==
MEM_CHECK
|| checkType ==
PAGE_CHECK_A
|| checkType ==
PAGE_CHECK_B
|| checkType ==
PROC_CHECK
)
83
{
84
wardenCheck->
Address
= address;
85
wardenCheck->
Length
= length;
86
}
87
88
// PROC_CHECK support missing
89
if
(checkType ==
MEM_CHECK
|| checkType ==
MPQ_CHECK
|| checkType ==
LUA_STR_CHECK
|| checkType ==
DRIVER_CHECK
|| checkType ==
MODULE_CHECK
)
90
wardenCheck->
Str
= str;
91
92
CheckStore
[id] = wardenCheck;
93
94
if
(checkType ==
MPQ_CHECK
|| checkType ==
MEM_CHECK
)
95
{
96
WardenCheckResult
* wr =
new
WardenCheckResult
();
97
wr->
Result
.
SetHexStr
(checkResult.c_str());
98
CheckResultStore
[id] = wr;
99
}
100
101
if
(comment.empty())
102
wardenCheck->
Comment
=
"Undocumented Check"
;
103
else
104
wardenCheck->
Comment
= comment;
105
106
++count;
107
}
while
(result->NextRow());
108
109
SF_LOG_INFO
(
"server.loading"
,
">> Loaded %u warden checks."
, count);
110
}
111
112
void
WardenCheckMgr::LoadWardenOverrides
()
113
{
114
// Check if Warden is enabled by config before loading anything
115
if
(!
sWorld
->GetBoolConfig(
WorldBoolConfigs::CONFIG_WARDEN_ENABLED
))
116
{
117
SF_LOG_INFO
(
"warden"
,
">> Warden disabled, loading check overrides skipped."
);
118
return
;
119
}
120
121
// 0 1
122
QueryResult
result =
CharacterDatabase
.Query(
"SELECT wardenId, action FROM warden_action"
);
123
124
if
(!result)
125
{
126
SF_LOG_INFO
(
"server.loading"
,
">> Loaded 0 Warden action overrides. DB table `warden_action` is empty!"
);
127
return
;
128
}
129
130
uint32
count = 0;
131
132
std::unique_lock<Skyfire::SharedMutex> guard(
_checkStoreLock
);
133
134
do
135
{
136
Field
* fields = result->Fetch();
137
138
uint16
checkId = fields[0].
GetUInt16
();
139
uint8
action = fields[1].
GetUInt8
();
140
141
// Check if action value is in range (0-2, see WardenActions enum)
142
if
(action >
WARDEN_ACTION_BAN
)
143
SF_LOG_ERROR
(
"warden"
,
"Warden check override action out of range (ID: %u, action: %u)"
, checkId, action);
144
// Check if check actually exists before accessing the CheckStore vector
145
else
if
(checkId >
CheckStore
.size())
146
SF_LOG_ERROR
(
"warden"
,
"Warden check action override for non-existing check (ID: %u, action: %u), skipped"
, checkId, action);
147
else
148
{
149
CheckStore
[checkId]->Action =
WardenActions
(action);
150
++count;
151
}
152
}
while
(result->NextRow());
153
154
SF_LOG_INFO
(
"server.loading"
,
">> Loaded %u warden action overrides."
, count);
155
}
156
157
WardenCheck
*
WardenCheckMgr::GetWardenDataById
(
uint16
Id)
158
{
159
if
(Id <
CheckStore
.size())
160
return
CheckStore
[Id];
161
162
return
NULL;
163
}
164
165
WardenCheckResult
*
WardenCheckMgr::GetWardenResultById
(
uint16
Id)
166
{
167
CheckResultContainer::const_iterator itr =
CheckResultStore
.find(Id);
168
if
(itr !=
CheckResultStore
.end())
169
return
itr->second;
170
return
NULL;
171
}
Common.h
DatabaseEnv.h
uint8
std::uint8_t uint8
Definition
Define.h:79
uint32
std::uint32_t uint32
Definition
Define.h:77
uint16
std::uint16_t uint16
Definition
Define.h:78
Log.h
SF_LOG_ERROR
#define SF_LOG_ERROR(filterType__,...)
Definition
Log.h:143
SF_LOG_INFO
#define SF_LOG_INFO(filterType__,...)
Definition
Log.h:137
QueryResult
Skyfire::AutoPtr< ResultSet, Skyfire::Mutex > QueryResult
Definition
QueryResult.h:48
Util.h
Warden.h
PROC_CHECK
@ PROC_CHECK
Definition
Warden.h:43
DRIVER_CHECK
@ DRIVER_CHECK
Definition
Warden.h:41
PAGE_CHECK_A
@ PAGE_CHECK_A
Definition
Warden.h:37
PAGE_CHECK_B
@ PAGE_CHECK_B
Definition
Warden.h:38
MPQ_CHECK
@ MPQ_CHECK
Definition
Warden.h:39
MEM_CHECK
@ MEM_CHECK
Definition
Warden.h:36
MODULE_CHECK
@ MODULE_CHECK
Definition
Warden.h:44
LUA_STR_CHECK
@ LUA_STR_CHECK
Definition
Warden.h:40
WardenCheckMgr.h
WardenActions
WardenActions
Definition
WardenCheckMgr.h:14
WARDEN_ACTION_BAN
@ WARDEN_ACTION_BAN
Definition
WardenCheckMgr.h:17
WorldPacket.h
WorldSession.h
BigNumber::SetHexStr
void SetHexStr(char const *str)
Definition
BigNumber.cpp:65
Field
Definition
Field.h:16
Field::GetUInt8
uint8 GetUInt8() const
Definition
Field.h:26
Field::GetString
std::string GetString() const
Definition
Field.h:228
Field::GetUInt16
uint16 GetUInt16() const
Definition
Field.h:69
Field::GetUInt32
uint32 GetUInt32() const
Definition
Field.h:105
WardenCheckMgr::LoadWardenOverrides
void LoadWardenOverrides()
Definition
WardenCheckMgr.cpp:112
WardenCheckMgr::~WardenCheckMgr
~WardenCheckMgr()
Definition
WardenCheckMgr.cpp:18
WardenCheckMgr::CheckStore
CheckContainer CheckStore
Definition
WardenCheckMgr.h:60
WardenCheckMgr::_checkStoreLock
Skyfire::SharedMutex _checkStoreLock
Definition
WardenCheckMgr.h:57
WardenCheckMgr::OtherChecksIdPool
std::vector< uint16 > OtherChecksIdPool
Definition
WardenCheckMgr.h:52
WardenCheckMgr::WardenCheckMgr
WardenCheckMgr()
Definition
WardenCheckMgr.cpp:16
WardenCheckMgr::GetWardenResultById
WardenCheckResult * GetWardenResultById(uint16 Id)
Definition
WardenCheckMgr.cpp:165
WardenCheckMgr::MemChecksIdPool
std::vector< uint16 > MemChecksIdPool
Definition
WardenCheckMgr.h:51
WardenCheckMgr::GetWardenDataById
WardenCheck * GetWardenDataById(uint16 Id)
Definition
WardenCheckMgr.cpp:157
WardenCheckMgr::CheckResultStore
CheckResultContainer CheckResultStore
Definition
WardenCheckMgr.h:61
WardenCheckMgr::LoadWardenChecks
void LoadWardenChecks()
Definition
WardenCheckMgr.cpp:27
CharacterDatabase
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition
Main.cpp:41
WorldDatabase
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition
Main.cpp:40
sWorld
#define sWorld
Definition
World.h:910
WorldIntConfigs::CONFIG_WARDEN_CLIENT_FAIL_ACTION
@ CONFIG_WARDEN_CLIENT_FAIL_ACTION
Definition
World.h:335
WorldBoolConfigs::CONFIG_WARDEN_ENABLED
@ CONFIG_WARDEN_ENABLED
Definition
World.h:158
WardenCheck
Definition
WardenCheckMgr.h:21
WardenCheck::Str
std::string Str
Definition
WardenCheckMgr.h:26
WardenCheck::CheckId
uint16 CheckId
Definition
WardenCheckMgr.h:28
WardenCheck::Comment
std::string Comment
Definition
WardenCheckMgr.h:27
WardenCheck::Action
enum WardenActions Action
Definition
WardenCheckMgr.h:29
WardenCheck::Data
BigNumber Data
Definition
WardenCheckMgr.h:23
WardenCheck::Address
uint32 Address
Definition
WardenCheckMgr.h:24
WardenCheck::Length
uint8 Length
Definition
WardenCheckMgr.h:25
WardenCheck::Type
uint8 Type
Definition
WardenCheckMgr.h:22
WardenCheckResult
Definition
WardenCheckMgr.h:33
WardenCheckResult::Result
BigNumber Result
Definition
WardenCheckMgr.h:34
src
server
game
Warden
WardenCheckMgr.cpp
Generated on
for Project SkyFire Core by
1.17.0