From ff41f8a661fb2ecd7514bfa9ff4040ca68ae7f93 Mon Sep 17 00:00:00 2001 From: twilightwanderer <88540658+twilightwanderer@users.noreply.github.com> Date: Tue, 28 Sep 2021 10:01:07 +0300 Subject: [PATCH] Fixing the chat client (#60920) Corrects the chat restriction on using ASII characters only. (This PR was created for Skyrat-TG, but the collaborator of that repository asked me to adapt this PR for tgstation.) This will fix #54598 In the original code, the chat client uses only ASII standard characters, which is very limited in its capabilities. For example, does not allow you to use specialized characters, which would have taken the atmosphere of the old messengers, as well as regional characters. The lack of regional characters complicates the game for non-English-speaking servers. For example, the Russian-speaking player community Space Station 13 The Fluffy Frontier uses the original Skyrat-tg build. And the players of this community almost do not use the chat client to communicate due to the fact that they can not use Cyrillic characters. --- code/__HELPERS/text.dm | 24 +++++++++++++++++++ .../file_system/programs/ntnrc_client.dm | 15 ++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm index ba465c32c1c..9c5eb58ebb0 100644 --- a/code/__HELPERS/text.dm +++ b/code/__HELPERS/text.dm @@ -989,3 +989,27 @@ GLOBAL_LIST_INIT(binary, list("0","1")) return word + "ay" //otherwise unmutated return word + +/** + * The procedure to check the text of the entered text on ntnrc_client.dm + * + * This procedure is designed to check the text you type into the chat client. + * It checks for invalid characters and the size of the entered text. + */ +/proc/reject_bad_chattext(text, max_length = 256) + var/non_whitespace = FALSE + var/char = "" + if (length(text) > max_length) + return + else + for(var/i = 1, i <= length(text), i += length(char)) + char = text[i] + switch(text2ascii(char)) + if(0 to 31) + return + if(32) + continue + else + non_whitespace = TRUE + if (non_whitespace) + return text diff --git a/code/modules/modular_computers/file_system/programs/ntnrc_client.dm b/code/modules/modular_computers/file_system/programs/ntnrc_client.dm index 29a4418d2ca..bd4c34bd341 100644 --- a/code/modules/modular_computers/file_system/programs/ntnrc_client.dm +++ b/code/modules/modular_computers/file_system/programs/ntnrc_client.dm @@ -1,3 +1,6 @@ +#define USERNAME_SIZE 32 +#define CHANNELNAME_SIZE 12 +#define MESSAGE_SIZE 2048 /datum/computer_file/program/chatclient filename = "ntnrc_client" @@ -44,7 +47,7 @@ if("PRG_speak") if(!channel || isnull(active_channel)) return - var/message = reject_bad_text(params["message"]) + var/message = reject_bad_chattext(params["message"], MESSAGE_SIZE) if(!message) return if(channel.password && (!(src in channel.active_clients) && !(src in channel.offline_clients))) @@ -76,7 +79,7 @@ active_channel = null return TRUE if("PRG_newchannel") - var/channel_title = reject_bad_text(params["new_channel_name"]) + var/channel_title = reject_bad_chattext(params["new_channel_name"], CHANNELNAME_SIZE) if(!channel_title) return var/datum/ntnet_conversation/C = new /datum/ntnet_conversation() @@ -99,7 +102,7 @@ netadmin_mode = TRUE return TRUE if("PRG_changename") - var/newname = sanitize(params["new_name"]) + var/newname = reject_bad_chattext(params["new_name"], USERNAME_SIZE) newname = replacetext(newname, " ", "_") if(!newname || newname == username) return @@ -135,7 +138,7 @@ if("PRG_renamechannel") if(!authed) return - var/newname = reject_bad_text(params["new_name"]) + var/newname = reject_bad_chattext(params["new_name"], CHANNELNAME_SIZE) if(!newname || !channel) return channel.add_status_message("Channel renamed from [channel.title] to [newname] by operator.") @@ -267,3 +270,7 @@ data["messages"] = list() return data + +#undef USERNAME_SIZE +#undef CHANNELNAME_SIZE +#undef MESSAGE_SIZE