· 5 years ago · Feb 23, 2020, 11:26 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 RegAdminCmd("sm_playerinfo", OnPlayerInfoCMD, ADMFLAG_UNBAN, "Shows SteamID2, SteamID3, SteamID64 and last seen IP of a given SteamID of any type, IP or nickname.");
50
51 /*
52
53 RegAdminCmd("sm_nameinfo", OnNameInfoCMD, ADMFLAG_UNBAN, "Shows SteamID2, SteamID3, SteamID64 and last seen IP explicitly searching with a nickname.");
54 RegAdminCmd("sm_steamid2info", OnSteamId2InfoCMD, ADMFLAG_UNBAN, "Shows SteamID3, SteamID64 and last seen IP explicitly searching with a SteamID2.");
55 RegAdminCmd("sm_steamid3info", OnSteamId3InfoCMD, ADMFLAG_UNBAN, "Shows SteamID2, SteamID64 and last seen IP explicitly searching with a SteamID3.");
56 RegAdminCmd("sm_steamid64info", OnSteamId64InfoCMD, ADMFLAG_UNBAN, "Shows SteamID2, SteamID3 and last seen IP explicitly searching with a SteamID64.");
57 RegAdminCmd("sm_ipinfo", OnIpInfoCMD, ADMFLAG_UNBAN, "Shows SteamID2, SteamID3, SteamID64 and last seen IP explicitly searching with an IP.");
58
59
60 RegAdminCmd("sm_playerinfo", OnPlayerInfoCMD, ADMFLAG_UNBAN, "Shows SteamID, Steam64ID and last seen IP of a given player name (must be connected)");
61 RegAdminCmd("sm_nameinfo", OnNameInfoCMD, ADMFLAG_UNBAN, "Shows SteamID, Steam64ID and last seen IP of a given player name");
62 RegAdminCmd("sm_steamidinfo", OnSteamIdInfoCMD, ADMFLAG_UNBAN, "Shows Steam64ID, last seen IP and last seen name of a given SteamID");
63 RegAdminCmd("sm_ipinfo", OnIpInfoCMD, ADMFLAG_UNBAN, "Shows all SteamID of a given IP");
64
65
66 RegAdminCmd("sm_playernames", OnPlayerNamesCMD, ADMFLAG_UNBAN, "Shows all seen names of a given player name (must be connected)");
67 RegAdminCmd("sm_steamidnames", OnSteamIdNamesCMD, ADMFLAG_UNBAN, "Shows all seen names of a given SteamID");
68 RegAdminCmd("sm_playerips", OnPlayerIpsCMD, ADMFLAG_UNBAN, "Shows all seen IPs of a given player name (must be connected)");
69 RegAdminCmd("sm_steamidips", OnSteamIdIpsCMD, ADMFLAG_UNBAN, "Shows all seen IPs of a given SteamID");
70 */
71
72 Database.Connect(SQL_FirstConnect, "PlayerRecord");
73}
74
75public void SQL_FirstConnect(Database db, const char[] error, any data)
76{
77 if (db == null || error[0] != '\0')
78 {
79 LogError("Database connect failure: %s", error);
80 return;
81 }
82
83 g_hDatabase = db;
84
85 g_hDatabase.SetCharset("utf8mb4");
86
87 g_hDatabase.Query(SQL_CreateAndInsertQuery, "CREATE TABLE IF NOT EXISTS `Players`"
88 ..."(`Date` INT(1) UNSIGNED NOT NULL DEFAULT unix_timestamp(), "
89 ..."`AccountID` INT(1) NOT NULL, "
90 ..."`IP` varchar(16) NOT NULL, "
91 ..."`Name` varchar(256) NOT NULL COLLATE 'utf8mb4_unicode_ci', "
92 ..."COLLATE='utf8mb4_unicode_ci' "
93 ..."ENGINE=InnoDB "
94 ..."ROW_FORMAT=COMPRESSED;");
95}
96
97public void OnClientAuthorized(int client)
98{
99 char sIP[16];
100 char sUserName[MAX_NAME_LENGTH];
101 int iAccountId = GetSteamAccountID(client);
102 bool bValidIP = GetClientIP(client, sIP, sizeof(sIP));
103 bool bValidName = GetClientName(client, sUserName, sizeof(sUserName));
104
105 if (bValidIP && bValidName)
106 {
107 char query[255];
108
109 g_hDatabase.Format(query, sizeof(query), "INSERT INTO "
110 ..."`Players`(`AccountID`, `IP`, `Name`) "
111 ..."VALUES ('%i', '%s', '%s') ON DUPLICATE KEY UPDATE "
112 ..."`Date` = unix_timestamp()", iAccountId, sIP, sUserName);
113
114 g_hDatabase.Query(SQL_CreateAndInsertQuery, query);
115 }
116}
117
118// Commands Functions
119
120static Action OnPlayerInfoCMD(int client, any args)
121{
122 int iAccountId;
123
124 char arg[256];
125 GetCmdArg(1, arg, sizeof(arg));
126
127 if (GetArgType(arg) == Arg_Steam2ID)
128 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam2ID);
129 else if (GetArgType(arg) == Arg_Steam3ID)
130 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam3ID);
131 else if (GetArgType(arg) == Arg_Steam32ID)
132 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam32ID);
133 else if (GetArgType(arg) == Arg_Steam64ID)
134 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam64ID);
135 else if (GetArgType(arg) == Arg_Name)
136 iAccountId = GetAccountIdByAny(client, arg, Arg_Steam64ID);
137
138 char query[255];
139
140 if (GetArgType(arg) == Arg_Name)
141 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP FROM Players WHERE Name LIKE '%s' ORDER BY `Players`.`Date` DESC LIMIT 1", arg);
142 else if (GetArgType(arg) == Arg_IP)
143 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP FROM Players WHERE IP = '%s' ORDER BY `Players`.`Date` DESC LIMIT 1", arg);
144 else
145 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP FROM Players WHERE AccountId = '%i' ORDER BY `Players`.`Date` DESC LIMIT 1", iAccountId);
146
147 DataPack pack = new DataPack();
148 pack.WriteString(arg);
149 pack.WriteCell(client);
150 pack.WriteCell(GetArgType(arg));
151
152 g_hDatabase.Query(OnInfoQuery, query, pack);
153}
154
155// SQL Query Functions
156
157public void OnInfoQuery(Database db, DBResultSet results, const char[] sError, any data)
158{
159 char arg[256];
160 pack.Reset();
161 pack.ReadString(arg, sizeof(arg));
162 int client = pack.ReadCell();
163 int iArgType = pack.ReadCell();
164
165 if(db == null || results == null || sError[0] != '\0')
166 {
167 LogError("Database query failure: %s", sError);
168 return;
169 }
170
171 if (!client)
172 return;
173
174 char sName[MAX_NAME_LENGTH];
175 char sIP[16];
176 char sAccountId[32];
177
178 while (results.FetchRow())
179 {
180 results.FetchString(0, sName, sizeof(sName));
181 results.FetchString(1, sIP, sizeof(sIP));
182 results.FetchString(2, sAccountId, sizeof(sAccountId));
183 }
184
185 if (results.RowCount != 0)
186 {
187 int iAccountId = StringToInt(sAccountId);
188
189 char sSteamId2[32];
190 char sSteamId3[32];
191 char sSteamId64[64];
192
193 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
194 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
195 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
196
197 if (iArgType == Arg_Steam2ID)
198 {
199 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
200 CPrintToChat(client, "{default}Last Name {green}- {olive}%s", sName);
201 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
202 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
203 CPrintToChat(client, "{default}Last IP {green}- {olive}%s", sIP);
204 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
205 }
206 else if (iArgType == Arg_Steam3ID || Arg_Steam32ID)
207 {
208 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
209 CPrintToChat(client, "{default}Last Name {green}- {olive}%s", sName);
210 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
211 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
212 CPrintToChat(client, "{default}Last IP {green}- {olive}%s", sIP);
213 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
214 }
215 else if (iArgType == Arg_Steam64ID)
216 {
217 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
218 CPrintToChat(client, "{default}Last Name {green}- {olive}%s", sName);
219 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
220 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
221 CPrintToChat(client, "{default}Last IP {green}- {olive}%s", sIP);
222 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
223 }
224 else if (iArgType == Arg_Name)
225 {
226 if (StrEqual(sName, arg))
227 {
228 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
229 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
230 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
231 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
232 CPrintToChat(client, "{default}Last IP {green}- {olive}%s", sIP);
233 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
234 }
235 else
236 {
237 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
238 CPrintToChat(client, "{default}Last Name {green}- {olive}%s", sName);
239 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
240 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
241 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
242 CPrintToChat(client, "{default}Last IP {green}- {olive}%s", sIP);
243 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
244 }
245 }
246 else if (iArgType == Arg_IP)
247 {
248 if (StrEqual(sIP, arg))
249 {
250 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
251 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
252 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
253 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
254 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
255 }
256 else
257 {
258 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
259 CPrintToChat(client, "{default}Last Name {green}- {olive}%s", sName);
260 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
261 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
262 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
263 CPrintToChat(client, "{default}Last IP {green}- {olive}%s", sIP);
264 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
265 }
266 }
267 }
268 else
269 {
270 if (iArgType == Arg_Name)
271 {
272 // add % at start
273 char query[256];
274 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP FROM Players WHERE Name LIKE '%s' ORDER BY `Players`.`Date` DESC LIMIT 1", arg);
275
276 DataPack pack = new DataPack();
277 pack.WriteString(arg);
278 pack.WriteCell(client);
279
280 g_hDatabase.Query(OnInfoQueryRetry1, query, pack);
281
282 // test %
283 PrintToServer("%%s", arg);
284 }
285 else
286 CPrintToChat(client, "[{green}!{default}] {red}No player found");
287 }
288}
289
290public void OnInfoQueryRetry1(Database db, DBResultSet results, const char[] sError, any data)
291{
292 char arg[256];
293 pack.Reset();
294 pack.ReadString(arg, sizeof(arg));
295 int client = pack.ReadCell();
296
297 if(db == null || results == null || sError[0] != '\0')
298 {
299 LogError("Database query failure: %s", sError);
300 return;
301 }
302
303 char sName[MAX_NAME_LENGTH];
304 char sIP[16];
305 char sAccountId[32];
306
307 while (results.FetchRow())
308 {
309 results.FetchString(0, sName, sizeof(sName));
310 results.FetchString(1, sIP, sizeof(sIP));
311 results.FetchString(2, sAccountId, sizeof(sAccountId));
312 }
313
314 if (results.RowCount != 0)
315 {
316 int iAccountId = StringToInt(sAccountId);
317
318 char sSteamId2[32];
319 char sSteamId3[32];
320 char sSteamId64[64];
321
322 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
323 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
324 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
325
326 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
327 CPrintToChat(client, "{default}Last Name {green}- {olive}%s", sName);
328 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
329 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
330 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
331 CPrintToChat(client, "{default}Last IP {green}- {olive}%s", sIP);
332 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
333 }
334 else
335 {
336 // add % at the end
337 char query[256];
338 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP FROM Players WHERE Name LIKE '%s' ORDER BY `Players`.`Date` DESC LIMIT 1", arg);
339
340 DataPack pack = new DataPack();
341 pack.WriteString(arg);
342 pack.WriteCell(client);
343
344 g_hDatabase.Query(OnInfoQueryRetry2, query, pack);
345
346 // test %
347 PrintToServer("%s%", arg);
348 }
349}
350
351public void OnInfoQueryRetry2(Database db, DBResultSet results, const char[] sError, any data)
352{
353 char arg[256];
354 pack.Reset();
355 pack.ReadString(arg, sizeof(arg));
356 int client = pack.ReadCell();
357
358 if(db == null || results == null || sError[0] != '\0')
359 {
360 LogError("Database query failure: %s", sError);
361 return;
362 }
363
364 if(db == null || results == null || sError[0] != '\0')
365 {
366 LogError("Database query failure: %s", sError);
367 return;
368 }
369
370 char sName[MAX_NAME_LENGTH];
371 char sIP[16];
372 char sAccountId[32];
373
374 while (results.FetchRow())
375 {
376 results.FetchString(0, sName, sizeof(sName));
377 results.FetchString(1, sIP, sizeof(sIP));
378 results.FetchString(2, sAccountId, sizeof(sAccountId));
379 }
380
381 if (results.RowCount != 0)
382 {
383 int iAccountId = StringToInt(sAccountId);
384
385 char sSteamId2[32];
386 char sSteamId3[32];
387 char sSteamId64[64];
388
389 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
390 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
391 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
392
393 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
394 CPrintToChat(client, "{default}Last Name {green}- {olive}%s", sName);
395 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
396 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
397 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
398 CPrintToChat(client, "{default}Last IP {green}- {olive}%s", sIP);
399 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
400 }
401 else
402 {
403 // add % at the end and start
404 char query[256];
405 g_hDatabase.Format(query, sizeof(query), "SELECT Name, IP FROM Players WHERE Name LIKE '%s' ORDER BY `Players`.`Date` DESC LIMIT 1", arg);
406
407 DataPack pack = new DataPack();
408 pack.WriteString(arg);
409 pack.WriteCell(client);
410
411 g_hDatabase.Query(OnInfoQueryRetry3, query, pack);
412
413 // test %
414 PrintToServer("%%s%", arg);
415 }
416}
417
418public void OnInfoQueryRetry3(Database db, DBResultSet results, const char[] sError, any data)
419{
420 char arg[256];
421 pack.Reset();
422 pack.ReadString(arg, sizeof(arg));
423 int client = pack.ReadCell();
424
425 if(db == null || results == null || sError[0] != '\0')
426 {
427 LogError("Database query failure: %s", sError);
428 return;
429 }
430
431 if(db == null || results == null || sError[0] != '\0')
432 {
433 LogError("Database query failure: %s", sError);
434 return;
435 }
436
437 char sName[MAX_NAME_LENGTH];
438 char sIP[16];
439 char sAccountId[32];
440
441 while (results.FetchRow())
442 {
443 results.FetchString(0, sName, sizeof(sName));
444 results.FetchString(1, sIP, sizeof(sIP));
445 results.FetchString(2, sAccountId, sizeof(sAccountId));
446 }
447
448 if (results.RowCount != 0)
449 {
450 int iAccountId = StringToInt(sAccountId);
451
452 char sSteamId2[32];
453 char sSteamId3[32];
454 char sSteamId64[64];
455
456 GetSteamId2ByAccountId(iAccountId, sSteamId2, sizeof(sSteamId2));
457 GetSteamId3ByAccountId(iAccountId, sSteamId3, sizeof(sSteamId3));
458 GetSteamId64ByAccountId(iAccountId, sSteamId64, sizeof(sSteamId64));
459
460 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
461 CPrintToChat(client, "{default}Last Name {green}- {olive}%s", sName);
462 CPrintToChat(client, "{default}SteamID2 {green}- {olive}%s", sSteamId2);
463 CPrintToChat(client, "{default}SteamID3 {green}- {olive}%s", sSteamId3);
464 CPrintToChat(client, "{default}SteamID64 {green}- {olive}%s", sSteamId64);
465 CPrintToChat(client, "{default}Last IP {green}- {olive}%s", sIP);
466 CPrintToChat(client, "[{green}!{default}]{blue}========================={default}[{green}!{default}]");
467 }
468 else
469 {
470 CPrintToChat(client, "[{green}!{default}] {red}No player found");
471 }
472}
473
474public void SQL_CreateAndInsertQuery(Database db, DBResultSet results, const char[] sError, any data)
475{
476 if(db == null || results == null || sError[0] != '\0')
477 {
478 LogError("Database query failure: %s", sError);
479 return;
480 }
481}
482
483// SteamID Classification Functions
484
485int GetArgType(const char[] arg)
486{
487 if (StrContains(arg, "STEAM_") != -1)
488 return Arg_Steam2ID;
489
490 if (StrContains(arg, "U:1:") != -1)
491 return Arg_Steam3ID;
492
493 if (IsIP(arg))
494 return Arg_IP;
495
496 if (StringToInt(arg))
497 return strlen(arg) > 16 ? Arg_Steam64ID : Arg_Steam32ID;
498
499 return Arg_Name;
500}
501
502bool IsIP(const char[] arg)
503{
504 int iDots;
505
506 for (int i = 0; i < strlen(arg); i++)
507 {
508 if (arg[i] == '.')
509 iDots++;
510 if (!IsCharNumeric(arg[i]) && arg[i] != '.')
511 return false;
512 }
513
514 if (iDots == 3)
515 return true;
516
517 return false;
518}
519
520// SteamID Convert Functions
521
522stock int GetAccountIdByAny(int client, const char[] arg, int iArgType)
523{
524 int iAccountId;
525
526 if (GetArgType(arg) == Arg_Steam2ID)
527 {
528 iAccountId = GetAccountIdBySteamId2(arg);
529
530 if (arg[6] == '\0')
531 {
532 CPrintToChat(client, "{blue}[{default}!{blue}] {default}If you are trying to use a SteamID2\n"
533 ..."{blue}[{default}!{blue}] {default}(ex: {olive}STEAM_0:1:191972089 {green}/ {olive}[STEAM_0:1:191972089]{default})\n"
534 ..."{blue}[{default}!{blue}] {default}Don't forget the {green}\"quotes\"{default}!");
535 }
536
537 return iAccountId;
538 }
539 else if (GetArgType(arg) == Arg_Steam3ID)
540 {
541 iAccountId = GetAccountIdBySteamId3(arg);
542
543 return iAccountId;
544 }
545 else if (GetArgType(arg) == Arg_Steam32ID)
546 {
547 iAccountId = StringToInt(arg);
548
549 return iAccountId;
550 }
551 else if (GetArgType(arg) == Arg_Steam64ID)
552 {
553 iAccountId = GetAccountIdBySteamId64(arg);
554 }
555 else if (GetArgType(arg) == Arg_Name)
556 {
557 if (arg[0] == 'U' && arg[1] == '\0')
558 {
559 CPrintToChat(client, "{blue}[{default}!{blue}] {default}If you are trying to use a SteamID2\n"
560 ..."{blue}[{default}!{blue}] {default}(ex: {olive}STEAM_0:1:191972089 {green}/ {olive}[STEAM_0:1:191972089]{default})\n"
561 ..."{blue}[{default}!{blue}] {default}Don't forget the {green}\"quotes\"{default}!");
562 }
563
564 return 0;
565 }
566
567 return 0;
568}
569
570stock int GetAccountIdBySteamId2(const char[] sSteamID2)
571{
572 char sBuffer[3][12];
573 ExplodeString(sSteamID2, ":", sBuffer, sizeof(sBuffer), sizeof(sBuffer[]));
574
575 return StringToInt(sBuffer[1]) + (StringToInt(sBuffer[2]) << 1);
576}
577
578stock int GetAccountIdBySteamId3(const char[] sSteamID3)
579{
580 char sBuffer[19];
581 strcopy(sBuffer, sizeof(sBuffer), sSteamID3);
582
583 int iBuffer = strlen(sBuffer) - 1;
584
585 if (sBuffer[iBuffer] == ']')
586 sBuffer[iBuffer] = '\0';
587
588 return StringToInt(sBuffer[FindCharInString(sBuffer, ':', true) + 1]);
589}
590
591stock int GetAccountIdBySteamId64(const char[] sSteam64)
592{
593 static const char sBase[] = "76561197960265728";
594 int iBorrow = 0;
595 char sAccount[17];
596 int iTemp;
597
598 for (int i = 16; i >= 0; --i)
599 {
600 if (iBorrow > 0)
601 {
602 iTemp = (sSteam64[i] - '0') - 1;
603
604 if (iTemp >= (sBase[i] - '0'))
605 {
606 iBorrow = 0;
607 sAccount[i] = (iTemp - ((sBase[i]) - '0')) + '0';
608 }
609 else
610 {
611 iBorrow = 1;
612 sAccount[i] = ((iTemp + 10) - (sBase[i] - '0')) + '0';
613 }
614 }
615 else
616 {
617 if ((sSteam64[i] - '0') >= (sBase[i] - '0'))
618 {
619 iBorrow = 0;
620 sAccount[i] = ((sSteam64[i] - '0') - (sBase[i] - '0')) + '0';
621 }
622 else
623 {
624 iBorrow = 1;
625 sAccount[i] = (((sSteam64[i] - '0') + 10) - (sBase[i] - '0') + '0');
626 }
627 }
628 }
629
630 return StringToInt(sAccount);
631}
632
633stock Action GetSteamId2ByAccountId(int iAccountId, char[] sSteamId2, int isizeof)
634{
635 EngineVersion e = GetEngineVersion();
636 int iEngine = (e == Engine_Left4Dead || e == Engine_Left4Dead2 || Engine_CSGO);
637 FormatEx(sSteamId2, isizeof, "STEAM_%i:%i:%i", iEngine, iAccountId % 2, iAccountId / 2);
638}
639
640stock Action GetSteamId3ByAccountId(int iAccountId, char[] sSteamId3, int isizeof)
641{
642 FormatEx(sSteamId3, isizeof, "[U:1:%i]", iAccountId);
643}
644
645stock void GetSteamId64ByAccountId(const int iAccountId, char[] sSteamId64, int isizeof)
646{
647 strcopy(sSteamId64, isizeof, "76561");
648
649 char sBuffer[11];
650 FormatEx(sBuffer, sizeof(sBuffer), "%010u", iAccountId);
651 FormatEx(sSteamId64[5], isizeof - 5, "%i", 1979 + 10 * (sBuffer[0] - '0') + sBuffer[1] - '0');
652
653 int iBuffer = StringToInt(sBuffer[2]) + 60265728;
654
655 if (iBuffer > 100000000)
656 {
657 iBuffer -= 100000000;
658 ++sSteamId64[8];
659
660 for (int i = 8; i > 4; --i)
661 {
662 if ( sSteamId64[i] > '9')
663 {
664 sSteamId64[i] = '0';
665 ++sSteamId64[i-1];
666 }
667 else
668 {
669 break;
670 }
671 }
672 }
673
674 FormatEx(sSteamId64[9], isizeof - 9, "%i", iBuffer);
675}