From bdfa8af9f359b8716d2159419ebe663e1ca4fe2f Mon Sep 17 00:00:00 2001 From: NovaBot <154629622+NovaBot13@users.noreply.github.com> Date: Thu, 4 Jul 2024 03:57:33 -0400 Subject: [PATCH] [MIRROR] Changes bitrunning hacker alias sanitization [MDB IGNORE] --- code/__HELPERS/text.dm | 40 ++++++++++++++++++++---- code/modules/client/preferences/names.dm | 33 +++++++++++++++++++ 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/code/__HELPERS/text.dm b/code/__HELPERS/text.dm index bef9657b9e6..5102a592e20 100644 --- a/code/__HELPERS/text.dm +++ b/code/__HELPERS/text.dm @@ -241,12 +241,7 @@ if(last_char_group == SPACES_DETECTED) t_out = copytext_char(t_out, 1, -1) //removes the last character (in this case a space) - for(var/bad_name in list("space","floor","wall","r-wall","monkey","unknown","inactive ai")) //prevents these common metagamey names - if(cmptext(t_out,bad_name)) - return //(not case sensitive) - - // Protects against names containing IC chat prohibited words. - if(is_ic_filtered(t_out) || is_soft_ic_filtered(t_out)) + if(!filter_name_ic(t_out)) return return t_out @@ -257,6 +252,39 @@ #undef LETTERS_DETECTED +/// Much more permissive version of reject_bad_name(). +/// Returns a trimmed string or null if the name is invalid. +/// Allows most characters except for IC chat prohibited words. +/proc/permissive_sanitize_name(value) + if(!istext(value)) // Not a string + return + + var/name_length = length(value) + if(name_length < 3) // Too short + return + + if(name_length > 3 * MAX_NAME_LEN) // Bad input + return + + var/trimmed = trim(value, MAX_NAME_LEN) + if(!filter_name_ic(trimmed)) // Contains IC chat prohibited words + return + + return trim_reduced(trimmed) + + +/// Helper proc to check if a name is valid for the IC filter +/proc/filter_name_ic(name) + for(var/bad_name in list("space", "floor", "wall", "r-wall", "monkey", "unknown", "inactive ai")) //prevents these common metagamey names + if(cmptext(name, bad_name)) + return FALSE //(not case sensitive) + + // Protects against names containing IC chat prohibited words. + if(is_ic_filtered(name) || is_soft_ic_filtered(name)) + return FALSE + + return TRUE + //html_encode helper proc that returns the smallest non null of two numbers //or 0 if they're both null (needed because of findtext returning 0 when a value is not present) diff --git a/code/modules/client/preferences/names.dm b/code/modules/client/preferences/names.dm index 5f8f80df620..0963a1d55bf 100644 --- a/code/modules/client/preferences/names.dm +++ b/code/modules/client/preferences/names.dm @@ -17,21 +17,26 @@ /// If the highest priority job matches this, will prioritize this name in the UI var/relevant_job + /datum/preference/name/apply_to_human(mob/living/carbon/human/target, value) // Only real_name applies directly, everything else is applied by something else return + /datum/preference/name/deserialize(input, datum/preferences/preferences) return reject_bad_name("[input]", allow_numbers) + /datum/preference/name/serialize(input) // `is_valid` should always be run before `serialize`, so it should not // be possible for this to return `null`. return reject_bad_name(input, allow_numbers) + /datum/preference/name/is_valid(value) return istext(value) && !isnull(reject_bad_name(value, allow_numbers)) + /// A character's real name /datum/preference/name/real_name explanation = "Name" @@ -174,3 +179,31 @@ return TRUE return FALSE +<<<<<<< HEAD +======= + + +/// The name to use while bitrunning +/datum/preference/name/hacker_alias + explanation = "Hacker alias" + group = "bitrunning" + savefile_key = "hacker_alias" + relevant_job = /datum/job/bitrunner + + +/datum/preference/name/hacker_alias/create_default_value() + return pick(GLOB.hacker_aliases) + + +/datum/preference/name/hacker_alias/is_valid(value) + return !isnull(permissive_sanitize_name(value)) + + +/datum/preference/name/hacker_alias/deserialize(input, datum/preferences/preferences) + return permissive_sanitize_name(input) + + +/datum/preference/name/hacker_alias/serialize(input) + return permissive_sanitize_name(input) + +>>>>>>> 6fa88c49744... [MIRROR] Changes bitrunning hacker alias sanitization [MDB IGNORE] (#3519)