TrinityCore
action_ip_logger.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "ScriptMgr.h"
19#include "DatabaseEnv.h"
20#include "Player.h"
21#include "Realm.h"
22#include "World.h"
23#include "WorldSession.h"
24
26{
27 // AccountActionIpLogger();
31 ACCOUNT_CHANGE_PW_FAIL = 3, // Only two types of account changes exist...
33 ACCOUNT_CHANGE_EMAIL_FAIL = 5, // ...so we log them individually
34 // OBSOLETE - ACCOUNT_LOGOUT = 6, /* Can not be logged. We still keep the type however */
35 // CharacterActionIpLogger();
39 // CharacterDeleteActionIpLogger();
42 // AccountActionIpLogger(), CharacterActionIpLogger(), CharacterActionIpLogger();
44};
45
47{
48 public:
49 AccountActionIpLogger() : AccountScript("AccountActionIpLogger") { }
50
51 // We log last_ip instead of last_attempt_ip, as login was successful
52 // ACCOUNT_LOGIN = 0
53 void OnAccountLogin(uint32 accountId) override
54 {
56 }
57
58 // We log last_attempt_ip instead of last_ip, as failed login doesn't necessarily mean approperiate user
59 // ACCOUNT_FAIL_LOGIN = 1
60 void OnFailedAccountLogin(uint32 accountId) override
61 {
63 }
64
65 // ACCOUNT_CHANGE_PW = 2
66 void OnPasswordChange(uint32 accountId) override
67 {
69 }
70
71 // ACCOUNT_CHANGE_PW_FAIL = 3
72 void OnFailedPasswordChange(uint32 accountId) override
73 {
75 }
76
77 // Registration Email can NOT be changed apart from GM level users. Thus, we do not require to log them...
78 // ACCOUNT_CHANGE_EMAIL = 4
79 void OnEmailChange(uint32 accountId) override
80 {
81 AccountIPLogAction(accountId, ACCOUNT_CHANGE_EMAIL); // ... they get logged by gm command logger anyway
82 }
83
84 // ACCOUNT_CHANGE_EMAIL_FAIL = 5
85 void OnFailedEmailChange(uint32 accountId) override
86 {
88 }
89
90 /* It's impossible to log the account logout process out of character selection - shouldn't matter anyway,
91 * as ip doesn't change through playing (obviously).*/
92 // ACCOUNT_LOGOUT = 6
94 {
95 // Action IP Logger is only intialized if config is set up
96 // Else, this script isn't loaded in the first place: We require no config check.
97
98 // We declare all the required variables
99 uint32 playerGuid = accountId;
100 uint32 realmId = realm.Id.Realm;
101 std::string systemNote = "ERROR"; // "ERROR" is a placeholder here. We change it later.
102
103 // With this switch, we change systemNote so that we have a more accurate phrasing of what type it is.
104 // Avoids Magicnumbers in SQL table
105 switch (aType)
106 {
107 case ACCOUNT_LOGIN:
108 systemNote = "Logged into WoW";
109 break;
111 systemNote = "Login to WoW Failed";
112 break;
114 systemNote = "Password Reset Completed";
115 break;
117 systemNote = "Password Reset Failed";
118 break;
120 systemNote = "Email Change Completed";
121 break;
123 systemNote = "Email Change Failed";
124 break;
125 /*case ACCOUNT_LOGOUT:
126 systemNote = "Logged on AccountLogout"; //Can not be logged
127 break;*/
128 // Neither should happen. Ever. Period. If it does, call Ghostbusters and all your local software defences to investigate.
129 case UNKNOWN_ACTION:
130 default:
131 systemNote = "ERROR! Unknown action!";
132 break;
133 }
134
135 // Once we have done everything, we can insert the new log.
136 // Seeing as the time differences should be minimal, we do not get unixtime and the timestamp right now;
137 // Rather, we let it be added with the SQL query.
138 if (aType != ACCOUNT_FAIL_LOGIN)
139 {
140 // As we can assume most account actions are NOT failed login, so this is the more accurate check.
141 // For those, we need last_ip...
143
144 stmt->setUInt32(0, playerGuid);
145 stmt->setUInt64(1, 0);
146 stmt->setUInt32(2, realmId);
147 stmt->setUInt8(3, aType);
148 stmt->setUInt32(4, playerGuid);
149 stmt->setString(5, systemNote);
150 LoginDatabase.Execute(stmt);
151 }
152 else // ... but for failed login, we query last_attempt_ip from account table. Which we do with an unique query
153 {
155
156 stmt->setUInt32(0, playerGuid);
157 stmt->setUInt64(1, 0);
158 stmt->setUInt32(2, realmId);
159 stmt->setUInt8(3, aType);
160 stmt->setUInt32(4, playerGuid);
161 stmt->setString(5, systemNote);
162 LoginDatabase.Execute(stmt);
163 }
164 return;
165 }
166};
167
169{
170 public:
171 CharacterActionIpLogger() : PlayerScript("CharacterActionIpLogger") { }
172
173 // CHARACTER_CREATE = 7
174 void OnCreate(Player* player) override
175 {
177 }
178
179 // CHARACTER_LOGIN = 8
180 void OnLogin(Player* player, bool /*firstLogin*/) override
181 {
183 }
184
185 // CHARACTER_LOGOUT = 9
186 void OnLogout(Player* player) override
187 {
189 }
190
191 // CHARACTER_DELETE = 10
192 // CHARACTER_FAILED_DELETE = 11
193 // We don't log either here - they require a guid
194
195 // UNKNOWN_ACTION = 12
196 // There is no real hook we could use for that.
197 // Shouldn't happen anyway, should it ? Nothing to see here.
198
201 {
202 // Action IP Logger is only intialized if config is set up
203 // Else, this script isn't loaded in the first place: We require no config check.
204
205 // We declare all the required variables
206 uint32 playerGuid = player->GetSession()->GetAccountId();
207 uint32 realmId = realm.Id.Realm;
208 const std::string currentIp = player->GetSession()->GetRemoteAddress();
209 std::string systemNote = "ERROR"; // "ERROR" is a placeholder here. We change it...
210
211 // ... with this switch, so that we have a more accurate phrasing of what type it is
212 switch (aType)
213 {
214 case CHARACTER_CREATE:
215 systemNote = "Character Created";
216 break;
217 case CHARACTER_LOGIN:
218 systemNote = "Logged onto Character";
219 break;
220 case CHARACTER_LOGOUT:
221 systemNote = "Logged out of Character";
222 break;
223 case CHARACTER_DELETE:
224 systemNote = "Character Deleted";
225 break;
227 systemNote = "Character Deletion Failed";
228 break;
229 // Neither should happen. Ever. Period. If it does, call Mythbusters.
230 case UNKNOWN_ACTION:
231 default:
232 systemNote = "ERROR! Unknown action!";
233 break;
234 }
235
236 // Once we have done everything, we can insert the new log.
238
239 stmt->setUInt32(0, playerGuid);
240 stmt->setUInt64(1, player->GetGUID().GetCounter());
241 stmt->setUInt32(2, realmId);
242 stmt->setUInt8(3, aType);
243 stmt->setString(4, currentIp); // We query the ip here.
244 stmt->setString(5, systemNote);
245 // Seeing as the time differences should be minimal, we do not get unixtime and the timestamp right now;
246 // Rather, we let it be added with the SQL query.
247
248 LoginDatabase.Execute(stmt);
249 return;
250 }
251};
252
254{
255public:
256 CharacterDeleteActionIpLogger() : PlayerScript("CharacterDeleteActionIpLogger") { }
257
258 // CHARACTER_DELETE = 10
259 void OnDelete(ObjectGuid guid, uint32 accountId) override
260 {
261 DeleteIPLogAction(guid, accountId, CHARACTER_DELETE);
262 }
263
264 // CHARACTER_FAILED_DELETE = 11
265 void OnFailedDelete(ObjectGuid guid, uint32 accountId) override
266 {
268 }
269
270 void DeleteIPLogAction(ObjectGuid guid, uint32 playerGuid, IPLoggingTypes aType)
271 {
272 // Action IP Logger is only intialized if config is set up
273 // Else, this script isn't loaded in the first place: We require no config check.
274
275 uint32 realmId = realm.Id.Realm;
276 // Query playerGuid/accountId, as we only have characterGuid
277 std::string systemNote = "ERROR"; // "ERROR" is a placeholder here. We change it later.
278
279 // With this switch, we change systemNote so that we have a more accurate phrasing of what type it is.
280 // Avoids Magicnumbers in SQL table
281 switch (aType)
282 {
283 case CHARACTER_DELETE:
284 systemNote = "Character Deleted";
285 break;
287 systemNote = "Character Deletion Failed";
288 break;
289 // Neither should happen. Ever. Period. If it does, call to whatever god you have for mercy and guidance.
290 case UNKNOWN_ACTION:
291 default:
292 systemNote = "ERROR! Unknown action!";
293 break;
294 }
295
296 // Once we have done everything, we can insert the new log.
298
299 stmt->setUInt32(0, playerGuid);
300 stmt->setUInt64(1, guid.GetCounter());
301 stmt->setUInt32(2, realmId);
302 stmt->setUInt8(3, aType);
303 stmt->setUInt32(4, playerGuid);
304 stmt->setString(5, systemNote);
305
306 // Seeing as the time differences should be minimal, we do not get unixtime and the timestamp right now;
307 // Rather, we let it be added with the SQL query.
308
309 LoginDatabase.Execute(stmt);
310 return;
311 }
312};
313
315{
319}
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
uint32_t uint32
Definition: Define.h:142
@ LOGIN_INS_ALDL_IP_LOGGING
Definition: LoginDatabase.h:95
@ LOGIN_INS_FACL_IP_LOGGING
Definition: LoginDatabase.h:96
@ LOGIN_INS_CHAR_IP_LOGGING
Definition: LoginDatabase.h:97
IPLoggingTypes
@ CHARACTER_DELETE
@ ACCOUNT_CHANGE_PW
@ ACCOUNT_CHANGE_EMAIL_FAIL
@ CHARACTER_CREATE
@ CHARACTER_LOGIN
@ CHARACTER_LOGOUT
@ ACCOUNT_LOGIN
@ ACCOUNT_CHANGE_PW_FAIL
@ UNKNOWN_ACTION
@ ACCOUNT_CHANGE_EMAIL
@ ACCOUNT_FAIL_LOGIN
@ CHARACTER_FAILED_DELETE
void AddSC_action_ip_logger()
void OnFailedPasswordChange(uint32 accountId) override
void OnAccountLogin(uint32 accountId) override
void OnPasswordChange(uint32 accountId) override
void OnFailedAccountLogin(uint32 accountId) override
void AccountIPLogAction(uint32 accountId, IPLoggingTypes aType)
void OnFailedEmailChange(uint32 accountId) override
void OnEmailChange(uint32 accountId) override
void CharacterIPLogAction(Player *player, IPLoggingTypes aType)
Logs a number of actions done by players with an IP.
void OnLogout(Player *player) override
void OnCreate(Player *player) override
void OnLogin(Player *player, bool) override
void OnFailedDelete(ObjectGuid guid, uint32 accountId) override
void OnDelete(ObjectGuid guid, uint32 accountId) override
void DeleteIPLogAction(ObjectGuid guid, uint32 playerGuid, IPLoggingTypes aType)
LowType GetCounter() const
Definition: ObjectGuid.h:293
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:159
WorldSession * GetSession() const
Definition: Player.h:2101
void setUInt8(const uint8 index, const uint8 value)
void setUInt32(const uint8 index, const uint32 value)
void setString(const uint8 index, const std::string &value)
void setUInt64(const uint8 index, const uint64 value)
std::string const & GetRemoteAddress() const
uint32 GetAccountId() const
Realm realm
Definition: World.cpp:3966
Battlenet::RealmHandle Id
Definition: Realm.h:82