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

feat(checker): Mutes & gags count natives, late load #1032

Open
wants to merge 1 commit 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
18 changes: 18 additions & 0 deletions game/addons/sourcemod/scripting/include/sourcebanschecker.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public void __pl_sourcebanschecker_SetNTVOptional()
{
MarkNativeAsOptional("SBPP_CheckerGetClientsBans");
MarkNativeAsOptional("SBPP_CheckerGetClientsComms");
MarkNativeAsOptional("SBPP_CheckerGetClientsMutes");
MarkNativeAsOptional("SBPP_CheckerGetClientsGags");
}
#endif

Expand All @@ -65,3 +67,19 @@ native int SBPP_CheckerGetClientsBans(int iClient);
* @return The number of comms bans of the client.
*********************************************************/
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.
*********************************************************/
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.
*********************************************************/
native int SBPP_CheckerGetClientsGags(int iClient);
87 changes: 69 additions & 18 deletions game/addons/sourcemod/scripting/sbpp_checker.sp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,23 @@

#include <sourcemod>

#define VERSION "1.8.2"
#define VERSION "1.8.3"
#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
#define Prefix "\x04[SourceBans++]\x01 "

bool g_bLate = false;
bool g_bPrintCheckOnConnect = true;

char g_DatabasePrefix[10] = "sb";

SMCParser g_ConfigParser;
Database g_DB;

int g_iBanCounts[MAXPLAYERS + 1];
int g_iCommsCounts[MAXPLAYERS + 1];

int g_iMuteCounts[MAXPLAYERS + 1];
int g_iGagCounts[MAXPLAYERS + 1];

public Plugin myinfo =
{
Expand All @@ -64,6 +67,11 @@ public void OnPluginStart()
RegAdminCmd("sb_reload", OnReloadCmd, ADMFLAG_RCON, "Reload sourcebans config and ban reason menu options");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

  • sm_listgags
  • sm_listmutes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, this feature can be done on the next version (1.8.4) 👍


Database.Connect(OnDatabaseConnected, "sourcebans");

if (g_bLate)
{
LateLoading();
}
}

public void OnMapStart()
Expand Down Expand Up @@ -91,6 +99,10 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max

CreateNative("SBPP_CheckerGetClientsBans", Native_SBCheckerGetClientsBans);
CreateNative("SBPP_CheckerGetClientsComms", Native_SBCheckerGetClientsComms);
CreateNative("SBPP_CheckerGetClientsMutes", Native_SBCheckerGetClientsMutes);
CreateNative("SBPP_CheckerGetClientsGags", Native_SBCheckerGetClientsGags);

g_bLate = late;

return APLRes_Success;
}
Expand All @@ -104,7 +116,19 @@ public int Native_SBCheckerGetClientsBans(Handle plugin, int numParams)
public int Native_SBCheckerGetClientsComms(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
return g_iCommsCounts[client];
return g_iMuteCounts[client] + g_iGagCounts[client];
}

public int Native_SBCheckerGetClientsMutes(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
return g_iMuteCounts[client];
}

public int Native_SBCheckerGetClientsGags(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
return g_iGagCounts[client];
}

public void OnClientAuthorized(int client, const char[] auth)
Expand All @@ -118,32 +142,46 @@ public void OnClientAuthorized(int client, const char[] auth)

char query[512], ip[30];
GetClientIP(client, ip, sizeof(ip));
FormatEx(query, sizeof(query), "SELECT COUNT(bid) FROM %s_bans WHERE (type = 0 AND authid LIKE 'STEAM_%%:%s') UNION ALL SELECT COUNT(bid) FROM %s_bans WHERE (type = 1 AND ip = '%s') UNION ALL SELECT COUNT(bid) FROM %s_comms WHERE authid LIKE 'STEAM_%%:%s'", g_DatabasePrefix, auth[8], g_DatabasePrefix, ip, g_DatabasePrefix, auth[8]);
FormatEx(query, sizeof(query),
"SELECT COUNT(bid) FROM %s_bans WHERE (type = 0 AND authid LIKE 'STEAM_%%:%s') \
UNION ALL \
SELECT COUNT(bid) FROM %s_bans WHERE (type = 1 AND ip = '%s') \
UNION ALL \
SELECT COUNT(bid) FROM %s_comms WHERE authid LIKE 'STEAM_%%:%s' AND type = 1 \
UNION ALL \
SELECT COUNT(bid) FROM %s_comms WHERE authid LIKE 'STEAM_%%:%s' AND type = 2",
g_DatabasePrefix, auth[8],
g_DatabasePrefix, ip,
g_DatabasePrefix, auth[8],
g_DatabasePrefix, auth[8]
);

g_DB.Query(OnConnectBanCheck, query, GetClientUserId(client), DBPrio_Low);
}

public void OnConnectBanCheck(Database db, DBResultSet results, const char[] error, any userid)
{
int client = GetClientOfUserId(userid);
int steamIdBanCount = 0;
if (!client || results == null || !results.FetchRow())
return;

steamIdBanCount = results.FetchInt(0);
// SteamID bans
g_iBanCounts[client] = results.FetchInt(0);

int ipBanCount = 0;
if (results.FetchRow()) {
ipBanCount = results.FetchInt(0);
}
int bancount = steamIdBanCount + ipBanCount;
// IP bans
if (results.FetchRow())
g_iBanCounts[client] += results.FetchInt(0);

int commcount = 0;
if (results.FetchRow()) {
commcount = results.FetchInt(0);
}
// Mutes (type = 1)
if (results.FetchRow())
g_iMuteCounts[client] = results.FetchInt(0);

// Gags (type = 2)
if (results.FetchRow())
g_iGagCounts[client] = results.FetchInt(0);

g_iBanCounts[client] = bancount;
g_iCommsCounts[client] = commcount;
int bancount = g_iBanCounts[client];
int commcount = g_iMuteCounts[client] + g_iGagCounts[client];

if (!g_bPrintCheckOnConnect)
return;
Expand Down Expand Up @@ -604,4 +642,17 @@ public SMCResult ReadConfig_KeyValue(SMCParser smc, const char[] key, const char
public SMCResult ReadConfig_EndSection(SMCParser smc)
{
return SMCParse_Continue;
}

stock void LateLoading()
{
char sSteam32ID[64];
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientConnected(i) || !IsClientInGame(i) || IsFakeClient(i) || !IsClientAuthorized(i))
continue;

GetClientAuthId(i, AuthId_Steam2, sSteam32ID, sizeof(sSteam32ID));
OnClientAuthorized(i, sSteam32ID);
}
}