From 201fc8a927b2d3e9be203956a2d05aede39c050f Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 27 Dec 2018 22:26:18 +1100 Subject: [PATCH] Allow custom profanity filter replacement --- MCGalaxy/Chat/ProfanityFilter.cs | 11 ++++++++--- MCGalaxy/Server/ServerConfig.cs | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/MCGalaxy/Chat/ProfanityFilter.cs b/MCGalaxy/Chat/ProfanityFilter.cs index 8d7e5a531..4d77f8a8f 100644 --- a/MCGalaxy/Chat/ProfanityFilter.cs +++ b/MCGalaxy/Chat/ProfanityFilter.cs @@ -50,13 +50,18 @@ namespace MCGalaxy { } if (!isFiltered) continue; - // If a bad word is found anywhere in the word, replace the word - int length = words[i].Length; - words[i] = "&c[&fBlocked&c]&f"; + // If a bad word is found anywhere in the word, replace the word + words[i] = Replace(words[i]); } return String.Join(" ", words); } + static string Replace(string word) { + string replacement = Server.Config.ProfanityReplacement; + // for * repeat to **** + return replacement.Length == 1 ? new string(replacement[0], word.Length) : replacement; + } + static void InitReduceTable() { if (reduceKeys != null) return; // Because some letters are similar (Like i and l), they are reduced to the same form. diff --git a/MCGalaxy/Server/ServerConfig.cs b/MCGalaxy/Server/ServerConfig.cs index d0ad5bd57..c53299d32 100644 --- a/MCGalaxy/Server/ServerConfig.cs +++ b/MCGalaxy/Server/ServerConfig.cs @@ -201,6 +201,8 @@ namespace MCGalaxy { internal List DisabledChatTokens = new List(); [ConfigBool("profanity-filter", "Other", false)] public bool ProfanityFiltering = false; + [ConfigString("profanity-replacement", "Other", "*")] + public string ProfanityReplacement = "*"; [ConfigString("host-state", "Other", "Alive")] public string ConsoleName = "Alive";