From 297ac38ecad4b3538a4c3792a08c42075b301196 Mon Sep 17 00:00:00 2001 From: Arokha Sieyes Date: Wed, 16 May 2018 17:57:26 -0400 Subject: [PATCH] Message send failure reflection When a post is too long to send, reflect it back to the user in the chatbox so they can copypaste it into separate messages. Also increases the message limit from 1024 to 2048. If a message is longer than 5-messages worth, it is not reflected and a warning is sent instead to avoid easily consuming bandwidth for DDOS purposes with long messages. I'd like to add markers in the message where the posts would have been truncated but that's... complicated. --- code/__defines/misc.dm | 2 +- code/modules/mob/emote.dm | 4 +-- code/modules/mob/living/carbon/human/say.dm | 2 +- code/modules/mob/say.dm | 4 +-- code/modules/mob/say_vr.dm | 32 +++++++++++++++++++-- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/code/__defines/misc.dm b/code/__defines/misc.dm index 79848c748a..eea0e7deda 100644 --- a/code/__defines/misc.dm +++ b/code/__defines/misc.dm @@ -104,7 +104,7 @@ #define WAIT_FINISH 4 // Setting this much higher than 1024 could allow spammers to DOS the server easily. -#define MAX_MESSAGE_LEN 1024 +#define MAX_MESSAGE_LEN 2048 //VOREStation Edit - I'm not sure about "easily". It can be a little longer. #define MAX_PAPER_MESSAGE_LEN 6144 #define MAX_BOOK_MESSAGE_LEN 24576 #define MAX_RECORD_LENGTH 24576 diff --git a/code/modules/mob/emote.dm b/code/modules/mob/emote.dm index f1ccde0a17..0ecdb2fc20 100644 --- a/code/modules/mob/emote.dm +++ b/code/modules/mob/emote.dm @@ -11,7 +11,7 @@ var/input if(!message) - input = sanitize(input(src,"Choose an emote to display.") as text|null) + input = sanitize_or_reflect(input(src,"Choose an emote to display.") as text|null, src) //VOREStation Edit - Reflect too long messages, within reason else input = message if(input) @@ -70,7 +70,7 @@ var/input if(!message) - input = sanitize(input(src, "Choose an emote to display.") as text|null) + input = sanitize_or_reflect(input(src, "Choose an emote to display.") as text|null, src) //VOREStation Edit - Reflect too long messages, within reason else input = message diff --git a/code/modules/mob/living/carbon/human/say.dm b/code/modules/mob/living/carbon/human/say.dm index a0276a15ac..d42c26880b 100644 --- a/code/modules/mob/living/carbon/human/say.dm +++ b/code/modules/mob/living/carbon/human/say.dm @@ -3,7 +3,7 @@ if(name != GetVoice()) alt_name = "(as [get_id_name("Unknown")])" - message = sanitize(message) + message = sanitize_or_reflect(message,src) //VOREStation Edit - Reflect too-long messages, within reason ..(message, alt_name = alt_name, whispering = whispering) /mob/living/carbon/human/proc/forcesay(list/append) diff --git a/code/modules/mob/say.dm b/code/modules/mob/say.dm index 206450c909..0b20c6cb7f 100644 --- a/code/modules/mob/say.dm +++ b/code/modules/mob/say.dm @@ -21,8 +21,8 @@ if(say_disabled) //This is here to try to identify lag problems usr << "Speech is currently admin-disabled." return - - message = sanitize(message) + + message = sanitize_or_reflect(message,src) //VOREStation Edit - Reflect too-long messages (within reason) set_typing_indicator(FALSE) if(use_me) diff --git a/code/modules/mob/say_vr.dm b/code/modules/mob/say_vr.dm index 0608b26cce..fbf9a9febb 100644 --- a/code/modules/mob/say_vr.dm +++ b/code/modules/mob/say_vr.dm @@ -11,7 +11,7 @@ usr << "Speech is currently admin-disabled." return - message = sanitize(message) + message = sanitize_or_reflect(message,src) //VOREStation Edit - Reflect too-long messages (within reason) if(!message) return @@ -31,7 +31,7 @@ var/input if(!message) - input = sanitize(input(src,"Choose an emote to display.") as text|null) + input = sanitize_or_reflect(input(src,"Choose an emote to display.") as text|null, src) else input = message @@ -61,3 +61,31 @@ /mob/proc/emote_vr(var/act, var/type, var/message) //This would normally go in say.dm if(act == "me") return custom_emote_vr(type, message) + +#define MAX_HUGE_MESSAGE_LEN 8192 +#define POST_DELIMITER_STR "\<\>" +/proc/sanitize_or_reflect(message,user) + //Way too long to send + if(length(message) > MAX_HUGE_MESSAGE_LEN) + fail_to_chat(user) + return + + message = sanitize(message, max_length = MAX_HUGE_MESSAGE_LEN) + + //Came back still too long to send + if(length(message) > MAX_MESSAGE_LEN) + fail_to_chat(user,message) + return null + else + return message + +/proc/fail_to_chat(user,message) + if(!message) + to_chat(user,"Your message was NOT SENT, either because it was FAR too long, or sanitized to nothing at all.") + return + + var/length = length(message) + var/posts = Ceiling(length/MAX_MESSAGE_LEN) + to_chat(user,message) + to_chat(user,"^ This message was NOT SENT ^ -- It was [length] characters, and the limit is [MAX_MESSAGE_LEN]. It would fit in [posts] separate messages.") +#undef MAX_HUGE_MESSAGE_LEN