From 9ab0cccdec391240764b6e2fff718ab4eda41bd1 Mon Sep 17 00:00:00 2001 From: Ghommie <42542238+Ghommie@users.noreply.github.com> Date: Fri, 27 Mar 2020 19:52:33 +0100 Subject: [PATCH] porting stuff --- code/modules/client/client_defines.dm | 4 +++ code/modules/client/client_procs.dm | 36 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/code/modules/client/client_defines.dm b/code/modules/client/client_defines.dm index 2bdb743fc7..1deb702de4 100644 --- a/code/modules/client/client_defines.dm +++ b/code/modules/client/client_defines.dm @@ -14,6 +14,10 @@ var/jobbancache = null //Used to cache this client's jobbans to save on DB queries 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. + ///How many messages sent in the last 10 seconds + var/total_message_count = 0 + ///Next tick to reset the total message counter + var/total_count_reset = 0 var/ircreplyamount = 0 ///////// diff --git a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm index 84096b1367..74885d0ac0 100644 --- a/code/modules/client/client_procs.dm +++ b/code/modules/client/client_procs.dm @@ -141,7 +141,43 @@ GLOBAL_LIST_INIT(blacklisted_builds, list( return 0 return 1 +/* + * Call back proc that should be checked in all paths where a client can send messages + * + * Handles checking for duplicate messages and people sending messages too fast + * + * The first checks are if you're sending too fast, this is defined as sending + * SPAM_TRIGGER_AUTOMUTE messages in + * 5 seconds, this will start supressing your messages, + * if you send 2* that limit, you also get muted + * + * The second checks for the same duplicate message too many times and mutes + * you for it + */ /client/proc/handle_spam_prevention(message, mute_type) + + //Increment message count + total_message_count += 1 + + //store the total to act on even after a reset + var/cache = total_message_count + + if(total_count_reset <= world.time) + total_message_count = 0 + total_count_reset = world.time + (5 SECONDS) + + //If they're really going crazy, mute them + if(cache >= SPAM_TRIGGER_AUTOMUTE * 2) + total_message_count = 0 + total_count_reset = 0 + cmd_admin_mute(src, mute_type, 1) + return 1 + + //Otherwise just supress the message + else if(cache >= SPAM_TRIGGER_AUTOMUTE) + return 1 + + if(CONFIG_GET(flag/automute_on) && !holder && last_message == message) src.last_message_count++ if(src.last_message_count >= SPAM_TRIGGER_AUTOMUTE)