summaryrefslogtreecommitdiff
path: root/scripting/notf2.sp
diff options
context:
space:
mode:
authorNW/RL <nwrl@dabikers.online>2024-05-30 23:25:16 -0500
committerNW/RL <nwrl@dabikers.online>2024-05-30 23:25:16 -0500
commite7f52993a06739fbd4accf783dff85f1a73868d3 (patch)
treec1e12fd901f8b825186558930704928e772af0b7 /scripting/notf2.sp
Initial Commit
Diffstat (limited to 'scripting/notf2.sp')
-rw-r--r--scripting/notf2.sp100
1 files changed, 100 insertions, 0 deletions
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 @@
1#include <sdkhooks>
2#include <sdktools>
3#include <sourcemod>
4#include <regex>
5#pragma newdecls required
6#pragma semicolon 1
7
8public Plugin myinfo = {
9 name = "nohashtagtf2",
10 author = "NW/RL",
11 description = "Kick players with \"#___TF2\" tokens in their name",
12 version = "0.0.1",
13 url = "https://git.dabikers.online/nohashtagtf2"
14};
15
16static ConVar ntf_enabled = null;
17static ConVar ntf_admins = null;
18static Regex nohash;
19
20public void OnPluginStart() {
21 // Set up ConVars
22 ntf_enabled = CreateConVar("ntf_enabled", "1", "Enables/disables kicking players", FCVAR_NONE, true, 0.0, true, 1.0);
23 ntf_admins = CreateConVar("ntf_admins", "0", "Target admins for having inappropriate names", FCVAR_NONE, true, 0.0, true, 1.0);
24 ntf_enabled.IntValue = 1;
25 ntf_admins.BoolValue = false;
26
27 // Create/execute a config file on load
28 AutoExecConfig(true, "nohashtagtf2");
29
30 // Regular expression setup
31 char regerrstr[256 + 1] = {0}; RegexError regerr;
32 nohash = CompileRegex("#.*tf2", PCRE_CASELESS | PCRE_UTF8, regerrstr, sizeof(regerrstr), regerr);
33 if(nohash == INVALID_HANDLE) {
34 PrintToServer("[No#TF2] Error - Could not compile regex: %s (ecode: %d)", regerrstr, regerr);
35 SetFailState("Could not compile regex: %s (%d)", regerrstr, regerr);
36 }
37
38 // Hook name change events
39 HookEvent("player_info", ntf_checkname, EventHookMode_Pre);
40
41 return;
42}
43
44public void OnClientPostAdminCheck(int client) {
45 // Skip everything if the plugin isn't enabled
46 if(ntf_enabled.IntValue != 1)
47 return;
48
49 // Skip if user is an admin
50 if(CheckCommandAccess(client, "nohashtagtf2", ADMFLAG_GENERIC) && !ntf_admins.BoolValue)
51 return;
52
53 // Get name & kick if the regex works
54 char name[128 + 1] = {0};
55 GetClientName(client, name, sizeof(name));
56 if(MatchRegex(nohash, name) > 0) {
57 KickClient(client, "Failed regex name check");
58 PrintToChatAll("[No#TF2] %s failed a regex name check", name);
59 }
60
61 return;
62}
63
64#define NTF_CHECKNAME_KEYERRORDEF "SHIT BROKE"
65static Action ntf_checkname (Event event, const char[] name, bool dontBroadcast) {
66 // Don't do anything if the plugin is disabled
67 if(ntf_enabled.IntValue != 1)
68 return Plugin_Continue;
69
70 // Get the player's name
71 char playername[128 + 1] = {0};
72 event.GetString("name", playername, sizeof(playername), NTF_CHECKNAME_KEYERRORDEF);
73
74 // 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)
75 if(strcmp(playername, NTF_CHECKNAME_KEYERRORDEF) == 0) {
76 PrintToServer("[No#TF2] Ran into a problem checking someone's changed name");
77 return Plugin_Continue;
78 }
79
80 // Get the client value from the returned userid
81 int userid = event.GetInt("userid", -1);
82 if(userid == -1) {
83 PrintToServer("[No#TF2] Couldn't get %s's userid");
84 return Plugin_Continue;
85 }
86 int clientid = GetClientOfUserId(userid);
87
88 // Check if the player is an admin (and if kicking admins is allowed)
89 if(CheckCommandAccess(clientid, "nohashtagtf2", ADMFLAG_GENERIC) && !ntf_admins.BoolValue)
90 return Plugin_Continue;
91
92 // Get name & kick if the regex works
93 GetClientName(clientid, playername, sizeof(playername));
94 if(MatchRegex(nohash, playername) > 0) {
95 KickClient(clientid, "Failed regex name check");
96 PrintToChatAll("[No#TF2] %s failed a regex name check", playername);
97 }
98
99 return Plugin_Continue;
100} \ No newline at end of file