Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SBPP Checker] Callback and initial values #894

Open
wants to merge 3 commits into
base: php81
Choose a base branch
from
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
14 changes: 11 additions & 3 deletions game/addons/sourcemod/scripting/include/sourcebanschecker.inc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// *************************************************************************
// *************************************************************************
// This file is part of SourceBans++.
//
// Copyright (C) 2014-2023 SourceBans++ Dev Team <https://github.com/sbpp>
Expand Down Expand Up @@ -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);

Expand All @@ -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);
21 changes: 17 additions & 4 deletions game/addons/sourcemod/scripting/sbpp_checker.sp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#include <sourcemod>

#define VERSION "1.8.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
Expand All @@ -39,8 +39,9 @@ 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;


public Plugin myinfo =
Expand All @@ -61,7 +62,7 @@ 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");

Database.Connect(OnDatabaseConnected, "sourcebans");
}

Expand Down Expand Up @@ -91,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;
}

Expand All @@ -106,6 +109,12 @@ public int Native_SBCheckerGetClientsComms(Handle plugin, int numParams)
return g_iCommsCounts[client];
}

public void OnClientDisconnect_Post(int client)
{
g_iBanCounts[client] = -1;
g_iCommsCounts[client] = -1;
}

public void OnClientAuthorized(int client, const char[] auth)
{
if (g_DB == null)
Expand Down Expand Up @@ -145,6 +154,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)
Expand Down