· 5 years ago · Feb 28, 2020, 06:32 PM
1/*
2 SourcePawn is Copyright (C) 2006-2008 AlliedModders LLC. All rights reserved.
3 SourceMod is Copyright (C) 2006-2008 AlliedModders LLC. All rights reserved.
4 Pawn and SMALL are Copyright (C) 1997-2008 ITB CompuPhase.
5 Source is Copyright (C) Valve Corporation.
6 All trademarks are property of their respective owners.
7 This program is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation, either version 3 of the License, or (at your
10 option) any later version.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#include <sourcemod>
20#include <multicolors>
21
22#pragma semicolon 1
23#pragma newdecls required
24
25enum
26{
27 Arg_Steam2ID,
28 Arg_Steam3ID,
29 Arg_Steam32ID,
30 Arg_Steam64ID,
31 Arg_Name,
32 Arg_IP,
33}
34
35Database g_hDatabase = null;
36
37public Plugin myinfo = {
38 name = "Player Info Recorder",
39 author = "Mis",
40 description = "Stores info in a database about each player that connects to the server.",
41 version = "0.1.0",
42 url = "https://github.com/misdocumeno/"
43};
44
45// Stock Functions
46
47public void OnPluginStart()
48{
49 // Info commands
50
51 //funciona
52 RegAdminCmd("sm_playerinfo", OnPlayerInfoCMD, ADMFLAG_UNBAN, "Shows names, all types of SteamID and IPs seen with a given SteamID of any type, IP or name.");
53 RegAdminCmd("sm_nameinfo", OnNameInfoCMD, ADMFLAG_UNBAN, "Shows names, all types of SteamID and IPs seen with a given name.");
54 RegAdminCmd("sm_ipinfo", OnIpInfoCMD, ADMFLAG_UNBAN, "Shows names, all types of SteamID and IPs of all players who have joined the server from the given IP.");
55
56 // v no player found v
57 RegAdminCmd("sm_steamid2info", OnSteamId2InfoCMD, ADMFLAG_UNBAN, "Shows last name, all types of SteamID, and last seen IP explicitly searching with a SteamID2.");
58 RegAdminCmd("sm_steamid3info", OnSteamId3InfoCMD, ADMFLAG_UNBAN, "Shows last name, all types of SteamID, and last seen IP explicitly searching with a SteamID3.");
59 RegAdminCmd("sm_steamid64info", OnSteamId64InfoCMD, ADMFLAG_UNBAN, "Shows last name, all types of SteamID, and last seen IP explicitly searching with a SteamID64.");
60
61 // History commands
62 // funciona
63 RegAdminCmd("sm_playerall", OnPlayerAll, ADMFLAG_UNBAN, "Shows a history of all names, all SteamID2, and all IPs of a given SteamID of any type, IP or name.");
64
65 // PROBAR REPETIDOS Y RETRY
66 RegAdminCmd("sm_namenames", OnNameNamesCMD, ADMFLAG_UNBAN, "Shows a history of all names explicitly searching with a nickname.");
67
68 // PROBAR REPETIDOS
69 RegAdminCmd("sm_steamid2names", OnSteamId2NamesCMD, ADMFLAG_UNBAN, "Shows a history of all names explicitly searching with a SteamID2.");
70 RegAdminCmd("sm_steamid3names", OnSteamId3NamesCMD, ADMFLAG_UNBAN, "Shows a history of all names explicitly searching with a SteamID3.");
71 RegAdminCmd("sm_steamid64names", OnSteamId64NamesCMD, ADMFLAG_UNBAN, "Shows a history of all names explicitly searching with a SteamID64.");
72
73 // PROBAR REPETIDOS
74 RegAdminCmd("sm_nameips", OnNameIpsCMD, ADMFLAG_UNBAN, "Shows a history of all IPs explicitly searching with a nickname.");
75 RegAdminCmd("sm_steamid2ips", OnSteamId2IpsCMD, ADMFLAG_UNBAN, "Shows a history of all IPs explicitly searching with SteamID2.");
76 RegAdminCmd("sm_steamid3ips", OnSteamId3IpsCMD, ADMFLAG_UNBAN, "Shows a history of all IPs explicitly searching with SteamID3.");
77 RegAdminCmd("sm_steamid64ips", OnSteamId64IpsCMD, ADMFLAG_UNBAN, "Shows a history of all IPs explicitly searching with SteamID64.");
78 RegAdminCmd("sm_ipall", OnIpSteamIds, ADMFLAG_UNBAN, "Shows a history of all types of SteamID and their respective names seen on an IP.");
79
80
81 HookEvent("player_changename", OnPlayerChangeName_Event, EventHookMode_Post);
82
83 Database.Connect(SQL_FirstConnect, "PlayerRecord");
84}
85
86public void SQL_FirstConnect(Database db, const char[] error, any data)
87{
88 if (db == null || error[0] != '\0')
89 {
90 LogError("Database connect failure: %s", error);
91 return;
92 }
93
94 g_hDatabase = db;
95
96 g_hDatabase.SetCharset("utf8mb4");
97
98 g_hDatabase.Query(SQL_CreateAndInsertQuery, "CREATE TABLE IF NOT EXISTS `Players`("
99 ..."`IndexID` INT(1) NOT NULL AUTO_INCREMENT, "
100 ..."`Date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, "
101 ..."`AccountID` INT(1) NOT NULL, "
102 ..."`IP` varchar(16) NOT NULL, "
103 ..."`Name` varchar(256) NOT NULL, "
104 ..."UNIQUE INDEX `authId_IP_Name`(`AccountID`, `IP`, `Name`), "
105 ..."PRIMARY KEY(IndexID)"
106 ...") COLLATE 'utf8mb4_unicode_ci' ENGINE = InnoDB ROW_FORMAT = COMPRESSED; "
107 ..."SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));");
108}
109
110public void OnClientAuthorized(int client)
111{
112 char sIP[16];
113 char sUserName[MAX_NAME_LENGTH];
114 int iAccountId = GetSteamAccountID(client);
115 bool bValidIP = GetClientIP(client, sIP, sizeof(sIP));
116 bool bValidName = GetClientName(client, sUserName, sizeof(sUserName));
117
118 if (iAccountId != 0 && bValidIP && bValidName)
119 {
120 char query[256];
121
122 g_hDatabase.Format(query, sizeof(query), "INSERT INTO "
123 ..."`Players`(`AccountID`, `IP`, `Name`) "
124 ..."VALUES ('%i', '%s', '%s') ON DUPLICATE KEY UPDATE "
125 ..."`Date` = CURRENT_TIMESTAMP", iAccountId, sIP, sUserName);
126
127 g_hDatabase.Query(SQL_CreateAndInsertQuery, query);
128 }
129}
130
131public Action OnPlayerChangeName_Event(Event event, const char[] name, bool dontBroadcast)
132{
133 int userid = event.GetInt("userid");
134 int client = GetClientOfUserId(userid);
135
136 char sIP[16];
137 char sUserName[MAX_NAME_LENGTH];
138 int iAccountId = GetSteamAccountID(client);
139 bool bValidIP = GetClientIP(client, sIP, sizeof(sIP));
140 event.GetString("newname", sUserName, sizeof(sUserName));
141
142 if (iAccountId != 0 && bValidIP)
143 {
144 char query[256];
145
146 g_hDatabase.Format(query, sizeof(query), "INSERT INTO "
147 ..."`Players`(`AccountID`, `IP`, `Name`) "
148 ..."VALUES ('%i', '%s', '%s') ON DUPLICATE KEY UPDATE "
149 ..."`Date` = CURRENT_TIMESTAMP", iAccountId, sIP, sUserName);
150
151 g_hDatabase.Query(SQL_CreateAndInsertQuery, query);
152 }
153}
154
155// Commands Functions
156
157static Action OnPlayerInfoCMD(int client, any args)
158{
159 if (!client)
160 return;
161
162 int iAccountId;
163
164 char arg[256];
165 GetCmdArg(1, arg, sizeof(arg));
166
167 if (GetArgType(arg) == Arg_Steam2ID)
168 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam2ID);
169 else if (GetArgType(arg) == Arg_Steam3ID)
170 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam3ID);
171 else if (GetArgType(arg) == Arg_Steam32ID)
172 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam32ID);
173 else if (GetArgType(arg) == Arg_Steam64ID)
174 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam64ID);
175 else if (GetArgType(arg) == Arg_Name)
176 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam64ID);
177
178 char query[256];
179
180 if (GetArgType(arg) == Arg_Name)
181 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE Name LIKE '%s' GROUP BY `Players`.`AccountID` ORDER BY `Players`.`Date`", arg);
182 else if (GetArgType(arg) == Arg_IP)
183 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE IP = '%s' GROUP BY `Players`.`AccountID` ORDER BY `Players`.`Date`", arg);
184 else
185 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE AccountID = '%i' ORDER BY `Players`.`Date` DESC LIMIT 1", iAccountId);
186
187 int userid = GetClientUserId(client);
188
189 DataPack hPlayerInfoPack = new DataPack();
190 hPlayerInfoPack.WriteString(arg);
191 hPlayerInfoPack.WriteCell(userid);
192 hPlayerInfoPack.WriteCell(GetArgType(arg));
193
194 g_hDatabase.Query(OnInfoQuery, query, hPlayerInfoPack);
195}
196
197static Action OnNameInfoCMD(int client, any args)
198{
199 if (!client)
200 return;
201
202 char arg[256];
203 GetCmdArg(1, arg, sizeof(arg));
204
205 char query[256];
206 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE Name LIKE '%s' GROUP BY `Players`.`AccountID` ORDER BY `Players`.`Date`", arg);
207
208 int userid = GetClientUserId(client);
209
210 DataPack hPlayerInfoPack = new DataPack();
211 hPlayerInfoPack.WriteString(arg);
212 hPlayerInfoPack.WriteCell(userid);
213 hPlayerInfoPack.WriteCell(Arg_Name);
214
215 g_hDatabase.Query(OnInfoQuery, query, hPlayerInfoPack);
216}
217
218static Action OnSteamId2InfoCMD(int client, any args)
219{
220 if (!client)
221 return;
222
223 int iAccountId;
224
225 char arg[256];
226 GetCmdArg(1, arg, sizeof(arg));
227
228 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam2ID);
229
230 char query[256];
231 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE AccountID = '%s' ORDER BY `Players`.`Date` DESC LIMIT 1", iAccountId);
232
233 int userid = GetClientUserId(client);
234
235 DataPack hPlayerInfoPack = new DataPack();
236 hPlayerInfoPack.WriteString(arg);
237 hPlayerInfoPack.WriteCell(userid);
238 hPlayerInfoPack.WriteCell(Arg_Steam2ID);
239
240 g_hDatabase.Query(OnInfoQuery, query, hPlayerInfoPack);
241}
242
243static Action OnSteamId3InfoCMD(int client, any args)
244{
245 if (!client)
246 return;
247
248 int iAccountId;
249
250 char arg[256];
251 GetCmdArg(1, arg, sizeof(arg));
252
253 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam3ID);
254
255 char query[256];
256 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE AccountID = '%s' ORDER BY `Players`.`Date` DESC LIMIT 1", iAccountId);
257
258 int userid = GetClientUserId(client);
259
260 DataPack hPlayerInfoPack = new DataPack();
261 hPlayerInfoPack.WriteString(arg);
262 hPlayerInfoPack.WriteCell(userid);
263 hPlayerInfoPack.WriteCell(Arg_Steam3ID);
264
265 g_hDatabase.Query(OnInfoQuery, query, hPlayerInfoPack);
266}
267
268static Action OnSteamId64InfoCMD(int client, any args)
269{
270 if (!client)
271 return;
272
273 int iAccountId;
274
275 char arg[256];
276 GetCmdArg(1, arg, sizeof(arg));
277
278 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam64ID);
279
280 char query[256];
281 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE AccountID = '%s' ORDER BY `Players`.`Date` DESC LIMIT 1", iAccountId);
282
283 int userid = GetClientUserId(client);
284
285 DataPack hPlayerInfoPack = new DataPack();
286 hPlayerInfoPack.WriteString(arg);
287 hPlayerInfoPack.WriteCell(userid);
288 hPlayerInfoPack.WriteCell(Arg_Steam64ID);
289
290 g_hDatabase.Query(OnInfoQuery, query, hPlayerInfoPack);
291}
292
293static Action OnIpInfoCMD(int client, any args)
294{
295 if (!client)
296 return;
297
298 char arg[256];
299 GetCmdArg(1, arg, sizeof(arg));
300
301 char query[256];
302 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE IP = '%s' GROUP BY `Players`.`AccountID` ORDER BY `Players`.`Date`", arg);
303
304 int userid = GetClientUserId(client);
305
306 DataPack hPlayerInfoPack = new DataPack();
307 hPlayerInfoPack.WriteString(arg);
308 hPlayerInfoPack.WriteCell(userid);
309 hPlayerInfoPack.WriteCell(Arg_IP);
310
311 g_hDatabase.Query(OnInfoQuery, query, hPlayerInfoPack);
312}
313
314
315static Action OnPlayerAll(int client, any args)
316{
317 if (!client)
318 return;
319
320 int iAccountId;
321
322 char arg[256];
323 GetCmdArg(1, arg, sizeof(arg));
324
325 if (GetArgType(arg) == Arg_Steam2ID)
326 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam2ID);
327 else if (GetArgType(arg) == Arg_Steam3ID)
328 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam3ID);
329 else if (GetArgType(arg) == Arg_Steam32ID)
330 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam32ID);
331 else if (GetArgType(arg) == Arg_Steam64ID)
332 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam64ID);
333 else if (GetArgType(arg) == Arg_Name)
334 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam64ID);
335
336 char query[256];
337
338 if (GetArgType(arg) == Arg_Name)
339 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE Name LIKE '%s' ORDER BY `Players`.`Date` DESC", arg);
340 else if (GetArgType(arg) == Arg_IP)
341 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE IP = '%s' ORDER BY `Players`.`Date` DESC", arg);
342 else
343 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE AccountID = '%i' ORDER BY `Players`.`Date` DESC", iAccountId);
344
345 int userid = GetClientUserId(client);
346
347 DataPack hHistoryAllPack = new DataPack();
348 hHistoryAllPack.WriteString(arg);
349 hHistoryAllPack.WriteCell(userid);
350 hHistoryAllPack.WriteCell(GetArgType(arg));
351
352 g_hDatabase.Query(OnHistoryAllQuery, query, hHistoryAllPack);
353}
354
355static Action OnNameNamesCMD(int client, any args)
356{
357 if (!client)
358 return;
359
360 char arg[256];
361 GetCmdArg(1, arg, sizeof(arg));
362
363 char query[256];
364 g_hDatabase.Format(query, sizeof(query), "SELECT AccountId FROM Players WHERE Name LIKE '%s'", arg);
365
366 int userid = GetClientUserId(client);
367
368 DataPack hNameOrIpPack = new DataPack();
369 hNameOrIpPack.WriteCell(userid);
370 hNameOrIpPack.WriteString(arg);
371
372 g_hDatabase.Query(OnNameNamesGotAccountIdCMD, query, hNameOrIpPack);
373}
374
375public void OnNameNamesGotAccountIdCMD(Database db, DBResultSet results, const char[] sError, DataPack hNameOrIpPack)
376{
377 hNameOrIpPack.Reset();
378 int userid = hNameOrIpPack.ReadCell();
379 char arg[MAX_NAME_LENGTH];
380 hNameOrIpPack.ReadString(arg, sizeof(arg));
381 delete hNameOrIpPack;
382
383 char sAccountId[32];
384
385 while (results.FetchRow())
386 results.FetchString(0, sAccountId, sizeof(sAccountId));
387
388 hNameOrIpPack.WriteCell(userid);
389 hNameOrIpPack.WriteString(arg);
390
391 if (results.RowCount != 0)
392 {
393 char query[256];
394 g_hDatabase.Format(query, sizeof(query), "SELECT DISTINCT Name FROM Players WHERE AccountID = '%s'", sAccountId);
395
396 g_hDatabase.Query(OnHistoryQuery, query, hNameOrIpPack);
397 }
398 else
399 {
400 char query[256];
401 g_hDatabase.Format(query, sizeof(query), "SELECT AccountId FROM Players WHERE Name LIKE '%%%s'", arg);
402
403 g_hDatabase.Query(OnNameNamesGotAccountIdCMDRetry1, query, hNameOrIpPack);
404 }
405}
406
407public void OnNameNamesGotAccountIdCMDRetry1(Database db, DBResultSet results, const char[] sError, DataPack hNameOrIpPack)
408{
409 hNameOrIpPack.Reset();
410 int userid = hNameOrIpPack.ReadCell();
411 char arg[MAX_NAME_LENGTH];
412 hNameOrIpPack.ReadString(arg, sizeof(arg));
413 delete hNameOrIpPack;
414
415 if(db == null || results == null || sError[0] != '\0')
416 {
417 LogError("Database query failure: %s", sError);
418 return;
419 }
420
421 char sAccountId[32];
422
423 while (results.FetchRow())
424 results.FetchString(0, sAccountId, sizeof(sAccountId));
425
426 hNameOrIpPack.WriteCell(userid);
427 hNameOrIpPack.WriteString(arg);
428
429
430 if (results.RowCount != 0)
431 {
432 char query[256];
433 g_hDatabase.Format(query, sizeof(query), "SELECT DISTINCT Name FROM Players WHERE AccountID = '%s'", sAccountId);
434
435 g_hDatabase.Query(OnHistoryQuery, query, hNameOrIpPack);
436 }
437 else
438 {
439 char query[256];
440 g_hDatabase.Format(query, sizeof(query), "SELECT AccountId FROM Players WHERE Name LIKE '%s%'", arg);
441
442 g_hDatabase.Query(OnNameNamesGotAccountIdCMDRetry2, query, hNameOrIpPack);
443 }
444}
445
446public void OnNameNamesGotAccountIdCMDRetry2(Database db, DBResultSet results, const char[] sError, DataPack hNameOrIpPack)
447{
448 hNameOrIpPack.Reset();
449 int userid = hNameOrIpPack.ReadCell();
450 char arg[MAX_NAME_LENGTH];
451 hNameOrIpPack.ReadString(arg, sizeof(arg));
452
453 delete hNameOrIpPack;
454
455 if(db == null || results == null || sError[0] != '\0')
456 {
457 LogError("Database query failure: %s", sError);
458 return;
459 }
460
461 if(db == null || results == null || sError[0] != '\0')
462 {
463 LogError("Database query failure: %s", sError);
464 return;
465 }
466
467 char sAccountId[32];
468
469 while (results.FetchRow())
470 results.FetchString(0, sAccountId, sizeof(sAccountId));
471
472 hNameOrIpPack.WriteCell(userid);
473 hNameOrIpPack.WriteString(arg);
474
475
476 if (results.RowCount != 0)
477 {
478 char query[256];
479 g_hDatabase.Format(query, sizeof(query), "SELECT DISTINCT Name FROM Players WHERE AccountID = '%s'", sAccountId);
480
481 g_hDatabase.Query(OnHistoryQuery, query, hNameOrIpPack);
482 }
483 else
484 {
485 char query[256];
486 g_hDatabase.Format(query, sizeof(query), "SELECT AccountId FROM Players WHERE Name LIKE '%%%s%%'", arg);
487
488 g_hDatabase.Query(OnNameNamesGotAccountIdCMDRetry3, query, hNameOrIpPack);
489 }
490}
491
492public void OnNameNamesGotAccountIdCMDRetry3(Database db, DBResultSet results, const char[] sError, DataPack hNameOrIpPack)
493{
494 hNameOrIpPack.Reset();
495 int userid = hNameOrIpPack.ReadCell();
496 char arg[MAX_NAME_LENGTH];
497 hNameOrIpPack.ReadString(arg, sizeof(arg));
498 delete hNameOrIpPack;
499
500 int client = GetClientOfUserId(userid);
501
502 if(db == null || results == null || sError[0] != '\0')
503 {
504 LogError("Database query failure: %s", sError);
505 return;
506 }
507
508 if(db == null || results == null || sError[0] != '\0')
509 {
510 LogError("Database query failure: %s", sError);
511 return;
512 }
513
514 char sAccountId[32];
515
516 while (results.FetchRow())
517 results.FetchString(0, sAccountId, sizeof(sAccountId));
518
519 hNameOrIpPack.WriteCell(userid);
520
521 if (results.RowCount != 0)
522 {
523 char query[256];
524 g_hDatabase.Format(query, sizeof(query), "SELECT DISTINCT Name FROM Players WHERE AccountID = '%s'", sAccountId);
525
526 g_hDatabase.Query(OnHistoryQuery, query, hNameOrIpPack);
527 }
528 else
529 {
530 CPrintToChat(client, "[{green}!{default}] {red}No player found");
531 }
532}
533
534static Action OnSteamId2NamesCMD(int client, any args)
535{
536 if (!client)
537 return;
538
539 int iAccountId;
540
541 char arg[256];
542 GetCmdArg(1, arg, sizeof(arg));
543
544 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam2ID);
545
546 char query[256];
547 g_hDatabase.Format(query, sizeof(query), "SELECT DISTINCT Name FROM Players WHERE AccountID = '%i'", iAccountId);
548
549 int userid = GetClientUserId(client);
550
551 DataPack hNameOrIpPack = new DataPack();
552 hNameOrIpPack.WriteCell(userid);
553 hNameOrIpPack.WriteCell(Arg_Name);
554
555 g_hDatabase.Query(OnHistoryQuery, query, hNameOrIpPack);
556}
557
558static Action OnSteamId3NamesCMD(int client, any args)
559{
560 if (!client)
561 return;
562
563 int iAccountId;
564
565 char arg[256];
566 GetCmdArg(1, arg, sizeof(arg));
567
568 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam3ID);
569
570 char query[256];
571 g_hDatabase.Format(query, sizeof(query), "SELECT DISTINCT Name FROM Players WHERE AccountID = '%i'", iAccountId);
572
573 int userid = GetClientUserId(client);
574
575 DataPack hNameOrIpPack = new DataPack();
576 hNameOrIpPack.WriteCell(userid);
577 hNameOrIpPack.WriteCell(Arg_Name);
578
579 g_hDatabase.Query(OnHistoryQuery, query, hNameOrIpPack);
580}
581
582static Action OnSteamId64NamesCMD(int client, any args)
583{
584 if (!client)
585 return;
586
587 int iAccountId;
588
589 char arg[256];
590 GetCmdArg(1, arg, sizeof(arg));
591
592 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam64ID);
593
594 char query[256];
595 g_hDatabase.Format(query, sizeof(query), "SELECT DISTINCT Name FROM Players WHERE AccountID = '%i'", iAccountId);
596
597 int userid = GetClientUserId(client);
598
599 DataPack hNameOrIpPack = new DataPack();
600 hNameOrIpPack.WriteCell(userid);
601 hNameOrIpPack.WriteCell(Arg_Name);
602
603 g_hDatabase.Query(OnHistoryQuery, query, hNameOrIpPack);
604}
605
606static Action OnNameIpsCMD(int client, any args)
607{
608 if (!client)
609 return;
610
611 char arg[256];
612 GetCmdArg(1, arg, sizeof(arg));
613
614 char query[256];
615 g_hDatabase.Format(query, sizeof(query), "SELECT DISTINCT IP FROM Players WHERE Name LIKE '%s'", arg);
616
617 int userid = GetClientUserId(client);
618
619 DataPack hNameOrIpPack = new DataPack();
620 hNameOrIpPack.WriteCell(userid);
621 hNameOrIpPack.WriteCell(Arg_IP);
622
623 g_hDatabase.Query(OnHistoryQuery, query, hNameOrIpPack);
624}
625
626static Action OnSteamId2IpsCMD(int client, any args)
627{
628 if (!client)
629 return;
630
631 int iAccountId;
632
633 char arg[256];
634 GetCmdArg(1, arg, sizeof(arg));
635
636 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam2ID);
637
638 char query[256];
639 g_hDatabase.Format(query, sizeof(query), "SELECT DISTINCT IP FROM Players WHERE AccountID = '%i'", iAccountId);
640
641 int userid = GetClientUserId(client);
642
643 DataPack hNameOrIpPack = new DataPack();
644 hNameOrIpPack.WriteCell(userid);
645 hNameOrIpPack.WriteCell(Arg_IP);
646
647 g_hDatabase.Query(OnHistoryQuery, query, hNameOrIpPack);
648}
649
650static Action OnSteamId3IpsCMD(int client, any args)
651{
652 if (!client)
653 return;
654
655 int iAccountId;
656
657 char arg[256];
658 GetCmdArg(1, arg, sizeof(arg));
659
660 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam3ID);
661
662 char query[256];
663 g_hDatabase.Format(query, sizeof(query), "SELECT DISTINCT IP FROM Players WHERE AccountID = '%i'", iAccountId);
664
665 int userid = GetClientUserId(client);
666
667 DataPack hNameOrIpPack = new DataPack();
668 hNameOrIpPack.WriteCell(userid);
669 hNameOrIpPack.WriteCell(Arg_IP);
670
671 g_hDatabase.Query(OnHistoryQuery, query, hNameOrIpPack);
672}
673
674static Action OnSteamId64IpsCMD(int client, any args)
675{
676 if (!client)
677 return;
678
679 int iAccountId;
680
681 char arg[256];
682 GetCmdArg(1, arg, sizeof(arg));
683
684 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam64ID);
685
686 char query[256];
687 g_hDatabase.Format(query, sizeof(query), "SELECT DISTINCT IP FROM Players WHERE AccountID = '%i'", iAccountId);
688
689 int userid = GetClientUserId(client);
690
691 DataPack hNameOrIpPack = new DataPack();
692 hNameOrIpPack.WriteCell(userid);
693 hNameOrIpPack.WriteCell(Arg_IP);
694
695 g_hDatabase.Query(OnHistoryQuery, query, hNameOrIpPack);
696}
697
698static Action OnIpSteamIds(int client, any args)
699{
700 if (!client)
701 return;
702
703 char arg[256];
704 GetCmdArg(1, arg, sizeof(arg));
705
706 char query[256];
707 g_hDatabase.Format(query, sizeof(query), "SELECT DISTINCT Name, AccountId FROM Players WHERE IP = '%s'", arg);
708
709 int userid = GetClientUserId(client);
710
711 DataPack hSteamIdPack = new DataPack();
712 hSteamIdPack.WriteCell(userid);
713
714 g_hDatabase.Query(OnHistoryIpQuery, query, hSteamIdPack);
715}
716
717// SQL Query Functions
718
719public void OnInfoQuery(Database db, DBResultSet results, const char[] sError, DataPack hPlayerInfoPack)
720{
721 char arg[256];
722 hPlayerInfoPack.Reset();
723 hPlayerInfoPack.ReadString(arg, sizeof(arg));
724 int userid = hPlayerInfoPack.ReadCell();
725 int iArgType = hPlayerInfoPack.ReadCell();
726 delete hPlayerInfoPack;
727
728 int client = GetClientOfUserId(userid);
729
730 if(db == null || results == null || sError[0] != '\0')
731 {
732 LogError("Database query failure: %s", sError);
733 return;
734 }
735
736 if (!client)
737 return;
738
739 DataPack hInfoQuery = new DataPack();
740 int iRowAmount;
741
742 while (results.FetchRow())
743 {
744 char sNameBuffer1[MAX_NAME_LENGTH];
745 char sIPBuffer1[16];
746 char sAccountIdBuffer1[32];
747
748 results.FetchString(0, sNameBuffer1, sizeof(sNameBuffer1));
749 results.FetchString(1, sIPBuffer1, sizeof(sIPBuffer1));
750 results.FetchString(2, sAccountIdBuffer1, sizeof(sAccountIdBuffer1));
751
752 hInfoQuery.WriteString(sNameBuffer1);
753 hInfoQuery.WriteString(sIPBuffer1);
754 hInfoQuery.WriteString(sAccountIdBuffer1);
755
756 iRowAmount++;
757 }
758
759 if (results.RowCount != 0)
760 {
761 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
762
763 hInfoQuery.Reset();
764
765 for (int i = 0; i < iRowAmount; i++)
766 {
767 if (i != 0)
768 CPrintToChat(client, "{green}----------");
769
770 char sNameBuffer2[MAX_NAME_LENGTH];
771 char sIPBuffer2[16];
772 char sAccountIdBuffer2[32];
773 hInfoQuery.ReadString(sNameBuffer2, sizeof(sNameBuffer2));
774 hInfoQuery.ReadString(sIPBuffer2, sizeof(sIPBuffer2));
775 hInfoQuery.ReadString(sAccountIdBuffer2, sizeof(sAccountIdBuffer2));
776
777 int iAccountId = StringToInt(sAccountIdBuffer2);
778
779 char sSteamId2[32];
780 char sSteamId3[32];
781 char sSteamId64[64];
782
783 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
784 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
785 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
786
787 if (iArgType == Arg_Name || iArgType == Arg_IP)
788 {
789 CPrintToChat(client, "{default}Name {green}- {olive}%s", sNameBuffer2);
790 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
791 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
792 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
793 CPrintToChat(client, "{default}IP {green}- {olive}%s", sIPBuffer2);
794 }
795 else
796 {
797 CPrintToChat(client, "{default}Last Name {green}- {olive}%s", sNameBuffer2);
798 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
799 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
800 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
801 CPrintToChat(client, "{default}Last IP {green}- {olive}%s", sIPBuffer2);
802 }
803 }
804
805 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
806 }
807 else
808 {
809 if (iArgType == Arg_Name)
810 {
811 char query[256];
812 g_hDatabase.Format(query, sizeof(query), "SELECT MAX (Date), Name, IP, AccountID FROM Players WHERE Name LIKE '%%%s' GROUP BY `Players`.`AccountID`", arg);
813
814 DataPack hPlayerInfoPack = new DataPack();
815 hPlayerInfoPack.WriteString(arg);
816 hPlayerInfoPack.WriteCell(userid);
817
818 g_hDatabase.Query(OnInfoQueryRetry1, query, hPlayerInfoPack);
819 }
820 else
821 CPrintToChat(client, "[{green}!{default}] {red}No player found");
822 }
823
824 delete hInfoQuery;
825}
826
827public void OnInfoQueryRetry1(Database db, DBResultSet results, const char[] sError, DataPack hPlayerInfoPack)
828{
829 char arg[256];
830 hPlayerInfoPack.Reset();
831 hPlayerInfoPack.ReadString(arg, sizeof(arg));
832 int userid = hPlayerInfoPack.ReadCell();
833 delete hPlayerInfoPack;
834
835 int client = GetClientOfUserId(userid);
836
837 if(db == null || results == null || sError[0] != '\0')
838 {
839 LogError("Database query failure: %s", sError);
840 return;
841 }
842
843 DataPack hInfoQuery = new DataPack();
844 int iRowAmount;
845
846 while (results.FetchRow())
847 {
848 char sNameBuffer1[MAX_NAME_LENGTH];
849 char sIPBuffer1[16];
850 char sAccountIdBuffer1[32];
851
852 results.FetchString(0, sNameBuffer1, sizeof(sNameBuffer1));
853 results.FetchString(1, sIPBuffer1, sizeof(sIPBuffer1));
854 results.FetchString(2, sAccountIdBuffer1, sizeof(sAccountIdBuffer1));
855
856 hInfoQuery.WriteString(sNameBuffer1);
857 hInfoQuery.WriteString(sIPBuffer1);
858 hInfoQuery.WriteString(sAccountIdBuffer1);
859
860 iRowAmount++;
861 }
862
863 if (results.RowCount != 0)
864 {
865 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
866
867 hInfoQuery.Reset();
868
869 for (int i = 0; i < iRowAmount; i++)
870 {
871 if (i != 0)
872 CPrintToChat(client, "{green}----------");
873
874 char sNameBuffer2[MAX_NAME_LENGTH];
875 char sIPBuffer2[16];
876 char sAccountIdBuffer2[32];
877 hInfoQuery.ReadString(sNameBuffer2, sizeof(sNameBuffer2));
878 hInfoQuery.ReadString(sIPBuffer2, sizeof(sIPBuffer2));
879 hInfoQuery.ReadString(sAccountIdBuffer2, sizeof(sAccountIdBuffer2));
880
881 int iAccountId = StringToInt(sAccountIdBuffer2);
882
883 char sSteamId2[32];
884 char sSteamId3[32];
885 char sSteamId64[64];
886
887 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
888 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
889 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
890
891 CPrintToChat(client, "{default}Name {green}- {olive}%s", sNameBuffer2);
892 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
893 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
894 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
895 CPrintToChat(client, "{default}IP {green}- {olive}%s", sIPBuffer2);
896 }
897
898 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
899 }
900 else
901 {
902 char query[256];
903 g_hDatabase.Format(query, sizeof(query), "SELECT MAX (Date), Name, IP, AccountID FROM Players WHERE Name LIKE '%s%' GROUP BY `Players`.`AccountID`", arg);
904
905 DataPack hPlayerInfoPack = new DataPack();
906 hPlayerInfoPack.WriteString(arg);
907 hPlayerInfoPack.WriteCell(userid);
908
909 g_hDatabase.Query(OnInfoQueryRetry2, query, hPlayerInfoPack);
910 }
911
912 delete hInfoQuery;
913}
914
915public void OnInfoQueryRetry2(Database db, DBResultSet results, const char[] sError, DataPack hPlayerInfoPack)
916{
917 char arg[256];
918 hPlayerInfoPack.Reset();
919 hPlayerInfoPack.ReadString(arg, sizeof(arg));
920 int userid = hPlayerInfoPack.ReadCell();
921 delete hPlayerInfoPack;
922
923 int client = GetClientOfUserId(userid);
924
925 if(db == null || results == null || sError[0] != '\0')
926 {
927 LogError("Database query failure: %s", sError);
928 return;
929 }
930
931 if(db == null || results == null || sError[0] != '\0')
932 {
933 LogError("Database query failure: %s", sError);
934 return;
935 }
936
937 DataPack hInfoQuery = new DataPack();
938 int iRowAmount;
939
940 while (results.FetchRow())
941 {
942 char sNameBuffer1[MAX_NAME_LENGTH];
943 char sIPBuffer1[16];
944 char sAccountIdBuffer1[32];
945
946 results.FetchString(0, sNameBuffer1, sizeof(sNameBuffer1));
947 results.FetchString(1, sIPBuffer1, sizeof(sIPBuffer1));
948 results.FetchString(2, sAccountIdBuffer1, sizeof(sAccountIdBuffer1));
949
950 hInfoQuery.WriteString(sNameBuffer1);
951 hInfoQuery.WriteString(sIPBuffer1);
952 hInfoQuery.WriteString(sAccountIdBuffer1);
953
954 iRowAmount++;
955 }
956
957 if (results.RowCount != 0)
958 {
959 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
960
961 hInfoQuery.Reset();
962
963 for (int i = 0; i < iRowAmount; i++)
964 {
965 if (i != 0)
966 CPrintToChat(client, "{green}----------");
967
968 char sNameBuffer2[MAX_NAME_LENGTH];
969 char sIPBuffer2[16];
970 char sAccountIdBuffer2[32];
971 hInfoQuery.ReadString(sNameBuffer2, sizeof(sNameBuffer2));
972 hInfoQuery.ReadString(sIPBuffer2, sizeof(sIPBuffer2));
973 hInfoQuery.ReadString(sAccountIdBuffer2, sizeof(sAccountIdBuffer2));
974
975 int iAccountId = StringToInt(sAccountIdBuffer2);
976
977 char sSteamId2[32];
978 char sSteamId3[32];
979 char sSteamId64[64];
980
981 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
982 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
983 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
984
985 CPrintToChat(client, "{default}Name {green}- {olive}%s", sNameBuffer2);
986 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
987 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
988 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
989 CPrintToChat(client, "{default}IP {green}- {olive}%s", sIPBuffer2);
990 }
991
992 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
993 }
994 else
995 {
996 char query[256];
997 g_hDatabase.Format(query, sizeof(query), "SELECT MAX (Date), Name, IP, AccountID FROM Players WHERE Name LIKE '%%%s%%' GROUP BY `Players`.`AccountID`", arg);
998
999 DataPack hPlayerInfoPack = new DataPack();
1000 hPlayerInfoPack.WriteString(arg);
1001 hPlayerInfoPack.WriteCell(userid);
1002
1003 g_hDatabase.Query(OnInfoQueryRetry3, query, hPlayerInfoPack);
1004 }
1005
1006 delete hInfoQuery;
1007}
1008
1009public void OnInfoQueryRetry3(Database db, DBResultSet results, const char[] sError, DataPack hPlayerInfoPack)
1010{
1011 char arg[256];
1012 hPlayerInfoPack.Reset();
1013 hPlayerInfoPack.ReadString(arg, sizeof(arg));
1014 int userid = hPlayerInfoPack.ReadCell();
1015 delete hPlayerInfoPack;
1016
1017 int client = GetClientOfUserId(userid);
1018
1019 if(db == null || results == null || sError[0] != '\0')
1020 {
1021 LogError("Database query failure: %s", sError);
1022 return;
1023 }
1024
1025 if(db == null || results == null || sError[0] != '\0')
1026 {
1027 LogError("Database query failure: %s", sError);
1028 return;
1029 }
1030
1031 DataPack hInfoQuery = new DataPack();
1032 int iRowAmount;
1033
1034 while (results.FetchRow())
1035 {
1036 char sNameBuffer1[MAX_NAME_LENGTH];
1037 char sIPBuffer1[16];
1038 char sAccountIdBuffer1[32];
1039
1040 results.FetchString(0, sNameBuffer1, sizeof(sNameBuffer1));
1041 results.FetchString(1, sIPBuffer1, sizeof(sIPBuffer1));
1042 results.FetchString(2, sAccountIdBuffer1, sizeof(sAccountIdBuffer1));
1043
1044 hInfoQuery.WriteString(sNameBuffer1);
1045 hInfoQuery.WriteString(sIPBuffer1);
1046 hInfoQuery.WriteString(sAccountIdBuffer1);
1047
1048 iRowAmount++;
1049 }
1050
1051 if (results.RowCount != 0)
1052 {
1053 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1054
1055 hInfoQuery.Reset();
1056
1057 for (int i = 0; i < iRowAmount; i++)
1058 {
1059 if (i != 0)
1060 CPrintToChat(client, "{green}----------");
1061
1062 char sNameBuffer2[MAX_NAME_LENGTH];
1063 char sIPBuffer2[16];
1064 char sAccountIdBuffer2[32];
1065 hInfoQuery.ReadString(sNameBuffer2, sizeof(sNameBuffer2));
1066 hInfoQuery.ReadString(sIPBuffer2, sizeof(sIPBuffer2));
1067 hInfoQuery.ReadString(sAccountIdBuffer2, sizeof(sAccountIdBuffer2));
1068
1069 int iAccountId = StringToInt(sAccountIdBuffer2);
1070
1071 char sSteamId2[32];
1072 char sSteamId3[32];
1073 char sSteamId64[64];
1074
1075 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
1076 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
1077 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
1078
1079 CPrintToChat(client, "{default}Name {green}- {olive}%s", sNameBuffer2);
1080 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
1081 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
1082 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
1083 CPrintToChat(client, "{default}IP {green}- {olive}%s", sIPBuffer2);
1084 }
1085
1086 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1087 }
1088 else
1089 CPrintToChat(client, "[{green}!{default}] {red}No player found");
1090
1091 delete hInfoQuery;
1092}
1093
1094public void OnHistoryAllQuery(Database db, DBResultSet results, const char[] sError, DataPack hHistoryAllPack)
1095{
1096 char arg[256];
1097 hHistoryAllPack.Reset();
1098 hHistoryAllPack.ReadString(arg, sizeof(arg));
1099 int userid = hHistoryAllPack.ReadCell();
1100 int iArgType = hHistoryAllPack.ReadCell();
1101 delete hHistoryAllPack;
1102
1103 int client = GetClientOfUserId(userid);
1104
1105 if(db == null || results == null || sError[0] != '\0')
1106 {
1107 LogError("Database query failure: %s", sError);
1108 return;
1109 }
1110
1111 if (!client)
1112 return;
1113
1114 DataPack hAllHistory = new DataPack();
1115 int iAllHistoryAmount;
1116
1117 while (results.FetchRow())
1118 {
1119 char sNameBuffer1[MAX_NAME_LENGTH];
1120 char sIPBuffer1[16];
1121 char sAccountIdBuffer1[32];
1122
1123 results.FetchString(0, sNameBuffer1, sizeof(sNameBuffer1));
1124 results.FetchString(1, sIPBuffer1, sizeof(sIPBuffer1));
1125 results.FetchString(2, sAccountIdBuffer1, sizeof(sAccountIdBuffer1));
1126
1127 hAllHistory.WriteString(sNameBuffer1);
1128 hAllHistory.WriteString(sIPBuffer1);
1129 hAllHistory.WriteString(sAccountIdBuffer1);
1130 iAllHistoryAmount++;
1131 }
1132
1133 if (results.RowCount != 0)
1134 {
1135 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1136
1137 hAllHistory.Reset();
1138
1139 for (int i = 0; i < iAllHistoryAmount; i++)
1140 {
1141 if (i != 0)
1142 CPrintToChat(client, "{green}----------");
1143
1144 char sNameBuffer2[MAX_NAME_LENGTH];
1145 char sIPBuffer2[16];
1146 char sAccountIdBuffer2[32];
1147 hAllHistory.ReadString(sNameBuffer2, sizeof(sNameBuffer2));
1148 hAllHistory.ReadString(sIPBuffer2, sizeof(sIPBuffer2));
1149 hAllHistory.ReadString(sAccountIdBuffer2, sizeof(sAccountIdBuffer2));
1150
1151 int iAccountId = StringToInt(sAccountIdBuffer2);
1152
1153 char sSteamId2[32];
1154 char sSteamId3[32];
1155 char sSteamId64[64];
1156
1157 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
1158 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
1159 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
1160
1161 CPrintToChat(client, "{default}Name: {olive}%s", sNameBuffer2);
1162 CPrintToChat(client, "{default}SteamId2: {olive}%s"
1163 ..."\n{default}SteamId3: {olive}%s"
1164 ..."\n{default}SteamId64: {olive}%s", sSteamId2, sSteamId3, sSteamId64);
1165 CPrintToChat(client, "{default}IP: {olive}%s", sIPBuffer2);
1166 }
1167
1168 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1169 }
1170 else
1171 {
1172 if (iArgType == Arg_Name)
1173 {
1174 char query[256];
1175 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE Name LIKE '%%%s' ORDER BY `Players`.`Date` DESC", arg);
1176
1177 DataPack hHistoryAllPack = new DataPack();
1178 hHistoryAllPack.WriteString(arg);
1179 hHistoryAllPack.WriteCell(userid);
1180
1181 g_hDatabase.Query(OnInfoQueryRetry1, query, hHistoryAllPack);
1182 }
1183 else
1184 CPrintToChat(client, "[{green}!{default}] {red}No player found");
1185 }
1186
1187 delete hAllHistory;
1188}
1189
1190public void OnHistoryAllQueryRetry1(Database db, DBResultSet results, const char[] sError, DataPack hHistoryAllPack)
1191{
1192 char arg[256];
1193 hHistoryAllPack.Reset();
1194 hHistoryAllPack.ReadString(arg, sizeof(arg));
1195 int userid = hHistoryAllPack.ReadCell();
1196 int iArgType = hHistoryAllPack.ReadCell();
1197 delete hHistoryAllPack;
1198
1199 int client = GetClientOfUserId(userid);
1200
1201 if(db == null || results == null || sError[0] != '\0')
1202 {
1203 LogError("Database query failure: %s", sError);
1204 return;
1205 }
1206
1207 DataPack hAllHistory = new DataPack();
1208 int iAllHistoryAmount;
1209
1210 while (results.FetchRow())
1211 {
1212 char sNameBuffer1[MAX_NAME_LENGTH];
1213 char sIPBuffer1[16];
1214 char sAccountIdBuffer1[32];
1215
1216 results.FetchString(0, sNameBuffer1, sizeof(sNameBuffer1));
1217 results.FetchString(1, sIPBuffer1, sizeof(sIPBuffer1));
1218 results.FetchString(2, sAccountIdBuffer1, sizeof(sAccountIdBuffer1));
1219
1220 hAllHistory.WriteString(sNameBuffer1);
1221 hAllHistory.WriteString(sIPBuffer1);
1222 hAllHistory.WriteString(sAccountIdBuffer1);
1223 iAllHistoryAmount++;
1224 }
1225
1226 if (results.RowCount != 0)
1227 {
1228 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1229
1230 hAllHistory.Reset();
1231
1232 for (int i = 0; i < iAllHistoryAmount; i++)
1233 {
1234 if (i != 0)
1235 CPrintToChat(client, "{green}----------");
1236
1237 char sNameBuffer2[MAX_NAME_LENGTH];
1238 char sIPBuffer2[16];
1239 char sAccountIdBuffer2[32];
1240 hAllHistory.ReadString(sNameBuffer2, sizeof(sNameBuffer2));
1241 hAllHistory.ReadString(sIPBuffer2, sizeof(sIPBuffer2));
1242 hAllHistory.ReadString(sAccountIdBuffer2, sizeof(sAccountIdBuffer2));
1243
1244 int iAccountId = StringToInt(sAccountIdBuffer2);
1245
1246 char sSteamId2[32];
1247 char sSteamId3[32];
1248 char sSteamId64[64];
1249
1250 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
1251 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
1252 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
1253
1254 CPrintToChat(client, "{default}Name: {olive}%s", sNameBuffer2);
1255 CPrintToChat(client, "{default}SteamId2: {olive}%s"
1256 ..."\n{default}SteamId3: {olive}%s"
1257 ..."\n{default}SteamId64: {olive}%s", sSteamId2, sSteamId3, sSteamId64);
1258 CPrintToChat(client, "{default}IP: {olive}%s", sIPBuffer2);
1259 }
1260
1261 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1262 }
1263 else
1264 {
1265 if (iArgType == Arg_Name)
1266 {
1267 char query[256];
1268 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE Name LIKE '%s%' ORDER BY `Players`.`Date` DESC", arg);
1269
1270 DataPack hHistoryAllPack = new DataPack();
1271 hHistoryAllPack.WriteString(arg);
1272 hHistoryAllPack.WriteCell(userid);
1273
1274 g_hDatabase.Query(OnInfoQueryRetry2, query, hHistoryAllPack);
1275 }
1276 else
1277 CPrintToChat(client, "[{green}!{default}] {red}No player found");
1278 }
1279
1280 delete hAllHistory;
1281}
1282
1283public void OnHistoryAllQueryRetry2(Database db, DBResultSet results, const char[] sError, DataPack hHistoryAllPack)
1284{
1285 char arg[256];
1286 hHistoryAllPack.Reset();
1287 hHistoryAllPack.ReadString(arg, sizeof(arg));
1288 int userid = hHistoryAllPack.ReadCell();
1289 int iArgType = hHistoryAllPack.ReadCell();
1290 delete hHistoryAllPack;
1291
1292 int client = GetClientOfUserId(userid);
1293
1294 if(db == null || results == null || sError[0] != '\0')
1295 {
1296 LogError("Database query failure: %s", sError);
1297 return;
1298 }
1299
1300 DataPack hAllHistory = new DataPack();
1301 int iAllHistoryAmount;
1302
1303 while (results.FetchRow())
1304 {
1305 char sNameBuffer1[MAX_NAME_LENGTH];
1306 char sIPBuffer1[16];
1307 char sAccountIdBuffer1[32];
1308
1309 results.FetchString(0, sNameBuffer1, sizeof(sNameBuffer1));
1310 results.FetchString(1, sIPBuffer1, sizeof(sIPBuffer1));
1311 results.FetchString(2, sAccountIdBuffer1, sizeof(sAccountIdBuffer1));
1312
1313 hAllHistory.WriteString(sNameBuffer1);
1314 hAllHistory.WriteString(sIPBuffer1);
1315 hAllHistory.WriteString(sAccountIdBuffer1);
1316 iAllHistoryAmount++;
1317 }
1318
1319 if (results.RowCount != 0)
1320 {
1321 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1322
1323 hAllHistory.Reset();
1324
1325 for (int i = 0; i < iAllHistoryAmount; i++)
1326 {
1327 if (i != 0)
1328 CPrintToChat(client, "{green}----------");
1329
1330 char sNameBuffer2[MAX_NAME_LENGTH];
1331 char sIPBuffer2[16];
1332 char sAccountIdBuffer2[32];
1333 hAllHistory.ReadString(sNameBuffer2, sizeof(sNameBuffer2));
1334 hAllHistory.ReadString(sIPBuffer2, sizeof(sIPBuffer2));
1335 hAllHistory.ReadString(sAccountIdBuffer2, sizeof(sAccountIdBuffer2));
1336
1337 int iAccountId = StringToInt(sAccountIdBuffer2);
1338
1339 char sSteamId2[32];
1340 char sSteamId3[32];
1341 char sSteamId64[64];
1342
1343 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
1344 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
1345 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
1346
1347 CPrintToChat(client, "{default}Name: {olive}%s", sNameBuffer2);
1348 CPrintToChat(client, "{default}SteamId2: {olive}%s"
1349 ..."\n{default}SteamId3: {olive}%s"
1350 ..."\n{default}SteamId64: {olive}%s", sSteamId2, sSteamId3, sSteamId64);
1351 CPrintToChat(client, "{default}IP: {olive}%s", sIPBuffer2);
1352 }
1353
1354 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1355 }
1356 else
1357 {
1358 if (iArgType == Arg_Name)
1359 {
1360 char query[256];
1361 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE Name LIKE '%%%s%%' ORDER BY `Players`.`Date` DESC", arg);
1362
1363 DataPack hHistoryAllPack = new DataPack();
1364 hHistoryAllPack.WriteString(arg);
1365 hHistoryAllPack.WriteCell(userid);
1366
1367 g_hDatabase.Query(OnHistoryAllQueryRetry3, query, hHistoryAllPack);
1368 }
1369 else
1370 CPrintToChat(client, "[{green}!{default}] {red}No player found");
1371 }
1372
1373 delete hAllHistory;
1374}
1375
1376public void OnHistoryAllQueryRetry3(Database db, DBResultSet results, const char[] sError, DataPack hHistoryAllPack)
1377{
1378 char arg[256];
1379 hHistoryAllPack.Reset();
1380 hHistoryAllPack.ReadString(arg, sizeof(arg));
1381 int userid = hHistoryAllPack.ReadCell();
1382 delete hHistoryAllPack;
1383
1384 int client = GetClientOfUserId(userid);
1385
1386 if(db == null || results == null || sError[0] != '\0')
1387 {
1388 LogError("Database query failure: %s", sError);
1389 return;
1390 }
1391
1392 if(db == null || results == null || sError[0] != '\0')
1393 {
1394 LogError("Database query failure: %s", sError);
1395 return;
1396 }
1397
1398 DataPack hInfoQuery = new DataPack();
1399 int iRowAmount;
1400
1401 while (results.FetchRow())
1402 {
1403 char sNameBuffer1[MAX_NAME_LENGTH];
1404 char sIPBuffer1[16];
1405 char sAccountIdBuffer1[32];
1406
1407 results.FetchString(0, sNameBuffer1, sizeof(sNameBuffer1));
1408 results.FetchString(1, sIPBuffer1, sizeof(sIPBuffer1));
1409 results.FetchString(2, sAccountIdBuffer1, sizeof(sAccountIdBuffer1));
1410
1411 hInfoQuery.WriteString(sNameBuffer1);
1412 hInfoQuery.WriteString(sIPBuffer1);
1413 hInfoQuery.WriteString(sAccountIdBuffer1);
1414
1415 iRowAmount++;
1416 }
1417
1418 if (results.RowCount != 0)
1419 {
1420 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1421
1422 hInfoQuery.Reset();
1423
1424 for (int i = 0; i < iRowAmount; i++)
1425 {
1426 if (i != 0)
1427 CPrintToChat(client, "{green}----------");
1428
1429 char sNameBuffer2[MAX_NAME_LENGTH];
1430 char sIPBuffer2[16];
1431 char sAccountIdBuffer2[32];
1432 hInfoQuery.ReadString(sNameBuffer2, sizeof(sNameBuffer2));
1433 hInfoQuery.ReadString(sIPBuffer2, sizeof(sIPBuffer2));
1434 hInfoQuery.ReadString(sAccountIdBuffer2, sizeof(sAccountIdBuffer2));
1435
1436 int iAccountId = StringToInt(sAccountIdBuffer2);
1437
1438 char sSteamId2[32];
1439 char sSteamId3[32];
1440 char sSteamId64[64];
1441
1442 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
1443 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
1444 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
1445
1446 CPrintToChat(client, "{default}Name {green}- {olive}%s", sNameBuffer2);
1447 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
1448 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
1449 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
1450 CPrintToChat(client, "{default}IP {green}- {olive}%s", sIPBuffer2);
1451 }
1452
1453 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1454 }
1455 else
1456 CPrintToChat(client, "[{green}!{default}] {red}No player found");
1457
1458 delete hInfoQuery;
1459}
1460
1461public void SQL_CreateAndInsertQuery(Database db, DBResultSet results, const char[] sError, any data)
1462{
1463 if(db == null || results == null || sError[0] != '\0')
1464 {
1465 LogError("Database query failure: %s", sError);
1466 return;
1467 }
1468}
1469
1470public void OnHistoryQuery(Database db, DBResultSet results, const char[] sError, DataPack hNameOrIpPack)
1471{
1472 hNameOrIpPack.Reset();
1473 int userid = hNameOrIpPack.ReadCell();
1474 delete hNameOrIpPack;
1475
1476 int client = GetClientOfUserId(userid);
1477
1478 if(db == null || results == null || sError[0] != '\0')
1479 {
1480 LogError("Database query failure: %s", sError);
1481 return;
1482 }
1483
1484 if (!client)
1485 return;
1486
1487 DataPack hNameOrIpHistory = new DataPack();
1488 int iNameOrIpHistoryAmount;
1489
1490 while (results.FetchRow())
1491 {
1492 char sNameOrIpBuffer1[MAX_NAME_LENGTH];
1493 results.FetchString(0, sNameOrIpBuffer1, sizeof(sNameOrIpBuffer1));
1494 hNameOrIpHistory.WriteString(sNameOrIpBuffer1);
1495 iNameOrIpHistoryAmount++;
1496 }
1497
1498 if (results.RowCount > 0)
1499 {
1500 hNameOrIpHistory.Reset();
1501
1502 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1503
1504 for (int i = 0; i < iNameOrIpHistoryAmount; i++)
1505 {
1506 if (i != 0)
1507 CPrintToChat(client, "{green}----------");
1508
1509 char sNameOrIpBuffer2[MAX_NAME_LENGTH];
1510 hNameOrIpHistory.ReadString(sNameOrIpBuffer2, sizeof(sNameOrIpBuffer2));
1511 CPrintToChat(client, "{olive}%s", sNameOrIpBuffer2);
1512 }
1513
1514 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1515 }
1516 else
1517 CPrintToChat(client, "[{green}!{default}] {red}No player found");
1518
1519 delete hNameOrIpHistory;
1520}
1521
1522public void OnHistoryIpQuery(Database db, DBResultSet results, const char[] sError, DataPack hSteamIdPack)
1523{
1524 hSteamIdPack.Reset();
1525 int userid = hSteamIdPack.ReadCell();
1526 delete hSteamIdPack;
1527
1528 int client = GetClientOfUserId(userid);
1529
1530 if(db == null || results == null || sError[0] != '\0')
1531 {
1532 LogError("Database query failure: %s", sError);
1533 return;
1534 }
1535
1536 if (!client)
1537 return;
1538
1539 DataPack hSteamIdHistory = new DataPack();
1540 int iSteamIdHistoryAmount;
1541
1542 while (results.FetchRow())
1543 {
1544 char sNameBuffer1[32];
1545 results.FetchString(0, sNameBuffer1, sizeof(sNameBuffer1));
1546 hSteamIdHistory.WriteString(sNameBuffer1);
1547
1548 char sSteamIdBuffer1[32];
1549 results.FetchString(1, sSteamIdBuffer1, sizeof(sSteamIdBuffer1));
1550 hSteamIdHistory.WriteString(sSteamIdBuffer1);
1551
1552 iSteamIdHistoryAmount++;
1553 }
1554
1555 if (results.RowCount > 0)
1556 {
1557 hSteamIdHistory.Reset();
1558
1559 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1560
1561 for (int i = 0; i < iSteamIdHistoryAmount; i++)
1562 {
1563 if (i != 0)
1564 CPrintToChat(client, "{green}----------");
1565
1566 char sNameBuffer2[MAX_NAME_LENGTH];
1567 hSteamIdHistory.ReadString(sNameBuffer2, sizeof(sNameBuffer2));
1568 char sSteamIdBuffer2[MAX_NAME_LENGTH];
1569 hSteamIdHistory.ReadString(sSteamIdBuffer2, sizeof(sSteamIdBuffer2));
1570
1571 int iAccountId = StringToInt(sSteamIdBuffer2);
1572 char sSteamId2[32];
1573 char sSteamId3[32];
1574 char sSteamId64[64];
1575
1576 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
1577 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
1578 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
1579
1580 CPrintToChat(client, "Name: {olive}%s"
1581 ..."\n{default}SteamId2: {olive}%s"
1582 ..."\n{default}SteamId3: {olive}%s"
1583 ..."\n{default}SteamId64: {olive}%s", sNameBuffer2, sSteamId2, sSteamId3, sSteamId64);
1584 }
1585
1586 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1587 }
1588 else
1589 CPrintToChat(client, "[{green}!{default}] {red}No player found");
1590
1591 delete hSteamIdHistory;
1592}
1593
1594// SteamID Classification Functions
1595
1596int GetArgType(const char[] arg)
1597{
1598 if (StrContains(arg, "STEAM_") != -1)
1599 return Arg_Steam2ID;
1600
1601 if (StrContains(arg, "U:1:") != -1)
1602 return Arg_Steam3ID;
1603
1604 if (IsIP(arg))
1605 return Arg_IP;
1606
1607 if (StringToInt(arg))
1608 return strlen(arg) > 16 ? Arg_Steam64ID : Arg_Steam32ID;
1609
1610 return Arg_Name;
1611}
1612
1613bool IsIP(const char[] arg)
1614{
1615 int iDots;
1616
1617 for (int i = 0; i < strlen(arg); i++)
1618 {
1619 if (arg[i] == '.')
1620 iDots++;
1621 if (!IsCharNumeric(arg[i]) && arg[i] != '.')
1622 return false;
1623 }
1624
1625 if (iDots == 3)
1626 return true;
1627
1628 return false;
1629}
1630
1631// SteamID Convert Functions
1632
1633stock int GetAccountIdByAny(int client, const char[] arg, int iArgType)
1634{
1635 int iAccountId;
1636
1637 if (GetArgType(arg) == Arg_Steam2ID)
1638 {
1639 iAccountId = GetAccountIdBySteamId2(arg);
1640
1641 if (arg[7] == '\0')
1642 {
1643 CPrintToChat(client, "{blue}[{default}!{blue}] {default}If you are trying to use a {blue}SteamID2\n"
1644 ..."{blue}[{default}!{blue}] {default}(e.g.: {olive}STEAM_0:1:191972089{default})\n"
1645 ..."{blue}[{default}!{blue}] {default}Don't forget the {green}\"quotes\"{default}!");
1646 }
1647
1648 return iAccountId;
1649 }
1650 else if (GetArgType(arg) == Arg_Steam3ID)
1651 {
1652 iAccountId = GetAccountIdBySteamId3(arg);
1653
1654 return iAccountId;
1655 }
1656 else if (GetArgType(arg) == Arg_Steam32ID)
1657 {
1658 iAccountId = StringToInt(arg);
1659
1660 return iAccountId;
1661 }
1662 else if (GetArgType(arg) == Arg_Steam64ID)
1663 {
1664 iAccountId = GetAccountIdBySteamId64(arg);
1665
1666 return iAccountId;
1667 }
1668 else if (GetArgType(arg) == Arg_Name)
1669 {
1670 if (arg[0] == 'U' && arg[1] == '\0')
1671 {
1672 CPrintToChat(client, "{blue}[{default}!{blue}] {default}If you are trying to use a {blue}SteamID3\n"
1673 ..."{blue}[{default}!{blue}] {default}(e.g.: {olive}U:1:383944179{default})\n"
1674 ..."{blue}[{default}!{blue}] {default}Don't forget the {green}\"quotes\"{default}!");
1675 }
1676 else if (arg[0] == '[' && arg[1] == 'U' && arg[2] == '\0')
1677 {
1678 CPrintToChat(client, "{blue}[{default}!{blue}] {default}If you are trying to use a {blue}SteamID3\n"
1679 ..."{blue}[{default}!{blue}] {default}(e.g.: {olive}[U:1:383944179]{default})\n"
1680 ..."{blue}[{default}!{blue}] {default}Don't forget the {green}\"quotes\"{default}!");
1681 }
1682
1683 return 0;
1684 }
1685
1686 return 0;
1687}
1688
1689stock int GetAccountIdBySteamId2(const char[] sSteamID2)
1690{
1691 char sBuffer[3][12];
1692 ExplodeString(sSteamID2, ":", sBuffer, sizeof(sBuffer), sizeof(sBuffer[]));
1693
1694 return StringToInt(sBuffer[1]) + (StringToInt(sBuffer[2]) << 1);
1695}
1696
1697stock int GetAccountIdBySteamId3(const char[] sSteamID3)
1698{
1699 char sBuffer[19];
1700 strcopy(sBuffer, sizeof(sBuffer), sSteamID3);
1701
1702 int iBuffer = strlen(sBuffer) - 1;
1703
1704 if (sBuffer[iBuffer] == ']')
1705 sBuffer[iBuffer] = '\0';
1706
1707 return StringToInt(sBuffer[FindCharInString(sBuffer, ':', true) + 1]);
1708}
1709
1710stock int GetAccountIdBySteamId64(const char[] sSteam64)
1711{
1712 static const char sBase[] = "76561197960265728";
1713 int iBorrow = 0;
1714 char sAccount[17];
1715 int iTemp;
1716
1717 for (int i = 16; i >= 0; --i)
1718 {
1719 if (iBorrow > 0)
1720 {
1721 iTemp = (sSteam64[i] - '0') - 1;
1722
1723 if (iTemp >= (sBase[i] - '0'))
1724 {
1725 iBorrow = 0;
1726 sAccount[i] = (iTemp - ((sBase[i]) - '0')) + '0';
1727 }
1728 else
1729 {
1730 iBorrow = 1;
1731 sAccount[i] = ((iTemp + 10) - (sBase[i] - '0')) + '0';
1732 }
1733 }
1734 else
1735 {
1736 if ((sSteam64[i] - '0') >= (sBase[i] - '0'))
1737 {
1738 iBorrow = 0;
1739 sAccount[i] = ((sSteam64[i] - '0') - (sBase[i] - '0')) + '0';
1740 }
1741 else
1742 {
1743 iBorrow = 1;
1744 sAccount[i] = (((sSteam64[i] - '0') + 10) - (sBase[i] - '0') + '0');
1745 }
1746 }
1747 }
1748
1749 return StringToInt(sAccount);
1750}
1751
1752stock Action GetSteamId2ByAccountId(int iAccountId, char[] sSteamId2, int isizeof)
1753{
1754 EngineVersion e = GetEngineVersion();
1755 int iEngine = (e == Engine_Left4Dead || e == Engine_Left4Dead2 || Engine_CSGO);
1756 FormatEx(sSteamId2, isizeof, "STEAM_%i:%i:%i", iEngine, iAccountId % 2, iAccountId / 2);
1757}
1758
1759stock Action GetSteamId3ByAccountId(int iAccountId, char[] sSteamId3, int isizeof)
1760{
1761 FormatEx(sSteamId3, isizeof, "[U:1:%i]", iAccountId);
1762}
1763
1764stock void GetSteamId64ByAccountId(const int iAccountId, char[] sSteamId64, int isizeof)
1765{
1766 strcopy(sSteamId64, isizeof, "76561");
1767
1768 char sBuffer[11];
1769 FormatEx(sBuffer, sizeof(sBuffer), "%010u", iAccountId);
1770 FormatEx(sSteamId64[5], isizeof - 5, "%i", 1979 + 10 * (sBuffer[0] - '0') + sBuffer[1] - '0');
1771
1772 int iBuffer = StringToInt(sBuffer[2]) + 60265728;
1773
1774 if (iBuffer > 100000000)
1775 {
1776 iBuffer -= 100000000;
1777 ++sSteamId64[8];
1778
1779 for (int i = 8; i > 4; --i)
1780 {
1781 if ( sSteamId64[i] > '9')
1782 {
1783 sSteamId64[i] = '0';
1784 ++sSteamId64[i-1];
1785 }
1786 else
1787 {
1788 break;
1789 }
1790 }
1791 }
1792
1793 FormatEx(sSteamId64[9], isizeof - 9, "%i", iBuffer);
1794}