1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#include <sdkhooks>
#include <sdktools>
#include <sourcemod>
#include <regex>
#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;
}
|