Browse Source

Renamed character blacklist

"FilteredMultiByteWhiteSpace" is wordy and some of the the character(s)
aren't actually designated as whitespace in the standard.
nosoop 7 years ago
parent
commit
42555746a8
1 changed files with 21 additions and 7 deletions
  1. 21 7
      scripting/csrd_name_filter.sp

+ 21 - 7
scripting/csrd_name_filter.sp

@@ -15,7 +15,7 @@
 
 #pragma newdecls required
 
-#define PLUGIN_VERSION "1.0.4"
+#define PLUGIN_VERSION "1.0.5"
 public Plugin myinfo = {
 	name = "[CSRD] Name Filter",
 	author = "nosoop",
@@ -27,7 +27,7 @@ public Plugin myinfo = {
 
 #define UNPRINTABLE_NAME_USER_FORMAT "unprintable (%d)"
 
-int g_FilteredMultiByteWhitespace[] = {
+int g_MultiByteNonPrinting[] = {
 	0xe2a080, // braille pattern blank U+2800
 	0
 };
@@ -65,7 +65,14 @@ void OnNameUpdated(int client) {
 		
 		bool bCharFiltered;
 		
-		// Filter out non-printing characters that can't be handled elsewhere.
+		/**
+		 * Filter out characters.
+		 * 
+		 * Note that while Steam may filter out whitespace characters in its interface, other
+		 * external applications may be used to bypass this restriction.
+		 * 
+		 * (We use `sm_rename` to test the filtering process.)
+		 */
 		switch (nCharBytes) {
 			case 3: {
 				// filter unicode invisible characters
@@ -103,25 +110,32 @@ void OnNameUpdated(int client) {
 			
 			SetClientNameLock(client);
 		}
+		
 		SetClientName(client, newNameBuffer);
 	}
 	// TODO else not name changed, but check if we can do other non-filter stuff? (trim)
 }
 
+/**
+ * Determines if the specified character is non-printing (whitespace or not supported).
+ * 
+ * References:
+ * http://www.unicode.org/faq/unsup_char.html
+ * https://en.wikipedia.org/wiki/Whitespace_character
+ */
 bool IsUnicodeCharInvisible(int uchar) {
 	// handle invisible math operators, &c. (U+205F ... U+206F)
-	// could do (char & 0xe281a0) plus check for U+205F, I think?
 	if (uchar >= 0xe2819f && uchar <= 0xe281af) {
 		return true;
 	}
 	
-	// handle other blacklisted characters
+	// handle other invisible characters
 	int c;
 	do {
-		if (uchar == g_FilteredMultiByteWhitespace[c]) {
+		if (uchar == g_MultiByteNonPrinting[c]) {
 			return true;
 		}
-	} while (g_FilteredMultiByteWhitespace[++c] != 0);
+	} while (g_MultiByteNonPrinting[++c] != 0);
 	
 	return false;
 }