summaryrefslogtreecommitdiff
path: root/nameblocker.sp
diff options
context:
space:
mode:
authornwrl <n/a>2025-07-29 15:05:34 -0500
committernwrl <n/a>2025-07-29 15:05:34 -0500
commit7830b7a40cb208625da80b94d074886be14f4ab4 (patch)
tree18b822c7df39a8b50f72e4b88cf4a11725cad9ec /nameblocker.sp
parent066e677535f83db457ea10f0488071675d2791cd (diff)
Start rewrite
Diffstat (limited to 'nameblocker.sp')
-rw-r--r--nameblocker.sp90
1 files changed, 90 insertions, 0 deletions
diff --git a/nameblocker.sp b/nameblocker.sp
index 2850ee2..8254cd0 100644
--- a/nameblocker.sp
+++ b/nameblocker.sp
@@ -1,6 +1,7 @@
1#pragma newdecls required 1#pragma newdecls required
2 2
3#include <sourcemod> 3#include <sourcemod>
4#include <regex>
4 5
5public Plugin myinfo = { 6public Plugin myinfo = {
6 name = "SM Name Blocker", 7 name = "SM Name Blocker",
@@ -9,3 +10,92 @@ public Plugin myinfo = {
9 version = "alpha-0.1", 10 version = "alpha-0.1",
10 url = "git.dabikers.online/smnameblocker" 11 url = "git.dabikers.online/smnameblocker"
11}; 12};
13
14#define HANDLE_SIZE 32
15// This exists because you can't sizeof() a Handle, but it IS specified to be a 32bit integer. This should also equal the size of
16// any other methodmap or descendant of Handle (like Regex)
17
18enum OperatingMode {
19 OP_DISABLED,
20 OP_KICK,
21 OP_BAN,
22 OP_TOOBIG
23}
24OperatingMode gOperMode = OP_DISABLED;
25
26ArrayList filterlist;
27// Note: Contents of ArrayLists are lost on map change / reload. I should store everything in a database,
28// then use the database to populate the list whenever it is cleared
29
30public void OnAllPluginsLoaded() {
31 filterlist = new ArrayList(ByteCountToCells(HANDLE_SIZE));
32}
33
34public void OnClientPostAdminCheck(int client) {
35 checkName(client);
36}
37
38public void OnClientSettingsChanged(int client) {
39 checkName(client);
40}
41
42
43
44void checkName(int client) {
45 if(client <= 0) return;
46
47 char name[64 + 1];
48 if(getName(client, name, sizeof(name)) <= 0)
49 return; // TODO: better error checking
50
51 RegexError reerr;
52 for(int i = 0, m = 0; i < filterlist.Length; i++) {
53 m = MatchRegex(filterlist.Get(i), name, reerr);
54
55 if(m == 0) continue;
56 if(m < 0) {
57 handleFailedRegex(client, reerr, name, sizeof(name));
58 return;
59 }
60
61 handleNameHit(client);
62 }
63
64 return;
65}
66
67int getName(int client, char[] buf, int buflen) {
68 if(client <= 0 || buflen <= 0) return -1;
69 if(IsNullString(buf)) return -1;
70
71 return Format(buf, buflen, "%N", client);
72}
73
74int handleNameHit(int client) {
75 if(client <= 0) return -1;
76
77 switch(gOperMode) {
78 case OP_DISABLED: {return 0;}
79 case OP_KICK: {
80 KickClient(client, "Failed Name Check");
81 // Log kick
82 return 0;
83 }
84 case OP_BAN: {
85 // BanClient()
86 // TODO: Interop with other ban systems
87 // Log ban
88 }
89 default: {
90 LogError("Operating mode in an invalid state");
91 return -1;
92 }
93 }
94
95 LogError("Broke out of switch statement that shouldn't have happened");
96 return -1; // Shouldn't get to this point
97}
98
99int handleFailedRegex(int client, RegexError reerr, char[] name, int namelen) {
100 return 0;
101} \ No newline at end of file