Skip to content

Commit

Permalink
Fixing the chat client (tgstation#60920)
Browse files Browse the repository at this point in the history
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 tgstation#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.
  • Loading branch information
twilightwanderer committed Sep 28, 2021
1 parent 3b275f8 commit ff41f8a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
24 changes: 24 additions & 0 deletions code/__HELPERS/text.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#define USERNAME_SIZE 32
#define CHANNELNAME_SIZE 12
#define MESSAGE_SIZE 2048

/datum/computer_file/program/chatclient
filename = "ntnrc_client"
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -267,3 +270,7 @@
data["messages"] = list()

return data

#undef USERNAME_SIZE
#undef CHANNELNAME_SIZE
#undef MESSAGE_SIZE

0 comments on commit ff41f8a

Please sign in to comment.