Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIRROR] [MIRROR] Changes bitrunning hacker alias sanitization [MDB IGNORE] #798

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions code/__HELPERS/text.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions code/modules/client/preferences/names.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -174,3 +179,31 @@
return TRUE

return FALSE
<<<<<<< HEAD

Check failure on line 182 in code/modules/client/preferences/names.dm

View workflow job for this annotation

GitHub Actions / Run Linters

got '<<', expected one of: newline, '/', identifier
=======


/// 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)
Loading