From fbdfde900c0517f1f7a19570286aff76e95fd32b Mon Sep 17 00:00:00 2001 From: Timberpoes Date: Mon, 28 Jun 2021 14:11:33 +0100 Subject: [PATCH] The to_chat proc no longer accepts null or empty strings and runtimes instead. (#59843) * Catch null text sent to to_chat * Brain traumas no longer send empty to_chat gain strings * Make to_chat_immediate changes and clean up args list formatting * Fix empty to_chat message where there is no memo for admins * Fix additional edge case where there are no messages for the ckey. --- code/datums/brain_damage/brain_trauma.dm | 3 +- code/modules/client/client_procs.dm | 8 +++- code/modules/tgchat/to_chat.dm | 57 ++++++++++++++++-------- 3 files changed, 47 insertions(+), 21 deletions(-) diff --git a/code/datums/brain_damage/brain_trauma.dm b/code/datums/brain_damage/brain_trauma.dm index 96db96f1f9e..0cafd103955 100644 --- a/code/datums/brain_damage/brain_trauma.dm +++ b/code/datums/brain_damage/brain_trauma.dm @@ -34,7 +34,8 @@ //Called when given to a mob /datum/brain_trauma/proc/on_gain() - to_chat(owner, gain_text) + if(gain_text) + to_chat(owner, gain_text) RegisterSignal(owner, COMSIG_MOB_SAY, .proc/handle_speech) RegisterSignal(owner, COMSIG_MOVABLE_HEAR, .proc/handle_hearing) diff --git a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm index 7e84a9b3226..40d25049c18 100644 --- a/code/modules/client/client_procs.dm +++ b/code/modules/client/client_procs.dm @@ -378,7 +378,9 @@ GLOBAL_LIST_INIT(blacklisted_builds, list( if(holder) add_admin_verbs() - to_chat(src, get_message_output("memo")) + var/memo_message = get_message_output("memo") + if(memo_message) + to_chat(src, memo_message) adminGreet() if (mob && reconnecting) var/stealth_admin = mob.client?.holder?.fakekey @@ -426,7 +428,9 @@ GLOBAL_LIST_INIT(blacklisted_builds, list( if(CONFIG_GET(flag/autoconvert_notes)) convert_notes_sql(ckey) - to_chat(src, get_message_output("message", ckey)) + var/user_messages = get_message_output("message", ckey) + if(user_messages) + to_chat(src, user_messages) if(!winexists(src, "asset_cache_browser")) // The client is using a custom skin, tell them. to_chat(src, span_warning("Unable to access asset cache browser, if you are using a custom skin file, please allow DS to download the updated version, if you are not, then make a bug report. This is not a critical issue but can cause issues with resource downloading, as it is impossible to know when extra resources arrived to you.")) diff --git a/code/modules/tgchat/to_chat.dm b/code/modules/tgchat/to_chat.dm index 3030ec7fe91..9f7b30af953 100644 --- a/code/modules/tgchat/to_chat.dm +++ b/code/modules/tgchat/to_chat.dm @@ -7,18 +7,28 @@ * Circumvents the message queue and sends the message * to the recipient (target) as soon as possible. */ -/proc/to_chat_immediate(target, html, - type = null, - text = null, - avoid_highlighting = FALSE, - // FIXME: These flags are now pointless and have no effect - handle_whitespace = TRUE, - trailing_newline = TRUE, - confidential = FALSE) - if(!target || (!html && !text)) +/proc/to_chat_immediate( + target, + html, + type = null, + text = null, + avoid_highlighting = FALSE, + // FIXME: These flags are now pointless and have no effect + handle_whitespace = TRUE, + trailing_newline = TRUE, + confidential = FALSE +) + // Useful where the integer 0 is the entire message. Use case is enabling to_chat(target, some_boolean) while preventing to_chat(target, "") + html = "[html]" + text = "[text]" + + if(!target) return + if(!html && !text) + CRASH("Empty or null string in to_chat proc call.") if(target == world) target = GLOB.clients + // Build a message var/message = list() if(type) message["type"] = type @@ -53,21 +63,32 @@ * html = "You have found [object]") * ``` */ -/proc/to_chat(target, html, - type = null, - text = null, - avoid_highlighting = FALSE, - // FIXME: These flags are now pointless and have no effect - handle_whitespace = TRUE, - trailing_newline = TRUE, - confidential = FALSE) +/proc/to_chat( + target, + html, + type = null, + text = null, + avoid_highlighting = FALSE, + // FIXME: These flags are now pointless and have no effect + handle_whitespace = TRUE, + trailing_newline = TRUE, + confidential = FALSE +) if(Master.current_runlevel == RUNLEVEL_INIT || !SSchat?.initialized) to_chat_immediate(target, html, type, text) return - if(!target || (!html && !text)) + + // Useful where the integer 0 is the entire message. Use case is enabling to_chat(target, some_boolean) while preventing to_chat(target, "") + html = "[html]" + text = "[text]" + + if(!target) return + if(!html && !text) + CRASH("Empty or null string in to_chat proc call.") if(target == world) target = GLOB.clients + // Build a message var/message = list() if(type) message["type"] = type