diff --git a/code/defines/procs/helpers.dm b/code/defines/procs/helpers.dm index e391f00ff67..1a7bb48cc21 100644 --- a/code/defines/procs/helpers.dm +++ b/code/defines/procs/helpers.dm @@ -128,18 +128,64 @@ return t //For sanitizing user inputs -/proc/reject_bad_text(var/text) - if(length(text) > 512) return //message too long +/proc/reject_bad_text(var/text, var/max_length=512) + if(length(text) > max_length) return //message too long var/non_whitespace = 0 for(var/i=1, i<=length(text), i++) switch(text2ascii(text,i)) if(62,60,92,47) return //rejects the text if it contains these bad characters: <, >, \ or / if(127 to 255) return //rejects weird letters like � if(0 to 31) return //more weird stuff - if(32) //whitespace + if(32) continue //whitespace else non_whitespace = 1 if(non_whitespace) return text //only accepts the text if it has some non-spaces +//proc for processing names to make it harder for people to use names to metagame. Much stricter than the above. +//Allows only characters (A...Z,a...z), spaces and apostrophes. +//There is a flag to allow numbers +//removes doublespaces and double apostrophes +//lowercases everything and capitalises the first letter of each word (or characters following an apostrophe) +//prevents names which are too short, have too many space, or not enough normal letters +/proc/reject_bad_name(var/t_in, var/allow_numbers=0, var/max_length=MAX_NAME_LEN) + if(length(t_in) > max_length) return //name too long + var/number_of_alphanumeric = 0 + var/number_of_spaces = 0 + var/last_char_group = 0 + var/t_out = "" + for(var/i=1, i<=length(t_in), i++) + var/ascii_char = text2ascii(t_in,i) + switch(ascii_char) + if(65 to 90) //Uppercase letters allowed + switch(last_char_group) + if(3,4,0) t_out += ascii2text(ascii_char) + else t_out += ascii2text(ascii_char+32) //lowercase if not preceeded by space or ' + last_char_group = 1 + number_of_alphanumeric++ + if(97 to 122) //Lowercase letters allowed + switch(last_char_group) + if(3,4,0) t_out += ascii2text(ascii_char-32) //uppercase if preceeded by space or ' + else t_out += ascii2text(ascii_char) + last_char_group = 2 + number_of_alphanumeric++ + if(32) //Space + if(i==1) continue + if(last_char_group!=3) t_out += ascii2text(ascii_char) //so we don't get double-spaces + last_char_group = 3 + number_of_spaces++ + if(39,45,46) //Apostrophe for dem Oirish names like "O'Neil", dashes for double-barreled names and periods for "James T. Kirk" and AI's + if(i==1) continue + if(last_char_group!=4) t_out += ascii2text(ascii_char) //so we don't get double apostrophes or whatever + last_char_group = 4 + if(48 to 57) + if(allow_numbers) + t_out += ascii2text(ascii_char) //Allow numbers (i.e. for borgs andd AIs) + number_of_alphanumeric++ + else + return + if(number_of_alphanumeric < 4) return //protects against tiny names like "A" and also names like "' ' ' ' ' ' ' '" + if(number_of_spaces > 4 || number_of_spaces < 1) return //protects against single-word names like "Unknown" and names like "I ' M A D E R P Spaces Lul" + return t_out + /proc/strip_html_simple(var/t,var/limit=MAX_MESSAGE_LEN) var/list/strip_chars = list("<",">") t = copytext(t,1,limit) diff --git a/code/modules/mob/new_player/preferences.dm b/code/modules/mob/new_player/preferences.dm index 074eefef44b..04abe6e2308 100644 --- a/code/modules/mob/new_player/preferences.dm +++ b/code/modules/mob/new_player/preferences.dm @@ -439,42 +439,30 @@ datum/preferences return 1 + if(link_tags["real_name"]) var/new_name switch(link_tags["real_name"]) if("input") - new_name = copytext( (input(user, "Please select a name:", "Character Generation") as text) ,1,MAX_NAME_LEN) - var/list/bad_characters = list("_", "\"", "<", ">", ";", "\[", "\]", "{", "}", "|", "\\","0","1","2","3","4","5","6","7","8","9") - for(var/c in bad_characters) - new_name = dd_replacetext(new_name, c, "") - - if(!new_name || (new_name == "Unknown") || (new_name == "floor") || (new_name == "wall") || (new_name == "r-wall")) - alert("Invalid name. Don't do that!") - return - - //Carn: To fix BYOND text-parsing errors caused by people using dumb capitalisation in their names. - var/tempname - for(var/N in dd_text2list(new_name, " ")) - if(N && tempname) //if both aren't null strings - tempname += " " - tempname += capitalize(lowertext(N)) - new_name = tempname + new_name = reject_bad_name( input(user, "Please select a name:", "Character Generation") as text|null ) if("random") randomize_name() if(new_name) real_name = new_name + else + user << "Invalid name. Your name should be at least ten letters and two words. It should be under [MAX_NAME_LEN] characters long. It may only contain the characters A-Z, a-z, -, ' and ." if(link_tags["age"]) switch(link_tags["age"]) if("input") - var/new_age = input(user, "Please select type in age: 15-45", "Character Generation") as num + var/new_age = input(user, "Please select type in age: 17-45", "Character Generation") as num if(new_age) - age = max(min(round(text2num(new_age)), 45), 15) + age = max(min(round(text2num(new_age)), 45), 17) if("random") - age = rand (20, 45) + age = rand (17, 45) if(link_tags["OOC"]) var/tempnote = ""