Browse Source

Removed name lock global variable

The function's only really used in one spot anyways, and I don't think
changing it to check if the command exists every time would have much of
an impact.
nosoop 7 years ago
parent
commit
d51cf387f2
1 changed files with 12 additions and 10 deletions
  1. 12 10
      scripting/csrd_name_filter.sp

+ 12 - 10
scripting/csrd_name_filter.sp

@@ -15,7 +15,7 @@
 
 #pragma newdecls required
 
-#define PLUGIN_VERSION "1.0.0"
+#define PLUGIN_VERSION "1.0.1"
 public Plugin myinfo = {
 	name = "[CSRD] Name Filter",
 	author = "nosoop",
@@ -27,8 +27,6 @@ public Plugin myinfo = {
 
 #define UNPRINTABLE_NAME_USER_FORMAT "unprintable (%d)"
 
-bool g_bNameLockSupported;
-
 int g_FilteredWhitespace[] = {
 	0xe2a080, // braille pattern blank U+2800
 	0x0a, // linefeed
@@ -42,8 +40,6 @@ public void OnPluginStart() {
 			OnNameUpdated(i);
 		}
 	}
-	
-	g_bNameLockSupported = CommandExists("namelockid");
 }
 
 public void OnClientConnected(int client) {
@@ -71,16 +67,20 @@ void OnNameUpdated(int client) {
 		
 		bool bCharFiltered;
 		
-		// Filter out whitespace
+		// Filter out non-printing characters that can't be handled elsewhere.
 		int c;
 		do {
 			bCharFiltered |= (fullChar == g_FilteredWhitespace[c]);
 		} while (g_FilteredWhitespace[++c] != 0 && !bCharFiltered);
 		
 		if (!bCharFiltered) {
-			// it's a character that we don't really care about 
+			// it's a character we're not filtering
 			StrCatMultiByteChar(newNameBuffer, sizeof(newNameBuffer), fullChar, nCharBytes);
 		} else {
+			// we filtered this one
+			// we could be as rude as they are in using unprintables, but we're nice
+			
+			// TODO check if the last character in new buffer is a space to prevent multiples
 			StrCat(newNameBuffer, sizeof(newNameBuffer), " ");
 		}
 		
@@ -106,12 +106,14 @@ void OnNameUpdated(int client) {
 }
 
 /**
- * Attempts to lock the specified client's name.
+ * Attempts to lock the specified client's name with the existing `namelockid` command.
  */
-stock void SetClientNameLock(int client, bool locked = true) {
-	if (g_bNameLockSupported) {
+stock bool SetClientNameLock(int client, bool locked = true) {
+	if (CommandExists("namelockid")) {
 		ServerCommand("namelockid %d %d", GetClientUserId(client), locked ? 0 : 1);
+		return true;
 	}
+	return false;
 }
 
 /**