From e7f52993a06739fbd4accf783dff85f1a73868d3 Mon Sep 17 00:00:00 2001 From: NW/RL Date: Thu, 30 May 2024 23:25:16 -0500 Subject: Initial Commit --- scripting/notf2.sp | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 scripting/notf2.sp (limited to 'scripting') diff --git a/scripting/notf2.sp b/scripting/notf2.sp new file mode 100644 index 0000000..cb18f7c --- /dev/null +++ b/scripting/notf2.sp @@ -0,0 +1,100 @@ +#include +#include +#include +#include +#pragma newdecls required +#pragma semicolon 1 + +public Plugin myinfo = { + name = "nohashtagtf2", + author = "NW/RL", + description = "Kick players with \"#___TF2\" tokens in their name", + version = "0.0.1", + url = "https://git.dabikers.online/nohashtagtf2" +}; + +static ConVar ntf_enabled = null; +static ConVar ntf_admins = null; +static Regex nohash; + +public void OnPluginStart() { + // Set up ConVars + ntf_enabled = CreateConVar("ntf_enabled", "1", "Enables/disables kicking players", FCVAR_NONE, true, 0.0, true, 1.0); + ntf_admins = CreateConVar("ntf_admins", "0", "Target admins for having inappropriate names", FCVAR_NONE, true, 0.0, true, 1.0); + ntf_enabled.IntValue = 1; + ntf_admins.BoolValue = false; + + // Create/execute a config file on load + AutoExecConfig(true, "nohashtagtf2"); + + // Regular expression setup + char regerrstr[256 + 1] = {0}; RegexError regerr; + nohash = CompileRegex("#.*tf2", PCRE_CASELESS | PCRE_UTF8, regerrstr, sizeof(regerrstr), regerr); + if(nohash == INVALID_HANDLE) { + PrintToServer("[No#TF2] Error - Could not compile regex: %s (ecode: %d)", regerrstr, regerr); + SetFailState("Could not compile regex: %s (%d)", regerrstr, regerr); + } + + // Hook name change events + HookEvent("player_info", ntf_checkname, EventHookMode_Pre); + + return; +} + +public void OnClientPostAdminCheck(int client) { + // Skip everything if the plugin isn't enabled + if(ntf_enabled.IntValue != 1) + return; + + // Skip if user is an admin + if(CheckCommandAccess(client, "nohashtagtf2", ADMFLAG_GENERIC) && !ntf_admins.BoolValue) + return; + + // Get name & kick if the regex works + char name[128 + 1] = {0}; + GetClientName(client, name, sizeof(name)); + if(MatchRegex(nohash, name) > 0) { + KickClient(client, "Failed regex name check"); + PrintToChatAll("[No#TF2] %s failed a regex name check", name); + } + + return; +} + +#define NTF_CHECKNAME_KEYERRORDEF "SHIT BROKE" +static Action ntf_checkname (Event event, const char[] name, bool dontBroadcast) { + // Don't do anything if the plugin is disabled + if(ntf_enabled.IntValue != 1) + return Plugin_Continue; + + // Get the player's name + char playername[128 + 1] = {0}; + event.GetString("name", playername, sizeof(playername), NTF_CHECKNAME_KEYERRORDEF); + + // If there's a key error for some reason, just continue and don't worry about it (maybe make this a convar to kick, just in case) + if(strcmp(playername, NTF_CHECKNAME_KEYERRORDEF) == 0) { + PrintToServer("[No#TF2] Ran into a problem checking someone's changed name"); + return Plugin_Continue; + } + + // Get the client value from the returned userid + int userid = event.GetInt("userid", -1); + if(userid == -1) { + PrintToServer("[No#TF2] Couldn't get %s's userid"); + return Plugin_Continue; + } + int clientid = GetClientOfUserId(userid); + + // Check if the player is an admin (and if kicking admins is allowed) + if(CheckCommandAccess(clientid, "nohashtagtf2", ADMFLAG_GENERIC) && !ntf_admins.BoolValue) + return Plugin_Continue; + + // Get name & kick if the regex works + GetClientName(clientid, playername, sizeof(playername)); + if(MatchRegex(nohash, playername) > 0) { + KickClient(clientid, "Failed regex name check"); + PrintToChatAll("[No#TF2] %s failed a regex name check", playername); + } + + return Plugin_Continue; +} \ No newline at end of file -- cgit v1.2.3