· 6 years ago · Nov 03, 2019, 02:54 PM
1#include <sdktools>
2#pragma newdecls required
3
4/*-> Database table name to use for connection <-*/
5#define DB_Name "game"
6/*###############################################*/
7
8//Variables
9Database db = null;
10ConVar CvarAdmFlag;
11int AdmFlag;
12char CPrefix[] = {"\x04[Whitelist] \x01"}; //Chat prefix
13
14//Plugin Info
15public Plugin myinfo =
16{
17 name = "Mysql Whitelist",
18 author = "Xines, johan123jo, Demoan(unfortunately)",
19 description = "Mysql database whitelister to control player access to server[s].",
20 version = "1.6",
21 url = ""
22};
23
24public void OnPluginStart()
25{
26 //INGAME Commands
27 RegAdminCmd("sm_whitelist", Main, ADMFLAG_ROOT, "Opens the menu to list/remove");
28 RegAdminCmd("sm_whitelist_add", Command_Add, ADMFLAG_ROOT, "Add a steamid to the database.");
29 RegAdminCmd("sm_whitelist_delete", Command_Delete, ADMFLAG_ROOT, "Deletes a steamid from the database.");
30 RegAdminCmd("sm_whitelist_list", Command_List, ADMFLAG_ROOT, "List all SteamIDs in the database.");
31
32 //Server Commands, Useable by Rcon or Console Whatever.
33 RegServerCmd("sm_server_whitelist_add", Server_Command_Add, "Add a steamid to the database. Useable by Rcon or Console");
34 RegServerCmd("sm_server_whitelist_delete", Server_Command_Delete, "Deletes a steamid from the database. Useable by Rcon or Console");
35
36 //Cvars
37 CvarAdmFlag = CreateConVar("sm_whitelist_adminflag", "0", "Admin flag required [a -> z] [0 = OFF].");
38 //Hook our cvar
39 HookConVarChange(CvarAdmFlag, Cvar_Change);
40
41 //DB stuff
42 if (SQL_CheckConfig("whitelister")) SQL_TConnect(OnDatabaseConnect, "whitelister");
43 else SetFailState("Can't find 'whitelister' entry in sourcemod/configs/databases.cfg!");
44}
45
46public void OnDatabaseConnect(Handle owner, Handle hndl, const char[] error, any data)
47{
48 if (hndl == null || strlen(error) > 0)
49 {
50 PrintToServer("[Mysql-Whitelist] Unable to connect to database (%s)", error);
51 LogError("[Mysql-Whitelist] Unable to connect to database (%s)", error);
52 return;
53 }
54 db = view_as<Database>(CloneHandle(hndl)); //Set global DB Handle
55
56 //Create Tables in DB if not exist
57 char sBuffer[512];
58 FormatEx(sBuffer, sizeof(sBuffer),
59 "CREATE TABLE IF NOT EXISTS `%s` (`steamid64` text CHARACTER SET utf8 COLLATE utf8_danish_ci);", DB_Name);
60 db.Query(SQL_ErrorCheckCallback, sBuffer, _, DBPrio_High);
61
62 //Success Print
63 PrintToServer("[Mysql-Whitelist] Successfully connected to database!");
64}
65
66public void Cvar_Change(Handle cvar, const char[] oldVal, const char[] newVal)
67{
68 AdmFlag = ReadFlagString(newVal);
69}
70
71public Action Main(int client, int args)
72{
73 ShowMain(client);
74 return Plugin_Handled;
75}
76
77/* ######## Main menu stuff - Start ######## */
78void ShowMain(int client)
79{
80 if(!IsValidClient(client)) return;
81
82 Menu MainMenu = new Menu(MainMenuHandler);
83 MainMenu.SetTitle("Whitelist Menu");
84 MainMenu.AddItem("Remove Player", "Remove Player");
85 MainMenu.AddItem("List Players", "List Players");
86 MainMenu.ExitButton = true;
87 MainMenu.Display(client, MENU_TIME_FOREVER);
88}
89
90public int MainMenuHandler(Menu MainMenu, MenuAction action, int client, int itemNum)
91{
92 if(!IsValidClient(client)) return;
93
94 switch (action)
95 {
96 case MenuAction_Select:
97 {
98 //Commands handling
99 char info[64];
100 MainMenu.GetItem(itemNum, info, sizeof(info));
101 if(strcmp(info, "Remove Player") == 0) ShowPlayerToRemove(client);
102 if(strcmp(info, "List Players") == 0) ListPlayers(client);
103 }
104 case MenuAction_Cancel:
105 {
106 if (itemNum == MenuCancel_ExitBack)
107 {
108 ShowMain(client);
109 }
110 }
111 case MenuAction_End:
112 {
113 delete MainMenu;
114 }
115 }
116}
117
118void ListPlayers(int client)
119{
120 if(!IsValidClient(client)) return;
121
122 //Make query
123 char query[256];
124 Format(query, sizeof(query), "SELECT * FROM %s", DB_Name);
125 db.Query(SQL_ListSteamids, query, GetClientUserId(client), DBPrio_High);
126
127 //Tell client/user we are querying.
128 PrintToChat(client, "%sQuery sent! Look in console for the List!", CPrefix);
129}
130
131void ShowPlayerToRemove(int client)
132{
133 if(!IsValidClient(client)) return;
134
135 char id[4], name[MAX_NAME_LENGTH];
136 Menu whitelistmenu_remove = new Menu(RemovePlayerHandle);
137 whitelistmenu_remove.SetTitle("Select Player to Remove");
138 for (int i = 1; i <= MaxClients; i++)
139 {
140 if (IsValidClient(i))
141 {
142 IntToString(GetClientUserId(i), id, sizeof(id));
143 GetClientName(i, name, sizeof(name));
144 whitelistmenu_remove.AddItem(id, name);
145 }
146 }
147 whitelistmenu_remove.ExitBackButton = true;
148 whitelistmenu_remove.ExitButton = true;
149 whitelistmenu_remove.Display(client, MENU_TIME_FOREVER);
150}
151/* ###################### Main menu stuff - End ###################### */
152
153/* ###################### Remove Player Module Start ###################### */
154public int RemovePlayerHandle(Menu whitelistmenu_remove, MenuAction action, int client, int param2)
155{
156 if(!IsValidClient(client)) return;
157
158 switch (action)
159 {
160 case MenuAction_Select:
161 {
162 char choice[4], charauth[64];
163 whitelistmenu_remove.GetItem(param2, choice, sizeof(choice));
164 int itarget = GetClientOfUserId(StringToInt(choice)); //Get target id from menu
165 for (int i = 1; i <= MaxClients; i++)
166 {
167 if (!IsValidClient(i) || i != itarget) continue; //Is client valid and is client our target.
168
169 //Get steam2 ID and store to charauth
170 if (!GetClientAuthId(i, AuthId_SteamID64, charauth, sizeof(charauth)))
171 {
172 //Tell client/user gathering steamid went wrong
173 PrintToChat(client, "%sCould not gather Steamid, try again!", CPrefix);
174 break;
175 }
176
177 //Pack Infos
178 DataPack Pack = new DataPack();
179 Pack.WriteCell(GetClientUserId(client));
180 Pack.WriteString(charauth);
181
182 //Make query
183 char query[256];
184 Format(query, sizeof(query), "SELECT steamid64 FROM %s WHERE steamid64 = '%s'", DB_Name, charauth);
185 db.Query(SQL_DeleteSteamid_Check, query, Pack, DBPrio_High);
186
187 //Tell client/user we are querying.
188 PrintToChat(client, "%sQuery sent please wait!", CPrefix);
189
190 //Magic query done, now goto menu
191 ShowPlayerToRemove(client);
192
193 //we're done
194 break;
195 }
196 }
197 case MenuAction_Cancel:
198 {
199 if (param2 == MenuCancel_ExitBack)
200 {
201 ShowMain(client);
202 }
203 }
204 case MenuAction_End:
205 {
206 delete whitelistmenu_remove;
207 }
208 }
209}
210/* ###################### Remove Player Module End ###################### */
211
212/* ######## Lots of SQL stuff below ######## */
213
214//Check Player Access First Check!
215public void OnClientAuthorized(int client, const char[] SteamID)
216{
217 if (IsFakeClient(client)) return; //Allow bots to skip this check.
218 AdminId Admin = FindAdminByIdentity(AUTHMETHOD_STEAM, SteamID);
219 if (AdmFlag != 0 && GetAdminFlags(Admin, Access_Effective) & AdmFlag) return;
220
221 //Start Checking
222 //Send a check query to the database to see if the user is in the database.
223 char query[256];
224 Format(query, sizeof(query), "SELECT steamid64 FROM %s WHERE steamid64 = '%s'", DB_Name, SteamID);
225 db.Query(SQL_CheckSteamID, query, GetClientUserId(client), DBPrio_High);
226}
227
228//Double Check our client, just incase person randomly somehow bypassed OnClientAuthorized check.
229public void OnClientPostAdminCheck(int client)
230{
231 if (!IsValidClient(client) || IsFakeClient(client)) return;
232
233 //Do Same check as in OnClientAuthorized, just different method.
234 char isteamid[64];
235 if(GetClientAuthId(client, AuthId_SteamID64, isteamid, sizeof(isteamid)))
236 {
237 if(AdmFlag != 0 && CheckAdmFlag(client)) return; //If Admin with Adm flag, Skip check.
238
239 //Start Checking
240 //Send a check query to the database to see if the user is in the database.
241 char query[256];
242 Format(query, sizeof(query), "SELECT steamid64 FROM %s WHERE steamid64 = '%s'", DB_Name, isteamid);
243 db.Query(SQL_CheckSteamID, query, GetClientUserId(client), DBPrio_High);
244 }
245 else KickClient(client, "Please retry connecting!"); //Tell clients to retry.
246}
247
248//Checks if the SteamID is in the database, if not the player will get kicked.
249public void SQL_CheckSteamID(Handle owner, DBResultSet results, const char[] error, any userid)
250{
251 int client = GetClientOfUserId(userid);
252 if (client == 0 || !IsClientConnected(client)) return; //connected check if not found do return
253 if (results == null || strlen(error) > 0)
254 {
255 LogError("[Mysql-Whitelist] Query failed! %s", error);
256 KickClient(client, "Authorization failed, please try again later.");
257 }
258 else if(results.RowCount == 0)
259 {
260 KickClient(client, "You are not allowed to join this server");
261 }
262}
263
264//Command to list all the SteamIDs in the database, and other stuff the command needs for it to work.
265public Action Command_List(int client, int args)
266{
267 if (IsValidClient(client))
268 {
269 char query[256];
270 Format(query, sizeof(query), "SELECT * FROM %s", DB_Name);
271 db.Query(SQL_ListSteamids, query, GetClientUserId(client), DBPrio_High);
272 }
273 return Plugin_Handled;
274}
275
276//Used by Command_List to query database for info.
277public void SQL_ListSteamids(Handle owner, DBResultSet results, const char[] error, any userid)
278{
279 int client = GetClientOfUserId(userid);
280 if (!IsValidClient(client)) return; //Stop if not valid!
281 if (results == null || strlen(error) > 0)
282 {
283 LogError("[Mysql-Whitelist] Query failed! %s", error);
284 PrintToChat(client, "%sQuery failed, please try again later.", CPrefix);
285 return;
286 }
287
288 //Everything is fine let's start
289 PrintToConsole(client, "########## SteamIDs in database ##########");
290 char steamid_f[256];
291 while(results.FetchRow()) //Fetch all rows
292 {
293 results.FetchString(0, steamid_f, sizeof(steamid_f));
294 PrintToConsole(client, "%s", steamid_f);
295 }
296 PrintToConsole(client, "##########################################");
297}
298
299//Command to add a SteamID into the database.
300public Action Command_Add(int client, int args)
301{
302 //Check if client is valid, do nothing if not!
303 if (!IsValidClient(client)) return Plugin_Handled;
304
305 if(args < 1)
306 {
307 ReplyToCommand(client, "Usage: sm_whitelist_add <steamid>");
308 return Plugin_Handled;
309 }
310
311 //Quick check to make sure format is steam2 id
312 char fsteam[64];
313 GetCmdArgString(fsteam, sizeof(fsteam));
314 if (StrContains(fsteam, "STEAM_0", false) == -1 && StrContains(fsteam, "STEAM_1", false) == -1)
315 {
316 ReplyToCommand(client, "%sInvalid SteamID Use Format: STEAM_1 or STEAM_0", CPrefix);
317 return Plugin_Handled;
318 }
319
320 //Pack Infos
321 DataPack Pack = new DataPack();
322 Pack.WriteCell(GetClientUserId(client));
323 Pack.WriteString(fsteam);
324
325 //Make Query
326 char query[256];
327 Format(query, sizeof(query), "SELECT steamid64 FROM %s WHERE steamid64 = '%s'", DB_Name, fsteam);
328 db.Query(SQL_AddSteamid_Check, query, Pack, DBPrio_High);
329
330 //Tell client/user we are querying.
331 PrintToChat(client, "%sQuery sent please wait!", CPrefix);
332
333 return Plugin_Handled;
334}
335
336//Checks if SteamID is already in the database.
337public void SQL_AddSteamid_Check(Handle owner, DBResultSet results, const char[] error, DataPack data)
338{
339 //Unpack our Infos
340 data.Reset();
341 int client = GetClientOfUserId(data.ReadCell());
342 char fsteam[64]; //SteamId
343 data.ReadString(fsteam, 64);
344
345 if (IsValidClient(client))
346 {
347 if (results == null || strlen(error) > 0)
348 {
349 LogError("[Mysql-Whitelist] Query failed! %s", error);
350 PrintToChat(client, "%sQuery failed, please try again later.", CPrefix);
351 }
352 else if (results.RowCount == 0)
353 {
354 //Pack Infos again
355 DataPack iPack = new DataPack();
356 iPack.WriteCell(GetClientUserId(client));
357 iPack.WriteString(fsteam);
358
359 char query[256];
360 Format(query, sizeof(query), "INSERT INTO %s (steamid64) VALUES ('%s')", DB_Name, fsteam);
361 db.Query(SQL_AddSteamid_Add, query, iPack, DBPrio_High);
362 }
363 else PrintToChat(client, "%sThe SteamID: %s is already in the database.", CPrefix, fsteam);
364 }
365 delete view_as<DataPack>(data);
366}
367
368//If SQL_AddSteamid_Check did not find a SteamID in the database it will add it to the database.
369public void SQL_AddSteamid_Add(Handle owner, DBResultSet results, const char[] error, DataPack data)
370{
371 //Unpack our Infos
372 data.Reset();
373 int client = GetClientOfUserId(data.ReadCell());
374 char steamid[64]; //SteamId
375 data.ReadString(steamid, 64);
376
377 if (IsValidClient(client))
378 {
379 if (results == null || strlen(error) > 0)
380 {
381 LogError("[Mysql-Whitelist] Query failed! %s", error);
382 PrintToChat(client, "%sQuery failed, please try again later. (See Logs)", CPrefix);
383 }
384 else PrintToChat(client, "%sThe SteamID: %s have been added to the database.", CPrefix, steamid);
385 }
386 delete view_as<DataPack>(data);
387}
388
389//Command to add a SteamID into the database. ServerCmd/Rcon
390public Action Server_Command_Add(int args)
391{
392 if (args < 1)
393 {
394 PrintToServer("Usage: sm_server_whitelist_add <steamid>");
395 return Plugin_Handled;
396 }
397 else
398 {
399 char fsteam[64];
400 GetCmdArgString(fsteam, sizeof(fsteam));
401 if (StrContains(fsteam, "STEAM_0", false) == -1 && StrContains(fsteam, "STEAM_1", false) == -1)
402 {
403 PrintToServer("%sInvalid SteamID Use Format: STEAM_1 or STEAM_0", CPrefix);
404 return Plugin_Handled;
405 }
406
407 //Remove stupid spaces
408 ReplaceString(fsteam, 64, " ", "");
409
410 //Pack Infos - We have to use Datapacks to pass arrays/string in querys...
411 DataPack Pack = new DataPack();
412 Pack.WriteString(fsteam);
413
414 //Make Query
415 char query[256];
416 Format(query, sizeof(query), "SELECT steamid64 FROM %s WHERE steamid64 = '%s'", DB_Name, fsteam);
417 db.Query(SQL_Server_AddSteamid_Check, query, Pack, DBPrio_Normal);
418
419 //Tell we are querying.
420 PrintToServer("%sQuery sent please wait!", CPrefix);
421 }
422 return Plugin_Handled;
423}
424
425//Checks if SteamID is already in the database. ServerCmd/Rcon
426public void SQL_Server_AddSteamid_Check(Handle owner, DBResultSet results, const char[] error, DataPack data)
427{
428 //Unpack our Infos
429 data.Reset();
430 char steamid[64]; //SteamId
431 data.ReadString(steamid, 64);
432
433 if (results == null || strlen(error) > 0)
434 {
435 LogError("[Mysql-Whitelist] Query failed! %s", error);
436 PrintToServer("%sQuery failed, please try again later.", CPrefix);
437 }
438 else if (results.RowCount == 0)
439 {
440 //Pack Infos - We have to use Datapacks to pass arrays/string in querys...
441 DataPack iPack = new DataPack();
442 iPack.WriteString(steamid);
443
444 char query[256];
445 Format(query, sizeof(query), "INSERT INTO %s (steamid64) VALUES ('%s')", DB_Name, steamid);
446 db.Query(SQL_Server_AddSteamid_Add, query, iPack, DBPrio_Normal);
447 }
448 else PrintToServer("%sThe SteamID: %s is already in the database.", CPrefix, steamid);
449
450 delete view_as<DataPack>(data);
451}
452
453//If SQL_Server_AddSteamid_Add did not find a SteamID in the database it will add it to the database.
454public void SQL_Server_AddSteamid_Add(Handle owner, DBResultSet results, const char[] error, DataPack data)
455{
456 //Unpack our Infos
457 data.Reset();
458 char steamid[64]; //SteamId
459 data.ReadString(steamid, 64);
460
461 if (results == null || strlen(error) > 0)
462 {
463 LogError("[Mysql-Whitelist] Query failed! %s", error);
464 PrintToServer("%sQuery failed, please try again later. (See Logs)", CPrefix);
465 }
466 else PrintToServer("%sThe SteamID: %s have been added to the database.", CPrefix, steamid);
467
468 delete view_as<DataPack>(data);
469}
470
471//Command to delete a SteamID from the database.
472public Action Command_Delete(int client, int args)
473{
474 //Check if client is valid, do nothing if not!
475 if (!IsValidClient(client)) return Plugin_Handled;
476
477 if (args < 1)
478 {
479 ReplyToCommand(client, "Usage: sm_whitelist_delete <steamid>");
480 return Plugin_Handled;
481 }
482
483 //Quick check to make sure format is steam2 id
484 char fsteam[64]
485 GetCmdArgString(fsteam, sizeof(fsteam));
486 if (StrContains(fsteam, "STEAM_0", false) == -1 && StrContains(fsteam, "STEAM_1", false) == -1)
487 {
488 ReplyToCommand(client, "%sInvalid SteamID Use Format: STEAM_1 or STEAM_0", CPrefix);
489 return Plugin_Handled;
490 }
491
492 //Pack Infos
493 DataPack Pack = new DataPack();
494 Pack.WriteCell(GetClientUserId(client));
495 Pack.WriteString(fsteam);
496
497 //Make Query
498 char query[256];
499 Format(query, sizeof(query), "SELECT steamid64 FROM %s WHERE steamid64 = '%s'", DB_Name, fsteam);
500 db.Query(SQL_DeleteSteamid_Check, query, Pack, DBPrio_High);
501
502 //Tell client/user we are querying.
503 PrintToChat(client, "%sQuery sent please wait!", CPrefix);
504
505 return Plugin_Handled;
506}
507
508//Querys the database to see if a SteamID exists, if it exists in the database it will delete the SteamID from the database.
509public void SQL_DeleteSteamid_Check(Handle owner, DBResultSet results, const char[] error, DataPack data)
510{
511 //Unpack our Infos
512 data.Reset();
513 int client = GetClientOfUserId(data.ReadCell());
514 char fsteam[64]; //SteamId
515 data.ReadString(fsteam, 64);
516
517 if (IsValidClient(client))
518 {
519 if (results == null || strlen(error) > 0)
520 {
521 LogError("[Mysql-Whitelist] Query failed! %s", error);
522 PrintToChat(client, "%sQuery failed, please try again later.", CPrefix);
523 }
524 else if (results.RowCount)
525 {
526 //Pack Infos again
527 DataPack iPack = new DataPack();
528 iPack.WriteCell(GetClientUserId(client));
529 iPack.WriteString(fsteam);
530
531 //Make Query
532 char query[256];
533 Format(query, sizeof(query), "DELETE FROM %s WHERE steamid64 = '%s'", DB_Name, fsteam);
534 db.Query(SQL_DeleteSteamid_Delete, query, iPack, DBPrio_High);
535 }
536 else PrintToChat(client, "%sThe SteamID: %s is not in the database.", CPrefix, fsteam);
537 }
538 delete view_as<DataPack>(data);
539}
540
541//Deletes the SteamID from the database, and kicks the client if active on the server.
542public void SQL_DeleteSteamid_Delete(Handle owner, DBResultSet results, const char[] error, DataPack data)
543{
544 //Unpack our Infos
545 data.Reset();
546 int client = GetClientOfUserId(data.ReadCell());
547 char fsteam[64]; //SteamId
548 data.ReadString(fsteam, 64);
549
550 if (IsValidClient(client))
551 {
552 if (results == null || strlen(error) > 0)
553 {
554 LogError("[Mysql-Whitelist] Query failed! %s", error);
555 PrintToChat(client, "%sQuery failed, please try again later.", CPrefix);
556 delete view_as<DataPack>(data); //Delete Datapack due to null or error
557 return;
558 }
559
560 //Everything is fine let's start
561 KickMatchingSteamid(fsteam); //Kick if found!
562 PrintToChat(client, "%sThe SteamID: %s have been deleted from the database.", CPrefix, fsteam);
563 }
564 delete view_as<DataPack>(data); //Delete Datapack we are done
565}
566
567public Action Server_Command_Delete(int args)
568{
569 if (args < 1)
570 {
571 PrintToServer("Usage: sm_server_whitelist_delete <steamid>");
572 return Plugin_Handled;
573 }
574 else
575 {
576 char fsteam[64];
577 GetCmdArgString(fsteam, sizeof(fsteam));
578 if (StrContains(fsteam, "STEAM_0", false) == -1 && StrContains(fsteam, "STEAM_1", false) == -1)
579 {
580 PrintToServer("%sInvalid SteamID Use Format: STEAM_1 or STEAM_0", CPrefix);
581 return Plugin_Handled;
582 }
583
584 //Remove stupid spaces
585 ReplaceString(fsteam, 64, " ", "");
586
587 //Pack Infos - We have to use Datapacks to pass arrays/string in querys...
588 DataPack Pack = new DataPack();
589 Pack.WriteString(fsteam);
590
591 //Make Query
592 char query[256];
593 Format(query, sizeof(query), "SELECT steamid64 FROM %s WHERE steamid64 = '%s'", DB_Name, fsteam);
594 db.Query(SQL_Server_DeleteSteamid_Check, query, Pack, DBPrio_Normal);
595
596 //Tell we are querying.
597 PrintToServer("%sQuery sent please wait!", CPrefix);
598 }
599 return Plugin_Handled;
600}
601
602//Querys the database to see if a SteamID exists, if it exists in the database it will delete the SteamID from the database.
603public void SQL_Server_DeleteSteamid_Check(Handle owner, DBResultSet results, const char[] error, DataPack data)
604{
605 //Unpack our Infos
606 data.Reset();
607 char fsteam[64]; //SteamId
608 data.ReadString(fsteam, 64);
609
610 if (results == null || strlen(error) > 0)
611 {
612 LogError("[Mysql-Whitelist] Query failed! %s", error);
613 PrintToServer("%sQuery failed, please try again later.", CPrefix);
614 }
615 else if (results.RowCount)
616 {
617 //Pack Infos again
618 DataPack iPack = new DataPack();
619 iPack.WriteString(fsteam);
620
621 //Make Query
622 char query[256];
623 Format(query, sizeof(query), "DELETE FROM %s WHERE steamid64 = '%s'", DB_Name, fsteam);
624 db.Query(SQL_Server_DeleteSteamid_Delete, query, iPack, DBPrio_High);
625 }
626 else PrintToServer("%sThe SteamID: %s is not in the database.", CPrefix, fsteam);
627
628 delete view_as<DataPack>(data);
629}
630
631//Deletes the SteamID from the database, and kicks the client if active on the server.
632public void SQL_Server_DeleteSteamid_Delete(Handle owner, DBResultSet results, const char[] error, DataPack data)
633{
634 //Unpack our Infos
635 data.Reset();
636 char fsteam[64]; //SteamId
637 data.ReadString(fsteam, 64);
638
639 if (results == null || strlen(error) > 0)
640 {
641 LogError("[Mysql-Whitelist] Query failed! %s", error);
642 PrintToServer("%sQuery failed, please try again later.", CPrefix);
643 delete view_as<DataPack>(data); //Delete Datapack due to null or error
644 return;
645 }
646
647 //Everything is fine let's start
648 KickMatchingSteamid(fsteam); //Kick if found!
649 PrintToServer("%sThe SteamID: %s have been deleted from the database.", CPrefix, fsteam);
650
651 delete view_as<DataPack>(data); //Delete Datapack we are done
652}
653
654//Used to kick people off server, if steamid is removed from database!
655void KickMatchingSteamid(char[] fsteam)
656{
657 char iauth[64];
658 for(int i = 1; i <= MaxClients; i++)
659 {
660 if (!IsValidClient(i)) continue;
661
662 if (!GetClientAuthId(i, AuthId_SteamID64, iauth, sizeof(iauth))) continue;
663
664 if (StrEqual(iauth, fsteam))
665 {
666 KickClient(i, "You are not allowed to be on this server");
667 break;
668 }
669 }
670}
671
672//Function to check for errors before doing query
673public void SQL_ErrorCheckCallback(Handle owner, DBResultSet results, const char[] error, any data)
674{
675 if (results == null || strlen(error) > 0)
676 {
677 LogError("[Mysql-Whitelist] Query failed! %s", error);
678 }
679}
680
681/** Stocks **/
682stock bool CheckAdmFlag(int client)
683{
684 AdminId admin = GetUserAdmin(client);
685 if (admin == INVALID_ADMIN_ID) return false;
686
687 //Do check
688 int count, found;
689 for (int i = 0; i <= 20; i++)
690 {
691 if (AdmFlag & (1<<i))
692 {
693 count++;
694 if (GetAdminFlag(admin, view_as<AdminFlag>(i))) found++;
695 }
696 }
697
698 if (count == found) return true;
699 else return false;
700}
701
702stock bool IsValidClient(int client)
703{
704 return (1 <= client <= MaxClients && IsClientInGame(client));
705}