[MIRROR] Changes bitrunning hacker alias sanitization (#28611)

* Changes bitrunning hacker alias sanitization (#84518)

## About The Pull Request
Bitrunning hacker names now permit most characters while staying within
the IC filter and length requirements. Made some helper procs to keep it
organized
## Why It's Good For The Game
You can now name yourself things like An1me_Sn1p3r
## Changelog
🆑
fix: Bitrunning hacker aliases are now much more permissive
/🆑

* Changes bitrunning hacker alias sanitization

---------

Co-authored-by: Jeremiah <42397676+jlsnow301@users.noreply.github.com>
This commit is contained in:
SkyratBot
2024-07-04 21:48:24 +05:30
committed by GitHub
co-authored by Jeremiah
parent 66e322715d
commit 8e7c3c92f0
2 changed files with 53 additions and 7 deletions
+34 -6
View File
@@ -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)
+19 -1
View File
@@ -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"
@@ -181,8 +186,21 @@
explanation = "Hacker alias"
group = "bitrunning"
savefile_key = "hacker_alias"
allow_numbers = TRUE
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)