From d17c6a8406bef0f6fde430449791058806a5e570 Mon Sep 17 00:00:00 2001 From: DosMike Date: Thu, 25 May 2023 19:05:08 +0200 Subject: [PATCH 1/3] Added forward when ban counts have been loaded and initialize values to -1 while unknown --- .../scripting/include/sourcebanschecker.inc | 14 +++++++++++--- .../sourcemod/scripting/sbpp_checker.sp | 19 ++++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/game/addons/sourcemod/scripting/include/sourcebanschecker.inc b/game/addons/sourcemod/scripting/include/sourcebanschecker.inc index a67c17e09..363dc9928 100644 --- a/game/addons/sourcemod/scripting/include/sourcebanschecker.inc +++ b/game/addons/sourcemod/scripting/include/sourcebanschecker.inc @@ -1,4 +1,4 @@ -// ************************************************************************* +// ************************************************************************* // This file is part of SourceBans++. // // Copyright (C) 2014-2023 SourceBans++ Dev Team @@ -53,7 +53,7 @@ public void __pl_sourcebanschecker_SetNTVOptional() * Get the number of bans of a client. * * @param iClient The client index of who you want to get the number of bans. - * @return The number of bans of the client. + * @return The number of bans of the client, or -1 if not yet available. *********************************************************/ native int SBPP_CheckerGetClientsBans(int iClient); @@ -62,6 +62,14 @@ native int SBPP_CheckerGetClientsBans(int iClient); * Get the number of comms bans of a client. * * @param iClient The client index of who you want to get the number of comms bans. - * @return The number of comms bans of the client. + * @return The number of comms bans of the client, or -1 if not yet available. *********************************************************/ native int SBPP_CheckerGetClientsComms(int iClient); + +/********************************************************** + * Called when the ban counts for a client are checked. + * Use the other natives to retrieve values. + * + * @param iClient The client index that was checked. + **********************************************************/ +forward void SBPP_CheckerClientBanCheckPost(int iClient); \ No newline at end of file diff --git a/game/addons/sourcemod/scripting/sbpp_checker.sp b/game/addons/sourcemod/scripting/sbpp_checker.sp index d786e9e39..08547c363 100644 --- a/game/addons/sourcemod/scripting/sbpp_checker.sp +++ b/game/addons/sourcemod/scripting/sbpp_checker.sp @@ -29,7 +29,7 @@ #include -#define VERSION "1.8.0" +#define VERSION "1.9.0" #define LISTBANS_USAGE "sm_listbans <#userid|name> - Lists a user's prior bans from Sourcebans" #define LISTCOMMS_USAGE "sm_listcomms <#userid|name> - Lists a user's prior comms from Sourcebans" #define INVALID_TARGET -1 @@ -41,6 +41,7 @@ Database g_DB; int g_iBanCounts[MAXPLAYERS + 1]; int g_iCommsCounts[MAXPLAYERS + 1]; +GlobalForward g_fwdClientBanCheckPost; public Plugin myinfo = @@ -61,6 +62,8 @@ public void OnPluginStart() RegAdminCmd("sm_listbans", OnListSourceBansCmd, ADMFLAG_GENERIC, LISTBANS_USAGE); RegAdminCmd("sm_listcomms", OnListSourceCommsCmd, ADMFLAG_GENERIC, LISTCOMMS_USAGE); RegAdminCmd("sb_reload", OnReloadCmd, ADMFLAG_RCON, "Reload sourcebans config and ban reason menu options"); + + g_fwdClientBanCheckPost = CreateGlobalForward("SBPP_CheckerClientBanCheckPost", ET_Ignore, Param_Cell); Database.Connect(OnDatabaseConnected, "sourcebans"); } @@ -106,6 +109,16 @@ public int Native_SBCheckerGetClientsComms(Handle plugin, int numParams) return g_iCommsCounts[client]; } +public void OnClientConnected(int client) +{ + g_iBanCounts[client] = g_iCommsCounts[client] = -1; // mark as not yet loaded +} + +public void OnClientDisconnect_Post(int client) +{ + g_iBanCounts[client] = g_iCommsCounts[client] = -1; +} + public void OnClientAuthorized(int client, const char[] auth) { if (g_DB == null) @@ -145,6 +158,10 @@ public void OnConnectBanCheck(Database db, DBResultSet results, const char[] err else if ( bancount ) { PrintToBanAdmins("%s%t", Prefix, "Ban Warning", client, bancount, ((bancount > 1 || bancount == 0) ? "s":"")); } + + Call_StartForward(g_fwdClientBanCheckPost); + Call_PushCell(client); + Call_Finish(); } public Action OnListSourceBansCmd(int client, int args) From 6e07c95eb184d230dae052144b3d781c08ec7cfe Mon Sep 17 00:00:00 2001 From: DosMike Date: Thu, 25 May 2023 19:22:46 +0200 Subject: [PATCH 2/3] Better handling of ban counts in SBPP checker --- game/addons/sourcemod/scripting/sbpp_checker.sp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/game/addons/sourcemod/scripting/sbpp_checker.sp b/game/addons/sourcemod/scripting/sbpp_checker.sp index 08547c363..724d7dc6d 100644 --- a/game/addons/sourcemod/scripting/sbpp_checker.sp +++ b/game/addons/sourcemod/scripting/sbpp_checker.sp @@ -39,8 +39,8 @@ char g_DatabasePrefix[10] = "sb"; SMCParser g_ConfigParser; Database g_DB; -int g_iBanCounts[MAXPLAYERS + 1]; -int g_iCommsCounts[MAXPLAYERS + 1]; +int g_iBanCounts[MAXPLAYERS + 1] = {-1, ...}; +int g_iCommsCounts[MAXPLAYERS + 1] = {-1, ...}; GlobalForward g_fwdClientBanCheckPost; @@ -109,14 +109,10 @@ public int Native_SBCheckerGetClientsComms(Handle plugin, int numParams) return g_iCommsCounts[client]; } -public void OnClientConnected(int client) -{ - g_iBanCounts[client] = g_iCommsCounts[client] = -1; // mark as not yet loaded -} - public void OnClientDisconnect_Post(int client) { - g_iBanCounts[client] = g_iCommsCounts[client] = -1; + g_iBanCounts[client] = -1; + g_iCommsCounts[client] = -1; } public void OnClientAuthorized(int client, const char[] auth) From a8ac6c6178c4dbac37e73769b538e9290a778ea1 Mon Sep 17 00:00:00 2001 From: DosMike Date: Thu, 13 Jun 2024 10:30:04 +0200 Subject: [PATCH 3/3] Adjust version and move CreateGlobalForward to AskPluginLoad --- game/addons/sourcemod/scripting/sbpp_checker.sp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/game/addons/sourcemod/scripting/sbpp_checker.sp b/game/addons/sourcemod/scripting/sbpp_checker.sp index 724d7dc6d..38550ab40 100644 --- a/game/addons/sourcemod/scripting/sbpp_checker.sp +++ b/game/addons/sourcemod/scripting/sbpp_checker.sp @@ -29,7 +29,7 @@ #include -#define VERSION "1.9.0" +#define VERSION "1.8.1" #define LISTBANS_USAGE "sm_listbans <#userid|name> - Lists a user's prior bans from Sourcebans" #define LISTCOMMS_USAGE "sm_listcomms <#userid|name> - Lists a user's prior comms from Sourcebans" #define INVALID_TARGET -1 @@ -63,8 +63,6 @@ public void OnPluginStart() RegAdminCmd("sm_listcomms", OnListSourceCommsCmd, ADMFLAG_GENERIC, LISTCOMMS_USAGE); RegAdminCmd("sb_reload", OnReloadCmd, ADMFLAG_RCON, "Reload sourcebans config and ban reason menu options"); - g_fwdClientBanCheckPost = CreateGlobalForward("SBPP_CheckerClientBanCheckPost", ET_Ignore, Param_Cell); - Database.Connect(OnDatabaseConnected, "sourcebans"); } @@ -94,6 +92,8 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max CreateNative("SBPP_CheckerGetClientsBans", Native_SBCheckerGetClientsBans); CreateNative("SBPP_CheckerGetClientsComms", Native_SBCheckerGetClientsComms); + g_fwdClientBanCheckPost = CreateGlobalForward("SBPP_CheckerClientBanCheckPost", ET_Ignore, Param_Cell); + return APLRes_Success; }