· 8 years ago · Apr 02, 2018, 05:06 PM
1#pragma semicolon 1
2#include <sourcemod>
3#include <sourcebans>
4
5#undef REQUIRE_PLUGIN
6#include <adminmenu>
7#tryinclude <updater>
8
9#define SB_VERSION "1.6.2++"
10#define SBR_VERSION "1.6.2"
11
12#if defined _updater_included
13#define UPDATE_URL "https://sbpp.github.io/updater/updatefile.txt"
14#endif
15
16//GLOBAL DEFINES
17#define YELLOW 0x01
18#define NAMECOLOR 0x02
19#define TEAMCOLOR 0x03
20#define GREEN 0x04
21
22#define DISABLE_ADDBAN 1
23#define DISABLE_UNBAN 2
24
25#define FLAG_LETTERS_SIZE 26
26
27//#define DEBUG
28
29enum State/* ConfigState */
30{
31 ConfigStateNone = 0,
32 ConfigStateConfig,
33 ConfigStateReasons,
34 ConfigStateHacking
35}
36
37new g_BanTarget[MAXPLAYERS + 1] = { -1, ... };
38new g_BanTime[MAXPLAYERS + 1] = { -1, ... };
39
40new State:ConfigState;
41new Handle:ConfigParser;
42
43new Handle:hTopMenu = INVALID_HANDLE;
44
45new const String:Prefix[] = "[SourceBans++] ";
46
47new String:ServerIp[24];
48new String:ServerPort[7];
49new String:DatabasePrefix[10] = "sb";
50new String:WebsiteAddress[128];
51
52/* Admin Stuff*/
53new AdminCachePart:loadPart;
54new bool:loadAdmins;
55new bool:loadGroups;
56new bool:loadOverrides;
57new curLoading = 0;
58new AdminFlag:g_FlagLetters[FLAG_LETTERS_SIZE];
59
60/* Admin KeyValues */
61new String:groupsLoc[128];
62new String:adminsLoc[128];
63new String:overridesLoc[128];
64
65/* Cvar handle*/
66new Handle:CvarHostIp;
67new Handle:CvarPort;
68
69/* Database handle */
70new Handle:DB;
71new Handle:SQLiteDB;
72
73/* Menu file globals */
74new Handle:ReasonMenuHandle;
75new Handle:HackingMenuHandle;
76
77/* Datapack and Timer handles */
78new Handle:PlayerRecheck[MAXPLAYERS + 1] = { INVALID_HANDLE, ... };
79new Handle:PlayerDataPack[MAXPLAYERS + 1] = { INVALID_HANDLE, ... };
80
81/* Player ban check status */
82new bool:PlayerStatus[MAXPLAYERS + 1];
83
84/* Disable of addban and unban */
85new CommandDisable;
86new bool:backupConfig = true;
87new bool:enableAdmins = true;
88
89/* Require a lastvisited from SB site */
90new bool:requireSiteLogin = false;
91
92/* Log Stuff */
93new String:logFile[256];
94
95/* Own Chat Reason */
96new g_ownReasons[MAXPLAYERS + 1] = { false, ... };
97
98new Float:RetryTime = 15.0;
99new ProcessQueueTime = 5;
100new bool:LateLoaded;
101new bool:AutoAdd;
102new bool:g_bConnecting = false;
103
104new serverID = -1;
105
106new Handle:g_hFwd_OnBanAdded;
107
108public Plugin:myinfo =
109{
110 name = "SourceBans++: Main Plugin",
111 author = "SourceBans Development Team, SourceBans++ Dev Team",
112 description = "Advanced ban management for the Source engine",
113 version = SBR_VERSION,
114 url = "https://sbpp.github.io"
115};
116
117#if SOURCEMOD_V_MAJOR >= 1 && SOURCEMOD_V_MINOR >= 3
118public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
119#else
120public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max)
121#endif
122{
123 RegPluginLibrary("sourcebans");
124 CreateNative("SBBanPlayer", Native_SBBanPlayer);
125 CreateNative("SourceBans_BanPlayer", Native_SBBanPlayer);
126
127 g_hFwd_OnBanAdded = CreateGlobalForward("SourceBans_OnBanPlayer", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_String);
128
129 LateLoaded = late;
130
131 #if SOURCEMOD_V_MAJOR >= 1 && SOURCEMOD_V_MINOR >= 3
132 return APLRes_Success;
133 #else
134 return true;
135 #endif
136}
137
138public OnPluginStart()
139{
140 LoadTranslations("common.phrases");
141 LoadTranslations("plugin.basecommands");
142 LoadTranslations("sourcebans.phrases");
143 LoadTranslations("basebans.phrases");
144 loadAdmins = loadGroups = loadOverrides = false;
145
146 CvarHostIp = FindConVar("hostip");
147 CvarPort = FindConVar("hostport");
148 CreateConVar("sb_version", SB_VERSION, _, FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY);
149 CreateConVar("sbr_version", SBR_VERSION, _, FCVAR_SPONLY | FCVAR_REPLICATED | FCVAR_NOTIFY);
150 RegServerCmd("sm_rehash", sm_rehash, "Reload SQL admins");
151 RegAdminCmd("sm_fmtkmpd", CommandBan, ADMFLAG_BAN, "sm_fmtkmpd <#userid|name> <minutes|0> [reason]", "sourcebans");
152 RegAdminCmd("sm_fmtkmpdip", CommandBanIp, ADMFLAG_BAN, "sm_fmtkmpdip <ip|#userid|name> <time> [reason]", "sourcebans");
153 RegAdminCmd("sm_addfmtkmpd", CommandAddBan, ADMFLAG_RCON, "sm_addfmtkmpd <time> <steamid> [reason]", "sourcebans");
154 RegAdminCmd("sm_unban", CommandUnban, ADMFLAG_UNBAN, "sm_unban <steamid|ip> [reason]", "sourcebans");
155 RegAdminCmd("sb_reload",
156 _CmdReload,
157 ADMFLAG_RCON,
158 "Reload sourcebans config and ban reason menu options",
159 "sourcebans");
160
161 RegConsoleCmd("say", ChatHook);
162 RegConsoleCmd("say_team", ChatHook);
163
164 if ((ReasonMenuHandle = CreateMenu(ReasonSelected)) != INVALID_HANDLE)
165 {
166 SetMenuPagination(ReasonMenuHandle, 8);
167 SetMenuExitBackButton(ReasonMenuHandle, true);
168 }
169
170 if ((HackingMenuHandle = CreateMenu(HackingSelected)) != INVALID_HANDLE)
171 {
172 SetMenuPagination(HackingMenuHandle, 8);
173 SetMenuExitBackButton(HackingMenuHandle, true);
174 }
175
176 g_FlagLetters = CreateFlagLetters();
177
178 BuildPath(Path_SM, logFile, sizeof(logFile), "logs/sourcebans.log");
179 g_bConnecting = true;
180
181 // Catch config error and show link to FAQ
182 if (!SQL_CheckConfig("sourcebans"))
183 {
184 if (ReasonMenuHandle != INVALID_HANDLE)
185 CloseHandle(ReasonMenuHandle);
186 if (HackingMenuHandle != INVALID_HANDLE)
187 CloseHandle(HackingMenuHandle);
188 LogToFile(logFile, "Database failure: Could not find Database conf \"sourcebans\". See FAQ: https://sbpp.sarabveer.me/faq/");
189 SetFailState("Database failure: Could not find Database conf \"sourcebans\"");
190 return;
191 }
192 SQL_TConnect(GotDatabase, "sourcebans");
193
194 BuildPath(Path_SM, groupsLoc, sizeof(groupsLoc), "configs/sourcebans/sb_admin_groups.cfg");
195
196 BuildPath(Path_SM, adminsLoc, sizeof(adminsLoc), "configs/sourcebans/sb_admins.cfg");
197
198 BuildPath(Path_SM, overridesLoc, sizeof(overridesLoc), "configs/sourcebans/overrides_backup.cfg");
199
200 InitializeBackupDB();
201
202 // This timer is what processes the SQLite queue when the database is unavailable
203 CreateTimer(float(ProcessQueueTime * 60), ProcessQueue);
204
205 if (LateLoaded)
206 {
207 AccountForLateLoading();
208 }
209
210 #if defined _updater_included
211 if (LibraryExists("updater"))
212 {
213 Updater_AddPlugin(UPDATE_URL);
214 }
215 #endif
216}
217
218#if defined _updater_included
219public OnLibraryAdded(const String:name[])
220{
221 if (StrEqual(name, "updater"))
222 {
223 Updater_AddPlugin(UPDATE_URL);
224 }
225}
226#endif
227
228public OnAllPluginsLoaded()
229{
230 new Handle:topmenu;
231 #if defined DEBUG
232 LogToFile(logFile, "OnAllPluginsLoaded()");
233 #endif
234
235 if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
236 {
237 OnAdminMenuReady(topmenu);
238 }
239}
240
241public OnConfigsExecuted()
242{
243 decl String:filename[200];
244 BuildPath(Path_SM, filename, sizeof(filename), "plugins/basebans.smx");
245 if (FileExists(filename))
246 {
247 decl String:newfilename[200];
248 BuildPath(Path_SM, newfilename, sizeof(newfilename), "plugins/disabled/basebans.smx");
249 ServerCommand("sm plugins unload basebans");
250 if (FileExists(newfilename))
251 DeleteFile(newfilename);
252 RenameFile(newfilename, filename);
253 LogToFile(logFile, "plugins/basebans.smx was unloaded and moved to plugins/disabled/basebans.smx");
254 }
255}
256
257public OnMapStart()
258{
259 ResetSettings();
260}
261
262public OnMapEnd()
263{
264 for (new i = 0; i <= MaxClients; i++)
265 {
266 if (PlayerDataPack[i] != INVALID_HANDLE)
267 {
268 /* Need to close reason pack */
269 CloseHandle(PlayerDataPack[i]);
270 PlayerDataPack[i] = INVALID_HANDLE;
271 }
272 }
273}
274
275// CLIENT CONNECTION FUNCTIONS //
276
277public Action:OnClientPreAdminCheck(client)
278{
279 if (!DB || GetUserAdmin(client) != INVALID_ADMIN_ID)
280 return Plugin_Continue;
281
282 return curLoading > 0 ? Plugin_Handled : Plugin_Continue;
283}
284
285public OnClientDisconnect(client)
286{
287 if (PlayerRecheck[client] != INVALID_HANDLE)
288 {
289 KillTimer(PlayerRecheck[client]);
290 PlayerRecheck[client] = INVALID_HANDLE;
291 }
292 g_ownReasons[client] = false;
293}
294
295public bool:OnClientConnect(client, String:rejectmsg[], maxlen)
296{
297 PlayerStatus[client] = false;
298 return true;
299}
300
301public OnClientAuthorized(client, const String:auth[])
302{
303 /* Do not check bots nor check player with lan steamid. */
304 if (auth[0] == 'B' || auth[9] == 'L' || DB == INVALID_HANDLE)
305 {
306 PlayerStatus[client] = true;
307 return;
308 }
309
310 decl String:Query[256], String:ip[30];
311 GetClientIP(client, ip, sizeof(ip));
312 FormatEx(Query, sizeof(Query), "SELECT bid FROM %s_bans WHERE ((type = 0 AND authid REGEXP '^STEAM_[0-9]:%s$') OR (type = 1 AND ip = '%s')) AND (length = '0' OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL", DatabasePrefix, auth[8], ip);
313 #if defined DEBUG
314 LogToFile(logFile, "Checking ban for: %s", auth);
315 #endif
316
317 SQL_TQuery(DB, VerifyBan, Query, GetClientUserId(client), DBPrio_High);
318}
319
320public OnRebuildAdminCache(AdminCachePart:part)
321{
322 loadPart = part;
323 switch (loadPart)
324 {
325 case AdminCache_Overrides:
326 loadOverrides = true;
327 case AdminCache_Groups:
328 loadGroups = true;
329 case AdminCache_Admins:
330 loadAdmins = true;
331 }
332 if (DB == INVALID_HANDLE) {
333 if (!g_bConnecting) {
334 g_bConnecting = true;
335 SQL_TConnect(GotDatabase, "sourcebans");
336 }
337 }
338 else {
339 GotDatabase(DB, DB, "", 0);
340 }
341}
342
343// COMMAND CODE //
344
345public Action:ChatHook(client, args)
346{
347 // is this player preparing to ban someone
348 if (g_ownReasons[client])
349 {
350 // get the reason
351 new String:reason[512];
352 GetCmdArgString(reason, sizeof(reason));
353 StripQuotes(reason);
354
355 g_ownReasons[client] = false;
356
357 if (StrEqual(reason[0], "!noreason"))
358 {
359 PrintToChat(client, "%c[%cSourceBans%c]%c %t", GREEN, NAMECOLOR, GREEN, NAMECOLOR, "Chat Reason Aborted");
360 return Plugin_Handled;
361 }
362
363 // ban him!
364 PrepareBan(client, g_BanTarget[client], g_BanTime[client], reason, sizeof(reason));
365
366 // block the reason to be sent in chat
367 return Plugin_Handled;
368 }
369 return Plugin_Continue;
370}
371
372public Action:_CmdReload(client, args)
373{
374 ResetSettings();
375 return Plugin_Handled;
376}
377
378public Action:CommandBan(client, args)
379{
380 if (args < 2)
381 {
382 ReplyToCommand(client, "%sUsage: sm_fmtkmpd <#userid|name> <time|0> [reason]", Prefix);
383 return Plugin_Handled;
384 }
385
386 // This is mainly for me sanity since client used to be called admin and target used to be called client
387 new admin = client;
388
389 // Get the target, find target returns a message on failure so we do not
390 decl String:buffer[100];
391 GetCmdArg(1, buffer, sizeof(buffer));
392 new target = FindTarget(client, buffer, true);
393 if (target == -1)
394 {
395 return Plugin_Handled;
396 }
397
398 // Get the ban time
399 GetCmdArg(2, buffer, sizeof(buffer));
400 new time = StringToInt(buffer);
401 if (!time && client && !(CheckCommandAccess(client, "sm_unban", ADMFLAG_UNBAN | ADMFLAG_ROOT)))
402 {
403 ReplyToCommand(client, "You do not have Perm Ban Permission");
404 return Plugin_Handled;
405 }
406
407 // Get the reason
408 new String:reason[128];
409 if (args >= 3)
410 {
411 GetCmdArg(3, reason, sizeof(reason));
412 for (new i = 4; i <= args; i++)
413 {
414 GetCmdArg(i, buffer, sizeof(buffer));
415 Format(reason, sizeof(reason), "%s %s", reason, buffer);
416 }
417 }
418 else
419 {
420 reason[0] = '\0';
421 }
422
423 g_BanTarget[client] = target;
424 g_BanTime[client] = time;
425
426 if (!PlayerStatus[target])
427 {
428 // The target has not been banned verify. It must be completed before you can ban anyone.
429 ReplyToCommand(admin, "%c[%cSourceBans%c]%c %t", GREEN, NAMECOLOR, GREEN, NAMECOLOR, "Ban Not Verified");
430 return Plugin_Handled;
431 }
432
433
434 CreateBan(client, target, time, reason);
435 return Plugin_Handled;
436}
437
438public Action:CommandBanIp(client, args)
439{
440 if (args < 2)
441 {
442 ReplyToCommand(client, "%sUsage: sm_fmtkmpdip <ip|#userid|name> <time> [reason]", Prefix);
443 return Plugin_Handled;
444 }
445
446 decl len, next_len;
447 decl String:Arguments[256];
448 decl String:arg[50], String:time[20];
449
450 GetCmdArgString(Arguments, sizeof(Arguments));
451 len = BreakString(Arguments, arg, sizeof(arg));
452
453 if ((next_len = BreakString(Arguments[len], time, sizeof(time))) != -1)
454 {
455 len += next_len;
456 }
457 else
458 {
459 len = 0;
460 Arguments[0] = '\0';
461 }
462
463 decl String:target_name[MAX_TARGET_LENGTH];
464 decl target_list[1], bool:tn_is_ml;
465 new target = -1;
466
467 if (ProcessTargetString(
468 arg,
469 client,
470 target_list,
471 1,
472 COMMAND_FILTER_CONNECTED | COMMAND_FILTER_NO_MULTI,
473 target_name,
474 sizeof(target_name),
475 tn_is_ml) > 0)
476 {
477 target = target_list[0];
478
479 if (!IsFakeClient(target) && CanUserTarget(client, target))
480 GetClientIP(target, arg, sizeof(arg));
481 }
482
483 decl String:adminIp[24], String:adminAuth[64];
484 new minutes = StringToInt(time);
485 if (!minutes && client && !(CheckCommandAccess(client, "sm_unban", ADMFLAG_UNBAN | ADMFLAG_ROOT)))
486 {
487 ReplyToCommand(client, "You do not have Perm Ban Permission");
488 return Plugin_Handled;
489 }
490 if (!client)
491 {
492 // setup dummy adminAuth and adminIp for server
493 strcopy(adminAuth, sizeof(adminAuth), "STEAM_ID_SERVER");
494 strcopy(adminIp, sizeof(adminIp), ServerIp);
495 } else {
496 GetClientIP(client, adminIp, sizeof(adminIp));
497 GetClientAuthId(client, AuthId_Steam2, adminAuth, sizeof(adminAuth));
498 }
499
500 // Pack everything into a data pack so we can retain it
501 new Handle:dataPack = CreateDataPack();
502 WritePackCell(dataPack, client);
503 WritePackCell(dataPack, minutes);
504 WritePackString(dataPack, Arguments[len]);
505 WritePackString(dataPack, arg);
506 WritePackString(dataPack, adminAuth);
507 WritePackString(dataPack, adminIp);
508
509 decl String:Query[256];
510 FormatEx(Query, sizeof(Query), "SELECT bid FROM %s_bans WHERE type = 1 AND ip = '%s' AND (length = 0 OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL",
511 DatabasePrefix, arg);
512
513 SQL_TQuery(DB, SelectBanIpCallback, Query, dataPack, DBPrio_High);
514 return Plugin_Handled;
515}
516
517public Action:CommandUnban(client, args)
518{
519 if (args < 1)
520 {
521 ReplyToCommand(client, "%sUsage: sm_unban <steamid|ip> [reason]", Prefix);
522 return Plugin_Handled;
523 }
524
525 if (CommandDisable & DISABLE_UNBAN)
526 {
527 // They must go to the website to unban people
528 ReplyToCommand(client, "%s%t", Prefix, "Can Not Unban", WebsiteAddress);
529 return Plugin_Handled;
530 }
531
532 decl len, String:Arguments[256], String:arg[50], String:adminAuth[64];
533 GetCmdArgString(Arguments, sizeof(Arguments));
534
535 if ((len = BreakString(Arguments, arg, sizeof(arg))) == -1)
536 {
537 len = 0;
538 Arguments[0] = '\0';
539 }
540 if (!client)
541 {
542 // setup dummy adminAuth and adminIp for server
543 strcopy(adminAuth, sizeof(adminAuth), "STEAM_ID_SERVER");
544 } else {
545 GetClientAuthId(client, AuthId_Steam2, adminAuth, sizeof(adminAuth));
546 }
547
548 // Pack everything into a data pack so we can retain it
549 new Handle:dataPack = CreateDataPack();
550 WritePackCell(dataPack, client);
551 WritePackString(dataPack, Arguments[len]);
552 WritePackString(dataPack, arg);
553 WritePackString(dataPack, adminAuth);
554
555 decl String:query[200];
556 if (strncmp(arg, "STEAM_", 6) == 0)
557 {
558 Format(query, sizeof(query), "SELECT bid FROM %s_bans WHERE (type = 0 AND authid = '%s') AND (length = '0' OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL", DatabasePrefix, arg);
559 } else {
560 Format(query, sizeof(query), "SELECT bid FROM %s_bans WHERE (type = 1 AND ip = '%s') AND (length = '0' OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL", DatabasePrefix, arg);
561 }
562 SQL_TQuery(DB, SelectUnbanCallback, query, dataPack);
563 return Plugin_Handled;
564}
565
566public Action:CommandAddBan(client, args)
567{
568 if (args < 2)
569 {
570 ReplyToCommand(client, "%sUsage: sm_addfmtkmpd <time> <steamid> [reason]", Prefix);
571 return Plugin_Handled;
572 }
573
574 if (CommandDisable & DISABLE_ADDBAN)
575 {
576 // They must go to the website to add bans
577 ReplyToCommand(client, "%s%t", Prefix, "Can Not Add Ban", WebsiteAddress);
578 return Plugin_Handled;
579 }
580
581 decl String:arg_string[256], String:time[50], String:authid[50];
582 GetCmdArgString(arg_string, sizeof(arg_string));
583
584 new len, total_len;
585
586 /* Get time */
587 if ((len = BreakString(arg_string, time, sizeof(time))) == -1)
588 {
589 ReplyToCommand(client, "%sUsage: sm_addfmtkmpd <time> <steamid> [reason]", Prefix);
590 return Plugin_Handled;
591 }
592 total_len += len;
593
594 /* Get steamid */
595 if ((len = BreakString(arg_string[total_len], authid, sizeof(authid))) != -1)
596 {
597 total_len += len;
598 }
599 else
600 {
601 total_len = 0;
602 arg_string[0] = '\0';
603 }
604
605 decl String:adminIp[24], String:adminAuth[64];
606 new minutes = StringToInt(time);
607 if (!minutes && client && !(CheckCommandAccess(client, "sm_unban", ADMFLAG_UNBAN | ADMFLAG_ROOT)))
608 {
609 ReplyToCommand(client, "You do not have Perm Ban Permission");
610 return Plugin_Handled;
611 }
612 if (!client)
613 {
614 // setup dummy adminAuth and adminIp for server
615 strcopy(adminAuth, sizeof(adminAuth), "STEAM_ID_SERVER");
616 strcopy(adminIp, sizeof(adminIp), ServerIp);
617 } else {
618 GetClientIP(client, adminIp, sizeof(adminIp));
619 GetClientAuthId(client, AuthId_Steam2, adminAuth, sizeof(adminAuth));
620 }
621
622 // Pack everything into a data pack so we can retain it
623 new Handle:dataPack = CreateDataPack();
624 WritePackCell(dataPack, client);
625 WritePackCell(dataPack, minutes);
626 WritePackString(dataPack, arg_string[total_len]);
627 WritePackString(dataPack, authid);
628 WritePackString(dataPack, adminAuth);
629 WritePackString(dataPack, adminIp);
630
631 decl String:Query[256];
632 FormatEx(Query, sizeof(Query), "SELECT bid FROM %s_bans WHERE type = 0 AND authid = '%s' AND (length = 0 OR ends > UNIX_TIMESTAMP()) AND RemoveType IS NULL",
633 DatabasePrefix, authid);
634
635 SQL_TQuery(DB, SelectAddbanCallback, Query, dataPack, DBPrio_High);
636 return Plugin_Handled;
637}
638
639public Action:sm_rehash(args)
640{
641 if (enableAdmins)
642 DumpAdminCache(AdminCache_Groups, true);
643 DumpAdminCache(AdminCache_Overrides, true);
644 return Plugin_Handled;
645}
646
647
648
649// MENU CODE //
650
651public OnAdminMenuReady(Handle:topmenu)
652{
653 #if defined DEBUG
654 LogToFile(logFile, "OnAdminMenuReady()");
655 #endif
656
657 /* Block us from being called twice */
658 if (topmenu == hTopMenu)
659 {
660 return;
661 }
662
663 /* Save the Handle */
664 hTopMenu = topmenu;
665
666 /* Find the "Player Commands" category */
667 new TopMenuObject:player_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_PLAYERCOMMANDS);
668
669 if (player_commands != INVALID_TOPMENUOBJECT)
670 {
671 // just to avoid "unused variable 'res'" warning
672 #if defined DEBUG
673 new TopMenuObject:res = AddToTopMenu(hTopMenu,
674 "sm_fmtkmpd", // Name
675 TopMenuObject_Item, // We are a submenu
676 AdminMenu_Ban, // Handler function
677 player_commands, // We are a submenu of Player Commands
678 "sm_fmtkmpd", // The command to be finally called (Override checks)
679 ADMFLAG_BAN); // What flag do we need to see the menu option
680 decl String:temp[125];
681 Format(temp, 125, "Result of AddToTopMenu: %d", res);
682 LogToFile(logFile, temp);
683 LogToFile(logFile, "Added Ban option to admin menu");
684 #else
685 AddToTopMenu(hTopMenu,
686 "sm_fmtkmpd", // Name
687 TopMenuObject_Item, // We are a submenu
688 AdminMenu_Ban, // Handler function
689 player_commands, // We are a submenu of Player Commands
690 "sm_fmtkmpd", // The command to be finally called (Override checks)
691 ADMFLAG_BAN); // What flag do we need to see the menu option
692 #endif
693 }
694}
695
696public AdminMenu_Ban(Handle:topmenu,
697 TopMenuAction:action, // Action being performed
698 TopMenuObject:object_id, // The object ID (if used)
699 param, // client idx of admin who chose the option (if used)
700 String:buffer[], // Output buffer (if used)
701 maxlength) // Output buffer (if used)
702{
703 /* Clear the Ownreason bool, so he is able to chat again;) */
704 g_ownReasons[param] = false;
705
706 #if defined DEBUG
707 LogToFile(logFile, "AdminMenu_Ban()");
708 #endif
709
710 switch (action)
711 {
712 // We are only being displayed, We only need to show the option name
713 case TopMenuAction_DisplayOption:
714 {
715 Format(buffer, maxlength, "%T", "Ban player", param);
716
717 #if defined DEBUG
718 LogToFile(logFile, "AdminMenu_Ban() -> Formatted the Ban option text");
719 #endif
720 }
721
722 case TopMenuAction_SelectOption:
723 {
724 DisplayBanTargetMenu(param); // Someone chose to ban someone, show the list of users menu
725
726 #if defined DEBUG
727 LogToFile(logFile, "AdminMenu_Ban() -> DisplayBanTargetMenu()");
728 #endif
729 }
730 }
731}
732
733public ReasonSelected(Handle:menu, MenuAction:action, param1, param2)
734{
735 switch (action)
736 {
737 case MenuAction_Select:
738 {
739 decl String:info[128], String:key[128];
740 GetMenuItem(menu, param2, key, sizeof(key), _, info, sizeof(info));
741
742 if (StrEqual("Hacking", key))
743 {
744 DisplayMenu(HackingMenuHandle, param1, MENU_TIME_FOREVER);
745 return;
746 }
747
748 else if (StrEqual("Own Reason", key)) // admin wants to use his own reason
749 {
750 g_ownReasons[param1] = true;
751 PrintToChat(param1, "%c[%cSourceBans%c]%c %t", GREEN, NAMECOLOR, GREEN, NAMECOLOR, "Chat Reason");
752 return;
753 }
754
755 else if (g_BanTarget[param1] != -1 && g_BanTime[param1] != -1)
756 PrepareBan(param1, g_BanTarget[param1], g_BanTime[param1], info, sizeof(info));
757 }
758
759 case MenuAction_Cancel:
760 {
761 if (param2 == MenuCancel_Disconnected)
762 {
763 if (PlayerDataPack[param1] != INVALID_HANDLE)
764 {
765 CloseHandle(PlayerDataPack[param1]);
766 PlayerDataPack[param1] = INVALID_HANDLE;
767 }
768 }
769
770 else
771 {
772 DisplayBanTimeMenu(param1);
773 }
774 }
775 }
776}
777
778public HackingSelected(Handle:menu, MenuAction:action, param1, param2)
779{
780 switch (action)
781 {
782 case MenuAction_Select:
783 {
784 decl String:info[128], String:key[128];
785 GetMenuItem(menu, param2, key, sizeof(key), _, info, sizeof(info));
786
787 if (g_BanTarget[param1] != -1 && g_BanTime[param1] != -1)
788 PrepareBan(param1, g_BanTarget[param1], g_BanTime[param1], info, sizeof(info));
789 }
790
791 case MenuAction_Cancel:
792 {
793 if (param2 == MenuCancel_Disconnected)
794 {
795 new Handle:Pack = PlayerDataPack[param1];
796
797 if (Pack != INVALID_HANDLE)
798 {
799 ReadPackCell(Pack); // admin index
800 ReadPackCell(Pack); // target index
801 ReadPackCell(Pack); // admin userid
802 ReadPackCell(Pack); // target userid
803 ReadPackCell(Pack); // time
804 new Handle:ReasonPack = Handle:ReadPackCell(Pack);
805
806 if (ReasonPack != INVALID_HANDLE)
807 {
808 CloseHandle(ReasonPack);
809 }
810
811 CloseHandle(Pack);
812 PlayerDataPack[param1] = INVALID_HANDLE;
813 }
814 }
815
816 else
817 {
818 DisplayMenu(ReasonMenuHandle, param1, MENU_TIME_FOREVER);
819 }
820 }
821 }
822}
823
824public MenuHandler_BanPlayerList(Handle:menu, MenuAction:action, param1, param2)
825{
826 #if defined DEBUG
827 LogToFile(logFile, "MenuHandler_BanPlayerList()");
828 #endif
829
830 switch (action)
831 {
832 case MenuAction_End:
833 {
834 CloseHandle(menu);
835 }
836
837 case MenuAction_Cancel:
838 {
839 if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
840 {
841 DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
842 }
843 }
844
845 case MenuAction_Select:
846 {
847 decl String:info[32], String:name[32];
848 new userid, target;
849
850 GetMenuItem(menu, param2, info, sizeof(info), _, name, sizeof(name));
851 userid = StringToInt(info);
852
853 if ((target = GetClientOfUserId(userid)) == 0)
854 {
855 PrintToChat(param1, "%s%t", Prefix, "Player no longer available");
856 }
857 else if (!CanUserTarget(param1, target))
858 {
859 PrintToChat(param1, "%s%t", Prefix, "Unable to target");
860 }
861 else
862 {
863 g_BanTarget[param1] = target;
864 DisplayBanTimeMenu(param1);
865 }
866 }
867 }
868}
869
870public MenuHandler_BanTimeList(Handle:menu, MenuAction:action, param1, param2)
871{
872 #if defined DEBUG
873 LogToFile(logFile, "MenuHandler_BanTimeList()");
874 #endif
875
876 switch (action)
877 {
878 case MenuAction_End:
879 {
880 CloseHandle(menu);
881 }
882
883 case MenuAction_Cancel:
884 {
885 if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
886 {
887 DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
888 }
889 }
890
891 case MenuAction_Select:
892 {
893 decl String:info[32];
894
895 GetMenuItem(menu, param2, info, sizeof(info));
896 g_BanTime[param1] = StringToInt(info);
897
898 //DisplayBanReasonMenu(param1);
899 DisplayMenu(ReasonMenuHandle, param1, MENU_TIME_FOREVER);
900 }
901 }
902}
903
904stock DisplayBanTargetMenu(client)
905{
906 #if defined DEBUG
907 LogToFile(logFile, "DisplayBanTargetMenu()");
908 #endif
909 new Handle:menu = CreateMenu(MenuHandler_BanPlayerList); // Create a new menu, pass it the handler.
910
911 decl String:title[100];
912 Format(title, sizeof(title), "%T:", "Ban player", client);
913
914 //Format(title, sizeof(title), "Ban player", client); // Create the title of the menu
915 SetMenuTitle(menu, title); // Set the title
916 SetMenuExitBackButton(menu, true); // Yes we want back/exit
917
918 AddTargetsToMenu(menu, // Add clients to our menu
919 client, // The client that called the display
920 false, // We want to see people connecting
921 false); // And dead people
922
923 DisplayMenu(menu, client, MENU_TIME_FOREVER); // Show the menu to the client FOREVER!
924}
925
926stock DisplayBanTimeMenu(client)
927{
928 #if defined DEBUG
929 LogToFile(logFile, "DisplayBanTimeMenu()");
930 #endif
931
932 new Handle:menu = CreateMenu(MenuHandler_BanTimeList);
933
934 decl String:title[100];
935 Format(title, sizeof(title), "%T:", "Ban player", client);
936 //Format(title, sizeof(title), "Ban player", client);
937 SetMenuTitle(menu, title);
938 SetMenuExitBackButton(menu, true);
939
940 if (CheckCommandAccess(client, "sm_unban", ADMFLAG_UNBAN | ADMFLAG_ROOT))
941 AddMenuItem(menu, "0", "Végleges");
942 AddMenuItem(menu, "1", "1 perc");
943 AddMenuItem(menu, "5", "5 perc");
944 AddMenuItem(menu, "15", "15 perc");
945 AddMenuItem(menu, "30", "30 perc");
946 AddMenuItem(menu, "60", "1 óra");
947 AddMenuItem(menu, "240", "4 óra");
948 AddMenuItem(menu, "360", "6 óra");
949 AddMenuItem(menu, "720", "12 óra");
950 AddMenuItem(menu, "1440", "1 nap");
951 AddMenuItem(menu, "10080", "1 hét");
952 AddMenuItem(menu, "43200", "1 hónap");
953 AddMenuItem(menu, "525600", "1 év");
954
955 DisplayMenu(menu, client, MENU_TIME_FOREVER);
956}
957
958stock ResetMenu()
959{
960 if (ReasonMenuHandle != INVALID_HANDLE)
961 {
962 RemoveAllMenuItems(ReasonMenuHandle);
963 }
964}
965
966// QUERY CALL BACKS //
967
968public GotDatabase(Handle:owner, Handle:hndl, const String:error[], any:data)
969{
970 if (hndl == INVALID_HANDLE)
971 {
972 LogToFile(logFile, "Database failure: %s. See FAQ: https://sbpp.sarabveer.me/faq/", error);
973 g_bConnecting = false;
974
975 // Parse the overrides backup!
976 ParseBackupConfig_Overrides();
977 return;
978 }
979
980 DB = hndl;
981
982 decl String:query[1024];
983 SQL_SetCharset(DB, "utf8");
984
985 InsertServerInfo();
986
987 //CreateTimer(900.0, PruneBans);
988
989 if (loadOverrides)
990 {
991 Format(query, 1024, "SELECT type, name, flags FROM %s_overrides", DatabasePrefix);
992 SQL_TQuery(DB, OverridesDone, query);
993 loadOverrides = false;
994 }
995
996 if (loadGroups && enableAdmins)
997 {
998 FormatEx(query, 1024, "SELECT name, flags, immunity, groups_immune \
999 FROM %s_srvgroups ORDER BY id", DatabasePrefix);
1000 curLoading++;
1001 SQL_TQuery(DB, GroupsDone, query);
1002
1003 #if defined DEBUG
1004 LogToFile(logFile, "Fetching Group List");
1005 #endif
1006 loadGroups = false;
1007 }
1008
1009 if (loadAdmins && enableAdmins)
1010 {
1011 new String:queryLastLogin[50] = "";
1012
1013 if (requireSiteLogin)
1014 queryLastLogin = "lastvisit IS NOT NULL AND lastvisit != '' AND";
1015
1016 if (serverID == -1)
1017 {
1018 FormatEx(query, 1024, "SELECT authid, srv_password, (SELECT name FROM %s_srvgroups WHERE name = srv_group AND flags != '') AS srv_group, srv_flags, user, immunity \
1019 FROM %s_admins_servers_groups AS asg \
1020 LEFT JOIN %s_admins AS a ON a.aid = asg.admin_id \
1021 WHERE %s (server_id = (SELECT sid FROM %s_servers WHERE ip = '%s' AND port = '%s' LIMIT 0,1) \
1022 OR srv_group_id = ANY (SELECT group_id FROM %s_servers_groups WHERE server_id = (SELECT sid FROM %s_servers WHERE ip = '%s' AND port = '%s' LIMIT 0,1))) \
1023 GROUP BY aid, authid, srv_password, srv_group, srv_flags, user",
1024 DatabasePrefix, DatabasePrefix, DatabasePrefix, queryLastLogin, DatabasePrefix, ServerIp, ServerPort, DatabasePrefix, DatabasePrefix, ServerIp, ServerPort);
1025 } else {
1026 FormatEx(query, 1024, "SELECT authid, srv_password, (SELECT name FROM %s_srvgroups WHERE name = srv_group AND flags != '') AS srv_group, srv_flags, user, immunity \
1027 FROM %s_admins_servers_groups AS asg \
1028 LEFT JOIN %s_admins AS a ON a.aid = asg.admin_id \
1029 WHERE %s server_id = %d \
1030 OR srv_group_id = ANY (SELECT group_id FROM %s_servers_groups WHERE server_id = %d) \
1031 GROUP BY aid, authid, srv_password, srv_group, srv_flags, user",
1032 DatabasePrefix, DatabasePrefix, DatabasePrefix, queryLastLogin, serverID, DatabasePrefix, serverID);
1033 }
1034 curLoading++;
1035 SQL_TQuery(DB, AdminsDone, query);
1036
1037 #if defined DEBUG
1038 LogToFile(logFile, "Fetching Admin List");
1039 LogToFile(logFile, query);
1040 #endif
1041 loadAdmins = false;
1042 }
1043 g_bConnecting = false;
1044}
1045
1046public VerifyInsert(Handle:owner, Handle:hndl, const String:error[], any:dataPack)
1047{
1048 if (dataPack == INVALID_HANDLE)
1049 {
1050 LogToFile(logFile, "Ban Failed: %s", error);
1051 return;
1052 }
1053
1054 if (hndl == INVALID_HANDLE || error[0])
1055 {
1056 LogToFile(logFile, "Verify Insert Query Failed: %s", error);
1057 new admin = ReadPackCell(dataPack);
1058 ReadPackCell(dataPack); // target
1059 ReadPackCell(dataPack); // admin userid
1060 ReadPackCell(dataPack); // target userid
1061 new time = ReadPackCell(dataPack);
1062 new Handle:reasonPack = Handle:ReadPackCell(dataPack);
1063 new String:reason[128];
1064 ReadPackString(reasonPack, reason, sizeof(reason));
1065 decl String:name[50];
1066 ReadPackString(dataPack, name, sizeof(name));
1067 decl String:auth[30];
1068 ReadPackString(dataPack, auth, sizeof(auth));
1069 decl String:ip[20];
1070 ReadPackString(dataPack, ip, sizeof(ip));
1071 decl String:adminAuth[30];
1072 ReadPackString(dataPack, adminAuth, sizeof(adminAuth));
1073 decl String:adminIp[20];
1074 ReadPackString(dataPack, adminIp, sizeof(adminIp));
1075 ResetPack(dataPack);
1076 ResetPack(reasonPack);
1077
1078 PlayerDataPack[admin] = INVALID_HANDLE;
1079 UTIL_InsertTempBan(time, name, auth, ip, reason, adminAuth, adminIp, Handle:dataPack);
1080 return;
1081 }
1082
1083 new admin = ReadPackCell(dataPack);
1084 new client = ReadPackCell(dataPack);
1085
1086 if (!IsClientConnected(client) || IsFakeClient(client))
1087 return;
1088
1089 ReadPackCell(dataPack); // admin userid
1090 new UserId = ReadPackCell(dataPack);
1091 new time = ReadPackCell(dataPack);
1092 new Handle:ReasonPack = Handle:ReadPackCell(dataPack);
1093
1094 decl String:Name[64];
1095 new String:Reason[128];
1096
1097 ReadPackString(dataPack, Name, sizeof(Name));
1098 ReadPackString(ReasonPack, Reason, sizeof(Reason));
1099
1100 if (!time)
1101 {
1102 if (Reason[0] == '\0')
1103 {
1104 ShowActivityEx(admin, Prefix, "%t", "Permabanned player", Name);
1105 } else {
1106 ShowActivityEx(admin, Prefix, "%t", "Permabanned player reason", Name, Reason);
1107 }
1108 } else {
1109 if (Reason[0] == '\0')
1110 {
1111 ShowActivityEx(admin, Prefix, "%t", "Banned player", Name, time);
1112 } else {
1113 ShowActivityEx(admin, Prefix, "%t", "Banned player reason", Name, time, Reason);
1114 }
1115 }
1116
1117 LogAction(admin, client, "\"%L\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", admin, client, time, Reason);
1118
1119 if (PlayerDataPack[admin] != INVALID_HANDLE)
1120 {
1121 CloseHandle(PlayerDataPack[admin]);
1122 CloseHandle(ReasonPack);
1123 PlayerDataPack[admin] = INVALID_HANDLE;
1124 }
1125
1126 // Kick player
1127 if (GetClientUserId(client) == UserId)
1128 KickClient(client, "%t", "Banned Check Site", WebsiteAddress);
1129}
1130
1131public SelectBanIpCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
1132{
1133 decl admin, minutes, String:adminAuth[30], String:adminIp[30], String:banReason[256], String:ip[16], String:Query[512];
1134 new String:reason[128];
1135 ResetPack(data);
1136 admin = ReadPackCell(data);
1137 minutes = ReadPackCell(data);
1138 ReadPackString(data, reason, sizeof(reason));
1139 ReadPackString(data, ip, sizeof(ip));
1140 ReadPackString(data, adminAuth, sizeof(adminAuth));
1141 ReadPackString(data, adminIp, sizeof(adminIp));
1142 SQL_EscapeString(DB, reason, banReason, sizeof(banReason));
1143
1144 if (error[0])
1145 {
1146 LogToFile(logFile, "Ban IP Select Query Failed: %s", error);
1147 if (admin && IsClientInGame(admin))
1148 PrintToChat(admin, "%sFailed to ban %s.", Prefix, ip);
1149 else
1150 PrintToServer("%sFailed to ban %s.", Prefix, ip);
1151 return;
1152 }
1153 if (SQL_GetRowCount(hndl))
1154 {
1155 if (admin && IsClientInGame(admin))
1156 PrintToChat(admin, "%s%s is already banned.", Prefix, ip);
1157 else
1158 PrintToServer("%s%s is already banned.", Prefix, ip);
1159 return;
1160 }
1161 if (serverID == -1)
1162 {
1163 FormatEx(Query, sizeof(Query), "INSERT INTO %s_bans (type, ip, name, created, ends, length, reason, aid, adminIp, sid, country) VALUES \
1164 (1, '%s', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + %d, %d, '%s', (SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'), '%s', \
1165 (SELECT sid FROM %s_servers WHERE ip = '%s' AND port = '%s' LIMIT 0,1), ' ')",
1166 DatabasePrefix, ip, (minutes * 60), (minutes * 60), banReason, DatabasePrefix, adminAuth, adminAuth[8], adminIp, DatabasePrefix, ServerIp, ServerPort);
1167 } else {
1168 FormatEx(Query, sizeof(Query), "INSERT INTO %s_bans (type, ip, name, created, ends, length, reason, aid, adminIp, sid, country) VALUES \
1169 (1, '%s', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + %d, %d, '%s', (SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'), '%s', \
1170 %d, ' ')",
1171 DatabasePrefix, ip, (minutes * 60), (minutes * 60), banReason, DatabasePrefix, adminAuth, adminAuth[8], adminIp, serverID);
1172 }
1173
1174 SQL_TQuery(DB, InsertBanIpCallback, Query, data, DBPrio_High);
1175}
1176
1177public InsertBanIpCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
1178{
1179 // if the pack is good unpack it and close the handle
1180 new admin, minutes;
1181 new String:reason[128];
1182 decl String:arg[30];
1183 if (data != INVALID_HANDLE)
1184 {
1185 ResetPack(data);
1186 admin = ReadPackCell(data);
1187 minutes = ReadPackCell(data);
1188 ReadPackString(data, reason, sizeof(reason));
1189 ReadPackString(data, arg, sizeof(arg));
1190 CloseHandle(data);
1191 } else {
1192 // Technically this should not be possible
1193 ThrowError("Invalid Handle in InsertBanIpCallback");
1194 }
1195
1196 // If error is not an empty string the query failed
1197 if (error[0] != '\0')
1198 {
1199 LogToFile(logFile, "Ban IP Insert Query Failed: %s", error);
1200 if (admin && IsClientInGame(admin))
1201 PrintToChat(admin, "%ssm_fmtkmpdip failed", Prefix);
1202 return;
1203 }
1204
1205 LogAction(admin,
1206 -1,
1207 "\"%L\" added ban (minutes \"%d\") (ip \"%s\") (reason \"%s\")",
1208 admin,
1209 minutes,
1210 arg,
1211 reason);
1212 if (admin && IsClientInGame(admin))
1213 PrintToChat(admin, "%s%s successfully banned", Prefix, arg);
1214 else
1215 PrintToServer("%s%s successfully banned", Prefix, arg);
1216}
1217
1218public SelectUnbanCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
1219{
1220 decl admin, String:arg[30], String:adminAuth[30], String:unbanReason[256];
1221 new String:reason[128];
1222 ResetPack(data);
1223 admin = ReadPackCell(data);
1224 ReadPackString(data, reason, sizeof(reason));
1225 ReadPackString(data, arg, sizeof(arg));
1226 ReadPackString(data, adminAuth, sizeof(adminAuth));
1227 SQL_EscapeString(DB, reason, unbanReason, sizeof(unbanReason));
1228
1229 // If error is not an empty string the query failed
1230 if (error[0] != '\0')
1231 {
1232 LogToFile(logFile, "Unban Select Query Failed: %s", error);
1233 if (admin && IsClientInGame(admin))
1234 {
1235 PrintToChat(admin, "%ssm_unban failed", Prefix);
1236 }
1237 return;
1238 }
1239
1240 // If there was no results then a ban does not exist for that id
1241 if (hndl == INVALID_HANDLE || !SQL_GetRowCount(hndl))
1242 {
1243 if (admin && IsClientInGame(admin))
1244 {
1245 PrintToChat(admin, "%sNo active bans found for that filter", Prefix);
1246 } else {
1247 PrintToServer("%sNo active bans found for that filter", Prefix);
1248 }
1249 return;
1250 }
1251
1252 // There is ban
1253 if (hndl != INVALID_HANDLE && SQL_FetchRow(hndl))
1254 {
1255 // Get the values from the existing ban record
1256 new bid = SQL_FetchInt(hndl, 0);
1257
1258 decl String:query[1000];
1259 Format(query, sizeof(query), "UPDATE %s_bans SET RemovedBy = (SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'), RemoveType = 'U', RemovedOn = UNIX_TIMESTAMP(), ureason = '%s' WHERE bid = %d",
1260 DatabasePrefix, DatabasePrefix, adminAuth, adminAuth[8], unbanReason, bid);
1261
1262 SQL_TQuery(DB, InsertUnbanCallback, query, data);
1263 }
1264 return;
1265}
1266
1267public InsertUnbanCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
1268{
1269 // if the pack is good unpack it and close the handle
1270 decl admin, String:arg[30];
1271 new String:reason[128];
1272 if (data != INVALID_HANDLE)
1273 {
1274 ResetPack(data);
1275 admin = ReadPackCell(data);
1276 ReadPackString(data, reason, sizeof(reason));
1277 ReadPackString(data, arg, sizeof(arg));
1278 CloseHandle(data);
1279 } else {
1280 // Technically this should not be possible
1281 ThrowError("Invalid Handle in InsertUnbanCallback");
1282 }
1283
1284 // If error is not an empty string the query failed
1285 if (error[0] != '\0')
1286 {
1287 LogToFile(logFile, "Unban Insert Query Failed: %s", error);
1288 if (admin && IsClientInGame(admin))
1289 {
1290 PrintToChat(admin, "%ssm_unban failed", Prefix);
1291 }
1292 return;
1293 }
1294
1295 LogAction(admin, -1, "\"%L\" removed ban (filter \"%s\") (reason \"%s\")", admin, arg, reason);
1296 if (admin && IsClientInGame(admin))
1297 {
1298 PrintToChat(admin, "%s%s successfully unbanned", Prefix, arg);
1299 } else {
1300 PrintToServer("%s%s successfully unbanned", Prefix, arg);
1301 }
1302}
1303
1304public SelectAddbanCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
1305{
1306 decl admin, minutes, String:adminAuth[30], String:adminIp[30], String:authid[20], String:banReason[256], String:Query[512];
1307 new String:reason[128];
1308 ResetPack(data);
1309 admin = ReadPackCell(data);
1310 minutes = ReadPackCell(data);
1311 ReadPackString(data, reason, sizeof(reason));
1312 ReadPackString(data, authid, sizeof(authid));
1313 ReadPackString(data, adminAuth, sizeof(adminAuth));
1314 ReadPackString(data, adminIp, sizeof(adminIp));
1315 SQL_EscapeString(DB, reason, banReason, sizeof(banReason));
1316
1317 if (error[0])
1318 {
1319 LogToFile(logFile, "Add Ban Select Query Failed: %s", error);
1320 if (admin && IsClientInGame(admin))
1321 PrintToChat(admin, "%sFailed to ban %s.", Prefix, authid);
1322 else
1323 PrintToServer("%sFailed to ban %s.", Prefix, authid);
1324 return;
1325 }
1326 if (SQL_GetRowCount(hndl))
1327 {
1328 if (admin && IsClientInGame(admin))
1329 PrintToChat(admin, "%s%s is already banned.", Prefix, authid);
1330 else
1331 PrintToServer("%s%s is already banned.", Prefix, authid);
1332 return;
1333 }
1334 if (serverID == -1)
1335 {
1336 FormatEx(Query, sizeof(Query), "INSERT INTO %s_bans (authid, name, created, ends, length, reason, aid, adminIp, sid, country) VALUES \
1337 ('%s', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + %d, %d, '%s', (SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'), '%s', \
1338 (SELECT sid FROM %s_servers WHERE ip = '%s' AND port = '%s' LIMIT 0,1), ' ')",
1339 DatabasePrefix, authid, (minutes * 60), (minutes * 60), banReason, DatabasePrefix, adminAuth, adminAuth[8], adminIp, DatabasePrefix, ServerIp, ServerPort);
1340 } else {
1341 FormatEx(Query, sizeof(Query), "INSERT INTO %s_bans (authid, name, created, ends, length, reason, aid, adminIp, sid, country) VALUES \
1342 ('%s', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + %d, %d, '%s', (SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'), '%s', \
1343 %d, ' ')",
1344 DatabasePrefix, authid, (minutes * 60), (minutes * 60), banReason, DatabasePrefix, adminAuth, adminAuth[8], adminIp, serverID);
1345 }
1346
1347 SQL_TQuery(DB, InsertAddbanCallback, Query, data, DBPrio_High);
1348}
1349
1350public InsertAddbanCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
1351{
1352 decl admin, minutes, String:authid[20];
1353 new String:reason[128];
1354 ResetPack(data);
1355 admin = ReadPackCell(data);
1356 minutes = ReadPackCell(data);
1357 ReadPackString(data, reason, sizeof(reason));
1358 ReadPackString(data, authid, sizeof(authid));
1359
1360 // If error is not an empty string the query failed
1361 if (error[0] != '\0')
1362 {
1363 LogToFile(logFile, "Add Ban Insert Query Failed: %s", error);
1364 if (admin && IsClientInGame(admin))
1365 {
1366 PrintToChat(admin, "%ssm_addfmtkmpd failed", Prefix);
1367 }
1368 return;
1369 }
1370
1371 LogAction(admin,
1372 -1,
1373 "\"%L\" added ban (minutes \"%i\") (id \"%s\") (reason \"%s\")",
1374 admin,
1375 minutes,
1376 authid,
1377 reason);
1378 if (admin && IsClientInGame(admin))
1379 {
1380 PrintToChat(admin, "%s%s successfully banned", Prefix, authid);
1381 } else {
1382 PrintToServer("%s%s successfully banned", Prefix, authid);
1383 }
1384}
1385
1386// ProcessQueueCallback is called as the result of selecting all the rows from the queue table
1387public ProcessQueueCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
1388{
1389 if (hndl == INVALID_HANDLE || strlen(error) > 0)
1390 {
1391 LogToFile(logFile, "Failed to retrieve queued bans from sqlite database, %s", error);
1392 return;
1393 }
1394
1395 decl String:auth[30];
1396 decl time;
1397 decl startTime;
1398 new String:reason[128];
1399 decl String:name[64];
1400 decl String:ip[20];
1401 decl String:adminAuth[30];
1402 decl String:adminIp[20];
1403 decl String:query[1024];
1404 decl String:banName[128];
1405 decl String:banReason[256];
1406 while (SQL_MoreRows(hndl))
1407 {
1408 // Oh noes! What happened?!
1409 if (!SQL_FetchRow(hndl))
1410 continue;
1411
1412 // if we get to here then there are rows in the queue pending processing
1413 SQL_FetchString(hndl, 0, auth, sizeof(auth));
1414 time = SQL_FetchInt(hndl, 1);
1415 startTime = SQL_FetchInt(hndl, 2);
1416 SQL_FetchString(hndl, 3, reason, sizeof(reason));
1417 SQL_FetchString(hndl, 4, name, sizeof(name));
1418 SQL_FetchString(hndl, 5, ip, sizeof(ip));
1419 SQL_FetchString(hndl, 6, adminAuth, sizeof(adminAuth));
1420 SQL_FetchString(hndl, 7, adminIp, sizeof(adminIp));
1421 SQL_EscapeString(SQLiteDB, name, banName, sizeof(banName));
1422 SQL_EscapeString(SQLiteDB, reason, banReason, sizeof(banReason));
1423 if (startTime + time * 60 > GetTime() || time == 0)
1424 {
1425 // This ban is still valid and should be entered into the db
1426 if (serverID == -1)
1427 {
1428 FormatEx(query, sizeof(query),
1429 "INSERT INTO %s_bans (ip, authid, name, created, ends, length, reason, aid, adminIp, sid) VALUES \
1430 ('%s', '%s', '%s', %d, %d, %d, '%s', (SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'), '%s', \
1431 (SELECT sid FROM %s_servers WHERE ip = '%s' AND port = '%s' LIMIT 0,1))",
1432 DatabasePrefix, ip, auth, banName, startTime, startTime + time * 60, time * 60, banReason, DatabasePrefix, adminAuth, adminAuth[8], adminIp, DatabasePrefix, ServerIp, ServerPort);
1433 }
1434 else
1435 {
1436 FormatEx(query, sizeof(query),
1437 "INSERT INTO %s_bans (ip, authid, name, created, ends, length, reason, aid, adminIp, sid) VALUES \
1438 ('%s', '%s', '%s', %d, %d, %d, '%s', (SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'), '%s', \
1439 %d)",
1440 DatabasePrefix, ip, auth, banName, startTime, startTime + time * 60, time * 60, banReason, DatabasePrefix, adminAuth, adminAuth[8], adminIp, serverID);
1441 }
1442 new Handle:authPack = CreateDataPack();
1443 WritePackString(authPack, auth);
1444 ResetPack(authPack);
1445 SQL_TQuery(DB, AddedFromSQLiteCallback, query, authPack);
1446 } else {
1447 // The ban is no longer valid and should be deleted from the queue
1448 FormatEx(query, sizeof(query), "DELETE FROM queue WHERE steam_id = '%s'", auth);
1449 SQL_TQuery(SQLiteDB, ErrorCheckCallback, query);
1450 }
1451 }
1452 // We have finished processing the queue but should process again in ProcessQueueTime minutes
1453 CreateTimer(float(ProcessQueueTime * 60), ProcessQueue);
1454}
1455
1456public AddedFromSQLiteCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
1457{
1458 decl String:buffer[512];
1459 decl String:auth[40];
1460 ReadPackString(data, auth, sizeof(auth));
1461 if (error[0] == '\0')
1462 {
1463 // The insert was successful so delete the record from the queue
1464 FormatEx(buffer, sizeof(buffer), "DELETE FROM queue WHERE steam_id = '%s'", auth);
1465 SQL_TQuery(SQLiteDB, ErrorCheckCallback, buffer);
1466
1467 // They are added to main banlist, so remove the temp ban
1468 RemoveBan(auth, BANFLAG_AUTHID);
1469
1470 } else {
1471 // the insert failed so we leave the record in the queue and increase our temporary ban
1472 FormatEx(buffer, sizeof(buffer), "banid %d %s", ProcessQueueTime, auth);
1473 ServerCommand(buffer);
1474 }
1475 CloseHandle(data);
1476}
1477
1478public ServerInfoCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
1479{
1480 if (error[0])
1481 {
1482 LogToFile(logFile, "Server Select Query Failed: %s", error);
1483 return;
1484 }
1485
1486 if (hndl == INVALID_HANDLE || SQL_GetRowCount(hndl) == 0)
1487 {
1488 // get the game folder name used to determine the mod
1489 decl String:desc[64], String:query[200];
1490 GetGameFolderName(desc, sizeof(desc));
1491 FormatEx(query, sizeof(query), "INSERT INTO %s_servers (ip, port, rcon, modid) VALUES ('%s', '%s', '', (SELECT mid FROM %s_mods WHERE modfolder = '%s'))", DatabasePrefix, ServerIp, ServerPort, DatabasePrefix, desc);
1492 SQL_TQuery(DB, ErrorCheckCallback, query);
1493 }
1494}
1495
1496public ErrorCheckCallback(Handle:owner, Handle:hndle, const String:error[], any:data)
1497{
1498 if (error[0])
1499 {
1500 LogToFile(logFile, "Query Failed: %s", error);
1501 }
1502}
1503
1504public VerifyBan(Handle:owner, Handle:hndl, const String:error[], any:userid)
1505{
1506 decl String:clientName[64];
1507 decl String:clientAuth[64];
1508 decl String:clientIp[64];
1509 new client = GetClientOfUserId(userid);
1510
1511 if (!client)
1512 return;
1513
1514 /* Failure happen. Do retry with delay */
1515 if (hndl == INVALID_HANDLE)
1516 {
1517 LogToFile(logFile, "Verify Ban Query Failed: %s", error);
1518 PlayerRecheck[client] = CreateTimer(RetryTime, ClientRecheck, client);
1519 return;
1520 }
1521 GetClientIP(client, clientIp, sizeof(clientIp));
1522 GetClientAuthId(client, AuthId_Steam2, clientAuth, sizeof(clientAuth));
1523 GetClientName(client, clientName, sizeof(clientName));
1524 if (SQL_GetRowCount(hndl) > 0)
1525 {
1526 decl String:buffer[40];
1527 decl String:Name[128];
1528 decl String:Query[512];
1529
1530 SQL_EscapeString(DB, clientName, Name, sizeof(Name));
1531 if (serverID == -1)
1532 {
1533 FormatEx(Query, sizeof(Query), "INSERT INTO %s_banlog (sid ,time ,name ,bid) VALUES \
1534 ((SELECT sid FROM %s_servers WHERE ip = '%s' AND port = '%s' LIMIT 0,1), UNIX_TIMESTAMP(), '%s', \
1535 (SELECT bid FROM %s_bans WHERE ((type = 0 AND authid REGEXP '^STEAM_[0-9]:%s$') OR (type = 1 AND ip = '%s')) AND RemoveType IS NULL LIMIT 0,1))",
1536 DatabasePrefix, DatabasePrefix, ServerIp, ServerPort, Name, DatabasePrefix, clientAuth[8], clientIp);
1537 }
1538 else
1539 {
1540 FormatEx(Query, sizeof(Query), "INSERT INTO %s_banlog (sid ,time ,name ,bid) VALUES \
1541 (%d, UNIX_TIMESTAMP(), '%s', \
1542 (SELECT bid FROM %s_bans WHERE ((type = 0 AND authid REGEXP '^STEAM_[0-9]:%s$') OR (type = 1 AND ip = '%s')) AND RemoveType IS NULL LIMIT 0,1))",
1543 DatabasePrefix, serverID, Name, DatabasePrefix, clientAuth[8], clientIp);
1544 }
1545
1546 SQL_TQuery(DB, ErrorCheckCallback, Query, client, DBPrio_High);
1547 FormatEx(buffer, sizeof(buffer), "banid 5 %s", clientAuth);
1548 ServerCommand(buffer);
1549 KickClient(client, "%t", "Banned Check Site", WebsiteAddress);
1550 return;
1551 }
1552 #if defined DEBUG
1553 LogToFile(logFile, "%s is NOT banned.", clientAuth);
1554 #endif
1555
1556 PlayerStatus[client] = true;
1557}
1558
1559public AdminsDone(Handle:owner, Handle:hndl, const String:error[], any:data)
1560{
1561 //SELECT authid, srv_password , srv_group, srv_flags, user
1562 if (hndl == INVALID_HANDLE || strlen(error) > 0)
1563 {
1564 --curLoading;
1565 CheckLoadAdmins();
1566 LogToFile(logFile, "Failed to retrieve admins from the database, %s", error);
1567 return;
1568 }
1569 decl String:authType[] = "steam";
1570 decl String:identity[66];
1571 decl String:password[66];
1572 decl String:groups[256];
1573 decl String:flags[32];
1574 decl String:name[66];
1575 new admCount = 0;
1576 new Immunity = 0;
1577 new AdminId:curAdm = INVALID_ADMIN_ID;
1578 new Handle:adminsKV = CreateKeyValues("Admins");
1579
1580 while (SQL_MoreRows(hndl))
1581 {
1582 SQL_FetchRow(hndl);
1583 if (SQL_IsFieldNull(hndl, 0))
1584 continue; // Sometimes some rows return NULL due to some setups
1585
1586 SQL_FetchString(hndl, 0, identity, 66);
1587 SQL_FetchString(hndl, 1, password, 66);
1588 SQL_FetchString(hndl, 2, groups, 256);
1589 SQL_FetchString(hndl, 3, flags, 32);
1590 SQL_FetchString(hndl, 4, name, 66);
1591
1592 Immunity = SQL_FetchInt(hndl, 5);
1593
1594 TrimString(name);
1595 TrimString(identity);
1596 TrimString(groups);
1597 TrimString(flags);
1598
1599 // Disable writing to file if they chose to
1600 if (backupConfig)
1601 {
1602 KvJumpToKey(adminsKV, name, true);
1603
1604 KvSetString(adminsKV, "auth", authType);
1605 KvSetString(adminsKV, "identity", identity);
1606
1607 if (strlen(flags) > 0)
1608 KvSetString(adminsKV, "flags", flags);
1609
1610 if (strlen(groups) > 0)
1611 KvSetString(adminsKV, "group", groups);
1612
1613 if (strlen(password) > 0)
1614 KvSetString(adminsKV, "password", password);
1615
1616 if (Immunity > 0)
1617 KvSetNum(adminsKV, "immunity", Immunity);
1618
1619 KvRewind(adminsKV);
1620 }
1621
1622 // find or create the admin using that identity
1623 if ((curAdm = FindAdminByIdentity(authType, identity)) == INVALID_ADMIN_ID)
1624 {
1625 curAdm = CreateAdmin(name);
1626 // That should never happen!
1627 if (!BindAdminIdentity(curAdm, authType, identity))
1628 {
1629 LogToFile(logFile, "Unable to bind admin %s to identity %s", name, identity);
1630 RemoveAdmin(curAdm);
1631 continue;
1632 }
1633 }
1634
1635 #if defined DEBUG
1636 LogToFile(logFile, "Given %s (%s) admin", name, identity);
1637 #endif
1638
1639 new curPos = 0;
1640 new GroupId:curGrp = INVALID_GROUP_ID;
1641 new numGroups;
1642 decl String:iterGroupName[64];
1643
1644 // Who thought this comma seperated group parsing would be a good idea?!
1645 /*
1646 decl String:grp[64];
1647 new nextPos = 0;
1648 while ((nextPos = SplitString(groups[curPos],",",grp,64)) != -1)
1649 {
1650 curPos += nextPos;
1651 curGrp = FindAdmGroup(grp);
1652 if (curGrp == INVALID_GROUP_ID)
1653 {
1654 LogToFile(logFile, "Unknown group \"%s\"",grp);
1655 }
1656 else
1657 {
1658 // Check, if he's not in the group already.
1659 numGroups = GetAdminGroupCount(curAdm);
1660 for(new i=0;i<numGroups;i++)
1661 {
1662 GetAdminGroup(curAdm, i, iterGroupName, sizeof(iterGroupName));
1663 // Admin is already part of the group, so don't try to inherit its permissions.
1664 if(StrEqual(iterGroupName, grp))
1665 {
1666 numGroups = -2;
1667 break;
1668 }
1669 }
1670 // Only try to inherit the group, if it's a new one.
1671 if (numGroups != -2 && !AdminInheritGroup(curAdm,curGrp))
1672 {
1673 LogToFile(logFile, "Unable to inherit group \"%s\"",grp);
1674 }
1675 }
1676 }*/
1677
1678 if (strcmp(groups[curPos], "") != 0)
1679 {
1680 curGrp = FindAdmGroup(groups[curPos]);
1681 if (curGrp == INVALID_GROUP_ID)
1682 {
1683 LogToFile(logFile, "Unknown group \"%s\"", groups[curPos]);
1684 }
1685 else
1686 {
1687 // Check, if he's not in the group already.
1688 numGroups = GetAdminGroupCount(curAdm);
1689 for (new i = 0; i < numGroups; i++)
1690 {
1691 GetAdminGroup(curAdm, i, iterGroupName, sizeof(iterGroupName));
1692 // Admin is already part of the group, so don't try to inherit its permissions.
1693 if (StrEqual(iterGroupName, groups[curPos]))
1694 {
1695 numGroups = -2;
1696 break;
1697 }
1698 }
1699
1700 // Only try to inherit the group, if it's a new one.
1701 if (numGroups != -2 && !AdminInheritGroup(curAdm, curGrp))
1702 {
1703 LogToFile(logFile, "Unable to inherit group \"%s\"", groups[curPos]);
1704 }
1705
1706 if (GetAdminImmunityLevel(curAdm) < Immunity)
1707 {
1708 SetAdminImmunityLevel(curAdm, Immunity);
1709 }
1710 #if defined DEBUG
1711 LogToFile(logFile, "Admin %s (%s) has %d immunity", name, identity, Immunity);
1712 #endif
1713 }
1714 }
1715
1716 if (strlen(password) > 0)
1717 SetAdminPassword(curAdm, password);
1718
1719 for (new i = 0; i < strlen(flags); ++i)
1720 {
1721 if (flags[i] < 'a' || flags[i] > 'z')
1722 continue;
1723
1724 if (g_FlagLetters[flags[i]-'a'] < Admin_Reservation)
1725 continue;
1726
1727 SetAdminFlag(curAdm, g_FlagLetters[flags[i]-'a'], true);
1728 }
1729 ++admCount;
1730 }
1731
1732 if (backupConfig)
1733 KeyValuesToFile(adminsKV, adminsLoc);
1734 CloseHandle(adminsKV);
1735
1736 #if defined DEBUG
1737 LogToFile(logFile, "Finished loading %i admins.", admCount);
1738 #endif
1739
1740 --curLoading;
1741 CheckLoadAdmins();
1742}
1743
1744public GroupsDone(Handle:owner, Handle:hndl, const String:error[], any:data)
1745{
1746 if (hndl == INVALID_HANDLE)
1747 {
1748 curLoading--;
1749 CheckLoadAdmins();
1750 LogToFile(logFile, "Failed to retrieve groups from the database, %s", error);
1751 return;
1752 }
1753 decl String:grpName[128], String:immuneGrpName[128];
1754 decl String:grpFlags[32];
1755 new Immunity;
1756 new grpCount = 0;
1757 new Handle:groupsKV = CreateKeyValues("Groups");
1758
1759 new GroupId:curGrp = INVALID_GROUP_ID;
1760 while (SQL_MoreRows(hndl))
1761 {
1762 SQL_FetchRow(hndl);
1763 if (SQL_IsFieldNull(hndl, 0))
1764 continue; // Sometimes some rows return NULL due to some setups
1765 SQL_FetchString(hndl, 0, grpName, 128);
1766 SQL_FetchString(hndl, 1, grpFlags, 32);
1767 Immunity = SQL_FetchInt(hndl, 2);
1768 SQL_FetchString(hndl, 3, immuneGrpName, 128);
1769
1770 TrimString(grpName);
1771 TrimString(grpFlags);
1772 TrimString(immuneGrpName);
1773
1774 // Ignore empty rows..
1775 if (!strlen(grpName))
1776 continue;
1777
1778 curGrp = CreateAdmGroup(grpName);
1779
1780 if (backupConfig)
1781 {
1782 KvJumpToKey(groupsKV, grpName, true);
1783 if (strlen(grpFlags) > 0)
1784 KvSetString(groupsKV, "flags", grpFlags);
1785 if (Immunity > 0)
1786 KvSetNum(groupsKV, "immunity", Immunity);
1787
1788 KvRewind(groupsKV);
1789 }
1790
1791 if (curGrp == INVALID_GROUP_ID)
1792 { //This occurs when the group already exists
1793 curGrp = FindAdmGroup(grpName);
1794 }
1795
1796 for (new i = 0; i < strlen(grpFlags); ++i)
1797 {
1798 if (grpFlags[i] < 'a' || grpFlags[i] > 'z')
1799 continue;
1800
1801 if (g_FlagLetters[grpFlags[i]-'a'] < Admin_Reservation)
1802 continue;
1803
1804 SetAdmGroupAddFlag(curGrp, g_FlagLetters[grpFlags[i]-'a'], true);
1805 }
1806
1807 // Set the group immunity.
1808 if (Immunity > 0)
1809 {
1810 SetAdmGroupImmunityLevel(curGrp, Immunity);
1811 #if defined DEBUG
1812 LogToFile(logFile, "Group %s has %d immunity", grpName, Immunity);
1813 #endif
1814 }
1815
1816 grpCount++;
1817 }
1818
1819 if (backupConfig)
1820 KeyValuesToFile(groupsKV, groupsLoc);
1821 CloseHandle(groupsKV);
1822
1823 #if defined DEBUG
1824 LogToFile(logFile, "Finished loading %i groups.", grpCount);
1825 #endif
1826
1827 // Load the group overrides
1828 decl String:query[512];
1829 FormatEx(query, 512, "SELECT sg.name, so.type, so.name, so.access FROM %s_srvgroups_overrides so LEFT JOIN %s_srvgroups sg ON sg.id = so.group_id ORDER BY sg.id", DatabasePrefix, DatabasePrefix);
1830 SQL_TQuery(DB, LoadGroupsOverrides, query);
1831
1832 /*if (reparse)
1833 {
1834 decl String:query[512];
1835 FormatEx(query,512,"SELECT name, immunity, groups_immune FROM %s_srvgroups ORDER BY id",DatabasePrefix);
1836 SQL_TQuery(DB,GroupsSecondPass,query);
1837 }
1838 else
1839 {
1840 curLoading--;
1841 CheckLoadAdmins();
1842 }*/
1843}
1844
1845// Reparse to apply inherited immunity
1846public GroupsSecondPass(Handle:owner, Handle:hndl, const String:error[], any:data)
1847{
1848 if (hndl == INVALID_HANDLE)
1849 {
1850 curLoading--;
1851 CheckLoadAdmins();
1852 LogToFile(logFile, "Failed to retrieve groups from the database, %s", error);
1853 return;
1854 }
1855 decl String:grpName[128], String:immunityGrpName[128];
1856
1857 new GroupId:curGrp = INVALID_GROUP_ID;
1858 new GroupId:immuneGrp = INVALID_GROUP_ID;
1859 while (SQL_MoreRows(hndl))
1860 {
1861 SQL_FetchRow(hndl);
1862 if (SQL_IsFieldNull(hndl, 0))
1863 continue; // Sometimes some rows return NULL due to some setups
1864
1865 SQL_FetchString(hndl, 0, grpName, 128);
1866 TrimString(grpName);
1867 if (strlen(grpName) == 0)
1868 continue;
1869
1870 SQL_FetchString(hndl, 2, immunityGrpName, sizeof(immunityGrpName));
1871 TrimString(immunityGrpName);
1872
1873 curGrp = FindAdmGroup(grpName);
1874 if (curGrp == INVALID_GROUP_ID)
1875 continue;
1876
1877 immuneGrp = FindAdmGroup(immunityGrpName);
1878 if (immuneGrp == INVALID_GROUP_ID)
1879 continue;
1880
1881 SetAdmGroupImmuneFrom(curGrp, immuneGrp);
1882
1883 #if defined DEBUG
1884 LogToFile(logFile, "Group %s inhertied immunity from group %s", grpName, immunityGrpName);
1885 #endif
1886 }
1887 --curLoading;
1888 CheckLoadAdmins();
1889}
1890
1891public LoadGroupsOverrides(Handle:owner, Handle:hndl, const String:error[], any:data)
1892{
1893 if (hndl == INVALID_HANDLE)
1894 {
1895 curLoading--;
1896 CheckLoadAdmins();
1897 LogToFile(logFile, "Failed to retrieve group overrides from the database, %s", error);
1898 return;
1899 }
1900 decl String:sGroupName[128], String:sType[16], String:sCommand[64], String:sAllowed[16];
1901 decl OverrideRule:iRule, OverrideType:iType;
1902
1903 new Handle:groupsKV = CreateKeyValues("Groups");
1904 FileToKeyValues(groupsKV, groupsLoc);
1905
1906 new GroupId:curGrp = INVALID_GROUP_ID;
1907 while (SQL_MoreRows(hndl))
1908 {
1909 SQL_FetchRow(hndl);
1910 if (SQL_IsFieldNull(hndl, 0))
1911 continue; // Sometimes some rows return NULL due to some setups
1912
1913 SQL_FetchString(hndl, 0, sGroupName, sizeof(sGroupName));
1914 TrimString(sGroupName);
1915 if (strlen(sGroupName) == 0)
1916 continue;
1917
1918 SQL_FetchString(hndl, 1, sType, sizeof(sType));
1919 SQL_FetchString(hndl, 2, sCommand, sizeof(sCommand));
1920 SQL_FetchString(hndl, 3, sAllowed, sizeof(sAllowed));
1921
1922 curGrp = FindAdmGroup(sGroupName);
1923 if (curGrp == INVALID_GROUP_ID)
1924 continue;
1925
1926 iRule = StrEqual(sAllowed, "allow") ? Command_Allow : Command_Deny;
1927 iType = StrEqual(sType, "group") ? Override_CommandGroup : Override_Command;
1928
1929 #if defined DEBUG
1930 PrintToServer("AddAdmGroupCmdOverride(%i, %s, %i, %i)", curGrp, sCommand, iType, iRule);
1931 #endif
1932
1933 // Save overrides into admin_groups.cfg backup
1934 if (KvJumpToKey(groupsKV, sGroupName))
1935 {
1936 KvJumpToKey(groupsKV, "Overrides", true);
1937 if (iType == Override_Command)
1938 KvSetString(groupsKV, sCommand, sAllowed);
1939 else
1940 {
1941 Format(sCommand, sizeof(sCommand), "@%s", sCommand);
1942 KvSetString(groupsKV, sCommand, sAllowed);
1943 }
1944 KvRewind(groupsKV);
1945 }
1946
1947 AddAdmGroupCmdOverride(curGrp, sCommand, iType, iRule);
1948 }
1949 curLoading--;
1950 CheckLoadAdmins();
1951
1952 if (backupConfig)
1953 KeyValuesToFile(groupsKV, groupsLoc);
1954 CloseHandle(groupsKV);
1955}
1956
1957public OverridesDone(Handle:owner, Handle:hndl, const String:error[], any:data)
1958{
1959 if (hndl == INVALID_HANDLE)
1960 {
1961 LogToFile(logFile, "Failed to retrieve overrides from the database, %s", error);
1962 ParseBackupConfig_Overrides();
1963 return;
1964 }
1965
1966 new Handle:hKV = CreateKeyValues("SB_Overrides");
1967
1968 decl String:sFlags[32], String:sName[64], String:sType[64];
1969 while (SQL_FetchRow(hndl))
1970 {
1971 SQL_FetchString(hndl, 0, sType, sizeof(sType));
1972 SQL_FetchString(hndl, 1, sName, sizeof(sName));
1973 SQL_FetchString(hndl, 2, sFlags, sizeof(sFlags));
1974
1975 // KeyValuesToFile won't add that key, if the value is ""..
1976 if (sFlags[0] == '\0')
1977 {
1978 sFlags[0] = ' ';
1979 sFlags[1] = '\0';
1980 }
1981
1982 #if defined DEBUG
1983 LogToFile(logFile, "Adding override (%s, %s, %s)", sType, sName, sFlags);
1984 #endif
1985
1986 if (StrEqual(sType, "command"))
1987 {
1988 AddCommandOverride(sName, Override_Command, ReadFlagString(sFlags));
1989 KvJumpToKey(hKV, "override_commands", true);
1990 KvSetString(hKV, sName, sFlags);
1991 KvGoBack(hKV);
1992 }
1993 else if (StrEqual(sType, "group"))
1994 {
1995 AddCommandOverride(sName, Override_CommandGroup, ReadFlagString(sFlags));
1996 KvJumpToKey(hKV, "override_groups", true);
1997 KvSetString(hKV, sName, sFlags);
1998 KvGoBack(hKV);
1999 }
2000 }
2001
2002 KvRewind(hKV);
2003
2004 if (backupConfig)
2005 KeyValuesToFile(hKV, overridesLoc);
2006 CloseHandle(hKV);
2007}
2008
2009// TIMER CALL BACKS //
2010
2011public Action:ClientRecheck(Handle:timer, any:client)
2012{
2013 decl String:Authid[64];
2014 if (!PlayerStatus[client] && IsClientConnected(client) && GetClientAuthId(client, AuthId_Steam2, Authid, sizeof(Authid)))
2015 {
2016 OnClientAuthorized(client, Authid);
2017 }
2018
2019 PlayerRecheck[client] = INVALID_HANDLE;
2020 return Plugin_Stop;
2021}
2022
2023/*
2024public Action:PruneBans(Handle:timer)
2025{
2026 decl String:Query[512];
2027 FormatEx(Query, sizeof(Query),
2028 "UPDATE %s_bans SET RemovedBy = 0, RemoveType = 'E', RemovedOn = UNIX_TIMESTAMP() WHERE length != '0' AND ends < UNIX_TIMESTAMP()",
2029 DatabasePrefix);
2030
2031 SQL_TQuery(DB, ErrorCheckCallback, Query);
2032 return Plugin_Continue;
2033}
2034*/
2035
2036public Action:ProcessQueue(Handle:timer, any:data)
2037{
2038 decl String:buffer[512];
2039 Format(buffer, sizeof(buffer), "SELECT steam_id, time, start_time, reason, name, ip, admin_id, admin_ip FROM queue");
2040 SQL_TQuery(SQLiteDB, ProcessQueueCallback, buffer);
2041}
2042
2043// PARSER //
2044
2045static InitializeConfigParser()
2046{
2047 if (ConfigParser == INVALID_HANDLE)
2048 {
2049 ConfigParser = SMC_CreateParser();
2050 SMC_SetReaders(ConfigParser, ReadConfig_NewSection, ReadConfig_KeyValue, ReadConfig_EndSection);
2051 }
2052}
2053
2054static InternalReadConfig(const String:path[])
2055{
2056 ConfigState = ConfigStateNone;
2057
2058 new SMCError:err = SMC_ParseFile(ConfigParser, path);
2059
2060 if (err != SMCError_Okay)
2061 {
2062 decl String:buffer[64];
2063 PrintToServer("%s", SMC_GetErrorString(err, buffer, sizeof(buffer)) ? buffer : "Fatal parse error");
2064 }
2065}
2066
2067public SMCResult:ReadConfig_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
2068{
2069 if (name[0])
2070 {
2071 if (strcmp("Config", name, false) == 0)
2072 {
2073 ConfigState = ConfigStateConfig;
2074 } else if (strcmp("BanReasons", name, false) == 0) {
2075 ConfigState = ConfigStateReasons;
2076 } else if (strcmp("HackingReasons", name, false) == 0) {
2077 ConfigState = ConfigStateHacking;
2078 }
2079 }
2080 return SMCParse_Continue;
2081}
2082
2083public SMCResult:ReadConfig_KeyValue(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes)
2084{
2085 if (!key[0])
2086 return SMCParse_Continue;
2087
2088 switch (ConfigState)
2089 {
2090 case ConfigStateConfig:
2091 {
2092 if (strcmp("website", key, false) == 0)
2093 {
2094 strcopy(WebsiteAddress, sizeof(WebsiteAddress), value);
2095 }
2096 else if (strcmp("Addban", key, false) == 0)
2097 {
2098 if (StringToInt(value) == 0)
2099 {
2100 CommandDisable |= DISABLE_ADDBAN;
2101 }
2102 }
2103 else if (strcmp("AutoAddServer", key, false) == 0)
2104 {
2105 AutoAdd = StringToInt(value) == 1;
2106 }
2107 else if (strcmp("Unban", key, false) == 0)
2108 {
2109 if (StringToInt(value) == 0)
2110 {
2111 CommandDisable |= DISABLE_UNBAN;
2112 }
2113 }
2114 else if (strcmp("DatabasePrefix", key, false) == 0)
2115 {
2116 strcopy(DatabasePrefix, sizeof(DatabasePrefix), value);
2117
2118 if (DatabasePrefix[0] == '\0')
2119 {
2120 DatabasePrefix = "sb";
2121 }
2122 }
2123 else if (strcmp("RetryTime", key, false) == 0)
2124 {
2125 RetryTime = StringToFloat(value);
2126 if (RetryTime < 15.0)
2127 {
2128 RetryTime = 15.0;
2129 } else if (RetryTime > 60.0) {
2130 RetryTime = 60.0;
2131 }
2132 }
2133 else if (strcmp("ProcessQueueTime", key, false) == 0)
2134 {
2135 ProcessQueueTime = StringToInt(value);
2136 }
2137 else if (strcmp("BackupConfigs", key, false) == 0)
2138 {
2139 backupConfig = StringToInt(value) == 1;
2140 }
2141 else if (strcmp("EnableAdmins", key, false) == 0)
2142 {
2143 enableAdmins = StringToInt(value) == 1;
2144 }
2145 else if (strcmp("RequireSiteLogin", key, false) == 0)
2146 {
2147 requireSiteLogin = StringToInt(value) == 1;
2148 }
2149 else if (strcmp("ServerID", key, false) == 0)
2150 {
2151 serverID = StringToInt(value);
2152 }
2153 }
2154
2155 case ConfigStateReasons:
2156 {
2157 if (ReasonMenuHandle != INVALID_HANDLE)
2158 {
2159 AddMenuItem(ReasonMenuHandle, key, value);
2160 }
2161 }
2162 case ConfigStateHacking:
2163 {
2164 if (HackingMenuHandle != INVALID_HANDLE)
2165 {
2166 AddMenuItem(HackingMenuHandle, key, value);
2167 }
2168 }
2169 }
2170 return SMCParse_Continue;
2171}
2172
2173public SMCResult:ReadConfig_EndSection(Handle:smc)
2174{
2175 return SMCParse_Continue;
2176}
2177
2178
2179/*********************************************************
2180 * Ban Player from server
2181 *
2182 * @param client The client index of the player to ban
2183 * @param time The time to ban the player for (in minutes, 0 = permanent)
2184 * @param reason The reason to ban the player from the server
2185 * @noreturn
2186 *********************************************************/
2187public Native_SBBanPlayer(Handle:plugin, numParams)
2188{
2189 new client = GetNativeCell(1);
2190 new target = GetNativeCell(2);
2191 new time = GetNativeCell(3);
2192 new String:reason[128];
2193 GetNativeString(4, reason, 128);
2194
2195 if (reason[0] == '\0')
2196 strcopy(reason, sizeof(reason), "Banned by SourceBans");
2197
2198 if (client && IsClientInGame(client))
2199 {
2200 new AdminId:aid = GetUserAdmin(client);
2201 if (aid == INVALID_ADMIN_ID)
2202 {
2203 ThrowNativeError(SP_ERROR_NATIVE, "Ban Error: Player is not an admin.");
2204 return 0;
2205 }
2206
2207 if (!GetAdminFlag(aid, Admin_Ban))
2208 {
2209 ThrowNativeError(SP_ERROR_NATIVE, "Ban Error: Player does not have BAN flag.");
2210 return 0;
2211 }
2212 }
2213
2214 PrepareBan(client, target, time, reason, sizeof(reason));
2215 return true;
2216}
2217
2218
2219// STOCK FUNCTIONS //
2220
2221public InitializeBackupDB()
2222{
2223 decl String:error[255];
2224 SQLiteDB = SQLite_UseDatabase("sourcebans-queue", error, sizeof(error));
2225 if (SQLiteDB == INVALID_HANDLE)
2226 SetFailState(error);
2227
2228 SQL_LockDatabase(SQLiteDB);
2229 SQL_FastQuery(SQLiteDB, "CREATE TABLE IF NOT EXISTS queue (steam_id TEXT PRIMARY KEY ON CONFLICT REPLACE, time INTEGER, start_time INTEGER, reason TEXT, name TEXT, ip TEXT, admin_id TEXT, admin_ip TEXT);");
2230 SQL_UnlockDatabase(SQLiteDB);
2231}
2232
2233public bool:CreateBan(client, target, time, String:reason[])
2234{
2235 decl String:adminIp[24], String:adminAuth[64];
2236 new admin = client;
2237
2238 // The server is the one calling the ban
2239 if (!admin)
2240 {
2241 if (reason[0] == '\0')
2242 {
2243 // We cannot pop the reason menu if the command was issued from the server
2244 PrintToServer("%s%T", Prefix, "Include Reason", LANG_SERVER);
2245 return false;
2246 }
2247
2248 // setup dummy adminAuth and adminIp for server
2249 strcopy(adminAuth, sizeof(adminAuth), "STEAM_ID_SERVER");
2250 strcopy(adminIp, sizeof(adminIp), ServerIp);
2251 } else {
2252 GetClientIP(admin, adminIp, sizeof(adminIp));
2253 GetClientAuthId(admin, AuthId_Steam2, adminAuth, sizeof(adminAuth));
2254 }
2255
2256 // target information
2257 decl String:ip[24], String:auth[64], String:name[64];
2258
2259 GetClientName(target, name, sizeof(name));
2260 GetClientIP(target, ip, sizeof(ip));
2261 if (!GetClientAuthId(target, AuthId_Steam2, auth, sizeof(auth)))
2262 return false;
2263
2264 new userid = admin ? GetClientUserId(admin) : 0;
2265
2266 // Pack everything into a data pack so we can retain it
2267 new Handle:dataPack = CreateDataPack();
2268 new Handle:reasonPack = CreateDataPack();
2269 WritePackString(reasonPack, reason);
2270
2271 WritePackCell(dataPack, admin);
2272 WritePackCell(dataPack, target);
2273 WritePackCell(dataPack, userid);
2274 WritePackCell(dataPack, GetClientUserId(target));
2275 WritePackCell(dataPack, time);
2276 WritePackCell(dataPack, _:reasonPack);
2277 WritePackString(dataPack, name);
2278 WritePackString(dataPack, auth);
2279 WritePackString(dataPack, ip);
2280 WritePackString(dataPack, adminAuth);
2281 WritePackString(dataPack, adminIp);
2282
2283 ResetPack(dataPack);
2284 ResetPack(reasonPack);
2285
2286 if (reason[0] != '\0')
2287 {
2288 // if we have a valid reason pass move forward with the ban
2289 if (DB != INVALID_HANDLE)
2290 {
2291 UTIL_InsertBan(time, name, auth, ip, reason, adminAuth, adminIp, dataPack);
2292 } else {
2293 UTIL_InsertTempBan(time, name, auth, ip, reason, adminAuth, adminIp, dataPack);
2294 }
2295 } else {
2296 // We need a reason so offer the administrator a menu of reasons
2297 PlayerDataPack[admin] = dataPack;
2298 DisplayMenu(ReasonMenuHandle, admin, MENU_TIME_FOREVER);
2299 ReplyToCommand(admin, "%c[%cSourceBans%c]%c %t", GREEN, NAMECOLOR, GREEN, NAMECOLOR, "Check Menu");
2300 }
2301
2302 Call_StartForward(g_hFwd_OnBanAdded);
2303 Call_PushCell(client);
2304 Call_PushCell(target);
2305 Call_PushCell(time);
2306 Call_PushString(reason);
2307 Call_Finish();
2308
2309 return true;
2310}
2311
2312stock UTIL_InsertBan(time, const String:Name[], const String:Authid[], const String:Ip[], const String:Reason[], const String:AdminAuthid[], const String:AdminIp[], Handle:Pack)
2313{
2314 //new Handle:dummy;
2315 //PruneBans(dummy);
2316 decl String:banName[128];
2317 decl String:banReason[256];
2318 decl String:Query[1024];
2319 SQL_EscapeString(DB, Name, banName, sizeof(banName));
2320 SQL_EscapeString(DB, Reason, banReason, sizeof(banReason));
2321 if (serverID == -1)
2322 {
2323 FormatEx(Query, sizeof(Query), "INSERT INTO %s_bans (ip, authid, name, created, ends, length, reason, aid, adminIp, sid, country) VALUES \
2324 ('%s', '%s', '%s', UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + %d, %d, '%s', IFNULL((SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'),'0'), '%s', \
2325 (SELECT sid FROM %s_servers WHERE ip = '%s' AND port = '%s' LIMIT 0,1), ' ')",
2326 DatabasePrefix, Ip, Authid, banName, (time * 60), (time * 60), banReason, DatabasePrefix, AdminAuthid, AdminAuthid[8], AdminIp, DatabasePrefix, ServerIp, ServerPort);
2327 } else {
2328 FormatEx(Query, sizeof(Query), "INSERT INTO %s_bans (ip, authid, name, created, ends, length, reason, aid, adminIp, sid, country) VALUES \
2329 ('%s', '%s', '%s', UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + %d, %d, '%s', IFNULL((SELECT aid FROM %s_admins WHERE authid = '%s' OR authid REGEXP '^STEAM_[0-9]:%s$'),'0'), '%s', \
2330 %d, ' ')",
2331 DatabasePrefix, Ip, Authid, banName, (time * 60), (time * 60), banReason, DatabasePrefix, AdminAuthid, AdminAuthid[8], AdminIp, serverID);
2332 }
2333
2334 SQL_TQuery(DB, VerifyInsert, Query, Pack, DBPrio_High);
2335}
2336
2337stock UTIL_InsertTempBan(time, const String:name[], const String:auth[], const String:ip[], const String:reason[], const String:adminAuth[], const String:adminIp[], Handle:dataPack)
2338{
2339 ReadPackCell(dataPack); // admin index
2340 new client = ReadPackCell(dataPack);
2341 ReadPackCell(dataPack); // admin userid
2342 ReadPackCell(dataPack); // target userid
2343 ReadPackCell(dataPack); // time
2344 new Handle:reasonPack = Handle:ReadPackCell(dataPack);
2345 if (reasonPack != INVALID_HANDLE)
2346 {
2347 CloseHandle(reasonPack);
2348 }
2349 CloseHandle(dataPack);
2350
2351 // we add a temporary ban and then add the record into the queue to be processed when the database is available
2352 decl String:buffer[50];
2353 Format(buffer, sizeof(buffer), "banid %d %s", ProcessQueueTime, auth);
2354 ServerCommand(buffer);
2355 if (IsClientInGame(client))
2356 KickClient(client, "%t", "Banned Check Site", WebsiteAddress);
2357
2358 decl String:banName[128];
2359 decl String:banReason[256];
2360 decl String:query[512];
2361 SQL_EscapeString(SQLiteDB, name, banName, sizeof(banName));
2362 SQL_EscapeString(SQLiteDB, reason, banReason, sizeof(banReason));
2363 FormatEx(query, sizeof(query), "INSERT INTO queue VALUES ('%s', %i, %i, '%s', '%s', '%s', '%s', '%s')",
2364 auth, time, GetTime(), banReason, banName, ip, adminAuth, adminIp);
2365 SQL_TQuery(SQLiteDB, ErrorCheckCallback, query);
2366}
2367
2368stock CheckLoadAdmins()
2369{
2370 for (new i = 1; i <= MaxClients; i++)
2371 {
2372 if (IsClientInGame(i) && IsClientAuthorized(i))
2373 {
2374 RunAdminCacheChecks(i);
2375 NotifyPostAdminCheck(i);
2376 }
2377 }
2378}
2379
2380stock InsertServerInfo()
2381{
2382 if (DB == INVALID_HANDLE)
2383 {
2384 return;
2385 }
2386
2387 decl String:query[100], pieces[4];
2388 new longip = GetConVarInt(CvarHostIp);
2389 pieces[0] = (longip >> 24) & 0x000000FF;
2390 pieces[1] = (longip >> 16) & 0x000000FF;
2391 pieces[2] = (longip >> 8) & 0x000000FF;
2392 pieces[3] = longip & 0x000000FF;
2393 FormatEx(ServerIp, sizeof(ServerIp), "%d.%d.%d.%d", pieces[0], pieces[1], pieces[2], pieces[3]);
2394 GetConVarString(CvarPort, ServerPort, sizeof(ServerPort));
2395
2396 if (AutoAdd != false)
2397 {
2398 FormatEx(query, sizeof(query), "SELECT sid FROM %s_servers WHERE ip = '%s' AND port = '%s'", DatabasePrefix, ServerIp, ServerPort);
2399 SQL_TQuery(DB, ServerInfoCallback, query);
2400 }
2401}
2402
2403stock PrepareBan(client, target, time, String:reason[], size)
2404{
2405 #if defined DEBUG
2406 LogToFile(logFile, "PrepareBan()");
2407 #endif
2408 if (!target || !IsClientInGame(target))
2409 return;
2410 decl String:authid[64], String:name[32], String:bannedSite[512];
2411 if (!GetClientAuthId(target, AuthId_Steam2, authid, sizeof(authid)))
2412 return;
2413 GetClientName(target, name, sizeof(name));
2414
2415
2416 if (CreateBan(client, target, time, reason))
2417 {
2418 if (!time)
2419 {
2420 if (reason[0] == '\0')
2421 {
2422 ShowActivity(client, "%t", "Permabanned player", name);
2423 } else {
2424 ShowActivity(client, "%t", "Permabanned player reason", name, reason);
2425 }
2426 } else {
2427 if (reason[0] == '\0')
2428 {
2429 ShowActivity(client, "%t", "Banned player", name, time);
2430 } else {
2431 ShowActivity(client, "%t", "Banned player reason", name, time, reason);
2432 }
2433 }
2434 LogAction(client, target, "\"%L\" banned \"%L\" (minutes \"%d\") (reason \"%s\")", client, target, time, reason);
2435
2436 if (time > 5 || time == 0)
2437 time = 5;
2438 Format(bannedSite, sizeof(bannedSite), "%T", "Banned Check Site", target, WebsiteAddress);
2439 BanClient(target, time, BANFLAG_AUTO, bannedSite, bannedSite, "sm_fmtkmpd", client);
2440 }
2441
2442 g_BanTarget[client] = -1;
2443 g_BanTime[client] = -1;
2444}
2445
2446stock ReadConfig()
2447{
2448 InitializeConfigParser();
2449
2450 if (ConfigParser == INVALID_HANDLE)
2451 {
2452 return;
2453 }
2454
2455 decl String:ConfigFile[PLATFORM_MAX_PATH];
2456 BuildPath(Path_SM, ConfigFile, sizeof(ConfigFile), "configs/sourcebans/sourcebans.cfg");
2457
2458 if (FileExists(ConfigFile))
2459 {
2460 InternalReadConfig(ConfigFile);
2461 PrintToServer("%sLoading configs/sourcebans.cfg config file", Prefix);
2462 } else {
2463 decl String:Error[PLATFORM_MAX_PATH + 64];
2464 FormatEx(Error, sizeof(Error), "%sFATAL *** ERROR *** can not find %s", Prefix, ConfigFile);
2465 LogToFile(logFile, "FATAL *** ERROR *** can not find %s", ConfigFile);
2466 SetFailState(Error);
2467 }
2468}
2469
2470stock ResetSettings()
2471{
2472 CommandDisable = 0;
2473
2474 ResetMenu();
2475 ReadConfig();
2476}
2477
2478stock ParseBackupConfig_Overrides()
2479{
2480 new Handle:hKV = CreateKeyValues("SB_Overrides");
2481 if (!FileToKeyValues(hKV, overridesLoc))
2482 return;
2483
2484 if (!KvGotoFirstSubKey(hKV))
2485 return;
2486
2487 decl String:sSection[16], String:sFlags[32], String:sName[64];
2488 decl OverrideType:type;
2489 do
2490 {
2491 KvGetSectionName(hKV, sSection, sizeof(sSection));
2492 if (StrEqual(sSection, "override_commands"))
2493 type = Override_Command;
2494 else if (StrEqual(sSection, "override_groups"))
2495 type = Override_CommandGroup;
2496 else
2497 continue;
2498
2499 if (KvGotoFirstSubKey(hKV, false))
2500 {
2501 do
2502 {
2503 KvGetSectionName(hKV, sName, sizeof(sName));
2504 KvGetString(hKV, NULL_STRING, sFlags, sizeof(sFlags));
2505 AddCommandOverride(sName, type, ReadFlagString(sFlags));
2506 #if defined _DEBUG
2507 PrintToServer("Adding override (%s, %s, %s)", sSection, sName, sFlags);
2508 #endif
2509 } while (KvGotoNextKey(hKV, false));
2510 KvGoBack(hKV);
2511 }
2512 }
2513 while (KvGotoNextKey(hKV));
2514 CloseHandle(hKV);
2515}
2516
2517stock AdminFlag:CreateFlagLetters()
2518{
2519 new AdminFlag:FlagLetters[FLAG_LETTERS_SIZE];
2520
2521 FlagLetters['a'-'a'] = Admin_Reservation;
2522 FlagLetters['b'-'a'] = Admin_Generic;
2523 FlagLetters['c'-'a'] = Admin_Kick;
2524 FlagLetters['d'-'a'] = Admin_Ban;
2525 FlagLetters['e'-'a'] = Admin_Unban;
2526 FlagLetters['f'-'a'] = Admin_Slay;
2527 FlagLetters['g'-'a'] = Admin_Changemap;
2528 FlagLetters['h'-'a'] = Admin_Convars;
2529 FlagLetters['i'-'a'] = Admin_Config;
2530 FlagLetters['j'-'a'] = Admin_Chat;
2531 FlagLetters['k'-'a'] = Admin_Vote;
2532 FlagLetters['l'-'a'] = Admin_Password;
2533 FlagLetters['m'-'a'] = Admin_RCON;
2534 FlagLetters['n'-'a'] = Admin_Cheats;
2535 FlagLetters['o'-'a'] = Admin_Custom1;
2536 FlagLetters['p'-'a'] = Admin_Custom2;
2537 FlagLetters['q'-'a'] = Admin_Custom3;
2538 FlagLetters['r'-'a'] = Admin_Custom4;
2539 FlagLetters['s'-'a'] = Admin_Custom5;
2540 FlagLetters['t'-'a'] = Admin_Custom6;
2541 FlagLetters['z'-'a'] = Admin_Root;
2542
2543 return FlagLetters;
2544}
2545
2546stock AccountForLateLoading()
2547{
2548 decl String:auth[30];
2549 for (new i = 1; i <= GetMaxClients(); i++)
2550 {
2551 if (IsClientConnected(i) && !IsFakeClient(i))
2552 {
2553 PlayerStatus[i] = false;
2554 }
2555 if (IsClientInGame(i) && !IsFakeClient(i) && IsClientAuthorized(i) && GetClientAuthId(i, AuthId_Steam2, auth, sizeof(auth)))
2556 {
2557 OnClientAuthorized(i, auth);
2558 }
2559 }
2560}