Skip to content

Commit 72df8c3

Browse files
authored
feat(checker): Mutes & gags count natives, late load (#1032)
1 parent 9e929b9 commit 72df8c3

File tree

2 files changed

+87
-18
lines changed

2 files changed

+87
-18
lines changed

game/addons/sourcemod/scripting/include/sourcebanschecker.inc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public void __pl_sourcebanschecker_SetNTVOptional()
4545
{
4646
MarkNativeAsOptional("SBPP_CheckerGetClientsBans");
4747
MarkNativeAsOptional("SBPP_CheckerGetClientsComms");
48+
MarkNativeAsOptional("SBPP_CheckerGetClientsMutes");
49+
MarkNativeAsOptional("SBPP_CheckerGetClientsGags");
4850
}
4951
#endif
5052

@@ -65,3 +67,19 @@ native int SBPP_CheckerGetClientsBans(int iClient);
6567
* @return The number of comms bans of the client.
6668
*********************************************************/
6769
native int SBPP_CheckerGetClientsComms(int iClient);
70+
71+
/*********************************************************
72+
* Get the number of mutes of a client.
73+
*
74+
* @param iClient The client index of who you want to get the number of mutes.
75+
* @return The number of mutes of the client.
76+
*********************************************************/
77+
native int SBPP_CheckerGetClientsMutes(int iClient);
78+
79+
/*********************************************************
80+
* Get the number of gags of a client.
81+
*
82+
* @param iClient The client index of who you want to get the number of gags.
83+
* @return The number of gags of the client.
84+
*********************************************************/
85+
native int SBPP_CheckerGetClientsGags(int iClient);

game/addons/sourcemod/scripting/sbpp_checker.sp

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,23 @@
2929

3030
#include <sourcemod>
3131

32-
#define VERSION "1.8.2"
32+
#define VERSION "1.8.3"
3333
#define LISTBANS_USAGE "sm_listbans <#userid|name> - Lists a user's prior bans from Sourcebans"
3434
#define LISTCOMMS_USAGE "sm_listcomms <#userid|name> - Lists a user's prior comms from Sourcebans"
3535
#define INVALID_TARGET -1
3636
#define Prefix "\x04[SourceBans++]\x01 "
3737

38+
bool g_bLate = false;
3839
bool g_bPrintCheckOnConnect = true;
40+
3941
char g_DatabasePrefix[10] = "sb";
42+
4043
SMCParser g_ConfigParser;
4144
Database g_DB;
4245

4346
int g_iBanCounts[MAXPLAYERS + 1];
44-
int g_iCommsCounts[MAXPLAYERS + 1];
45-
47+
int g_iMuteCounts[MAXPLAYERS + 1];
48+
int g_iGagCounts[MAXPLAYERS + 1];
4649

4750
public Plugin myinfo =
4851
{
@@ -64,6 +67,11 @@ public void OnPluginStart()
6467
RegAdminCmd("sb_reload", OnReloadCmd, ADMFLAG_RCON, "Reload sourcebans config and ban reason menu options");
6568

6669
Database.Connect(OnDatabaseConnected, "sourcebans");
70+
71+
if (g_bLate)
72+
{
73+
LateLoading();
74+
}
6775
}
6876

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

92100
CreateNative("SBPP_CheckerGetClientsBans", Native_SBCheckerGetClientsBans);
93101
CreateNative("SBPP_CheckerGetClientsComms", Native_SBCheckerGetClientsComms);
102+
CreateNative("SBPP_CheckerGetClientsMutes", Native_SBCheckerGetClientsMutes);
103+
CreateNative("SBPP_CheckerGetClientsGags", Native_SBCheckerGetClientsGags);
104+
105+
g_bLate = late;
94106

95107
return APLRes_Success;
96108
}
@@ -104,7 +116,19 @@ public int Native_SBCheckerGetClientsBans(Handle plugin, int numParams)
104116
public int Native_SBCheckerGetClientsComms(Handle plugin, int numParams)
105117
{
106118
int client = GetNativeCell(1);
107-
return g_iCommsCounts[client];
119+
return g_iMuteCounts[client] + g_iGagCounts[client];
120+
}
121+
122+
public int Native_SBCheckerGetClientsMutes(Handle plugin, int numParams)
123+
{
124+
int client = GetNativeCell(1);
125+
return g_iMuteCounts[client];
126+
}
127+
128+
public int Native_SBCheckerGetClientsGags(Handle plugin, int numParams)
129+
{
130+
int client = GetNativeCell(1);
131+
return g_iGagCounts[client];
108132
}
109133

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

119143
char query[512], ip[30];
120144
GetClientIP(client, ip, sizeof(ip));
121-
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]);
145+
FormatEx(query, sizeof(query),
146+
"SELECT COUNT(bid) FROM %s_bans WHERE (type = 0 AND authid LIKE 'STEAM_%%:%s') \
147+
UNION ALL \
148+
SELECT COUNT(bid) FROM %s_bans WHERE (type = 1 AND ip = '%s') \
149+
UNION ALL \
150+
SELECT COUNT(bid) FROM %s_comms WHERE authid LIKE 'STEAM_%%:%s' AND type = 1 \
151+
UNION ALL \
152+
SELECT COUNT(bid) FROM %s_comms WHERE authid LIKE 'STEAM_%%:%s' AND type = 2",
153+
g_DatabasePrefix, auth[8],
154+
g_DatabasePrefix, ip,
155+
g_DatabasePrefix, auth[8],
156+
g_DatabasePrefix, auth[8]
157+
);
158+
122159
g_DB.Query(OnConnectBanCheck, query, GetClientUserId(client), DBPrio_Low);
123160
}
124161

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

132-
steamIdBanCount = results.FetchInt(0);
168+
// SteamID bans
169+
g_iBanCounts[client] = results.FetchInt(0);
133170

134-
int ipBanCount = 0;
135-
if (results.FetchRow()) {
136-
ipBanCount = results.FetchInt(0);
137-
}
138-
int bancount = steamIdBanCount + ipBanCount;
171+
// IP bans
172+
if (results.FetchRow())
173+
g_iBanCounts[client] += results.FetchInt(0);
139174

140-
int commcount = 0;
141-
if (results.FetchRow()) {
142-
commcount = results.FetchInt(0);
143-
}
175+
// Mutes (type = 1)
176+
if (results.FetchRow())
177+
g_iMuteCounts[client] = results.FetchInt(0);
178+
179+
// Gags (type = 2)
180+
if (results.FetchRow())
181+
g_iGagCounts[client] = results.FetchInt(0);
144182

145-
g_iBanCounts[client] = bancount;
146-
g_iCommsCounts[client] = commcount;
183+
int bancount = g_iBanCounts[client];
184+
int commcount = g_iMuteCounts[client] + g_iGagCounts[client];
147185

148186
if (!g_bPrintCheckOnConnect)
149187
return;
@@ -604,4 +642,17 @@ public SMCResult ReadConfig_KeyValue(SMCParser smc, const char[] key, const char
604642
public SMCResult ReadConfig_EndSection(SMCParser smc)
605643
{
606644
return SMCParse_Continue;
645+
}
646+
647+
stock void LateLoading()
648+
{
649+
char sSteam32ID[64];
650+
for (int i = 1; i <= MaxClients; i++)
651+
{
652+
if (!IsClientConnected(i) || !IsClientInGame(i) || IsFakeClient(i) || !IsClientAuthorized(i))
653+
continue;
654+
655+
GetClientAuthId(i, AuthId_Steam2, sSteam32ID, sizeof(sSteam32ID));
656+
OnClientAuthorized(i, sSteam32ID);
657+
}
607658
}

0 commit comments

Comments
 (0)