Project SkyFire Core
SkyFire 5.4.8 server core API documentation
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"
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
17
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
28{
29 // Check if Warden is enabled by config before loading anything
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
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 {
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
113{
114 // Check if Warden is enabled by config before loading anything
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
158{
159 if (Id < CheckStore.size())
160 return CheckStore[Id];
161
162 return NULL;
163}
164
166{
167 CheckResultContainer::const_iterator itr = CheckResultStore.find(Id);
168 if (itr != CheckResultStore.end())
169 return itr->second;
170 return NULL;
171}
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
std::uint16_t uint16
Definition Define.h:78
#define SF_LOG_ERROR(filterType__,...)
Definition Log.h:143
#define SF_LOG_INFO(filterType__,...)
Definition Log.h:137
Skyfire::AutoPtr< ResultSet, Skyfire::Mutex > QueryResult
Definition QueryResult.h:48
@ PROC_CHECK
Definition Warden.h:43
@ DRIVER_CHECK
Definition Warden.h:41
@ PAGE_CHECK_A
Definition Warden.h:37
@ PAGE_CHECK_B
Definition Warden.h:38
@ MPQ_CHECK
Definition Warden.h:39
@ MEM_CHECK
Definition Warden.h:36
@ MODULE_CHECK
Definition Warden.h:44
@ LUA_STR_CHECK
Definition Warden.h:40
WardenActions
@ WARDEN_ACTION_BAN
void SetHexStr(char const *str)
Definition BigNumber.cpp:65
Definition Field.h:16
uint8 GetUInt8() const
Definition Field.h:26
std::string GetString() const
Definition Field.h:228
uint16 GetUInt16() const
Definition Field.h:69
uint32 GetUInt32() const
Definition Field.h:105
CheckContainer CheckStore
Skyfire::SharedMutex _checkStoreLock
std::vector< uint16 > OtherChecksIdPool
WardenCheckResult * GetWardenResultById(uint16 Id)
std::vector< uint16 > MemChecksIdPool
WardenCheck * GetWardenDataById(uint16 Id)
CheckResultContainer CheckResultStore
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition Main.cpp:41
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition Main.cpp:40
#define sWorld
Definition World.h:910
@ CONFIG_WARDEN_CLIENT_FAIL_ACTION
Definition World.h:335
@ CONFIG_WARDEN_ENABLED
Definition World.h:158
std::string Str
std::string Comment
enum WardenActions Action
BigNumber Data