Files
Aurora.3/code/modules/client/preference_setup/general/05_background.dm
skull132 a3ec0cf45d Better SQL prepared statements (#2474)
The system used to be of complexity O(n^2). Essentially two for loops running per every argument. Which ended up being surprisingly slow (there were instances where I saw the argument parser as using quite a lot of CPU time).

This replaces it with a more linear algorithm. It's somewhere near O(n) where n is the length of the unparsed query. Which is more stable and faaaster. This comes with two changes, however:

Parameters inside the query now have to be delimited from both sides with : (colons). The alternative to this would be to use something like $n or just assume that space marks the end of a marker. Only the former is workable, the latter would break a few queries already.
Arguments in the argument array no longer have to be prefixed by : (colons). So, while in the query you would write :thing:, you'd initialize the array of args as: list("thing" = somevar). It could be made to work without it, but eh, I think this is fine.
Argument validation is slightly weaker. What I mean by this is that with the old system, unused keys would result in an error. This is no longer a thing. Missing keys will still result in an error, however.
One more improvement: double delimiting removes an edge case where if key A partially covers key B, depending on the order, key A would mangle key B.
Updated and tested all queries that I could find. So this should be good.
2017-05-29 21:17:41 +03:00

160 lines
7.6 KiB
Plaintext

/datum/category_item/player_setup_item/general/background
name = "Background"
sort_order = 5
/datum/category_item/player_setup_item/general/background/load_character(var/savefile/S)
S["med_record"] >> pref.med_record
S["sec_record"] >> pref.sec_record
S["gen_record"] >> pref.gen_record
S["home_system"] >> pref.home_system
S["citizenship"] >> pref.citizenship
S["faction"] >> pref.faction
S["religion"] >> pref.religion
S["nanotrasen_relation"] >> pref.nanotrasen_relation
/datum/category_item/player_setup_item/general/background/save_character(var/savefile/S)
S["med_record"] << pref.med_record
S["sec_record"] << pref.sec_record
S["gen_record"] << pref.gen_record
S["home_system"] << pref.home_system
S["citizenship"] << pref.citizenship
S["faction"] << pref.faction
S["religion"] << pref.religion
S["nanotrasen_relation"] << pref.nanotrasen_relation
/datum/category_item/player_setup_item/general/background/gather_load_query()
return list("ss13_characters_flavour" = list("vars" = list("records_employment" = "gen_record",
"records_medical" = "med_record",
"records_security" = "sec_record",
"records_ccia" = "ccia_record"),
"args" = list("char_id")),
"ss13_characters" = list("vars" = list("home_system", "citizenship", "faction", "religion"), "args" = list("id")))
/datum/category_item/player_setup_item/general/background/gather_load_parameters()
return list("id" = pref.current_character, "char_id" = pref.current_character)
/datum/category_item/player_setup_item/general/background/gather_save_query()
return list("ss13_characters_flavour" = list("records_employment",
"records_medical",
"records_security",
"char_id" = 1),
"ss13_characters" = list("home_system", "citizenship", "faction", "religion", "id" = 1, "ckey" = 1))
/datum/category_item/player_setup_item/general/background/gather_save_parameters()
return list("records_employment" = pref.gen_record,
"records_medical" = pref.med_record,
"records_security" = pref.sec_record,
"char_id" = pref.current_character,
"home_system" = pref.home_system,
"citizenship" = pref.citizenship,
"faction" = pref.faction,
"religion" = pref.religion,
"id" = pref.current_character,
"ckey" = pref.client.ckey)
/datum/category_item/player_setup_item/general/background/sanitize_character()
if(!pref.home_system)
pref.home_system = "Unset"
if(!pref.citizenship)
pref.citizenship = "None"
if(!pref.faction)
pref.faction = "None"
if(!pref.religion)
pref.religion = "None"
pref.nanotrasen_relation = sanitize_inlist(pref.nanotrasen_relation, COMPANY_ALIGNMENTS, initial(pref.nanotrasen_relation))
/datum/category_item/player_setup_item/general/background/content(var/mob/user)
. += "<b>Background Information</b><br>"
. += "[company_name] Relation: <a href='?src=\ref[src];nt_relation=1'>[pref.nanotrasen_relation]</a><br/>"
. += "Home System: <a href='?src=\ref[src];home_system=1'>[pref.home_system]</a><br/>"
. += "Citizenship: <a href='?src=\ref[src];citizenship=1'>[pref.citizenship]</a><br/>"
. += "Faction: <a href='?src=\ref[src];faction=1'>[pref.faction]</a><br/>"
. += "Religion: <a href='?src=\ref[src];religion=1'>[pref.religion]</a><br/>"
. += "<br/><b>Records</b>:<br/>"
if(jobban_isbanned(user, "Records"))
. += "<span class='danger'>You are banned from using character records.</span><br>"
else
. += "Medical Records:<br>"
. += "<a href='?src=\ref[src];set_medical_records=1'>[TextPreview(pref.med_record,40)]</a><br><br>"
. += "Employment Records:<br>"
. += "<a href='?src=\ref[src];set_general_records=1'>[TextPreview(pref.gen_record,40)]</a><br><br>"
. += "Security Records:<br>"
. += "<a href='?src=\ref[src];set_security_records=1'>[TextPreview(pref.sec_record,40)]</a><br>"
/datum/category_item/player_setup_item/general/background/OnTopic(var/href,var/list/href_list, var/mob/user)
if(href_list["nt_relation"])
var/new_relation = input(user, "Choose your relation to NT. Note that this represents what others can find out about your character by researching your background, not what your character actually thinks.", "Character Preference", pref.nanotrasen_relation) as null|anything in COMPANY_ALIGNMENTS
if(new_relation && CanUseTopic(user))
pref.nanotrasen_relation = new_relation
return TOPIC_REFRESH
else if(href_list["home_system"])
var/choice = input(user, "Please choose a home system.", "Character Preference", pref.home_system) as null|anything in home_system_choices + list("Unset","Other")
if(!choice || !CanUseTopic(user))
return TOPIC_NOACTION
if(choice == "Other")
var/raw_choice = sanitize(input(user, "Please enter a home system.", "Character Preference") as text|null, MAX_NAME_LEN)
if(raw_choice && CanUseTopic(user))
pref.home_system = raw_choice
else
pref.home_system = choice
return TOPIC_REFRESH
else if(href_list["citizenship"])
var/choice = input(user, "Please choose your current citizenship.", "Character Preference", pref.citizenship) as null|anything in citizenship_choices + list("None","Other")
if(!choice || !CanUseTopic(user))
return TOPIC_NOACTION
if(choice == "Other")
var/raw_choice = sanitize(input(user, "Please enter your current citizenship.", "Character Preference") as text|null, MAX_NAME_LEN)
if(raw_choice && CanUseTopic(user))
pref.citizenship = raw_choice
else
pref.citizenship = choice
return TOPIC_REFRESH
else if(href_list["faction"])
var/choice = input(user, "Please choose a faction to work for.", "Character Preference", pref.faction) as null|anything in faction_choices + list("None","Other")
if(!choice || !CanUseTopic(user))
return TOPIC_NOACTION
if(choice == "Other")
var/raw_choice = sanitize(input(user, "Please enter a faction.", "Character Preference") as text|null, MAX_NAME_LEN)
if(raw_choice)
pref.faction = raw_choice
else
pref.faction = choice
return TOPIC_REFRESH
else if(href_list["religion"])
var/choice = input(user, "Please choose a religion.", "Character Preference", pref.religion) as null|anything in religion_choices + list("None","Other")
if(!choice || !CanUseTopic(user))
return TOPIC_NOACTION
if(choice == "Other")
var/raw_choice = sanitize(input(user, "Please enter a religon.", "Character Preference") as text|null, MAX_NAME_LEN)
if(raw_choice)
pref.religion = sanitize(raw_choice)
else
pref.religion = choice
return TOPIC_REFRESH
else if(href_list["set_medical_records"])
var/new_medical = sanitize(input(user,"Enter medical information here.","Character Preference", html_decode(pref.med_record)) as message|null, MAX_PAPER_MESSAGE_LEN, extra = 0)
if(!isnull(new_medical) && !jobban_isbanned(user, "Records") && CanUseTopic(user))
pref.med_record = new_medical
return TOPIC_REFRESH
else if(href_list["set_general_records"])
var/new_general = sanitize(input(user,"Enter employment information here.","Character Preference", html_decode(pref.gen_record)) as message|null, MAX_PAPER_MESSAGE_LEN, extra = 0)
if(!isnull(new_general) && !jobban_isbanned(user, "Records") && CanUseTopic(user))
pref.gen_record = new_general
return TOPIC_REFRESH
else if(href_list["set_security_records"])
var/sec_medical = sanitize(input(user,"Enter security information here.","Character Preference", html_decode(pref.sec_record)) as message|null, MAX_PAPER_MESSAGE_LEN, extra = 0)
if(!isnull(sec_medical) && !jobban_isbanned(user, "Records") && CanUseTopic(user))
pref.sec_record = sec_medical
return TOPIC_REFRESH
return ..()