From 7830b7a40cb208625da80b94d074886be14f4ab4 Mon Sep 17 00:00:00 2001 From: nwrl Date: Tue, 29 Jul 2025 15:05:34 -0500 Subject: Start rewrite --- nameblocker.sp | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'nameblocker.sp') diff --git a/nameblocker.sp b/nameblocker.sp index 2850ee2..8254cd0 100644 --- a/nameblocker.sp +++ b/nameblocker.sp @@ -1,6 +1,7 @@ #pragma newdecls required #include +#include public Plugin myinfo = { name = "SM Name Blocker", @@ -9,3 +10,92 @@ public Plugin myinfo = { version = "alpha-0.1", url = "git.dabikers.online/smnameblocker" }; + +#define HANDLE_SIZE 32 +// 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 +// any other methodmap or descendant of Handle (like Regex) + +enum OperatingMode { + OP_DISABLED, + OP_KICK, + OP_BAN, + OP_TOOBIG +} +OperatingMode gOperMode = OP_DISABLED; + +ArrayList filterlist; +// Note: Contents of ArrayLists are lost on map change / reload. I should store everything in a database, +// then use the database to populate the list whenever it is cleared + +public void OnAllPluginsLoaded() { + filterlist = new ArrayList(ByteCountToCells(HANDLE_SIZE)); +} + +public void OnClientPostAdminCheck(int client) { + checkName(client); +} + +public void OnClientSettingsChanged(int client) { + checkName(client); +} + + + +void checkName(int client) { + if(client <= 0) return; + + char name[64 + 1]; + if(getName(client, name, sizeof(name)) <= 0) + return; // TODO: better error checking + + RegexError reerr; + for(int i = 0, m = 0; i < filterlist.Length; i++) { + m = MatchRegex(filterlist.Get(i), name, reerr); + + if(m == 0) continue; + if(m < 0) { + handleFailedRegex(client, reerr, name, sizeof(name)); + return; + } + + handleNameHit(client); + } + + return; +} + +int getName(int client, char[] buf, int buflen) { + if(client <= 0 || buflen <= 0) return -1; + if(IsNullString(buf)) return -1; + + return Format(buf, buflen, "%N", client); +} + +int handleNameHit(int client) { + if(client <= 0) return -1; + + switch(gOperMode) { + case OP_DISABLED: {return 0;} + case OP_KICK: { + KickClient(client, "Failed Name Check"); + // Log kick + return 0; + } + case OP_BAN: { + // BanClient() + // TODO: Interop with other ban systems + // Log ban + } + default: { + LogError("Operating mode in an invalid state"); + return -1; + } + } + + LogError("Broke out of switch statement that shouldn't have happened"); + return -1; // Shouldn't get to this point +} + +int handleFailedRegex(int client, RegexError reerr, char[] name, int namelen) { + return 0; +} \ No newline at end of file -- cgit v1.2.3