Skip to content

Commit

Permalink
Merge pull request #172 from sapphonie/general-ban-msgs
Browse files Browse the repository at this point in the history
Generalized ban msgs
  • Loading branch information
sapphonie authored Oct 24, 2023
2 parents d64cec4 + b51317e commit 503d030
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
4 changes: 3 additions & 1 deletion scripting/stac.sp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#define MAXPLAYERS 101
#endif

#if !defined (AUTOLOAD_EXTENSIONS)
#define AUTOLOAD_EXTENSIONS
#endif
// REQUIRED extensions:
// SteamWorks for being able to make webrequests: https://forums.alliedmods.net/showthread.php?t=229556
// Get latest version from here: https://github.com/KyleSanderson/SteamWorks/releases
Expand Down Expand Up @@ -53,7 +55,7 @@
#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "6.1.1"
#define PLUGIN_VERSION "6.1.2"

#define UPDATE_URL "https://raw.githubusercontent.com/sapphonie/StAC-tf2/master/updatefile.txt"

Expand Down
19 changes: 19 additions & 0 deletions scripting/stac/stac_cvars.sp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,25 @@ void initCvars()
);
HookConVarChange(stac_ban_for_misccheats, setStacVars);



stac_generic_ban_msgs =
AutoExecConfig_CreateConVar
(
"stac_generic_ban_msgs",
"1",
"[StAC] Use a generic message when banning clients - this goes in SourceBans, chat, and other public places, but it does NOT change your logs.\n\
You should almost always leave this alone.\n\
(recommended 1)",
FCVAR_NONE,
true,
0.0,
true,
1.0
);



// cheatvars ban bool
if (optimizeCvars)
{
Expand Down
1 change: 1 addition & 0 deletions scripting/stac/stac_globals.sp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ConVar stac_ban_duration;
ConVar stac_verbose_info;
ConVar stac_max_allowed_turn_secs;
ConVar stac_ban_for_misccheats;
ConVar stac_generic_ban_msgs;
ConVar stac_optimize_cvars;
ConVar stac_max_aimsnap_detections;
ConVar stac_max_psilent_detections;
Expand Down
31 changes: 26 additions & 5 deletions scripting/stac/stac_stocks.sp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ void OpenStacLog()
if (!DirExists(path, false))
{
LogMessage("[StAC] StAC directory not extant! Creating...");
// 511 = unix 775 ?
if (!CreateDirectory(path, 511, false))
// chmod perms - rwxrwxr-x . it needs to be octal.
// yes I could use the FPERM flags but pawn doesn't have constexpr and i don't want to make a mess
// with a bunch of ORs and not being able to check it in my IDE
static int perms = 0o775;
if (!CreateDirectory(path, perms, false))
{
LogMessage("[StAC] StAC directory could not be created!");
}
Expand All @@ -47,6 +50,10 @@ void CloseStacLog()
}

// log to StAC log file
// This strips color strings, e.g.
// {color}test{color2}
// will become
// test
void StacLog(const char[] format, any ...)
{
// crutch for reloading the plugin and still printing to our log file
Expand Down Expand Up @@ -80,6 +87,8 @@ void StacLog(const char[] format, any ...)
char colored_buffer[254];
strcopy(colored_buffer, sizeof(colored_buffer), buffer);

// strip out any instances of "[StAC] " at the front of the string so we don't get double instances of it later
ReplaceStringEx(colored_buffer, sizeof(colored_buffer), "[StAC] ", "", 7, -1, true);

if (StrEqual(os, "linux"))
{
Expand Down Expand Up @@ -393,18 +402,30 @@ bool IsValidSrcTV(int client)

/********** MISC FUNCS **********/

void BanUser(int userid, char[] reason, char[] pubreason)
void BanUser(int userid, char reason[128], char pubreason[256])
{
int cl = GetClientOfUserId(userid);

// prevent double bans
if (userBanQueued[cl])
{
KickClient(cl, "Banned by StAC");
KickClient(cl, "Banned from server");
return;
}

StacNotify(userid, reason);

char cleaned_pubreason[256];
if ( stac_generic_ban_msgs.BoolValue )
{
Format(reason, sizeof(reason), "%t", "GenericBanMsg", cl);
Format(cleaned_pubreason, sizeof(cleaned_pubreason), "%t", "GenericBanAllChat", cl);
}
else
{
strcopy(cleaned_pubreason, sizeof(cleaned_pubreason), pubreason);
}

// make sure we dont detect on already banned players
userBanQueued[cl] = true;

Expand Down Expand Up @@ -466,7 +487,7 @@ void BanUser(int userid, char[] reason, char[] pubreason)
// KickClient(cl, "%s", reason);
}

MC_PrintToChatAll("%s", pubreason);
MC_PrintToChatAll("%s", cleaned_pubreason);
StacLog("%s", pubreason);
}

Expand Down
10 changes: 9 additions & 1 deletion translations/stac.phrases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
- kick and ban messages already have a period at the end of them in TF2, so don't add one
- ban messages get printed to banned client as the kick reason if not using sourcebans and posted to sourcebans as the "ban reason" if you have it installed
*/

"GenericBanAllChat"
{
"#format" "{1:N}"
"en" "{hotpink}[StAC]{white} Player {1} was {palegreen}BANNED{white} for {mediumpurple}cheating{white}!"
}
"GenericBanMsg"
{
"en" "[StAC] Banned for cheating"
}
/*

____ __ _ _
Expand Down

0 comments on commit 503d030

Please sign in to comment.