Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions game/addons/sourcemod/scripting/include/sourcebanschecker.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -64,22 +64,30 @@ 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);

/*********************************************************
* 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);

/*********************************************************
* 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);
30 changes: 27 additions & 3 deletions game/addons/sourcemod/scripting/sbpp_checker.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
{
Expand Down Expand Up @@ -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;
Expand All @@ -163,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];
}

Expand All @@ -178,6 +185,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)
Expand Down Expand Up @@ -217,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);

Expand All @@ -235,6 +255,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;

Expand Down
Loading