From 9e0137381b99e4d555f25be48ca0b00df31f262a Mon Sep 17 00:00:00 2001
From: Git-Nivrak <59925169+Git-Nivrak@users.noreply.github.com>
Date: Thu, 8 Aug 2024 09:58:32 +0300
Subject: [PATCH 1/9] a
---
.../configuration/entries/general.dm | 2 ++
code/game/verbs/ooc.dm | 6 ++++++
code/modules/mob/dead/observer/say.dm | 3 +++
code/modules/mob/living/say.dm | 21 +++++++++++++++++++
config/example/config.txt | 1 +
config/example/word_filter.txt | 4 ++++
6 files changed, 37 insertions(+)
create mode 100644 config/example/word_filter.txt
diff --git a/code/controllers/configuration/entries/general.dm b/code/controllers/configuration/entries/general.dm
index 627859369231..6df6e1c5ca18 100644
--- a/code/controllers/configuration/entries/general.dm
+++ b/code/controllers/configuration/entries/general.dm
@@ -672,3 +672,5 @@ This maintains a list of ip addresses that are able to bypass topic filtering.
/datum/config_entry/string/repo_name
/datum/config_entry/string/org
+
+/datum/config_entry/str_list/word_filter
diff --git a/code/game/verbs/ooc.dm b/code/game/verbs/ooc.dm
index a5ecea8b05a4..4d52635c6f88 100644
--- a/code/game/verbs/ooc.dm
+++ b/code/game/verbs/ooc.dm
@@ -7,6 +7,9 @@
to_chat(src, "Guests may not use OOC.")
return
+ if(!filter_message(src, msg))
+ return
+
msg = trim(strip_html(msg))
if(!msg) return
@@ -101,6 +104,9 @@
to_chat(src, "Guests may not use LOOC.")
return
+ if(!filter_message(src, msg))
+ return
+
msg = trim(strip_html(msg))
if(!msg) return
diff --git a/code/modules/mob/dead/observer/say.dm b/code/modules/mob/dead/observer/say.dm
index b9a972bda5c2..b8aa921cec5f 100644
--- a/code/modules/mob/dead/observer/say.dm
+++ b/code/modules/mob/dead/observer/say.dm
@@ -12,6 +12,9 @@
if (src.client.handle_spam_prevention(message, MUTE_DEADCHAT))
return
+ if(!filter_message(src, message))
+ return
+
. = src.say_dead(message)
diff --git a/code/modules/mob/living/say.dm b/code/modules/mob/living/say.dm
index 7f3af1449266..ca0ea8e50efe 100644
--- a/code/modules/mob/living/say.dm
+++ b/code/modules/mob/living/say.dm
@@ -62,6 +62,24 @@ GLOBAL_LIST_INIT(department_radio_keys, list(
/proc/prefix_to_channel(prefix)
return GLOB.department_radio_keys[prefix]
+/proc/filter_message(user, message)
+ var/list/banned_words = CONFIG_GET(str_list/word_filter)
+ var/message_lowercase = lowertext(message)
+
+ for(var/word in banned_words)
+ if(findtext(message_lowercase, lowertext(word)))
+ to_chat(user,
+ html = "\n-- Word Filter Message --",
+ )
+ to_chat(user,
+ type = MESSAGE_TYPE_ADMINPM,
+ html = "\nYour message has been automatically filtered due to its contents. Trying to circumvent this filter will get you banned.",
+ )
+ SEND_SOUND(user, sound('sound/effects/adminhelp_new.ogg'))
+ return FALSE
+
+ return TRUE
+
///Shows custom speech bubbles for screaming, *warcry etc.
/mob/living/proc/show_speech_bubble(bubble_name, bubble_type = bubble_icon)
@@ -81,6 +99,9 @@ GLOBAL_LIST_INIT(department_radio_keys, list(
if(SEND_SIGNAL(src, COMSIG_LIVING_SPEAK, message, speaking, verb, alt_name, italics, message_range, speech_sound, sound_vol, nolog, message_mode) & COMPONENT_OVERRIDE_SPEAK) return
+ if(!filter_message(src, message))
+ return
+
message = process_chat_markup(message, list("~", "_"))
for(var/dst=0; dst<=1; dst++) //Will run twice if src has a clone
diff --git a/config/example/config.txt b/config/example/config.txt
index d63e6822465c..ca63e4ed93c1 100644
--- a/config/example/config.txt
+++ b/config/example/config.txt
@@ -5,6 +5,7 @@
# $include resources.txt
# $include icon_source.txt
# $include relays.txt
+$include word_filter.txt
## Server name: This appears at the top of the screen in-game. In this case it will read "tgstation: station_name" where station_name is the randomly generated name of the station for the round. Remove the # infront of SERVERNAME and replace 'tgstation' with the name of your choice
# SERVERNAME spacestation13
diff --git a/config/example/word_filter.txt b/config/example/word_filter.txt
new file mode 100644
index 000000000000..b14d233b2a1b
--- /dev/null
+++ b/config/example/word_filter.txt
@@ -0,0 +1,4 @@
+## Word filter
+## WORD_FILTER
+## Case insensitive
+#WORD_FILTER wordToBan
From db07646c0b90dcbd5f7878d2aef44441e5f94ec5 Mon Sep 17 00:00:00 2001
From: Git-Nivrak <59925169+Git-Nivrak@users.noreply.github.com>
Date: Thu, 8 Aug 2024 15:19:52 +0300
Subject: [PATCH 2/9] regex
---
code/modules/mob/living/say.dm | 2 +-
config/example/word_filter.txt | 4 +++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/code/modules/mob/living/say.dm b/code/modules/mob/living/say.dm
index ca0ea8e50efe..ea3d54a7a3ba 100644
--- a/code/modules/mob/living/say.dm
+++ b/code/modules/mob/living/say.dm
@@ -67,7 +67,7 @@ GLOBAL_LIST_INIT(department_radio_keys, list(
var/message_lowercase = lowertext(message)
for(var/word in banned_words)
- if(findtext(message_lowercase, lowertext(word)))
+ if(findtext(message_lowercase, regex(lowertext(word))))
to_chat(user,
html = "\n-- Word Filter Message --",
)
diff --git a/config/example/word_filter.txt b/config/example/word_filter.txt
index b14d233b2a1b..a6c19e7e21a2 100644
--- a/config/example/word_filter.txt
+++ b/config/example/word_filter.txt
@@ -1,4 +1,6 @@
## Word filter
## WORD_FILTER
-## Case insensitive
+## Case insensitive, Uses regex
#WORD_FILTER wordToBan
+#WORD_FILTER otherwordtoban
+#WORD_FILTER wordtoban.*withregex
From 62c452094aef5bcbc5f99a2e880e00b40924d2da Mon Sep 17 00:00:00 2001
From: Git-Nivrak <59925169+Git-Nivrak@users.noreply.github.com>
Date: Tue, 20 Aug 2024 11:48:22 +0300
Subject: [PATCH 3/9] a
---
.../configuration/entries/general.dm | 2 +-
code/modules/mob/living/say.dm | 27 ++++++++++---------
config/example/config.txt | 4 +--
config/example/word_filter.txt | 8 +++---
4 files changed, 20 insertions(+), 21 deletions(-)
diff --git a/code/controllers/configuration/entries/general.dm b/code/controllers/configuration/entries/general.dm
index 6df6e1c5ca18..b8a67dee6541 100644
--- a/code/controllers/configuration/entries/general.dm
+++ b/code/controllers/configuration/entries/general.dm
@@ -673,4 +673,4 @@ This maintains a list of ip addresses that are able to bypass topic filtering.
/datum/config_entry/string/org
-/datum/config_entry/str_list/word_filter
+/datum/config_entry/string/word_filter
diff --git a/code/modules/mob/living/say.dm b/code/modules/mob/living/say.dm
index ea3d54a7a3ba..33b698a6cbfa 100644
--- a/code/modules/mob/living/say.dm
+++ b/code/modules/mob/living/say.dm
@@ -63,20 +63,21 @@ GLOBAL_LIST_INIT(department_radio_keys, list(
return GLOB.department_radio_keys[prefix]
/proc/filter_message(user, message)
- var/list/banned_words = CONFIG_GET(str_list/word_filter)
+ var/filter = CONFIG_GET(string/word_filter)
var/message_lowercase = lowertext(message)
-
- for(var/word in banned_words)
- if(findtext(message_lowercase, regex(lowertext(word))))
- to_chat(user,
- html = "\n-- Word Filter Message --",
- )
- to_chat(user,
- type = MESSAGE_TYPE_ADMINPM,
- html = "\nYour message has been automatically filtered due to its contents. Trying to circumvent this filter will get you banned.",
- )
- SEND_SOUND(user, sound('sound/effects/adminhelp_new.ogg'))
- return FALSE
+ if(!filter)
+ return TRUE
+
+ if(findtext(message_lowercase, regex(filter)))
+ to_chat(user,
+ html = "\n-- Word Filter Message --",
+ )
+ to_chat(user,
+ type = MESSAGE_TYPE_ADMINPM,
+ html = "\nYour message has been automatically filtered due to its contents. Trying to circumvent this filter will get you banned.",
+ )
+ SEND_SOUND(user, sound('sound/effects/adminhelp_new.ogg'))
+ return FALSE
return TRUE
diff --git a/config/example/config.txt b/config/example/config.txt
index ca63e4ed93c1..cdff7ad6c164 100644
--- a/config/example/config.txt
+++ b/config/example/config.txt
@@ -5,7 +5,7 @@
# $include resources.txt
# $include icon_source.txt
# $include relays.txt
-$include word_filter.txt
+# $include word_filter.txt
## Server name: This appears at the top of the screen in-game. In this case it will read "tgstation: station_name" where station_name is the randomly generated name of the station for the round. Remove the # infront of SERVERNAME and replace 'tgstation' with the name of your choice
# SERVERNAME spacestation13
@@ -258,4 +258,4 @@ CLIENT_ERROR_VERSION 514
## GITHUB API
#GITHUB_APP_API
#REPO_NAME cmss13
-#ORG cmss13-devs
\ No newline at end of file
+#ORG cmss13-devs
diff --git a/config/example/word_filter.txt b/config/example/word_filter.txt
index a6c19e7e21a2..0e025a0b0b11 100644
--- a/config/example/word_filter.txt
+++ b/config/example/word_filter.txt
@@ -1,6 +1,4 @@
## Word filter
-## WORD_FILTER
-## Case insensitive, Uses regex
-#WORD_FILTER wordToBan
-#WORD_FILTER otherwordtoban
-#WORD_FILTER wordtoban.*withregex
+## WORD_FILTER
+## Case sensitive
+WORD_FILTER retard
From 9df2f0c4bb71ebf592a08b69f9641e6c9a3f38be Mon Sep 17 00:00:00 2001
From: Git-Nivrak <59925169+Git-Nivrak@users.noreply.github.com>
Date: Tue, 20 Aug 2024 11:49:56 +0300
Subject: [PATCH 4/9] review
---
config/example/word_filter.txt | 1 -
1 file changed, 1 deletion(-)
diff --git a/config/example/word_filter.txt b/config/example/word_filter.txt
index 0e025a0b0b11..9a59534ebfd1 100644
--- a/config/example/word_filter.txt
+++ b/config/example/word_filter.txt
@@ -1,4 +1,3 @@
## Word filter
## WORD_FILTER
## Case sensitive
-WORD_FILTER retard
From 7b1c805431d466ab1454a91d7c28e88db3611fdf Mon Sep 17 00:00:00 2001
From: Git-Nivrak <59925169+Git-Nivrak@users.noreply.github.com>
Date: Thu, 22 Aug 2024 15:03:53 +0300
Subject: [PATCH 5/9] Update say.dm
---
code/modules/mob/living/say.dm | 1 +
1 file changed, 1 insertion(+)
diff --git a/code/modules/mob/living/say.dm b/code/modules/mob/living/say.dm
index 33b698a6cbfa..d4577bd4835e 100644
--- a/code/modules/mob/living/say.dm
+++ b/code/modules/mob/living/say.dm
@@ -77,6 +77,7 @@ GLOBAL_LIST_INIT(department_radio_keys, list(
html = "\nYour message has been automatically filtered due to its contents. Trying to circumvent this filter will get you banned.",
)
SEND_SOUND(user, sound('sound/effects/adminhelp_new.ogg'))
+ log_admin("[user.client] triggered the chat filter with the following message: [message].")
return FALSE
return TRUE
From e375a014935f65d1a8db7ebdc35d87aa3bcafa33 Mon Sep 17 00:00:00 2001
From: harryob <55142896+harryob@users.noreply.github.com>
Date: Thu, 22 Aug 2024 13:28:18 +0100
Subject: [PATCH 6/9] linter fail
---
code/modules/mob/dead/observer/say.dm | 2 +-
code/modules/mob/living/say.dm | 8 ++++----
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/code/modules/mob/dead/observer/say.dm b/code/modules/mob/dead/observer/say.dm
index b8aa921cec5f..04e93095f42d 100644
--- a/code/modules/mob/dead/observer/say.dm
+++ b/code/modules/mob/dead/observer/say.dm
@@ -12,7 +12,7 @@
if (src.client.handle_spam_prevention(message, MUTE_DEADCHAT))
return
- if(!filter_message(src, message))
+ if(!filter_message(client, message))
return
. = src.say_dead(message)
diff --git a/code/modules/mob/living/say.dm b/code/modules/mob/living/say.dm
index d4577bd4835e..9f74a9c8380d 100644
--- a/code/modules/mob/living/say.dm
+++ b/code/modules/mob/living/say.dm
@@ -62,12 +62,12 @@ GLOBAL_LIST_INIT(department_radio_keys, list(
/proc/prefix_to_channel(prefix)
return GLOB.department_radio_keys[prefix]
-/proc/filter_message(user, message)
+/proc/filter_message(client/user, message)
var/filter = CONFIG_GET(string/word_filter)
var/message_lowercase = lowertext(message)
if(!filter)
return TRUE
-
+
if(findtext(message_lowercase, regex(filter)))
to_chat(user,
html = "\n-- Word Filter Message --",
@@ -77,9 +77,9 @@ GLOBAL_LIST_INIT(department_radio_keys, list(
html = "\nYour message has been automatically filtered due to its contents. Trying to circumvent this filter will get you banned.",
)
SEND_SOUND(user, sound('sound/effects/adminhelp_new.ogg'))
- log_admin("[user.client] triggered the chat filter with the following message: [message].")
+ log_admin("[user.ckey] triggered the chat filter with the following message: [message].")
return FALSE
-
+
return TRUE
///Shows custom speech bubbles for screaming, *warcry etc.
From 824d72b12849a36459d33bf7e606ec53bc91b250 Mon Sep 17 00:00:00 2001
From: harryob <55142896+harryob@users.noreply.github.com>
Date: Thu, 22 Aug 2024 13:55:52 +0100
Subject: [PATCH 7/9] tidyup and use existing word filter
---
code/controllers/configuration/configuration.dm | 14 +++++++-------
code/modules/mob/living/say.dm | 6 ++----
config/example/config.txt | 1 -
config/example/word_filter.txt | 3 ---
4 files changed, 9 insertions(+), 15 deletions(-)
delete mode 100644 config/example/word_filter.txt
diff --git a/code/controllers/configuration/configuration.dm b/code/controllers/configuration/configuration.dm
index 7207f878614a..b74275d2cee2 100644
--- a/code/controllers/configuration/configuration.dm
+++ b/code/controllers/configuration/configuration.dm
@@ -19,7 +19,7 @@
var/motd
var/policy
- var/static/regex/ic_filter_regex
+ var/static/regex/word_filter_regex
var/is_loaded = FALSE
@@ -315,21 +315,21 @@
/datum/controller/configuration/proc/LoadChatFilter()
- var/list/in_character_filter = list()
+ var/list/word_filter = list()
- if(!fexists("[directory]/in_character_filter.txt"))
+ if(!fexists("[directory]/word_filter.txt"))
return
- log_config("Loading config file in_character_filter.txt...")
+ log_config("Loading config file word_filter.txt...")
- for(var/line in file2list("[directory]/in_character_filter.txt"))
+ for(var/line in file2list("[directory]/word_filter.txt"))
if(!line)
continue
if(findtextEx(line,"#",1,2))
continue
- in_character_filter += REGEX_QUOTE(line)
+ word_filter += REGEX_QUOTE(line)
- ic_filter_regex = length(in_character_filter) ? regex("\\b([jointext(in_character_filter, "|")])\\b", "i") : null
+ word_filter_regex = length(word_filter) ? regex("\\b([jointext(word_filter, "|")])\\b", "i") : null
//Message admins when you can.
/datum/controller/configuration/proc/DelayedMessageAdmins(text)
diff --git a/code/modules/mob/living/say.dm b/code/modules/mob/living/say.dm
index 9f74a9c8380d..5bd2b4283c86 100644
--- a/code/modules/mob/living/say.dm
+++ b/code/modules/mob/living/say.dm
@@ -63,12 +63,10 @@ GLOBAL_LIST_INIT(department_radio_keys, list(
return GLOB.department_radio_keys[prefix]
/proc/filter_message(client/user, message)
- var/filter = CONFIG_GET(string/word_filter)
- var/message_lowercase = lowertext(message)
- if(!filter)
+ if(!config.word_filter_regex)
return TRUE
- if(findtext(message_lowercase, regex(filter)))
+ if(config.word_filter_regex.Find(message))
to_chat(user,
html = "\n-- Word Filter Message --",
)
diff --git a/config/example/config.txt b/config/example/config.txt
index cdff7ad6c164..07dfe6f1b839 100644
--- a/config/example/config.txt
+++ b/config/example/config.txt
@@ -5,7 +5,6 @@
# $include resources.txt
# $include icon_source.txt
# $include relays.txt
-# $include word_filter.txt
## Server name: This appears at the top of the screen in-game. In this case it will read "tgstation: station_name" where station_name is the randomly generated name of the station for the round. Remove the # infront of SERVERNAME and replace 'tgstation' with the name of your choice
# SERVERNAME spacestation13
diff --git a/config/example/word_filter.txt b/config/example/word_filter.txt
deleted file mode 100644
index 9a59534ebfd1..000000000000
--- a/config/example/word_filter.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-## Word filter
-## WORD_FILTER
-## Case sensitive
From 168347dcd954bf059f8bb58bd292e2de4d57ae90 Mon Sep 17 00:00:00 2001
From: harryob <55142896+harryob@users.noreply.github.com>
Date: Thu, 22 Aug 2024 13:57:19 +0100
Subject: [PATCH 8/9] redundant config line
---
code/controllers/configuration/entries/general.dm | 2 --
1 file changed, 2 deletions(-)
diff --git a/code/controllers/configuration/entries/general.dm b/code/controllers/configuration/entries/general.dm
index b8a67dee6541..627859369231 100644
--- a/code/controllers/configuration/entries/general.dm
+++ b/code/controllers/configuration/entries/general.dm
@@ -672,5 +672,3 @@ This maintains a list of ip addresses that are able to bypass topic filtering.
/datum/config_entry/string/repo_name
/datum/config_entry/string/org
-
-/datum/config_entry/string/word_filter
From 644dcc30e6c12787bb6c8b56c7241808e8eb119e Mon Sep 17 00:00:00 2001
From: harryob <55142896+harryob@users.noreply.github.com>
Date: Thu, 22 Aug 2024 14:36:58 +0100
Subject: [PATCH 9/9] example file
---
config/example/word_filter.txt | 1 +
1 file changed, 1 insertion(+)
create mode 100644 config/example/word_filter.txt
diff --git a/config/example/word_filter.txt b/config/example/word_filter.txt
new file mode 100644
index 000000000000..aab5cae627fa
--- /dev/null
+++ b/config/example/word_filter.txt
@@ -0,0 +1 @@
+# Words that should be filtered from being said, both IC and OOC, should be included here, one per line. Case insensitive.