From 75176722e7ef5dfb836e64a64e232c2ad30fb76c Mon Sep 17 00:00:00 2001 From: Markolie Date: Tue, 8 Nov 2016 17:01:44 +0100 Subject: [PATCH 1/4] Add OOC throttling --- code/__DEFINES/misc.dm | 3 +++ code/game/verbs/ooc.dm | 4 ++-- code/modules/admin/verbs/adminhelp.dm | 2 +- code/modules/admin/verbs/adminpm.dm | 2 +- code/modules/admin/verbs/pray.dm | 2 +- code/modules/client/client defines.dm | 5 +++-- code/modules/client/client procs.dm | 24 +++++++++++++++--------- 7 files changed, 26 insertions(+), 16 deletions(-) diff --git a/code/__DEFINES/misc.dm b/code/__DEFINES/misc.dm index dad6165400f..e271654146c 100644 --- a/code/__DEFINES/misc.dm +++ b/code/__DEFINES/misc.dm @@ -287,3 +287,6 @@ #define SHELTER_DEPLOY_BAD_TURFS "bad turfs" #define SHELTER_DEPLOY_BAD_AREA "bad area" #define SHELTER_DEPLOY_ANCHORED_OBJECTS "anchored objects" + +// The cooldown on OOC messages such as OOC, LOOC, praying and adminhelps +#define OOC_COOLDOWN 20 diff --git a/code/game/verbs/ooc.dm b/code/game/verbs/ooc.dm index 2c896f3dbdf..f209e652b38 100644 --- a/code/game/verbs/ooc.dm +++ b/code/game/verbs/ooc.dm @@ -32,7 +32,7 @@ var/global/admin_ooc_colour = "#b82e00" if(prefs.muted & MUTE_OOC) to_chat(src, "You cannot use OOC (muted).") return - if(handle_spam_prevention(msg, MUTE_OOC)) + if(handle_spam_prevention(msg, MUTE_OOC, OOC_COOLDOWN)) return if(findtext(msg, "byond://")) to_chat(src, "Advertising other servers is not allowed.") @@ -168,7 +168,7 @@ var/global/admin_ooc_colour = "#b82e00" if(prefs.muted & MUTE_OOC) to_chat(src, "You cannot use LOOC (muted).") return - if(handle_spam_prevention(msg,MUTE_OOC)) + if(handle_spam_prevention(msg, MUTE_OOC, OOC_COOLDOWN)) return if(findtext(msg, "byond://")) to_chat(src, "Advertising other servers is not allowed.") diff --git a/code/modules/admin/verbs/adminhelp.dm b/code/modules/admin/verbs/adminhelp.dm index d78ef5dcde3..c17671995ff 100644 --- a/code/modules/admin/verbs/adminhelp.dm +++ b/code/modules/admin/verbs/adminhelp.dm @@ -24,7 +24,7 @@ var/list/adminhelp_ignored_words = list("unknown","the","a","an","of","monkey"," if(!msg) return - if(src.handle_spam_prevention(msg,MUTE_ADMINHELP)) + if(handle_spam_prevention(msg, MUTE_ADMINHELP, OOC_COOLDOWN)) return msg = sanitize(copytext(msg,1,MAX_MESSAGE_LEN)) diff --git a/code/modules/admin/verbs/adminpm.dm b/code/modules/admin/verbs/adminpm.dm index d711a3f5910..63241ce43c5 100644 --- a/code/modules/admin/verbs/adminpm.dm +++ b/code/modules/admin/verbs/adminpm.dm @@ -99,7 +99,7 @@ adminhelp(msg) //admin we are replying to has vanished, adminhelp instead return - if(src.handle_spam_prevention(msg,MUTE_ADMINHELP)) + if(handle_spam_prevention(msg, MUTE_ADMINHELP, OOC_COOLDOWN)) return //clean the message if it's not sent by a high-rank admin diff --git a/code/modules/admin/verbs/pray.dm b/code/modules/admin/verbs/pray.dm index 03365b38385..486b95f5a1b 100644 --- a/code/modules/admin/verbs/pray.dm +++ b/code/modules/admin/verbs/pray.dm @@ -9,7 +9,7 @@ if(usr.client.prefs.muted & MUTE_PRAY) to_chat(usr, "\red You cannot pray (muted).") return - if(src.client.handle_spam_prevention(msg,MUTE_PRAY)) + if(client.handle_spam_prevention(msg, MUTE_PRAY, OOC_COOLDOWN)) return var/image/cross = image('icons/obj/storage.dmi',"bible") diff --git a/code/modules/client/client defines.dm b/code/modules/client/client defines.dm index c1cbd07daee..8f2adef5a1b 100644 --- a/code/modules/client/client defines.dm +++ b/code/modules/client/client defines.dm @@ -4,8 +4,9 @@ //////////////// var/datum/admins/holder = null - var/last_message = "" //Contains the last message sent by this client - used to protect against copy-paste spamming. - var/last_message_count = 0 //contins a number of how many times a message identical to last_message was sent. + var/last_message = "" //contains the last message sent by this client - used to protect against copy-paste spamming. + var/last_message_count = 0 //contains a number of how many times a message identical to last_message was sent. + var/last_message_time = 0 //holds the last time (based on world.time) a message was sent ///////// //OTHER// diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm index 7a668e375fc..b13fd42c38e 100644 --- a/code/modules/client/client procs.dm +++ b/code/modules/client/client procs.dm @@ -233,19 +233,25 @@ return 0 return 1 -/client/proc/handle_spam_prevention(var/message, var/mute_type) - if(config.automute_on && !holder && src.last_message == message) - src.last_message_count++ - if(src.last_message_count >= SPAM_TRIGGER_AUTOMUTE) - to_chat(src, "\red You have exceeded the spam filter limit for identical messages. An auto-mute was applied.") - cmd_admin_mute(src.mob, mute_type, 1) +/client/proc/handle_spam_prevention(var/message, var/mute_type, var/throttle = 0) + if(config.automute_on && !holder && last_message == message) + last_message_count++ + if(last_message_count >= SPAM_TRIGGER_AUTOMUTE) + to_chat(src, "You have exceeded the spam filter limit for identical messages. An auto-mute was applied.") + cmd_admin_mute(mob, mute_type, 1) return 1 - if(src.last_message_count >= SPAM_TRIGGER_WARNING) - to_chat(src, "\red You are nearing the spam filter limit for identical messages.") + if(last_message_count >= SPAM_TRIGGER_WARNING) + to_chat(src, "You are nearing the spam filter limit for identical messages.") return 0 + else if(throttle) + if((last_message_time + throttle > world.time) && !check_rights(R_ADMIN, 0)) + var/wait_time = round(((last_message_time + throttle) - world.time) / 10, 1) + to_chat(src, "You are sending messages to quickly. Please wait [wait_time] [wait_time == 1 ? "second" : "seconds"] before sending another message.") + return 1 + last_message_time = world.time else last_message = message - src.last_message_count = 0 + last_message_count = 0 return 0 //This stops files larger than UPLOAD_LIMIT being sent from client to server via input(), client.Import() etc. From 34c3e7fb8a9ab41ee08132908153e1551887b93d Mon Sep 17 00:00:00 2001 From: Markolie Date: Tue, 8 Nov 2016 17:08:52 +0100 Subject: [PATCH 2/4] Prioritize throttle, better admin right check --- code/modules/client/client procs.dm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm index b13fd42c38e..17c454bb7e2 100644 --- a/code/modules/client/client procs.dm +++ b/code/modules/client/client procs.dm @@ -234,7 +234,13 @@ return 1 /client/proc/handle_spam_prevention(var/message, var/mute_type, var/throttle = 0) - if(config.automute_on && !holder && last_message == message) + if(throttle) + if((last_message_time + throttle > world.time) && !check_rights(R_ADMIN, 0)) + var/wait_time = round(((last_message_time + throttle) - world.time) / 10, 1) + to_chat(src, "You are sending messages to quickly. Please wait [wait_time] [wait_time == 1 ? "second" : "seconds"] before sending another message.") + return 1 + last_message_time = world.time + if(config.automute_on && !check_rights(R_ADMIN, 0) && last_message == message) last_message_count++ if(last_message_count >= SPAM_TRIGGER_AUTOMUTE) to_chat(src, "You have exceeded the spam filter limit for identical messages. An auto-mute was applied.") @@ -243,12 +249,6 @@ if(last_message_count >= SPAM_TRIGGER_WARNING) to_chat(src, "You are nearing the spam filter limit for identical messages.") return 0 - else if(throttle) - if((last_message_time + throttle > world.time) && !check_rights(R_ADMIN, 0)) - var/wait_time = round(((last_message_time + throttle) - world.time) / 10, 1) - to_chat(src, "You are sending messages to quickly. Please wait [wait_time] [wait_time == 1 ? "second" : "seconds"] before sending another message.") - return 1 - last_message_time = world.time else last_message = message last_message_count = 0 From 30f5874ca861fcccee4751e6a3f39ea077ef77c8 Mon Sep 17 00:00:00 2001 From: Markolie Date: Tue, 8 Nov 2016 18:08:52 +0100 Subject: [PATCH 3/4] Reduce the cooldown to 1 second --- code/__DEFINES/misc.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/__DEFINES/misc.dm b/code/__DEFINES/misc.dm index e271654146c..6b9f2b4a9a1 100644 --- a/code/__DEFINES/misc.dm +++ b/code/__DEFINES/misc.dm @@ -289,4 +289,4 @@ #define SHELTER_DEPLOY_ANCHORED_OBJECTS "anchored objects" // The cooldown on OOC messages such as OOC, LOOC, praying and adminhelps -#define OOC_COOLDOWN 20 +#define OOC_COOLDOWN 10 From 4ae1855a647121e340770c8409ffd3c6c5240298 Mon Sep 17 00:00:00 2001 From: Mark van Alphen Date: Wed, 9 Nov 2016 07:46:38 +0100 Subject: [PATCH 4/4] Reduce cooldown to 0.5 seconds --- code/__DEFINES/misc.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/__DEFINES/misc.dm b/code/__DEFINES/misc.dm index 6b9f2b4a9a1..dcb4501ce6e 100644 --- a/code/__DEFINES/misc.dm +++ b/code/__DEFINES/misc.dm @@ -289,4 +289,4 @@ #define SHELTER_DEPLOY_ANCHORED_OBJECTS "anchored objects" // The cooldown on OOC messages such as OOC, LOOC, praying and adminhelps -#define OOC_COOLDOWN 10 +#define OOC_COOLDOWN 5