From a6d3e3cefc27119d56e92eb074a002bb11a0e048 Mon Sep 17 00:00:00 2001 From: Rushaway Date: Thu, 3 Sep 2026 10:53:44 +0200 Subject: [PATCH 1/2] feat(checker): add SBPP_CheckerClientBanCheckPost forward and -1 initial values Ports upstream sbpp/sourcebans-pp#894. - Initialize g_iBanCounts/g_iMuteCounts/g_iGagCounts to -1 so the natives report "not yet available" rather than stale values before the async OnConnectBanCheck callback resolves. - Reset those counts to -1 in OnClientDisconnect_Post. - Add global forward SBPP_CheckerClientBanCheckPost(int iClient), created in AskPluginLoad2 and fired from OnConnectBanCheck once counts are populated (before the PrintCheckOnConnect guard so it always runs). - Document the new -1 return contract and the forward in the include. Adapted to fork divergence: fork splits comms into separate mute/gag counts and uses SB_VERSION, so no manual VERSION bump; forward creation lives in the fork's AskPluginLoad2 alongside g_bLate. Co-Authored-By: Claude Sonnet 5 Co-authored-by: DosMike --- .../scripting/include/sourcebanschecker.inc | 16 ++++++++++---- .../sourcemod/scripting/sbpp_checker.sp | 21 ++++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/game/addons/sourcemod/scripting/include/sourcebanschecker.inc b/game/addons/sourcemod/scripting/include/sourcebanschecker.inc index f0be9fd44..da6f0414e 100644 --- a/game/addons/sourcemod/scripting/include/sourcebanschecker.inc +++ b/game/addons/sourcemod/scripting/include/sourcebanschecker.inc @@ -55,7 +55,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); @@ -64,7 +64,7 @@ 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); @@ -72,7 +72,7 @@ native int SBPP_CheckerGetClientsComms(int iClient); * Get the number of mutes of a client. * * @param iClient The client index of who you want to get the number of mutes. - * @return The number of mutes of the client. + * @return The number of mutes of the client, or -1 if not yet available. *********************************************************/ native int SBPP_CheckerGetClientsMutes(int iClient); @@ -80,6 +80,14 @@ native int SBPP_CheckerGetClientsMutes(int iClient); * Get the number of gags of a client. * * @param iClient The client index of who you want to get the number of gags. - * @return The number of gags of the client. + * @return The number of gags of the client, or -1 if not yet available. *********************************************************/ native int SBPP_CheckerGetClientsGags(int iClient); + +/********************************************************** + * Called when the ban counts for a client have been checked. + * Use the natives above to retrieve the values. + * + * @param iClient The client index that was checked. + **********************************************************/ +forward void SBPP_CheckerClientBanCheckPost(int iClient); diff --git a/game/addons/sourcemod/scripting/sbpp_checker.sp b/game/addons/sourcemod/scripting/sbpp_checker.sp index e06781f59..d787d47e6 100644 --- a/game/addons/sourcemod/scripting/sbpp_checker.sp +++ b/game/addons/sourcemod/scripting/sbpp_checker.sp @@ -55,9 +55,11 @@ DatabaseState g_DatabaseState; int g_iSequence = 0; int g_iConnectLock = 0; -int g_iBanCounts[MAXPLAYERS + 1]; -int g_iMuteCounts[MAXPLAYERS + 1]; -int g_iGagCounts[MAXPLAYERS + 1]; +int g_iBanCounts[MAXPLAYERS + 1] = {-1, ...}; +int g_iMuteCounts[MAXPLAYERS + 1] = {-1, ...}; +int g_iGagCounts[MAXPLAYERS + 1] = {-1, ...}; + +GlobalForward g_fwdClientBanCheckPost; public Plugin myinfo = { @@ -149,6 +151,8 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max CreateNative("SBPP_CheckerGetClientsMutes", Native_SBCheckerGetClientsMutes); CreateNative("SBPP_CheckerGetClientsGags", Native_SBCheckerGetClientsGags); + g_fwdClientBanCheckPost = CreateGlobalForward("SBPP_CheckerClientBanCheckPost", ET_Ignore, Param_Cell); + g_bLate = late; return APLRes_Success; @@ -178,6 +182,13 @@ public int Native_SBCheckerGetClientsGags(Handle plugin, int numParams) return g_iGagCounts[client]; } +public void OnClientDisconnect_Post(int client) +{ + g_iBanCounts[client] = -1; + g_iMuteCounts[client] = -1; + g_iGagCounts[client] = -1; +} + public void OnClientAuthorized(int client, const char[] auth) { if (g_DB == null) @@ -235,6 +246,10 @@ public void OnConnectBanCheck(Database db, DBResultSet results, const char[] err int bancount = g_iBanCounts[client]; int commcount = g_iMuteCounts[client] + g_iGagCounts[client]; + Call_StartForward(g_fwdClientBanCheckPost); + Call_PushCell(client); + Call_Finish(); + if (!g_bPrintCheckOnConnect) return; From c1c277abd68f78e173f75e8757b9200ce9dca3b0 Mon Sep 17 00:00:00 2001 From: Rushaway Date: Thu, 3 Sep 2026 14:08:34 +0200 Subject: [PATCH 2/2] review fixes - SBPP_CheckerGetClientsComms returned -2 (the sum of two -1 sentinels) before the check resolved, breaking the "-1 if not yet available" contract the include now documents. Return -1 when either half is unavailable. - OnConnectBanCheck only assigns the mute/gag counters from optional FetchRow() branches. If the result set ever came back short, those stayed at -1 while the ban count was populated, making commcount negative and firing bogus "Comm Warning" prints (the `if (commcount)` truthiness test passes for -1/-2). Clear the sentinel on both counters once the check completes, so post-check values are always >= 0. Co-Authored-By: Claude Sonnet 5 Co-authored-by: DosMike --- game/addons/sourcemod/scripting/sbpp_checker.sp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/game/addons/sourcemod/scripting/sbpp_checker.sp b/game/addons/sourcemod/scripting/sbpp_checker.sp index d787d47e6..b5f32ca8d 100644 --- a/game/addons/sourcemod/scripting/sbpp_checker.sp +++ b/game/addons/sourcemod/scripting/sbpp_checker.sp @@ -167,6 +167,9 @@ public int Native_SBCheckerGetClientsBans(Handle plugin, int numParams) public int Native_SBCheckerGetClientsComms(Handle plugin, int numParams) { int client = GetNativeCell(1); + if (g_iMuteCounts[client] == -1 || g_iGagCounts[client] == -1) + return -1; + return g_iMuteCounts[client] + g_iGagCounts[client]; } @@ -228,6 +231,12 @@ public void OnConnectBanCheck(Database db, DBResultSet results, const char[] err if (!client || results == null || !results.FetchRow()) return; + // The check completed: clear the "not yet available" sentinel on the counters + // that are only filled in by the optional rows below, so that the natives and + // the arithmetic underneath never operate on -1. + g_iMuteCounts[client] = 0; + g_iGagCounts[client] = 0; + // SteamID bans g_iBanCounts[client] = results.FetchInt(0);