TrinityCore
Loading...
Searching...
No Matches
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 "WorldSession.h"
22#include "World.h"
23#include "Realm.h"
24
26{
27
28 // AccountActionIpLogger();
32 ACCOUNT_CHANGE_PW_FAIL = 3, // Only two types of account changes exist...
34 ACCOUNT_CHANGE_EMAIL_FAIL = 5, // ...so we log them individually
35 // OBSOLETE - ACCOUNT_LOGOUT = 6, /* Can not be logged. We still keep the type however */
36 // CharacterActionIpLogger();
40 // CharacterDeleteActionIpLogger();
43 // AccountActionIpLogger(), CharacterActionIpLogger(), CharacterActionIpLogger();
45};
46
48{
49 public:
50 AccountActionIpLogger() : AccountScript("AccountActionIpLogger") { }
51
52 // We log last_ip instead of last_attempt_ip, as login was successful
53 // ACCOUNT_LOGIN = 0
54 void OnAccountLogin(uint32 accountId) override
55 {
57 }
58
59 // We log last_attempt_ip instead of last_ip, as failed login doesn't necessarily mean approperiate user
60 // ACCOUNT_FAIL_LOGIN = 1
61 void OnFailedAccountLogin(uint32 accountId) override
62 {
64 }
65
66 // ACCOUNT_CHANGE_PW = 2
67 void OnPasswordChange(uint32 accountId) override
68 {
70 }
71
72 // ACCOUNT_CHANGE_PW_FAIL = 3
73 void OnFailedPasswordChange(uint32 accountId) override
74 {
76 }
77
78 // Registration Email can NOT be changed apart from GM level users. Thus, we do not require to log them...
79 // ACCOUNT_CHANGE_EMAIL = 4
80 void OnEmailChange(uint32 accountId) override
81 {
82 AccountIPLogAction(accountId, ACCOUNT_CHANGE_EMAIL); // ... they get logged by gm command logger anyway
83 }
84
85 // ACCOUNT_CHANGE_EMAIL_FAIL = 5
86 void OnFailedEmailChange(uint32 accountId) override
87 {
89 }
90
91 /* It's impossible to log the account logout process out of character selection - shouldn't matter anyway,
92 * as ip doesn't change through playing (obviously).*/
93 // ACCOUNT_LOGOUT = 6
95 {
96 // Action IP Logger is only intialized if config is set up
97 // Else, this script isn't loaded in the first place: We require no config check.
98
99 // We declare all the required variables
100 uint32 playerGuid = accountId;
101 uint32 realmId = realm.Id.Realm;
102 std::string systemNote = "ERROR"; // "ERROR" is a placeholder here. We change it later.
103
104 // With this switch, we change systemNote so that we have a more accurate phrasing of what type it is.
105 // Avoids Magicnumbers in SQL table
106 switch (aType)
107 {
108 case ACCOUNT_LOGIN:
109 systemNote = "Logged into WoW";
110 break;
112 systemNote = "Login to WoW Failed";
113 break;
115 systemNote = "Password Reset Completed";
116 break;
118 systemNote = "Password Reset Failed";
119 break;
121 systemNote = "Email Change Completed";
122 break;
124 systemNote = "Email Change Failed";
125 break;
126 /*case ACCOUNT_LOGOUT:
127 systemNote = "Logged on AccountLogout"; //Can not be logged
128 break;*/
129 // Neither should happen. Ever. Period. If it does, call Ghostbusters and all your local software defences to investigate.
130 case UNKNOWN_ACTION:
131 default:
132 systemNote = "ERROR! Unknown action!";
133 break;
134 }
135
136 // Once we have done everything, we can insert the new log.
137 // Seeing as the time differences should be minimal, we do not get unixtime and the timestamp right now;
138 // Rather, we let it be added with the SQL query.
139 if (aType != ACCOUNT_FAIL_LOGIN)
140 {
141 // As we can assume most account actions are NOT failed login, so this is the more accurate check.
142 // For those, we need last_ip...
144
145 stmt->setUInt32(0, playerGuid);
146 stmt->setUInt64(1, 0);
147 stmt->setUInt32(2, realmId);
148 stmt->setUInt8(3, aType);
149 stmt->setUInt32(4, playerGuid);
150 stmt->setString(5, systemNote);
151 LoginDatabase.Execute(stmt);
152 }
153 else // ... but for failed login, we query last_attempt_ip from account table. Which we do with an unique query
154 {
156
157 stmt->setUInt32(0, playerGuid);
158 stmt->setUInt64(1, 0);
159 stmt->setUInt32(2, realmId);
160 stmt->setUInt8(3, aType);
161 stmt->setUInt32(4, playerGuid);
162 stmt->setString(5, systemNote);
163 LoginDatabase.Execute(stmt);
164 }
165 return;
166 }
167};
168
170{
171 public:
172 CharacterActionIpLogger() : PlayerScript("CharacterActionIpLogger") { }
173
174 // CHARACTER_CREATE = 7
175 void OnCreate(Player* player) override
176 {
178 }
179
180 // CHARACTER_LOGIN = 8
181 void OnLogin(Player* player, bool /*firstLogin*/) override
182 {
184 }
185
186 // CHARACTER_LOGOUT = 9
187 void OnLogout(Player* player) override
188 {
190 }
191
192 // CHARACTER_DELETE = 10
193 // CHARACTER_FAILED_DELETE = 11
194 // We don't log either here - they require a guid
195
196 // UNKNOWN_ACTION = 12
197 // There is no real hook we could use for that.
198 // Shouldn't happen anyway, should it ? Nothing to see here.
199
202 {
203 // Action IP Logger is only intialized if config is set up
204 // Else, this script isn't loaded in the first place: We require no config check.
205
206 // We declare all the required variables
207 uint32 playerGuid = player->GetSession()->GetAccountId();
208 uint32 realmId = realm.Id.Realm;
209 const std::string currentIp = player->GetSession()->GetRemoteAddress();
210 std::string systemNote = "ERROR"; // "ERROR" is a placeholder here. We change it...
211
212 // ... with this switch, so that we have a more accurate phrasing of what type it is
213 switch (aType)
214 {
215 case CHARACTER_CREATE:
216 systemNote = "Character Created";
217 break;
218 case CHARACTER_LOGIN:
219 systemNote = "Logged onto Character";
220 break;
221 case CHARACTER_LOGOUT:
222 systemNote = "Logged out of Character";
223 break;
224 case CHARACTER_DELETE:
225 systemNote = "Character Deleted";
226 break;
228 systemNote = "Character Deletion Failed";
229 break;
230 // Neither should happen. Ever. Period. If it does, call Mythbusters.
231 case UNKNOWN_ACTION:
232 default:
233 systemNote = "ERROR! Unknown action!";
234 break;
235 }
236
237 // Once we have done everything, we can insert the new log.
239
240 stmt->setUInt32(0, playerGuid);
241 stmt->setUInt64(1, player->GetGUID().GetCounter());
242 stmt->setUInt32(2, realmId);
243 stmt->setUInt8(3, aType);
244 stmt->setString(4, currentIp); // We query the ip here.
245 stmt->setString(5, systemNote);
246 // Seeing as the time differences should be minimal, we do not get unixtime and the timestamp right now;
247 // Rather, we let it be added with the SQL query.
248
249 LoginDatabase.Execute(stmt);
250 return;
251 }
252};
253
255{
256public:
257 CharacterDeleteActionIpLogger() : PlayerScript("CharacterDeleteActionIpLogger") { }
258
259 // CHARACTER_DELETE = 10
260 void OnDelete(ObjectGuid guid, uint32 accountId) override
261 {
262 DeleteIPLogAction(guid, accountId, CHARACTER_DELETE);
263 }
264
265 // CHARACTER_FAILED_DELETE = 11
266 void OnFailedDelete(ObjectGuid guid, uint32 accountId) override
267 {
269 }
270
271 void DeleteIPLogAction(ObjectGuid guid, uint32 playerGuid, IPLoggingTypes aType)
272 {
273 // Action IP Logger is only intialized if config is set up
274 // Else, this script isn't loaded in the first place: We require no config check.
275
276 uint32 realmId = realm.Id.Realm;
277 // Query playerGuid/accountId, as we only have characterGuid
278 std::string systemNote = "ERROR"; // "ERROR" is a placeholder here. We change it later.
279
280 // With this switch, we change systemNote so that we have a more accurate phrasing of what type it is.
281 // Avoids Magicnumbers in SQL table
282 switch (aType)
283 {
284 case CHARACTER_DELETE:
285 systemNote = "Character Deleted";
286 break;
288 systemNote = "Character Deletion Failed";
289 break;
290 // Neither should happen. Ever. Period. If it does, call to whatever god you have for mercy and guidance.
291 case UNKNOWN_ACTION:
292 default:
293 systemNote = "ERROR! Unknown action!";
294 break;
295 }
296
297 // Once we have done everything, we can insert the new log.
299
300 stmt->setUInt32(0, playerGuid);
301 stmt->setUInt64(1, guid.GetCounter());
302 stmt->setUInt32(2, realmId);
303 stmt->setUInt8(3, aType);
304 stmt->setUInt32(4, playerGuid);
305 stmt->setString(5, systemNote);
306
307 // Seeing as the time differences should be minimal, we do not get unixtime and the timestamp right now;
308 // Rather, we let it be added with the SQL query.
309
310 LoginDatabase.Execute(stmt);
311 return;
312 }
313};
314
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
uint32_t uint32
Definition Define.h:133
@ LOGIN_INS_ALDL_IP_LOGGING
@ LOGIN_INS_FACL_IP_LOGGING
@ LOGIN_INS_CHAR_IP_LOGGING
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:156
static ObjectGuid GetGUID(Object const *o)
Definition Object.h:78
WorldSession * GetSession() const
Definition Player.h:1719
void setUInt32(uint8 index, uint32 value)
void setUInt64(uint8 index, uint64 value)
void setUInt8(uint8 index, uint8 value)
void setString(uint8 index, std::string const &value)
std::string const & GetRemoteAddress() const
uint32 GetAccountId() const
Realm realm
Definition World.cpp:3605
uint32 Realm
Definition Realm.h:44
RealmHandle Id
Definition Realm.h:67