From 0fa87b7bbd7ff291abdda0a508cb85ecf5ba40c9 Mon Sep 17 00:00:00 2001 From: Kyle Spier-Swenson Date: Sun, 28 Jul 2019 14:09:33 -0700 Subject: [PATCH] [s]Throttle mind notes (memories) (#45555) * Throttle mind notes (memories) Some dipshit is spamming this on ss13 servers Limits to 100 times the message limit (removing old text after that), and one call every 5 game seconds. * Throttle at the right place * Not here * We really need a generic throttler solution --- code/datums/mind.dm | 3 +++ code/modules/mob/mob.dm | 10 ++++++---- code/modules/mob/mob_defines.dm | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/code/datums/mind.dm b/code/datums/mind.dm index da01e6136d1..2a492dfefc6 100644 --- a/code/datums/mind.dm +++ b/code/datums/mind.dm @@ -129,6 +129,9 @@ last_death = world.time /datum/mind/proc/store_memory(new_text) + var/newlength = length(memory) + length(new_text) + if (newlength > MAX_MESSAGE_LEN * 100) + memory = copytext(memory, -newlength-MAX_MESSAGE_LEN * 100) memory += "[new_text]
" /datum/mind/proc/wipe_memory() diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index ff49b57448d..5d643851d87 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -536,11 +536,13 @@ /mob/verb/add_memory(msg as message) set name = "Add Note" set category = "IC" - - msg = copytext(msg, 1, MAX_MESSAGE_LEN) - msg = sanitize(msg) - if(mind) + if (world.time < memory_throttle_time) + return + memory_throttle_time = world.time + 5 SECONDS + msg = copytext(msg, 1, MAX_MESSAGE_LEN) + msg = sanitize(msg) + mind.store_memory(msg) else to_chat(src, "You don't have a mind datum for some reason, so you can't add a note to it.") diff --git a/code/modules/mob/mob_defines.dm b/code/modules/mob/mob_defines.dm index 5d96ba1321f..fa7b062f068 100644 --- a/code/modules/mob/mob_defines.dm +++ b/code/modules/mob/mob_defines.dm @@ -199,3 +199,5 @@ ///THe z level this mob is currently registered in var/registered_z = null + + var/memory_throttle_time = 0