· 5 years ago · Feb 28, 2020, 06:08 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 hPlayerInfoPack.WriteString(arg);
815 hPlayerInfoPack.WriteCell(userid);
816
817 g_hDatabase.Query(OnInfoQueryRetry1, query, hPlayerInfoPack);
818 }
819 else
820 CPrintToChat(client, "[{green}!{default}] {red}No player found");
821 }
822
823 delete hInfoQuery;
824}
825
826public void OnInfoQueryRetry1(Database db, DBResultSet results, const char[] sError, DataPack hPlayerInfoPack)
827{
828 char arg[256];
829 hPlayerInfoPack.Reset();
830 hPlayerInfoPack.ReadString(arg, sizeof(arg));
831 int userid = hPlayerInfoPack.ReadCell();
832 delete hPlayerInfoPack;
833
834 int client = GetClientOfUserId(userid);
835
836 if(db == null || results == null || sError[0] != '\0')
837 {
838 LogError("Database query failure: %s", sError);
839 return;
840 }
841
842 DataPack hInfoQuery = new DataPack();
843 int iRowAmount;
844
845 while (results.FetchRow())
846 {
847 char sNameBuffer1[MAX_NAME_LENGTH];
848 char sIPBuffer1[16];
849 char sAccountIdBuffer1[32];
850
851 results.FetchString(0, sNameBuffer1, sizeof(sNameBuffer1));
852 results.FetchString(1, sIPBuffer1, sizeof(sIPBuffer1));
853 results.FetchString(2, sAccountIdBuffer1, sizeof(sAccountIdBuffer1));
854
855 hInfoQuery.WriteString(sNameBuffer1);
856 hInfoQuery.WriteString(sIPBuffer1);
857 hInfoQuery.WriteString(sAccountIdBuffer1);
858
859 iRowAmount++;
860 }
861
862 if (results.RowCount != 0)
863 {
864 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
865
866 hInfoQuery.Reset();
867
868 for (int i = 0; i < iRowAmount; i++)
869 {
870 if (i != 0)
871 CPrintToChat(client, "{green}----------");
872
873 char sNameBuffer2[MAX_NAME_LENGTH];
874 char sIPBuffer2[16];
875 char sAccountIdBuffer2[32];
876 hInfoQuery.ReadString(sNameBuffer2, sizeof(sNameBuffer2));
877 hInfoQuery.ReadString(sIPBuffer2, sizeof(sIPBuffer2));
878 hInfoQuery.ReadString(sAccountIdBuffer2, sizeof(sAccountIdBuffer2));
879
880 int iAccountId = StringToInt(sAccountIdBuffer2);
881
882 char sSteamId2[32];
883 char sSteamId3[32];
884 char sSteamId64[64];
885
886 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
887 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
888 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
889
890 CPrintToChat(client, "{default}Name {green}- {olive}%s", sNameBuffer2);
891 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
892 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
893 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
894 CPrintToChat(client, "{default}IP {green}- {olive}%s", sIPBuffer2);
895 }
896
897 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
898 }
899 else
900 {
901 char query[256];
902 g_hDatabase.Format(query, sizeof(query), "SELECT MAX (Date), Name, IP, AccountID FROM Players WHERE Name LIKE '%s%' GROUP BY `Players`.`AccountID`", arg);
903
904 hPlayerInfoPack.WriteString(arg);
905 hPlayerInfoPack.WriteCell(userid);
906
907 g_hDatabase.Query(OnInfoQueryRetry2, query, hPlayerInfoPack);
908 }
909
910 delete hInfoQuery;
911}
912
913public void OnInfoQueryRetry2(Database db, DBResultSet results, const char[] sError, DataPack hPlayerInfoPack)
914{
915 char arg[256];
916 hPlayerInfoPack.Reset();
917 hPlayerInfoPack.ReadString(arg, sizeof(arg));
918 int userid = hPlayerInfoPack.ReadCell();
919 delete hPlayerInfoPack;
920
921 int client = GetClientOfUserId(userid);
922
923 if(db == null || results == null || sError[0] != '\0')
924 {
925 LogError("Database query failure: %s", sError);
926 return;
927 }
928
929 if(db == null || results == null || sError[0] != '\0')
930 {
931 LogError("Database query failure: %s", sError);
932 return;
933 }
934
935 DataPack hInfoQuery = new DataPack();
936 int iRowAmount;
937
938 while (results.FetchRow())
939 {
940 char sNameBuffer1[MAX_NAME_LENGTH];
941 char sIPBuffer1[16];
942 char sAccountIdBuffer1[32];
943
944 results.FetchString(0, sNameBuffer1, sizeof(sNameBuffer1));
945 results.FetchString(1, sIPBuffer1, sizeof(sIPBuffer1));
946 results.FetchString(2, sAccountIdBuffer1, sizeof(sAccountIdBuffer1));
947
948 hInfoQuery.WriteString(sNameBuffer1);
949 hInfoQuery.WriteString(sIPBuffer1);
950 hInfoQuery.WriteString(sAccountIdBuffer1);
951
952 iRowAmount++;
953 }
954
955 if (results.RowCount != 0)
956 {
957 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
958
959 hInfoQuery.Reset();
960
961 for (int i = 0; i < iRowAmount; i++)
962 {
963 if (i != 0)
964 CPrintToChat(client, "{green}----------");
965
966 char sNameBuffer2[MAX_NAME_LENGTH];
967 char sIPBuffer2[16];
968 char sAccountIdBuffer2[32];
969 hInfoQuery.ReadString(sNameBuffer2, sizeof(sNameBuffer2));
970 hInfoQuery.ReadString(sIPBuffer2, sizeof(sIPBuffer2));
971 hInfoQuery.ReadString(sAccountIdBuffer2, sizeof(sAccountIdBuffer2));
972
973 int iAccountId = StringToInt(sAccountIdBuffer2);
974
975 char sSteamId2[32];
976 char sSteamId3[32];
977 char sSteamId64[64];
978
979 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
980 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
981 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
982
983 CPrintToChat(client, "{default}Name {green}- {olive}%s", sNameBuffer2);
984 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
985 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
986 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
987 CPrintToChat(client, "{default}IP {green}- {olive}%s", sIPBuffer2);
988 }
989
990 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
991 }
992 else
993 {
994 char query[256];
995 g_hDatabase.Format(query, sizeof(query), "SELECT MAX (Date), Name, IP, AccountID FROM Players WHERE Name LIKE '%%%s%%' GROUP BY `Players`.`AccountID`", arg);
996
997 hPlayerInfoPack.WriteString(arg);
998 hPlayerInfoPack.WriteCell(userid);
999
1000 g_hDatabase.Query(OnInfoQueryRetry3, query, hPlayerInfoPack);
1001 }
1002
1003 delete hInfoQuery;
1004}
1005
1006public void OnInfoQueryRetry3(Database db, DBResultSet results, const char[] sError, DataPack hPlayerInfoPack)
1007{
1008 char arg[256];
1009 hPlayerInfoPack.Reset();
1010 hPlayerInfoPack.ReadString(arg, sizeof(arg));
1011 int userid = hPlayerInfoPack.ReadCell();
1012 delete hPlayerInfoPack;
1013
1014 int client = GetClientOfUserId(userid);
1015
1016 if(db == null || results == null || sError[0] != '\0')
1017 {
1018 LogError("Database query failure: %s", sError);
1019 return;
1020 }
1021
1022 if(db == null || results == null || sError[0] != '\0')
1023 {
1024 LogError("Database query failure: %s", sError);
1025 return;
1026 }
1027
1028 DataPack hInfoQuery = new DataPack();
1029 int iRowAmount;
1030
1031 while (results.FetchRow())
1032 {
1033 char sNameBuffer1[MAX_NAME_LENGTH];
1034 char sIPBuffer1[16];
1035 char sAccountIdBuffer1[32];
1036
1037 results.FetchString(0, sNameBuffer1, sizeof(sNameBuffer1));
1038 results.FetchString(1, sIPBuffer1, sizeof(sIPBuffer1));
1039 results.FetchString(2, sAccountIdBuffer1, sizeof(sAccountIdBuffer1));
1040
1041 hInfoQuery.WriteString(sNameBuffer1);
1042 hInfoQuery.WriteString(sIPBuffer1);
1043 hInfoQuery.WriteString(sAccountIdBuffer1);
1044
1045 iRowAmount++;
1046 }
1047
1048 if (results.RowCount != 0)
1049 {
1050 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1051
1052 hInfoQuery.Reset();
1053
1054 for (int i = 0; i < iRowAmount; i++)
1055 {
1056 if (i != 0)
1057 CPrintToChat(client, "{green}----------");
1058
1059 char sNameBuffer2[MAX_NAME_LENGTH];
1060 char sIPBuffer2[16];
1061 char sAccountIdBuffer2[32];
1062 hInfoQuery.ReadString(sNameBuffer2, sizeof(sNameBuffer2));
1063 hInfoQuery.ReadString(sIPBuffer2, sizeof(sIPBuffer2));
1064 hInfoQuery.ReadString(sAccountIdBuffer2, sizeof(sAccountIdBuffer2));
1065
1066 int iAccountId = StringToInt(sAccountIdBuffer2);
1067
1068 char sSteamId2[32];
1069 char sSteamId3[32];
1070 char sSteamId64[64];
1071
1072 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
1073 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
1074 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
1075
1076 CPrintToChat(client, "{default}Name {green}- {olive}%s", sNameBuffer2);
1077 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
1078 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
1079 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
1080 CPrintToChat(client, "{default}IP {green}- {olive}%s", sIPBuffer2);
1081 }
1082
1083 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1084 }
1085 else
1086 CPrintToChat(client, "[{green}!{default}] {red}No player found");
1087
1088 delete hInfoQuery;
1089}
1090
1091public void OnHistoryAllQuery(Database db, DBResultSet results, const char[] sError, DataPack hHistoryAllPack)
1092{
1093 char arg[256];
1094 hHistoryAllPack.Reset();
1095 hHistoryAllPack.ReadString(arg, sizeof(arg));
1096 int userid = hHistoryAllPack.ReadCell();
1097 int iArgType = hHistoryAllPack.ReadCell();
1098 delete hHistoryAllPack;
1099
1100 int client = GetClientOfUserId(userid);
1101
1102 if(db == null || results == null || sError[0] != '\0')
1103 {
1104 LogError("Database query failure: %s", sError);
1105 return;
1106 }
1107
1108 if (!client)
1109 return;
1110
1111 DataPack hAllHistory = new DataPack();
1112 int iAllHistoryAmount;
1113
1114 while (results.FetchRow())
1115 {
1116 char sNameBuffer1[MAX_NAME_LENGTH];
1117 char sIPBuffer1[16];
1118 char sAccountIdBuffer1[32];
1119
1120 results.FetchString(0, sNameBuffer1, sizeof(sNameBuffer1));
1121 results.FetchString(1, sIPBuffer1, sizeof(sIPBuffer1));
1122 results.FetchString(2, sAccountIdBuffer1, sizeof(sAccountIdBuffer1));
1123
1124 hAllHistory.WriteString(sNameBuffer1);
1125 hAllHistory.WriteString(sIPBuffer1);
1126 hAllHistory.WriteString(sAccountIdBuffer1);
1127 iAllHistoryAmount++;
1128 }
1129
1130 if (results.RowCount != 0)
1131 {
1132 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1133
1134 hAllHistory.Reset();
1135
1136 for (int i = 0; i < iAllHistoryAmount; i++)
1137 {
1138 if (i != 0)
1139 CPrintToChat(client, "{green}----------");
1140
1141 char sNameBuffer2[MAX_NAME_LENGTH];
1142 char sIPBuffer2[16];
1143 char sAccountIdBuffer2[32];
1144 hAllHistory.ReadString(sNameBuffer2, sizeof(sNameBuffer2));
1145 hAllHistory.ReadString(sIPBuffer2, sizeof(sIPBuffer2));
1146 hAllHistory.ReadString(sAccountIdBuffer2, sizeof(sAccountIdBuffer2));
1147
1148 int iAccountId = StringToInt(sAccountIdBuffer2);
1149
1150 char sSteamId2[32];
1151 char sSteamId3[32];
1152 char sSteamId64[64];
1153
1154 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
1155 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
1156 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
1157
1158 CPrintToChat(client, "{default}Name: {olive}%s", sNameBuffer2);
1159 CPrintToChat(client, "{default}SteamId2: {olive}%s"
1160 ..."\n{default}SteamId3: {olive}%s"
1161 ..."\n{default}SteamId64: {olive}%s", sSteamId2, sSteamId3, sSteamId64);
1162 CPrintToChat(client, "{default}IP: {olive}%s", sIPBuffer2);
1163 }
1164
1165 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1166 }
1167 else
1168 {
1169 if (iArgType == Arg_Name)
1170 {
1171 char query[256];
1172 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE Name LIKE '%%%s' ORDER BY `Players`.`Date` DESC", arg);
1173
1174 hHistoryAllPack.WriteString(arg);
1175 hHistoryAllPack.WriteCell(userid);
1176
1177 g_hDatabase.Query(OnInfoQueryRetry1, query, hHistoryAllPack);
1178 }
1179 else
1180 CPrintToChat(client, "[{green}!{default}] {red}No player found");
1181 }
1182
1183 delete hAllHistory;
1184}
1185
1186public void OnHistoryAllQueryRetry1(Database db, DBResultSet results, const char[] sError, DataPack hHistoryAllPack)
1187{
1188 char arg[256];
1189 hHistoryAllPack.Reset();
1190 hHistoryAllPack.ReadString(arg, sizeof(arg));
1191 int userid = hHistoryAllPack.ReadCell();
1192 int iArgType = hHistoryAllPack.ReadCell();
1193 delete hHistoryAllPack;
1194
1195 int client = GetClientOfUserId(userid);
1196
1197 if(db == null || results == null || sError[0] != '\0')
1198 {
1199 LogError("Database query failure: %s", sError);
1200 return;
1201 }
1202
1203 DataPack hAllHistory = new DataPack();
1204 int iAllHistoryAmount;
1205
1206 while (results.FetchRow())
1207 {
1208 char sNameBuffer1[MAX_NAME_LENGTH];
1209 char sIPBuffer1[16];
1210 char sAccountIdBuffer1[32];
1211
1212 results.FetchString(0, sNameBuffer1, sizeof(sNameBuffer1));
1213 results.FetchString(1, sIPBuffer1, sizeof(sIPBuffer1));
1214 results.FetchString(2, sAccountIdBuffer1, sizeof(sAccountIdBuffer1));
1215
1216 hAllHistory.WriteString(sNameBuffer1);
1217 hAllHistory.WriteString(sIPBuffer1);
1218 hAllHistory.WriteString(sAccountIdBuffer1);
1219 iAllHistoryAmount++;
1220 }
1221
1222 if (results.RowCount != 0)
1223 {
1224 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1225
1226 hAllHistory.Reset();
1227
1228 for (int i = 0; i < iAllHistoryAmount; i++)
1229 {
1230 if (i != 0)
1231 CPrintToChat(client, "{green}----------");
1232
1233 char sNameBuffer2[MAX_NAME_LENGTH];
1234 char sIPBuffer2[16];
1235 char sAccountIdBuffer2[32];
1236 hAllHistory.ReadString(sNameBuffer2, sizeof(sNameBuffer2));
1237 hAllHistory.ReadString(sIPBuffer2, sizeof(sIPBuffer2));
1238 hAllHistory.ReadString(sAccountIdBuffer2, sizeof(sAccountIdBuffer2));
1239
1240 int iAccountId = StringToInt(sAccountIdBuffer2);
1241
1242 char sSteamId2[32];
1243 char sSteamId3[32];
1244 char sSteamId64[64];
1245
1246 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
1247 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
1248 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
1249
1250 CPrintToChat(client, "{default}Name: {olive}%s", sNameBuffer2);
1251 CPrintToChat(client, "{default}SteamId2: {olive}%s"
1252 ..."\n{default}SteamId3: {olive}%s"
1253 ..."\n{default}SteamId64: {olive}%s", sSteamId2, sSteamId3, sSteamId64);
1254 CPrintToChat(client, "{default}IP: {olive}%s", sIPBuffer2);
1255 }
1256
1257 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1258 }
1259 else
1260 {
1261 if (iArgType == Arg_Name)
1262 {
1263 char query[256];
1264 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE Name LIKE '%s%' ORDER BY `Players`.`Date` DESC", arg);
1265
1266 hHistoryAllPack.WriteString(arg);
1267 hHistoryAllPack.WriteCell(userid);
1268
1269 g_hDatabase.Query(OnInfoQueryRetry2, query, hHistoryAllPack);
1270 }
1271 else
1272 CPrintToChat(client, "[{green}!{default}] {red}No player found");
1273 }
1274
1275 delete hAllHistory;
1276}
1277
1278public void OnHistoryAllQueryRetry2(Database db, DBResultSet results, const char[] sError, DataPack hHistoryAllPack)
1279{
1280 char arg[256];
1281 hHistoryAllPack.Reset();
1282 hHistoryAllPack.ReadString(arg, sizeof(arg));
1283 int userid = hHistoryAllPack.ReadCell();
1284 int iArgType = hHistoryAllPack.ReadCell();
1285 delete hHistoryAllPack;
1286
1287 int client = GetClientOfUserId(userid);
1288
1289 if(db == null || results == null || sError[0] != '\0')
1290 {
1291 LogError("Database query failure: %s", sError);
1292 return;
1293 }
1294
1295 DataPack hAllHistory = new DataPack();
1296 int iAllHistoryAmount;
1297
1298 while (results.FetchRow())
1299 {
1300 char sNameBuffer1[MAX_NAME_LENGTH];
1301 char sIPBuffer1[16];
1302 char sAccountIdBuffer1[32];
1303
1304 results.FetchString(0, sNameBuffer1, sizeof(sNameBuffer1));
1305 results.FetchString(1, sIPBuffer1, sizeof(sIPBuffer1));
1306 results.FetchString(2, sAccountIdBuffer1, sizeof(sAccountIdBuffer1));
1307
1308 hAllHistory.WriteString(sNameBuffer1);
1309 hAllHistory.WriteString(sIPBuffer1);
1310 hAllHistory.WriteString(sAccountIdBuffer1);
1311 iAllHistoryAmount++;
1312 }
1313
1314 if (results.RowCount != 0)
1315 {
1316 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1317
1318 hAllHistory.Reset();
1319
1320 for (int i = 0; i < iAllHistoryAmount; i++)
1321 {
1322 if (i != 0)
1323 CPrintToChat(client, "{green}----------");
1324
1325 char sNameBuffer2[MAX_NAME_LENGTH];
1326 char sIPBuffer2[16];
1327 char sAccountIdBuffer2[32];
1328 hAllHistory.ReadString(sNameBuffer2, sizeof(sNameBuffer2));
1329 hAllHistory.ReadString(sIPBuffer2, sizeof(sIPBuffer2));
1330 hAllHistory.ReadString(sAccountIdBuffer2, sizeof(sAccountIdBuffer2));
1331
1332 int iAccountId = StringToInt(sAccountIdBuffer2);
1333
1334 char sSteamId2[32];
1335 char sSteamId3[32];
1336 char sSteamId64[64];
1337
1338 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
1339 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
1340 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
1341
1342 CPrintToChat(client, "{default}Name: {olive}%s", sNameBuffer2);
1343 CPrintToChat(client, "{default}SteamId2: {olive}%s"
1344 ..."\n{default}SteamId3: {olive}%s"
1345 ..."\n{default}SteamId64: {olive}%s", sSteamId2, sSteamId3, sSteamId64);
1346 CPrintToChat(client, "{default}IP: {olive}%s", sIPBuffer2);
1347 }
1348
1349 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1350 }
1351 else
1352 {
1353 if (iArgType == Arg_Name)
1354 {
1355 char query[256];
1356 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP, AccountID FROM Players WHERE Name LIKE '%%%s%%' ORDER BY `Players`.`Date` DESC", arg);
1357
1358 hHistoryAllPack.WriteString(arg);
1359 hHistoryAllPack.WriteCell(userid);
1360
1361 g_hDatabase.Query(OnInfoQueryRetry2, query, hHistoryAllPack);
1362 }
1363 else
1364 CPrintToChat(client, "[{green}!{default}] {red}No player found");
1365 }
1366
1367 delete hAllHistory;
1368}
1369
1370public void SQL_CreateAndInsertQuery(Database db, DBResultSet results, const char[] sError, any data)
1371{
1372 if(db == null || results == null || sError[0] != '\0')
1373 {
1374 LogError("Database query failure: %s", sError);
1375 return;
1376 }
1377}
1378
1379public void OnHistoryQuery(Database db, DBResultSet results, const char[] sError, DataPack hNameOrIpPack)
1380{
1381 hNameOrIpPack.Reset();
1382 int userid = hNameOrIpPack.ReadCell();
1383 delete hNameOrIpPack;
1384
1385 int client = GetClientOfUserId(userid);
1386
1387 if(db == null || results == null || sError[0] != '\0')
1388 {
1389 LogError("Database query failure: %s", sError);
1390 return;
1391 }
1392
1393 if (!client)
1394 return;
1395
1396 DataPack hNameOrIpHistory = new DataPack();
1397 int iNameOrIpHistoryAmount;
1398
1399 while (results.FetchRow())
1400 {
1401 char sNameOrIpBuffer1[MAX_NAME_LENGTH];
1402 results.FetchString(0, sNameOrIpBuffer1, sizeof(sNameOrIpBuffer1));
1403 hNameOrIpHistory.WriteString(sNameOrIpBuffer1);
1404 iNameOrIpHistoryAmount++;
1405 }
1406
1407 if (results.RowCount > 0)
1408 {
1409 hNameOrIpHistory.Reset();
1410
1411 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1412
1413 for (int i = 0; i < iNameOrIpHistoryAmount; i++)
1414 {
1415 if (i != 0)
1416 CPrintToChat(client, "{green}----------");
1417
1418 char sNameOrIpBuffer2[MAX_NAME_LENGTH];
1419 hNameOrIpHistory.ReadString(sNameOrIpBuffer2, sizeof(sNameOrIpBuffer2));
1420 CPrintToChat(client, "{olive}%s", sNameOrIpBuffer2);
1421 }
1422
1423 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1424 }
1425 else
1426 CPrintToChat(client, "[{green}!{default}] {red}No player found");
1427
1428 delete hNameOrIpHistory;
1429}
1430
1431public void OnHistoryIpQuery(Database db, DBResultSet results, const char[] sError, DataPack hSteamIdPack)
1432{
1433 hSteamIdPack.Reset();
1434 int userid = hSteamIdPack.ReadCell();
1435 delete hSteamIdPack;
1436
1437 int client = GetClientOfUserId(userid);
1438
1439 if(db == null || results == null || sError[0] != '\0')
1440 {
1441 LogError("Database query failure: %s", sError);
1442 return;
1443 }
1444
1445 if (!client)
1446 return;
1447
1448 DataPack hSteamIdHistory = new DataPack();
1449 int iSteamIdHistoryAmount;
1450
1451 while (results.FetchRow())
1452 {
1453 char sNameBuffer1[32];
1454 results.FetchString(0, sNameBuffer1, sizeof(sNameBuffer1));
1455 hSteamIdHistory.WriteString(sNameBuffer1);
1456
1457 char sSteamIdBuffer1[32];
1458 results.FetchString(1, sSteamIdBuffer1, sizeof(sSteamIdBuffer1));
1459 hSteamIdHistory.WriteString(sSteamIdBuffer1);
1460
1461 iSteamIdHistoryAmount++;
1462 }
1463
1464 if (results.RowCount > 0)
1465 {
1466 hSteamIdHistory.Reset();
1467
1468 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1469
1470 for (int i = 0; i < iSteamIdHistoryAmount; i++)
1471 {
1472 if (i != 0)
1473 CPrintToChat(client, "{green}----------");
1474
1475 char sNameBuffer2[MAX_NAME_LENGTH];
1476 hSteamIdHistory.ReadString(sNameBuffer2, sizeof(sNameBuffer2));
1477 char sSteamIdBuffer2[MAX_NAME_LENGTH];
1478 hSteamIdHistory.ReadString(sSteamIdBuffer2, sizeof(sSteamIdBuffer2));
1479
1480 int iAccountId = StringToInt(sSteamIdBuffer2);
1481 char sSteamId2[32];
1482 char sSteamId3[32];
1483 char sSteamId64[64];
1484
1485 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
1486 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
1487 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
1488
1489 CPrintToChat(client, "Name: {olive}%s"
1490 ..."\n{default}SteamId2: {olive}%s"
1491 ..."\n{default}SteamId3: {olive}%s"
1492 ..."\n{default}SteamId64: {olive}%s", sNameBuffer2, sSteamId2, sSteamId3, sSteamId64);
1493 }
1494
1495 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
1496 }
1497 else
1498 CPrintToChat(client, "[{green}!{default}] {red}No player found");
1499
1500 delete hSteamIdHistory;
1501}
1502
1503// SteamID Classification Functions
1504
1505int GetArgType(const char[] arg)
1506{
1507 if (StrContains(arg, "STEAM_") != -1)
1508 return Arg_Steam2ID;
1509
1510 if (StrContains(arg, "U:1:") != -1)
1511 return Arg_Steam3ID;
1512
1513 if (IsIP(arg))
1514 return Arg_IP;
1515
1516 if (StringToInt(arg))
1517 return strlen(arg) > 16 ? Arg_Steam64ID : Arg_Steam32ID;
1518
1519 return Arg_Name;
1520}
1521
1522bool IsIP(const char[] arg)
1523{
1524 int iDots;
1525
1526 for (int i = 0; i < strlen(arg); i++)
1527 {
1528 if (arg[i] == '.')
1529 iDots++;
1530 if (!IsCharNumeric(arg[i]) && arg[i] != '.')
1531 return false;
1532 }
1533
1534 if (iDots == 3)
1535 return true;
1536
1537 return false;
1538}
1539
1540// SteamID Convert Functions
1541
1542stock int GetAccountIdByAny(int client, const char[] arg, int iArgType)
1543{
1544 int iAccountId;
1545
1546 if (GetArgType(arg) == Arg_Steam2ID)
1547 {
1548 iAccountId = GetAccountIdBySteamId2(arg);
1549
1550 if (arg[7] == '\0')
1551 {
1552 CPrintToChat(client, "{blue}[{default}!{blue}] {default}If you are trying to use a {blue}SteamID2\n"
1553 ..."{blue}[{default}!{blue}] {default}(e.g.: {olive}STEAM_0:1:191972089{default})\n"
1554 ..."{blue}[{default}!{blue}] {default}Don't forget the {green}\"quotes\"{default}!");
1555 }
1556
1557 return iAccountId;
1558 }
1559 else if (GetArgType(arg) == Arg_Steam3ID)
1560 {
1561 iAccountId = GetAccountIdBySteamId3(arg);
1562
1563 return iAccountId;
1564 }
1565 else if (GetArgType(arg) == Arg_Steam32ID)
1566 {
1567 iAccountId = StringToInt(arg);
1568
1569 return iAccountId;
1570 }
1571 else if (GetArgType(arg) == Arg_Steam64ID)
1572 {
1573 iAccountId = GetAccountIdBySteamId64(arg);
1574
1575 return iAccountId;
1576 }
1577 else if (GetArgType(arg) == Arg_Name)
1578 {
1579 if (arg[0] == 'U' && arg[1] == '\0')
1580 {
1581 CPrintToChat(client, "{blue}[{default}!{blue}] {default}If you are trying to use a {blue}SteamID3\n"
1582 ..."{blue}[{default}!{blue}] {default}(e.g.: {olive}U:1:383944179{default})\n"
1583 ..."{blue}[{default}!{blue}] {default}Don't forget the {green}\"quotes\"{default}!");
1584 }
1585 else if (arg[0] == '[' && arg[1] == 'U' && arg[2] == '\0')
1586 {
1587 CPrintToChat(client, "{blue}[{default}!{blue}] {default}If you are trying to use a {blue}SteamID3\n"
1588 ..."{blue}[{default}!{blue}] {default}(e.g.: {olive}[U:1:383944179]{default})\n"
1589 ..."{blue}[{default}!{blue}] {default}Don't forget the {green}\"quotes\"{default}!");
1590 }
1591
1592 return 0;
1593 }
1594
1595 return 0;
1596}
1597
1598stock int GetAccountIdBySteamId2(const char[] sSteamID2)
1599{
1600 char sBuffer[3][12];
1601 ExplodeString(sSteamID2, ":", sBuffer, sizeof(sBuffer), sizeof(sBuffer[]));
1602
1603 return StringToInt(sBuffer[1]) + (StringToInt(sBuffer[2]) << 1);
1604}
1605
1606stock int GetAccountIdBySteamId3(const char[] sSteamID3)
1607{
1608 char sBuffer[19];
1609 strcopy(sBuffer, sizeof(sBuffer), sSteamID3);
1610
1611 int iBuffer = strlen(sBuffer) - 1;
1612
1613 if (sBuffer[iBuffer] == ']')
1614 sBuffer[iBuffer] = '\0';
1615
1616 return StringToInt(sBuffer[FindCharInString(sBuffer, ':', true) + 1]);
1617}
1618
1619stock int GetAccountIdBySteamId64(const char[] sSteam64)
1620{
1621 static const char sBase[] = "76561197960265728";
1622 int iBorrow = 0;
1623 char sAccount[17];
1624 int iTemp;
1625
1626 for (int i = 16; i >= 0; --i)
1627 {
1628 if (iBorrow > 0)
1629 {
1630 iTemp = (sSteam64[i] - '0') - 1;
1631
1632 if (iTemp >= (sBase[i] - '0'))
1633 {
1634 iBorrow = 0;
1635 sAccount[i] = (iTemp - ((sBase[i]) - '0')) + '0';
1636 }
1637 else
1638 {
1639 iBorrow = 1;
1640 sAccount[i] = ((iTemp + 10) - (sBase[i] - '0')) + '0';
1641 }
1642 }
1643 else
1644 {
1645 if ((sSteam64[i] - '0') >= (sBase[i] - '0'))
1646 {
1647 iBorrow = 0;
1648 sAccount[i] = ((sSteam64[i] - '0') - (sBase[i] - '0')) + '0';
1649 }
1650 else
1651 {
1652 iBorrow = 1;
1653 sAccount[i] = (((sSteam64[i] - '0') + 10) - (sBase[i] - '0') + '0');
1654 }
1655 }
1656 }
1657
1658 return StringToInt(sAccount);
1659}
1660
1661stock Action GetSteamId2ByAccountId(int iAccountId, char[] sSteamId2, int isizeof)
1662{
1663 EngineVersion e = GetEngineVersion();
1664 int iEngine = (e == Engine_Left4Dead || e == Engine_Left4Dead2 || Engine_CSGO);
1665 FormatEx(sSteamId2, isizeof, "STEAM_%i:%i:%i", iEngine, iAccountId % 2, iAccountId / 2);
1666}
1667
1668stock Action GetSteamId3ByAccountId(int iAccountId, char[] sSteamId3, int isizeof)
1669{
1670 FormatEx(sSteamId3, isizeof, "[U:1:%i]", iAccountId);
1671}
1672
1673stock void GetSteamId64ByAccountId(const int iAccountId, char[] sSteamId64, int isizeof)
1674{
1675 strcopy(sSteamId64, isizeof, "76561");
1676
1677 char sBuffer[11];
1678 FormatEx(sBuffer, sizeof(sBuffer), "%010u", iAccountId);
1679 FormatEx(sSteamId64[5], isizeof - 5, "%i", 1979 + 10 * (sBuffer[0] - '0') + sBuffer[1] - '0');
1680
1681 int iBuffer = StringToInt(sBuffer[2]) + 60265728;
1682
1683 if (iBuffer > 100000000)
1684 {
1685 iBuffer -= 100000000;
1686 ++sSteamId64[8];
1687
1688 for (int i = 8; i > 4; --i)
1689 {
1690 if ( sSteamId64[i] > '9')
1691 {
1692 sSteamId64[i] = '0';
1693 ++sSteamId64[i-1];
1694 }
1695 else
1696 {
1697 break;
1698 }
1699 }
1700 }
1701
1702 FormatEx(sSteamId64[9], isizeof - 9, "%i", iBuffer);
1703}