From df5761dd3fa7c393b5a0a7a18981ca5a3c58b28c Mon Sep 17 00:00:00 2001 From: Mahzel Date: Thu, 11 Feb 2016 22:52:04 +0100 Subject: [PATCH 1/7] SQL characters pass 1 --- code/modules/client/client_saveSQL.dm | 478 ++++++++++++++++++++++++++ code/modules/client/preferences.dm | 17 +- 2 files changed, 494 insertions(+), 1 deletion(-) create mode 100644 code/modules/client/client_saveSQL.dm diff --git a/code/modules/client/client_saveSQL.dm b/code/modules/client/client_saveSQL.dm new file mode 100644 index 00000000000..3c7b8997a1a --- /dev/null +++ b/code/modules/client/client_saveSQL.dm @@ -0,0 +1,478 @@ +//handles saving to SQL Format +//MAKE SURE YOU KEEP THIS UP TO DATE! +//if the db can't be updated, return 0 +//if the db was updated, return 1 +var/chardata[] +var/jobsdata[] +var/flavourdata[] +var/miscdata[] +var/DBQuery/query +var/TextQuery +var/char_id +var/char_slot +/datum/preferences/proc/SQLsave_character(var/cslot) + char_slot = cslot + for(var/ckey in preferences_datums) + var/datum/preferences/D = preferences_datums[ckey] + log_debug("Ckey is [ckey]") + if(D == src) + establish_db_connection() + if(!dbcon.IsConnected()) + return 0 + else + log_debug("db connected, real name is [real_name]") + if(!getCharId()) + log_debug("New Character") + query = dbcon.NewQuery("INSERT INTO ss13_characters (ckey, slot) VALUES ('[ckey]', '[cslot]')") + query.Execute() + log_debug(dbcon.ErrorMsg()) + getCharId() + InsertCharData() + log_debug(dbcon.ErrorMsg()) + query = dbcon.NewQuery("UPDATE SS13_characters SET Character_key = (SELECT id FROM characters_data WHERE char_id = [char_id]) WHERE id = [char_id] ") + query.Execute() + log_debug(dbcon.ErrorMsg()) + else + log_debug("ID = [char_id]") + log_debug("Update entry") + UpdateCharData() + log_debug("Save query executed") + return 1 + log_debug("No ckey in datums") + return 0 + +/datum/preferences/proc/SQLload_character(slot) + char_slot = slot + if(!getCharId()) + return 0 + log_debug("Loading character ID [char_id] from slot [char_slot]) + return LoadCharData() + +/datum/preferences/proc/InsertCharData() + TextQuery = "INSERT INTO characters_data (age, backbag, b_type, char_id, eyes_B, eyes_G, eyes_R, facial_B, facial_G, facial_R, facial_style, " + TextQuery += "gender, hair_B, hair_G, hair_R, hair_style, isRandom, language, name, OOC,skin_B, skin_G, skin_R, skin_tone, spawnpoint, species, undershirt, underwear) VALUES " + TextQuery += "('[age]', '[backbag]', '[b_type]', '[char_id]', '[b_eyes]', '[g_eyes]', '[r_eyes]', '[b_facial]', '[g_facial]', '[r_facial]', '[f_style]', " + TextQuery += "'[gender]', '[b_hair]', '[g_hair]', '[r_hair]', '[h_style]', '[be_random_name]', '[language]', '[real_name]', " + TextQuery += "'[metadata]', '[b_skin]', '[g_skin]', '[r_skin]', '[s_tone]', '[spawnpoint]', '[species]', '[undershirt]', '[underwear]')" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + return 1 + +/datum/preferences/proc/UpdateCharData() + TextQuery = "UPDATE characters_data SET age = '[age]', backbag='[backbag]', b_type='[b_type]', eyes_B = '[b_eyes]', eyes_G='[g_eyes]', eyes_R='[r_eyes]'," + TextQuery += "facial_B='[b_facial]', facial_G='[g_facial]', facial_R='[r_facial]', facial_style='[f_style]', gender = '[gender]', hair_B='[b_hair]', hair_G='[g_hair]'," + TextQuery += "hair_R='[r_hair]', hair_style='[h_style]', isRandom='[be_random_name]', language='[language]', name='[real_name]', OOC='[metadata]',skin_B='[b_skin]', skin_G='[g_skin]'," + TextQuery += "skin_R='[r_skin]', skin_tone='[s_tone]', spawnpoint='[spawnpoint]', species='[species]', undershirt='[undershirt]', underwear='[underwear]' " + TextQuery += "WHERE char_id = [char_id]" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + return 1 + +/datum/preferences/proc/LoadCharData() + TextQuery = "SELECT age, backbag, b_type, eyes_B, eyes_G, eyes_R, facial_B, facial_G, facial_R, facial_style, gender, " + TextQuery += "hair_B, hair_G, hair_R, hair_style, isRandom, language, name, OOC, skin_B, skin_G, skin_R, skin_tone, spawnpoint, species, undershirt, underwear " + TextQuery += "FROM character_data WHERE char_id = [char_id]" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + if(!query.RowCount()) + return 0 + log_debug("Load query executed successfully") + query.NextRow() + age = query.item[1] + backbag = query.item[2] + b_type = query.item[3] + eyes_B = query.item[4] + eyes_G = query.item[5] + eyes_R = query.item[6] + facial_R = query.item[7] + facial_G = query.item[8] + facial_R = query.item[9] + facial_style = query.item[10] + gender = query.item[11] + hair_B = query.item[12] + hair_G = query.item[13] + hair_R = query.item[14] + hair_style = query.item[15] + isRandom = query.item[16] + language = query.item[17] + name = query.item[18] + OOC = query.item[19] + skin_B = query.item[20] + skin_G = query.item[21] + skin_R = query.item[22] + skin_tone = query.item[23] + spawnpoint = query.item[24] + species = query.item[25] + undershirt = query.item[26] + underwear = query.item[27] + return 1 + +/datum/preferences/proc/getCharId() + TextQuery = "SELECT id FROM ss13_characters WHERE ckey='[ckey]' AND slot = '[char_slot]'" + log_debug(TextQuery) + query = dbcon.NewQuery("SELECT id FROM ss13_characters WHERE ckey='[ckey]' AND slot = '[char_slot]'") + log_debug("Query ready") + query.Execute() + var/rowDebug = query.RowCount() + log_debug("Query executed, [rowDebug] rows") + if(!query.RowCount()) + return null + query.NextRow() + char_id = query.item[1] + log_debug("GetCharId : [char_id]") + return char_id + +/* //Character + chardata.Add(age) + chardata.Add(backbag) + chardata.Add(metadata) + chardata.Add(real_name) + chardata.Add(be_random_name) + chardata.Add(gender) + chardata.Add(species) + chardata.Add(language) + chardata.Add(r_hair) + chardata.Add(g_hair) + chardata.Add(b_hair) + chardata.Add(r_facial) + chardata.Add(g_facial) + chardata.Add(b_facial) + chardata.Add(s_tone) + chardata.Add(r_skin) + chardata.Add(g_skin) + chardata.Add(b_skin) + chardata.Add(h_style) + chardata.Add(f_style) + chardata.Add(r_eyes) + chardata.Add(g_eyes) + chardata.Add(b_eyes) + chardata.Add(underwear) + chardata.Add(undershirt) + chardata.Add(b_type) + chardata.Add(spawnpoint) + + //Jobs + S["alternate_option"] << alternate_option + S["job_civilian_high"] << job_civilian_high + S["job_civilian_med"] << job_civilian_med + S["job_civilian_low"] << job_civilian_low + S["job_medsci_high"] << job_medsci_high + S["job_medsci_med"] << job_medsci_med + S["job_medsci_low"] << job_medsci_low + S["job_engsec_high"] << job_engsec_high + S["job_engsec_med"] << job_engsec_med + S["job_engsec_low"] << job_engsec_low + + //Flavour Text + S["flavor_texts_general"] << flavor_texts["general"] + S["flavor_texts_head"] << flavor_texts["head"] + S["flavor_texts_face"] << flavor_texts["face"] + S["flavor_texts_eyes"] << flavor_texts["eyes"] + S["flavor_texts_torso"] << flavor_texts["torso"] + S["flavor_texts_arms"] << flavor_texts["arms"] + S["flavor_texts_hands"] << flavor_texts["hands"] + S["flavor_texts_legs"] << flavor_texts["legs"] + S["flavor_texts_feet"] << flavor_texts["feet"] + + //Flavour text for robots. + S["flavour_texts_robot_Default"] << flavour_texts_robot["Default"] + for(var/module in robot_module_types) + S["flavour_texts_robot_[module]"] << flavour_texts_robot[module] + + //Miscellaneous + S["med_record"] << med_record + S["sec_record"] << sec_record + S["gen_record"] << gen_record + S["player_alt_titles"] << player_alt_titles + S["be_special"] << be_special + S["disabilities"] << disabilities + S["used_skillpoints"] << used_skillpoints + S["skills"] << skills + S["skill_specialization"] << skill_specialization + S["organ_data"] << organ_data + S["rlimb_data"] << rlimb_data + S["gear"] << gear + S["home_system"] << home_system + S["citizenship"] << citizenship + S["faction"] << faction + S["religion"] << religion + + S["nanotrasen_relation"] << nanotrasen_relation + //S["skin_style"] << skin_style + + S["uplinklocation"] << uplinklocation + S["exploit_record"] << exploit_record + + S["UI_style_color"] << UI_style_color + S["UI_style_alpha"] << UI_style_alpha*/ + + +/*/datum/preferences/proc/SQLSave_Preferences() + //Sanitize + ooccolor = sanitize_hexcolor(ooccolor, initial(ooccolor)) + lastchangelog = sanitize_text(lastchangelog, initial(lastchangelog)) + UI_style = sanitize_inlist(UI_style, list("White", "Midnight","Orange","old"), initial(UI_style)) + be_special = sanitize_integer(be_special, 0, 65535, initial(be_special)) + default_slot = sanitize_integer(default_slot, 1, config.character_slots, initial(default_slot)) + toggles = sanitize_integer(toggles, 0, 65535, initial(toggles)) + UI_style_color = sanitize_hexcolor(UI_style_color, initial(UI_style_color)) + UI_style_alpha = sanitize_integer(UI_style_alpha, 0, 255, initial(UI_style_alpha)) + + query = dbcon.Query("INSERT INTO (oocolor, lastchangelog, UI_style, be_special, default_slot, toggles, UI_style_color, UI_style_alpha) VALUES ([oocolor], [lastchangelog], [UI_style], [be_special], [default_slot], [toggles], [UI_style_color], [UI_style_alpha])") + else + var/id = query.item[2] + query = dbcon.Query("UPDATE aurora_characters SET ooccolor=[ooccolor], lastchangelog=[lastchangelog], UI_style=[UI_style], be_special=[be_special], default_slot=[default_slot], toggles = [toggles], UI_style_color = [UI_style_color], UI_style_alpha = [UI_style_alpha] WHERE aurora_characters.id=[id]") + query.Execute() + return 1 + +/datum/preferences/proc/savefile_update() + if(savefile_version < 8) //lazily delete everything + additional files so they can be saved in the new format + for(var/ckey in preferences_datums) + var/datum/preferences/D = preferences_datums[ckey] + if(D == src) + var/delpath = "data/player_saves/[copytext(ckey,1,2)]/[ckey]/" + if(delpath && fexists(delpath)) + fdel(delpath) + break + return 0 + + if(savefile_version == SAVEFILE_VERSION_MAX) //update successful. + save_preferences() + save_character() + return 1 + return 0 + +/datum/preferences/proc/load_path(ckey,filename="preferences.sav") + if(!ckey) return + path = "data/player_saves/[copytext(ckey,1,2)]/[ckey]/[filename]" + savefile_version = SAVEFILE_VERSION_MAX + +/datum/preferences/proc/load_preferences() + if(!path) return 0 + if(!fexists(path)) return 0 + var/savefile/S = new /savefile(path) + if(!S) return 0 + S.cd = "/" + + S["version"] >> savefile_version + //Conversion + if(!savefile_version || !isnum(savefile_version) || savefile_version < SAVEFILE_VERSION_MIN || savefile_version > SAVEFILE_VERSION_MAX) + if(!savefile_update()) //handles updates + savefile_version = SAVEFILE_VERSION_MAX + save_preferences() + save_character() + return 0 + + //general preferences + S["ooccolor"] >> ooccolor + S["lastchangelog"] >> lastchangelog + S["UI_style"] >> UI_style + S["be_special"] >> be_special + S["default_slot"] >> default_slot + S["toggles"] >> toggles + S["UI_style_color"] >> UI_style_color + S["UI_style_alpha"] >> UI_style_alpha + + //Sanitize + ooccolor = sanitize_hexcolor(ooccolor, initial(ooccolor)) + lastchangelog = sanitize_text(lastchangelog, initial(lastchangelog)) + UI_style = sanitize_inlist(UI_style, list("White", "Midnight","Orange","old"), initial(UI_style)) + be_special = sanitize_integer(be_special, 0, 65535, initial(be_special)) + default_slot = sanitize_integer(default_slot, 1, config.character_slots, initial(default_slot)) + toggles = sanitize_integer(toggles, 0, 65535, initial(toggles)) + UI_style_color = sanitize_hexcolor(UI_style_color, initial(UI_style_color)) + UI_style_alpha = sanitize_integer(UI_style_alpha, 0, 255, initial(UI_style_alpha)) + + return 1 + +/datum/preferences/proc/save_preferences() + if(!path) return 0 + var/savefile/S = new /savefile(path) + if(!S) return 0 + S.cd = "/" + + S["version"] << savefile_version + + //general preferences + S["ooccolor"] << ooccolor + S["lastchangelog"] << lastchangelog + S["UI_style"] << UI_style + S["be_special"] << be_special + S["default_slot"] << default_slot + S["toggles"] << toggles + + return 1 + +/datum/preferences/proc/load_character(slot) + if(!path) return 0 + if(!fexists(path)) return 0 + var/savefile/S = new /savefile(path) + if(!S) return 0 + S.cd = "/" + if(!slot) slot = default_slot + slot = sanitize_integer(slot, 1, config.character_slots, initial(default_slot)) + if(slot != default_slot) + default_slot = slot + S["default_slot"] << slot + S.cd = "/character[slot]" + + //Character + S["OOC_Notes"] >> metadata + S["real_name"] >> real_name + S["name_is_always_random"] >> be_random_name + S["gender"] >> gender + S["age"] >> age + S["species"] >> species + S["language"] >> language + S["spawnpoint"] >> spawnpoint + + //colors to be consolidated into hex strings (requires some work with dna code) + S["hair_red"] >> r_hair + S["hair_green"] >> g_hair + S["hair_blue"] >> b_hair + S["facial_red"] >> r_facial + S["facial_green"] >> g_facial + S["facial_blue"] >> b_facial + S["skin_tone"] >> s_tone + S["skin_red"] >> r_skin + S["skin_green"] >> g_skin + S["skin_blue"] >> b_skin + S["hair_style_name"] >> h_style + S["facial_style_name"] >> f_style + S["eyes_red"] >> r_eyes + S["eyes_green"] >> g_eyes + S["eyes_blue"] >> b_eyes + S["underwear"] >> underwear + S["undershirt"] >> undershirt + S["backbag"] >> backbag + S["b_type"] >> b_type + + //Jobs + S["alternate_option"] >> alternate_option + S["job_civilian_high"] >> job_civilian_high + S["job_civilian_med"] >> job_civilian_med + S["job_civilian_low"] >> job_civilian_low + S["job_medsci_high"] >> job_medsci_high + S["job_medsci_med"] >> job_medsci_med + S["job_medsci_low"] >> job_medsci_low + S["job_engsec_high"] >> job_engsec_high + S["job_engsec_med"] >> job_engsec_med + S["job_engsec_low"] >> job_engsec_low + + //Flavour Text + S["flavor_texts_general"] >> flavor_texts["general"] + S["flavor_texts_head"] >> flavor_texts["head"] + S["flavor_texts_face"] >> flavor_texts["face"] + S["flavor_texts_eyes"] >> flavor_texts["eyes"] + S["flavor_texts_torso"] >> flavor_texts["torso"] + S["flavor_texts_arms"] >> flavor_texts["arms"] + S["flavor_texts_hands"] >> flavor_texts["hands"] + S["flavor_texts_legs"] >> flavor_texts["legs"] + S["flavor_texts_feet"] >> flavor_texts["feet"] + + //Flavour text for robots. + S["flavour_texts_robot_Default"] >> flavour_texts_robot["Default"] + for(var/module in robot_module_types) + S["flavour_texts_robot_[module]"] >> flavour_texts_robot[module] + + //Miscellaneous + S["med_record"] >> med_record + S["sec_record"] >> sec_record + S["gen_record"] >> gen_record + S["be_special"] >> be_special + S["disabilities"] >> disabilities + S["player_alt_titles"] >> player_alt_titles + S["used_skillpoints"] >> used_skillpoints + S["skills"] >> skills + S["skill_specialization"] >> skill_specialization + S["organ_data"] >> organ_data + S["rlimb_data"] >> rlimb_data + S["gear"] >> gear + S["home_system"] >> home_system + S["citizenship"] >> citizenship + S["faction"] >> faction + S["religion"] >> religion + + S["nanotrasen_relation"] >> nanotrasen_relation + //S["skin_style"] >> skin_style + + S["uplinklocation"] >> uplinklocation + S["exploit_record"] >> exploit_record + + S["UI_style_color"] << UI_style_color + S["UI_style_alpha"] << UI_style_alpha + + //Sanitize + metadata = sanitize_text(metadata, initial(metadata)) + real_name = sanitizeName(real_name) + + if(isnull(species) || !(species in playable_species)) + species = "Human" + + if(isnum(underwear)) + var/list/undies = gender == MALE ? underwear_m : underwear_f + underwear = undies[undies[underwear]] + + if(isnum(undershirt)) + undershirt = undershirt_t[undershirt_t[undershirt]] + + if(isnull(language)) language = "None" + if(isnull(spawnpoint)) spawnpoint = "Arrivals Shuttle" + if(isnull(nanotrasen_relation)) nanotrasen_relation = initial(nanotrasen_relation) + if(!real_name) real_name = random_name(gender) + be_random_name = sanitize_integer(be_random_name, 0, 1, initial(be_random_name)) + gender = sanitize_gender(gender) + age = sanitize_integer(age, AGE_MIN, AGE_MAX, initial(age)) + r_hair = sanitize_integer(r_hair, 0, 255, initial(r_hair)) + g_hair = sanitize_integer(g_hair, 0, 255, initial(g_hair)) + b_hair = sanitize_integer(b_hair, 0, 255, initial(b_hair)) + r_facial = sanitize_integer(r_facial, 0, 255, initial(r_facial)) + g_facial = sanitize_integer(g_facial, 0, 255, initial(g_facial)) + b_facial = sanitize_integer(b_facial, 0, 255, initial(b_facial)) + s_tone = sanitize_integer(s_tone, -185, 34, initial(s_tone)) + r_skin = sanitize_integer(r_skin, 0, 255, initial(r_skin)) + g_skin = sanitize_integer(g_skin, 0, 255, initial(g_skin)) + b_skin = sanitize_integer(b_skin, 0, 255, initial(b_skin)) + h_style = sanitize_inlist(h_style, hair_styles_list, initial(h_style)) + f_style = sanitize_inlist(f_style, facial_hair_styles_list, initial(f_style)) + r_eyes = sanitize_integer(r_eyes, 0, 255, initial(r_eyes)) + g_eyes = sanitize_integer(g_eyes, 0, 255, initial(g_eyes)) + b_eyes = sanitize_integer(b_eyes, 0, 255, initial(b_eyes)) + backbag = sanitize_integer(backbag, 1, backbaglist.len, initial(backbag)) + b_type = sanitize_text(b_type, initial(b_type)) + + alternate_option = sanitize_integer(alternate_option, 0, 2, initial(alternate_option)) + job_civilian_high = sanitize_integer(job_civilian_high, 0, 65535, initial(job_civilian_high)) + job_civilian_med = sanitize_integer(job_civilian_med, 0, 65535, initial(job_civilian_med)) + job_civilian_low = sanitize_integer(job_civilian_low, 0, 65535, initial(job_civilian_low)) + job_medsci_high = sanitize_integer(job_medsci_high, 0, 65535, initial(job_medsci_high)) + job_medsci_med = sanitize_integer(job_medsci_med, 0, 65535, initial(job_medsci_med)) + job_medsci_low = sanitize_integer(job_medsci_low, 0, 65535, initial(job_medsci_low)) + job_engsec_high = sanitize_integer(job_engsec_high, 0, 65535, initial(job_engsec_high)) + job_engsec_med = sanitize_integer(job_engsec_med, 0, 65535, initial(job_engsec_med)) + job_engsec_low = sanitize_integer(job_engsec_low, 0, 65535, initial(job_engsec_low)) + + if(!skills) skills = list() + if(!used_skillpoints) used_skillpoints= 0 + if(isnull(disabilities)) disabilities = 0 + if(!player_alt_titles) player_alt_titles = new() + if(!organ_data) src.organ_data = list() + if(!rlimb_data) src.rlimb_data = list() + if(!gear) src.gear = list() + //if(!skin_style) skin_style = "Default" + + if(!home_system) home_system = "Unset" + if(!citizenship) citizenship = "None" + if(!faction) faction = "None" + if(!religion) religion = "None" + + return 1 + + + + +#undef SAVEFILE_VERSION_MAX +#undef SAVEFILE_VERSION_MIN*/ \ No newline at end of file diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm index eedd4b9136a..fc2f9bcb6cd 100644 --- a/code/modules/client/preferences.dm +++ b/code/modules/client/preferences.dm @@ -32,6 +32,7 @@ datum/preferences //doohickeys for savefiles var/path var/default_slot = 1 //Holder so it doesn't default to slot 1, rather the last one used + var/current_slot = 1 var/savefile_version = 0 //non-preference stuff @@ -141,6 +142,7 @@ datum/preferences load_path(C.ckey) if(load_preferences()) if(load_character()) + current_slot = getCharSlot() return gender = pick(MALE, FEMALE) real_name = random_name(gender,species) @@ -1594,6 +1596,7 @@ datum/preferences if("save") save_preferences() + SQLsave_character(current_slot) save_character() if("reload") @@ -1608,7 +1611,8 @@ datum/preferences close_load_dialog(user) if("changeslot") - load_character(text2num(href_list["num"])) + current_slot = text2num(href_list["num"]) + load_character(current_slot) close_load_dialog(user) ShowChoices(user) @@ -1743,5 +1747,16 @@ datum/preferences dat += "" user << browse(dat, "window=saves;size=300x390") +/datum/preferences/proc/getCharSlot() //get character slot from savefile + var/savefile/S = new /savefile(path) + if(S) + var/name + for(var/i=1, i<= config.character_slots, i++) + S.cd = "/character[i]" + S["real_name"] >> name + if(name == real_name) + return i + return 1 + /datum/preferences/proc/close_load_dialog(mob/user) user << browse(null, "window=saves") From 8fcf7f25179d8f2f3695744c8d735fdd58dcf21a Mon Sep 17 00:00:00 2001 From: Mahzel Date: Mon, 29 Feb 2016 23:53:50 +0100 Subject: [PATCH 2/7] SQL SHOULD be OK. Need testsing. Complete SQL functions added, need implementation in preferences.dm and testing. --- code/modules/client/client_saveSQL.dm | 561 ++++++++++++-------------- 1 file changed, 259 insertions(+), 302 deletions(-) diff --git a/code/modules/client/client_saveSQL.dm b/code/modules/client/client_saveSQL.dm index 3c7b8997a1a..43ee0565f30 100644 --- a/code/modules/client/client_saveSQL.dm +++ b/code/modules/client/client_saveSQL.dm @@ -21,21 +21,34 @@ var/char_slot return 0 else log_debug("db connected, real name is [real_name]") - if(!getCharId()) + if(!getCharId(ckey)) log_debug("New Character") query = dbcon.NewQuery("INSERT INTO ss13_characters (ckey, slot) VALUES ('[ckey]', '[cslot]')") query.Execute() log_debug(dbcon.ErrorMsg()) getCharId() InsertCharData() + InsertJobsData() + InsertFlavourData() + InsertRobotFlavourData() + InsertMiscData() log_debug(dbcon.ErrorMsg()) - query = dbcon.NewQuery("UPDATE SS13_characters SET Character_key = (SELECT id FROM characters_data WHERE char_id = [char_id]) WHERE id = [char_id] ") + TextQuery = "UPDATE SS13_characters SET Character_key = (SELECT id FROM characters_data WHERE char_id = [char_id]), " + TextQuery += "Jobs_key = (SELECT id FROM characters_jobs WHERE char_id = [char_id]), " + TextQuery += "Flavour_key = (SELECT id FROM characters_flavour WHERE char_id = [char_id]), " + TextQuery += "Misc_key = (SELECT id FROM characters_misc WHERE char_id = [char_id]), " + TextQuery += "Robot_key = (SELECT id FROM characters_robot_flavour WHERE char_id = [char_id]) WHERE id = [char_id] " + query = dbcon.NewQuery(TextQuery) query.Execute() log_debug(dbcon.ErrorMsg()) else log_debug("ID = [char_id]") log_debug("Update entry") UpdateCharData() + UpdateJobsData() + UpdateFlavourData() + UpdateRobotFlavourData() + UpdateMiscData() log_debug("Save query executed") return 1 log_debug("No ckey in datums") @@ -45,8 +58,29 @@ var/char_slot char_slot = slot if(!getCharId()) return 0 - log_debug("Loading character ID [char_id] from slot [char_slot]) - return LoadCharData() + log_debug("Loading character ID [char_id] from slot [char_slot]") + if(LoadCharData()) + if(LoadJobsData()) + if(LoadFlavourData()) + if(LoadRobotFlavourData()) + if(LoadMiscData()) + return 1 + return 0 + +/datum/preferences/proc/getCharId(var/ckey) + TextQuery = "SELECT id FROM ss13_characters WHERE ckey='[ckey]' AND slot = '[char_slot]'" + log_debug(TextQuery) + query = dbcon.NewQuery("SELECT id FROM ss13_characters WHERE ckey='[ckey]' AND slot = '[char_slot]'") + log_debug("Query ready") + query.Execute() + var/rowDebug = query.RowCount() + log_debug("Query executed, [rowDebug] rows") + if(!query.RowCount()) + return null + query.NextRow() + char_id = query.item[1] + log_debug("GetCharId : [char_id]") + return char_id /datum/preferences/proc/InsertCharData() TextQuery = "INSERT INTO characters_data (age, backbag, b_type, char_id, eyes_B, eyes_G, eyes_R, facial_B, facial_G, facial_R, facial_style, " @@ -84,134 +118,247 @@ var/char_slot age = query.item[1] backbag = query.item[2] b_type = query.item[3] - eyes_B = query.item[4] - eyes_G = query.item[5] - eyes_R = query.item[6] - facial_R = query.item[7] - facial_G = query.item[8] - facial_R = query.item[9] - facial_style = query.item[10] + b_eyes = query.item[4] + g_eyes = query.item[5] + r_eyes = query.item[6] + b_facial = query.item[7] + g_facial = query.item[8] + r_facial = query.item[9] + f_style = query.item[10] gender = query.item[11] - hair_B = query.item[12] - hair_G = query.item[13] - hair_R = query.item[14] - hair_style = query.item[15] - isRandom = query.item[16] + b_hair = query.item[12] + g_hair = query.item[13] + r_hair = query.item[14] + h_style = query.item[15] + be_random_name = query.item[16] language = query.item[17] - name = query.item[18] - OOC = query.item[19] - skin_B = query.item[20] - skin_G = query.item[21] - skin_R = query.item[22] - skin_tone = query.item[23] + real_name = query.item[18] + metadata = query.item[19] + b_skin = query.item[20] + g_skin = query.item[21] + r_skin = query.item[22] + s_tone = query.item[23] spawnpoint = query.item[24] species = query.item[25] undershirt = query.item[26] underwear = query.item[27] return 1 -/datum/preferences/proc/getCharId() - TextQuery = "SELECT id FROM ss13_characters WHERE ckey='[ckey]' AND slot = '[char_slot]'" +/datum/preferences/proc/InsertJobsData() + TextQuery = "INSERT INTO characters_jobs (char_id, Alternate, civ_high, civ_med, civ_low, medsci_high, medsci_med, medsci_low, engsec_high, engsec_med, engsec_low) " + TextQuery += " VALUES ('[alternate_option]', '[job_civilian_high]', '[job_civilian_med]', '[job_civilian_low]', '[job_medsci_high]', '[job_medsci_med]', '[job_medsci_low]', " + TextQuery += "'[job_engsec_high]', '[job_engsec_med]', '[job_engsec_low]')" log_debug(TextQuery) - query = dbcon.NewQuery("SELECT id FROM ss13_characters WHERE ckey='[ckey]' AND slot = '[char_slot]'") - log_debug("Query ready") + query = dbcon.NewQuery(TextQuery) + query.Execute() + return 1 + +/datum/preferences/proc/UpdateJobsData() + TextQuery = "UPDATE characters_jobs SET Alternate='[alternate_option]', civ_high='[job_civilian_high]', civ_med='[job_civilian_med]', civ_low='[job_civilian_low]', " + TextQuery += "medsci_high='[job_medsci_high]', medsci_med='[job_medsci_med]', medsci_low='[job_medsci_low]', " + TextQuery += "engsec_high='[job_engsec_high]', engsec_med='[job_engsec_med]', engsec_low='[job_engsec_low]' WHERE char_id = [char_id] " + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + return 1 + +/datum/preferences/proc/LoadJobsData() + TextQuery = "SELECT * FROM characters_jobs WHERE char_id = [char_id]" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) query.Execute() - var/rowDebug = query.RowCount() - log_debug("Query executed, [rowDebug] rows") if(!query.RowCount()) - return null + return 0 + log_debug("Load query executed successfully") query.NextRow() - char_id = query.item[1] - log_debug("GetCharId : [char_id]") - return char_id + alternate_option = query.item[3] + job_civilian_high = query.item[4] + job_civilian_med = query.item[5] + job_civilian_low = query.item[6] + job_medsci_high = query.item[7] + job_medsci_med = query.item[8] + job_medsci_low = query.item[9] + job_engsec_high = query.item[10] + job_engsec_med = query.item[11] + job_engsec_low = query.item[12] + return 1 -/* //Character - chardata.Add(age) - chardata.Add(backbag) - chardata.Add(metadata) - chardata.Add(real_name) - chardata.Add(be_random_name) - chardata.Add(gender) - chardata.Add(species) - chardata.Add(language) - chardata.Add(r_hair) - chardata.Add(g_hair) - chardata.Add(b_hair) - chardata.Add(r_facial) - chardata.Add(g_facial) - chardata.Add(b_facial) - chardata.Add(s_tone) - chardata.Add(r_skin) - chardata.Add(g_skin) - chardata.Add(b_skin) - chardata.Add(h_style) - chardata.Add(f_style) - chardata.Add(r_eyes) - chardata.Add(g_eyes) - chardata.Add(b_eyes) - chardata.Add(underwear) - chardata.Add(undershirt) - chardata.Add(b_type) - chardata.Add(spawnpoint) +/datum/preferences/proc/InsertFlavourData() + TextQuery = "INSERT INTO characters_flavour (char_id, generals, head, face, eyes, torso, arms, hands, legs, feet) " + TextQuery += " VALUES ('[char_id]','[flavor_texts["general"]]', '[flavor_texts["head"]]', '[flavor_texts["face"]]', '[flavor_texts["eyes"]]', '[flavor_texts["torso"]]', " + TextQuery += "'[flavor_texts["arms"]]', '[flavor_texts["hands"]]', '[flavor_texts["legs"]]', '[flavor_texts["feet"]]')" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + return 1 - //Jobs - S["alternate_option"] << alternate_option - S["job_civilian_high"] << job_civilian_high - S["job_civilian_med"] << job_civilian_med - S["job_civilian_low"] << job_civilian_low - S["job_medsci_high"] << job_medsci_high - S["job_medsci_med"] << job_medsci_med - S["job_medsci_low"] << job_medsci_low - S["job_engsec_high"] << job_engsec_high - S["job_engsec_med"] << job_engsec_med - S["job_engsec_low"] << job_engsec_low +/datum/preferences/proc/UpdateFlavourData() + TextQuery = "UPDATE characters_flavour SET generals='[flavor_texts["general"]]', head='[flavor_texts["head"]]', face='[flavor_texts["face"]]', eyes='[flavor_texts["eyes"]]', " + TextQuery += "torso='[flavor_texts["torso"]]', arms='[flavor_texts["arms"]]', hands='[flavor_texts["hands"]]', legs='[flavor_texts["legs"]]', feet='[flavor_texts["feet"]]' " + TextQuery += "WHERE char_id = [char_id]" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + return 1 - //Flavour Text - S["flavor_texts_general"] << flavor_texts["general"] - S["flavor_texts_head"] << flavor_texts["head"] - S["flavor_texts_face"] << flavor_texts["face"] - S["flavor_texts_eyes"] << flavor_texts["eyes"] - S["flavor_texts_torso"] << flavor_texts["torso"] - S["flavor_texts_arms"] << flavor_texts["arms"] - S["flavor_texts_hands"] << flavor_texts["hands"] - S["flavor_texts_legs"] << flavor_texts["legs"] - S["flavor_texts_feet"] << flavor_texts["feet"] +/datum/preferences/proc/LoadFlavourData() + TextQuery = "SELECT * FROM characters_flavour WHERE char_id = [char_id]" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + if(!query.RowCount()) + return 0 + log_debug("Load query executed successfully") + query.NextRow() + flavor_texts["general"] = query.item[3] + flavor_texts["head"] = query.item[4] + flavor_texts["face"] = query.item[5] + flavor_texts["eyes"] = query.item[6] + flavor_texts["torso"] = query.item[7] + flavor_texts["arms"] = query.item[8] + flavor_texts["hands"]= query.item[9] + flavor_texts["legs"] = query.item[10] + flavor_texts["feet"] = query.item[11] + return 1 - //Flavour text for robots. - S["flavour_texts_robot_Default"] << flavour_texts_robot["Default"] - for(var/module in robot_module_types) - S["flavour_texts_robot_[module]"] << flavour_texts_robot[module] +/datum/preferences/proc/InsertRobotFlavourData() + TextQuery = "INSERT INTO characters_robot_flavour (char_id, Default_Robot, Standard, Engineering, Construction, Surgeon, Crisis, Miner, Janitor, Service, Clerical, Security, Research) " + TextQuery += " VALUES ('[char_id]','[flavour_texts_robot["Default"]]', '[flavour_texts_robot["Standard"]]', '[flavour_texts_robot["Engineering"]]', '[flavour_texts_robot["Construction"]]', " + TextQuery += "'[flavour_texts_robot["Surgeon"]]', '[flavour_texts_robot["Crisis"]]', '[flavour_texts_robot["Miner"]]', '[flavour_texts_robot["Janitor"]]', '[flavour_texts_robot["Service"]]', " + TextQuery += "'[flavour_texts_robot["Clerical"]]', '[flavour_texts_robot["Security"]]','[flavour_texts_robot["Research"]]')" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + return 1 - //Miscellaneous - S["med_record"] << med_record - S["sec_record"] << sec_record - S["gen_record"] << gen_record - S["player_alt_titles"] << player_alt_titles - S["be_special"] << be_special - S["disabilities"] << disabilities - S["used_skillpoints"] << used_skillpoints - S["skills"] << skills - S["skill_specialization"] << skill_specialization - S["organ_data"] << organ_data - S["rlimb_data"] << rlimb_data - S["gear"] << gear - S["home_system"] << home_system - S["citizenship"] << citizenship - S["faction"] << faction - S["religion"] << religion +/datum/preferences/proc/UpdateRobotFlavourData() + TextQuery = "UPDATE characters_robot_flavour SET Default_Robot='[flavour_texts_robot["Default"]]', Standard='[flavour_texts_robot["Standard"]]', Engineering='[flavour_texts_robot["Engineering"]]', " + TextQuery += "Construction='[flavour_texts_robot["Construction"]]', Surgeon='[flavour_texts_robot["Surgeon"]]', Crisis='[flavour_texts_robot["Crisis"]]', Miner='[flavour_texts_robot["Miner"]]', " + TextQuery += "Janitor='[flavour_texts_robot["Janitor"]]', Service='[flavour_texts_robot["Service"]]', Clerical='[flavour_texts_robot["Clerical"]]', " + TextQuery += "Security='[flavour_texts_robot["Security"]]', Research='[flavour_texts_robot["Research"]]' WHERE char_id = [char_id]" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + return 1 - S["nanotrasen_relation"] << nanotrasen_relation - //S["skin_style"] << skin_style +/datum/preferences/proc/LoadRobotFlavourData() + TextQuery = "SELECT * FROM characters_robot_flavour WHERE char_id = [char_id]" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + if(!query.RowCount()) + return 0 + log_debug("Load query executed successfully") + query.NextRow() + flavour_texts_robot["Default"] = query.item[3] + flavour_texts_robot["Standard"] = query.item[4] + flavour_texts_robot["Engineering"] = query.item[5] + flavour_texts_robot["Construction"] = query.item[6] + flavour_texts_robot["Surgeon"] = query.item[7] + flavour_texts_robot["Crisis"] = query.item[8] + flavour_texts_robot["Miner"] = query.item[9] + flavour_texts_robot["Janitor"] = query.item[10] + flavour_texts_robot["Service"] = query.item[11] + flavour_texts_robot["Clerical"] = query.item[12] + flavour_texts_robot["Security"] = query.item[13] + flavour_texts_robot["Research"] = query.item[14] + return 1 - S["uplinklocation"] << uplinklocation - S["exploit_record"] << exploit_record +/datum/preferences/proc/InsertMiscData() + sanitizePrefs() + TextQuery = "INSERT INTO characters_misc (char_id, med_rec, sec_rec, gen_rec, alt_titles, disab, used_skill, skills, skills_spec, organ_dat, limb_dat, gear," + TextQuery += "home_sys, citizen, faction, religion, NT_relation, uplink_loc, exploit_rec) VALUES (" + TextQuery += "'[char_id]', '[med_record]', '[sec_record]', '[gen_record]', '[player_alt_titles]', '[disabilities]', '[used_skillpoints]', '[skills]', " + TextQuery += "'[skill_specialization]', '[organ_data]', '[rlimb_data]', '[gear]', '[home_system]', '[citizenship]', '[faction]', '[religion]', '[nanotrasen_relation]', " + TextQuery += "'[uplinklocation]', '[exploit_record]')" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + return 1 - S["UI_style_color"] << UI_style_color - S["UI_style_alpha"] << UI_style_alpha*/ +/datum/preferences/proc/UpdateMiscData() + TextQuery = "UPDATE characters_misc SET med_rec='[med_record]', sec_rec='[sec_record]', gen_rec='[gen_record]', alt_titles='[player_alt_titles]', disab='[disabilities]', " + TextQuery += "used_skill='[used_skillpoints]', skills='[skills]', skills_spec='[skill_specialization]', organ_dat='[organ_data]', limb_dat='[rlimb_data]', gear='[gear]', " + TextQuery += "home_sys='[home_system]', citizen='[citizenship]', faction='[faction]', religion='[religion]', NT_relation='[nanotrasen_relation]', uplink_loc='[uplinklocation]', " + TextQuery += "exploit_rec='[exploit_record]' WHERE char_id = [char_id]" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + return 1 +/datum/preferences/proc/LoadMiscData() + TextQuery = "SELECT * FROM characters_misc WHERE char_id = [char_id]" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + if(!query.RowCount()) + return 0 + log_debug("Load query executed successfully") + query.NextRow() + med_record = query.item[3] + sec_record = query.item[4] + gen_record = query.item[5] + player_alt_titles = query.item[6] + disabilities = query.item[7] + used_skillpoints = query.item[8] + skills = query.item[9] + skill_specialization = query.item[10] + organ_data = query.item[11] + rlimb_data = query.item[12] + gear = query.item[13] + home_system = query.item[14] + citizenship = query.item[15] + faction = query.item[16] + religion = query.item[17] + nanotrasen_relation = query.item[18] + uplinklocation = query.item[19] + exploit_record = query.item[20] + return 1 -/*/datum/preferences/proc/SQLSave_Preferences() - //Sanitize +/datum/preferences/proc/SavePrefData(var/ckey) + TextQuery = "SELECT * FROM characters_misc WHERE ckey = [ckey]" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + if(query.RowCount()) + return UpdatePrefData(ckey) + sanitizePrefs() + TextQuery = "INSERT INTO player_preferences (ckey, ooccolor, lastchangelog, UI_style, default_slot, toggles, UI_style_color, UI_style_alpha, be_special) " + TextQuery += "VALUES ('[ckey]', '[ooccolor]','[lastchangelog]', '[UI_style]', '[default_slot]', '[toggles]', '[UI_style_color]', '[UI_style_alpha]','[be_special]')" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + return 1 + +/datum/preferences/proc/UpdatePrefData(var/ckey) + sanitizePrefs() + TextQuery = "UPDATE player_preferences SET ooccolor='[ooccolor]', lastchangelog='[lastchangelog]', UI_style='[UI_style]', default_slot='[default_slot]', toggles='[toggles]', " + TextQuery += "UI_style_color='[UI_style_color]', UI_style_alpha='[UI_style_alpha]', be_special='[be_special]') WHERE ckey = [ckey]" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + return 1 + +/datum/preferences/proc/LoadPrefData(var/ckey) + TextQuery = "SELECT * FROM characters_misc WHERE ckey = [ckey]" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + if(!query.RowCount()) + return SavePrefData(ckey) + log_debug("Load query executed successfully") + query.NextRow() + ooccolor = query.item[3] + lastchangelog = query.item[4] + UI_style = query.item[5] + default_slot = query.item[6] + toggles = query.item[7] + UI_style_color = query.item[8] + UI_style_alpha = query.item[9] + be_special = query.item[10] + return 1 + +/datum/preferences/proc/sanitizePrefs() ooccolor = sanitize_hexcolor(ooccolor, initial(ooccolor)) lastchangelog = sanitize_text(lastchangelog, initial(lastchangelog)) UI_style = sanitize_inlist(UI_style, list("White", "Midnight","Orange","old"), initial(UI_style)) @@ -220,192 +367,10 @@ var/char_slot toggles = sanitize_integer(toggles, 0, 65535, initial(toggles)) UI_style_color = sanitize_hexcolor(UI_style_color, initial(UI_style_color)) UI_style_alpha = sanitize_integer(UI_style_alpha, 0, 255, initial(UI_style_alpha)) - - query = dbcon.Query("INSERT INTO (oocolor, lastchangelog, UI_style, be_special, default_slot, toggles, UI_style_color, UI_style_alpha) VALUES ([oocolor], [lastchangelog], [UI_style], [be_special], [default_slot], [toggles], [UI_style_color], [UI_style_alpha])") - else - var/id = query.item[2] - query = dbcon.Query("UPDATE aurora_characters SET ooccolor=[ooccolor], lastchangelog=[lastchangelog], UI_style=[UI_style], be_special=[be_special], default_slot=[default_slot], toggles = [toggles], UI_style_color = [UI_style_color], UI_style_alpha = [UI_style_alpha] WHERE aurora_characters.id=[id]") - query.Execute() - return 1 - -/datum/preferences/proc/savefile_update() - if(savefile_version < 8) //lazily delete everything + additional files so they can be saved in the new format - for(var/ckey in preferences_datums) - var/datum/preferences/D = preferences_datums[ckey] - if(D == src) - var/delpath = "data/player_saves/[copytext(ckey,1,2)]/[ckey]/" - if(delpath && fexists(delpath)) - fdel(delpath) - break - return 0 - - if(savefile_version == SAVEFILE_VERSION_MAX) //update successful. - save_preferences() - save_character() return 1 - return 0 -/datum/preferences/proc/load_path(ckey,filename="preferences.sav") - if(!ckey) return - path = "data/player_saves/[copytext(ckey,1,2)]/[ckey]/[filename]" - savefile_version = SAVEFILE_VERSION_MAX +/datum/preferences/proc/SanitizeCharacter() -/datum/preferences/proc/load_preferences() - if(!path) return 0 - if(!fexists(path)) return 0 - var/savefile/S = new /savefile(path) - if(!S) return 0 - S.cd = "/" - - S["version"] >> savefile_version - //Conversion - if(!savefile_version || !isnum(savefile_version) || savefile_version < SAVEFILE_VERSION_MIN || savefile_version > SAVEFILE_VERSION_MAX) - if(!savefile_update()) //handles updates - savefile_version = SAVEFILE_VERSION_MAX - save_preferences() - save_character() - return 0 - - //general preferences - S["ooccolor"] >> ooccolor - S["lastchangelog"] >> lastchangelog - S["UI_style"] >> UI_style - S["be_special"] >> be_special - S["default_slot"] >> default_slot - S["toggles"] >> toggles - S["UI_style_color"] >> UI_style_color - S["UI_style_alpha"] >> UI_style_alpha - - //Sanitize - ooccolor = sanitize_hexcolor(ooccolor, initial(ooccolor)) - lastchangelog = sanitize_text(lastchangelog, initial(lastchangelog)) - UI_style = sanitize_inlist(UI_style, list("White", "Midnight","Orange","old"), initial(UI_style)) - be_special = sanitize_integer(be_special, 0, 65535, initial(be_special)) - default_slot = sanitize_integer(default_slot, 1, config.character_slots, initial(default_slot)) - toggles = sanitize_integer(toggles, 0, 65535, initial(toggles)) - UI_style_color = sanitize_hexcolor(UI_style_color, initial(UI_style_color)) - UI_style_alpha = sanitize_integer(UI_style_alpha, 0, 255, initial(UI_style_alpha)) - - return 1 - -/datum/preferences/proc/save_preferences() - if(!path) return 0 - var/savefile/S = new /savefile(path) - if(!S) return 0 - S.cd = "/" - - S["version"] << savefile_version - - //general preferences - S["ooccolor"] << ooccolor - S["lastchangelog"] << lastchangelog - S["UI_style"] << UI_style - S["be_special"] << be_special - S["default_slot"] << default_slot - S["toggles"] << toggles - - return 1 - -/datum/preferences/proc/load_character(slot) - if(!path) return 0 - if(!fexists(path)) return 0 - var/savefile/S = new /savefile(path) - if(!S) return 0 - S.cd = "/" - if(!slot) slot = default_slot - slot = sanitize_integer(slot, 1, config.character_slots, initial(default_slot)) - if(slot != default_slot) - default_slot = slot - S["default_slot"] << slot - S.cd = "/character[slot]" - - //Character - S["OOC_Notes"] >> metadata - S["real_name"] >> real_name - S["name_is_always_random"] >> be_random_name - S["gender"] >> gender - S["age"] >> age - S["species"] >> species - S["language"] >> language - S["spawnpoint"] >> spawnpoint - - //colors to be consolidated into hex strings (requires some work with dna code) - S["hair_red"] >> r_hair - S["hair_green"] >> g_hair - S["hair_blue"] >> b_hair - S["facial_red"] >> r_facial - S["facial_green"] >> g_facial - S["facial_blue"] >> b_facial - S["skin_tone"] >> s_tone - S["skin_red"] >> r_skin - S["skin_green"] >> g_skin - S["skin_blue"] >> b_skin - S["hair_style_name"] >> h_style - S["facial_style_name"] >> f_style - S["eyes_red"] >> r_eyes - S["eyes_green"] >> g_eyes - S["eyes_blue"] >> b_eyes - S["underwear"] >> underwear - S["undershirt"] >> undershirt - S["backbag"] >> backbag - S["b_type"] >> b_type - - //Jobs - S["alternate_option"] >> alternate_option - S["job_civilian_high"] >> job_civilian_high - S["job_civilian_med"] >> job_civilian_med - S["job_civilian_low"] >> job_civilian_low - S["job_medsci_high"] >> job_medsci_high - S["job_medsci_med"] >> job_medsci_med - S["job_medsci_low"] >> job_medsci_low - S["job_engsec_high"] >> job_engsec_high - S["job_engsec_med"] >> job_engsec_med - S["job_engsec_low"] >> job_engsec_low - - //Flavour Text - S["flavor_texts_general"] >> flavor_texts["general"] - S["flavor_texts_head"] >> flavor_texts["head"] - S["flavor_texts_face"] >> flavor_texts["face"] - S["flavor_texts_eyes"] >> flavor_texts["eyes"] - S["flavor_texts_torso"] >> flavor_texts["torso"] - S["flavor_texts_arms"] >> flavor_texts["arms"] - S["flavor_texts_hands"] >> flavor_texts["hands"] - S["flavor_texts_legs"] >> flavor_texts["legs"] - S["flavor_texts_feet"] >> flavor_texts["feet"] - - //Flavour text for robots. - S["flavour_texts_robot_Default"] >> flavour_texts_robot["Default"] - for(var/module in robot_module_types) - S["flavour_texts_robot_[module]"] >> flavour_texts_robot[module] - - //Miscellaneous - S["med_record"] >> med_record - S["sec_record"] >> sec_record - S["gen_record"] >> gen_record - S["be_special"] >> be_special - S["disabilities"] >> disabilities - S["player_alt_titles"] >> player_alt_titles - S["used_skillpoints"] >> used_skillpoints - S["skills"] >> skills - S["skill_specialization"] >> skill_specialization - S["organ_data"] >> organ_data - S["rlimb_data"] >> rlimb_data - S["gear"] >> gear - S["home_system"] >> home_system - S["citizenship"] >> citizenship - S["faction"] >> faction - S["religion"] >> religion - - S["nanotrasen_relation"] >> nanotrasen_relation - //S["skin_style"] >> skin_style - - S["uplinklocation"] >> uplinklocation - S["exploit_record"] >> exploit_record - - S["UI_style_color"] << UI_style_color - S["UI_style_alpha"] << UI_style_alpha - - //Sanitize metadata = sanitize_text(metadata, initial(metadata)) real_name = sanitizeName(real_name) @@ -462,17 +427,9 @@ var/char_slot if(!organ_data) src.organ_data = list() if(!rlimb_data) src.rlimb_data = list() if(!gear) src.gear = list() - //if(!skin_style) skin_style = "Default" if(!home_system) home_system = "Unset" if(!citizenship) citizenship = "None" if(!faction) faction = "None" if(!religion) religion = "None" - - return 1 - - - - -#undef SAVEFILE_VERSION_MAX -#undef SAVEFILE_VERSION_MIN*/ \ No newline at end of file + return 1 \ No newline at end of file From 14370d36b6282549fb0912dac0d6c8e4e492c26a Mon Sep 17 00:00:00 2001 From: Mahzel Date: Tue, 15 Mar 2016 23:51:35 +0100 Subject: [PATCH 3/7] characters db continued This one's not bad, but we need to think about how to integrate to the main system. Dual save? --- SQL/aurora_characters_db.sql | 400 ++++++++++++++++++++++++++ baystation12.dme | 1 + code/modules/client/client_saveSQL.dm | 354 ++++++++++++++++++++--- code/modules/client/preferences.dm | 93 +++++- 4 files changed, 796 insertions(+), 52 deletions(-) create mode 100644 SQL/aurora_characters_db.sql diff --git a/SQL/aurora_characters_db.sql b/SQL/aurora_characters_db.sql new file mode 100644 index 00000000000..4b89f730ca1 --- /dev/null +++ b/SQL/aurora_characters_db.sql @@ -0,0 +1,400 @@ +-- phpMyAdmin SQL Dump +-- version 4.5.3.1 +-- http://www.phpmyadmin.net +-- +-- Host: 127.0.0.1 +-- Generation Time: Mar 15, 2016 at 10:38 PM +-- Server version: 5.7.10 +-- PHP Version: 5.6.17 + +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; + +-- +-- Database: `aurora_test` +-- + +-- -------------------------------------------------------- + +-- +-- Table structure for table `characters_data` +-- + +CREATE TABLE `characters_data` ( + `Id` int(11) NOT NULL, + `char_id` int(11) NOT NULL, + `OOC` varchar(512) DEFAULT NULL, + `name` varchar(128) NOT NULL, + `isRandom` tinyint(1) DEFAULT NULL, + `gender` varchar(32) DEFAULT NULL, + `age` int(11) DEFAULT NULL, + `species` varchar(32) DEFAULT NULL, + `language` varchar(128) DEFAULT NULL, + `hair_R` int(11) DEFAULT NULL, + `hair_G` int(11) DEFAULT NULL, + `hair_B` int(11) DEFAULT NULL, + `facial_R` int(11) DEFAULT NULL, + `facial_G` int(11) DEFAULT NULL, + `facial_B` int(11) DEFAULT NULL, + `skin_tone` int(11) DEFAULT NULL, + `skin_R` int(11) DEFAULT NULL, + `skin_G` int(11) DEFAULT NULL, + `skin_B` int(11) DEFAULT NULL, + `hair_style` varchar(32) DEFAULT NULL, + `facial_style` varchar(32) DEFAULT NULL, + `eyes_R` int(11) DEFAULT NULL, + `eyes_G` int(11) DEFAULT NULL, + `eyes_B` int(11) DEFAULT NULL, + `underwear` varchar(32) DEFAULT NULL, + `undershirt` varchar(32) DEFAULT NULL, + `backbag` int(11) DEFAULT NULL, + `b_type` varchar(32) DEFAULT NULL, + `spawnpoint` varchar(32) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `characters_flavour` +-- + +CREATE TABLE `characters_flavour` ( + `id` int(11) NOT NULL, + `char_id` int(11) NOT NULL, + `generals` text NOT NULL, + `head` text NOT NULL, + `face` text NOT NULL, + `eyes` text NOT NULL, + `torso` text NOT NULL, + `arms` text NOT NULL, + `hands` text NOT NULL, + `legs` text NOT NULL, + `feet` text NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `characters_gear` +-- + +CREATE TABLE `characters_gear` ( + `id` int(11) NOT NULL, + `char_id` int(11) NOT NULL, + `gear1` text, + `gear2` text, + `gear3` text, + `gear4` text, + `gear5` text +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `characters_jobs` +-- + +CREATE TABLE `characters_jobs` ( + `id` int(11) NOT NULL, + `char_id` int(11) NOT NULL, + `Alternate` int(11) NOT NULL, + `civ_high` int(11) NOT NULL, + `civ_med` int(11) NOT NULL, + `civ_low` int(11) NOT NULL, + `medsci_high` int(11) NOT NULL, + `medsci_med` int(11) NOT NULL, + `medsci_low` int(11) NOT NULL, + `engsec_high` int(11) NOT NULL, + `engsec_med` int(11) NOT NULL, + `engsec_low` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `characters_misc` +-- + +CREATE TABLE `characters_misc` ( + `id` int(11) NOT NULL, + `char_id` int(11) NOT NULL, + `med_rec` text NOT NULL, + `sec_rec` text NOT NULL, + `gen_rec` text NOT NULL, + `disab` text NOT NULL, + `used_skill` text NOT NULL, + `skills_spec` text NOT NULL, + `home_sys` text NOT NULL, + `citizen` text NOT NULL, + `faction` text NOT NULL, + `religion` text NOT NULL, + `NT_relation` text NOT NULL, + `uplink_loc` text NOT NULL, + `exploit_rec` text NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `characters_organs` +-- + +CREATE TABLE `characters_organs` ( + `id` int(11) NOT NULL, + `char_id` int(11) NOT NULL, + `l_leg` text, + `r_leg` text, + `l_arm` text, + `r_arm` text, + `l_foot` text, + `r_foot` text, + `l_hand` text, + `r_hand` text, + `heart` text, + `eyes` text +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `characters_rlimb` +-- + +CREATE TABLE `characters_rlimb` ( + `id` int(11) NOT NULL, + `char_id` int(11) NOT NULL, + `l_leg` text, + `r_leg` text, + `l_arm` text, + `r_arm` text, + `l_foot` text, + `r_foot` text, + `l_hand` text, + `r_hand` text +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `characters_robot_flavour` +-- + +CREATE TABLE `characters_robot_flavour` ( + `id` int(11) NOT NULL, + `char_id` int(11) DEFAULT NULL, + `Default_Robot` text, + `Standard` text, + `Engineering` text, + `Construction` text, + `Surgeon` text, + `Crisis` text, + `Miner` text, + `Janitor` text, + `Service` text, + `Clerical` text, + `Security` text, + `Research` text +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `characters_skills` +-- + +CREATE TABLE `characters_skills` ( + `id` int(11) NOT NULL, + `char_id` int(11) NOT NULL, + `Command` int(11) NOT NULL, + `Botany` int(11) NOT NULL, + `Cooking` int(11) NOT NULL, + `Close_Combat` int(11) NOT NULL, + `Weapons_Expertise` int(11) NOT NULL, + `Forensics` int(11) NOT NULL, + `NanoTrasen_Law` int(11) NOT NULL, + `EVA` int(11) NOT NULL, + `Construction` int(11) NOT NULL, + `Electrical` int(11) NOT NULL, + `Atmos` int(11) NOT NULL, + `Engines` int(11) NOT NULL, + `Heavy_Mach` int(11) NOT NULL, + `Complex_Devices` int(11) NOT NULL, + `Information_Tech` int(11) NOT NULL, + `Genetics` int(11) NOT NULL, + `Chemistry` int(11) NOT NULL, + `Science` int(11) NOT NULL, + `Medicine` int(11) NOT NULL, + `Anatomy` int(11) NOT NULL, + `Virology` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `player_preferences` +-- + +CREATE TABLE `player_preferences` ( + `id` int(11) NOT NULL, + `ckey` text NOT NULL, + `ooccolor` text NOT NULL, + `lastchangelog` text NOT NULL, + `UI_style` text NOT NULL, + `default_slot` int(11) NOT NULL, + `toggles` int(11) NOT NULL, + `UI_style_color` text NOT NULL, + `UI_style_alpha` int(11) NOT NULL, + `be_special` int(11) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +-- -------------------------------------------------------- + +-- +-- Table structure for table `ss13_characters` +-- + +CREATE TABLE `ss13_characters` ( + `id` int(11) NOT NULL, + `ckey` varchar(32) DEFAULT NULL, + `slot` int(11) DEFAULT '0', + `Character_Name` text +) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT; + +-- +-- Indexes for dumped tables +-- + +-- +-- Indexes for table `characters_data` +-- +ALTER TABLE `characters_data` + ADD PRIMARY KEY (`Id`); + +-- +-- Indexes for table `characters_flavour` +-- +ALTER TABLE `characters_flavour` + ADD PRIMARY KEY (`id`); + +-- +-- Indexes for table `characters_gear` +-- +ALTER TABLE `characters_gear` + ADD PRIMARY KEY (`id`); + +-- +-- Indexes for table `characters_jobs` +-- +ALTER TABLE `characters_jobs` + ADD PRIMARY KEY (`id`); + +-- +-- Indexes for table `characters_misc` +-- +ALTER TABLE `characters_misc` + ADD PRIMARY KEY (`id`); + +-- +-- Indexes for table `characters_organs` +-- +ALTER TABLE `characters_organs` + ADD PRIMARY KEY (`id`); + +-- +-- Indexes for table `characters_rlimb` +-- +ALTER TABLE `characters_rlimb` + ADD PRIMARY KEY (`id`); + +-- +-- Indexes for table `characters_robot_flavour` +-- +ALTER TABLE `characters_robot_flavour` + ADD PRIMARY KEY (`id`); + +-- +-- Indexes for table `characters_skills` +-- +ALTER TABLE `characters_skills` + ADD PRIMARY KEY (`id`); + +-- +-- Indexes for table `player_preferences` +-- +ALTER TABLE `player_preferences` + ADD PRIMARY KEY (`id`); + +-- +-- Indexes for table `ss13_characters` +-- +ALTER TABLE `ss13_characters` + ADD PRIMARY KEY (`id`); + +-- +-- AUTO_INCREMENT for dumped tables +-- + +-- +-- AUTO_INCREMENT for table `characters_data` +-- +ALTER TABLE `characters_data` + MODIFY `Id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; +-- +-- AUTO_INCREMENT for table `characters_flavour` +-- +ALTER TABLE `characters_flavour` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; +-- +-- AUTO_INCREMENT for table `characters_gear` +-- +ALTER TABLE `characters_gear` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6; +-- +-- AUTO_INCREMENT for table `characters_jobs` +-- +ALTER TABLE `characters_jobs` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; +-- +-- AUTO_INCREMENT for table `characters_misc` +-- +ALTER TABLE `characters_misc` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; +-- +-- AUTO_INCREMENT for table `characters_organs` +-- +ALTER TABLE `characters_organs` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2; +-- +-- AUTO_INCREMENT for table `characters_rlimb` +-- +ALTER TABLE `characters_rlimb` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2; +-- +-- AUTO_INCREMENT for table `characters_robot_flavour` +-- +ALTER TABLE `characters_robot_flavour` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; +-- +-- AUTO_INCREMENT for table `characters_skills` +-- +ALTER TABLE `characters_skills` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; +-- +-- AUTO_INCREMENT for table `player_preferences` +-- +ALTER TABLE `player_preferences` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; +-- +-- AUTO_INCREMENT for table `ss13_characters` +-- +ALTER TABLE `ss13_characters` + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/baystation12.dme b/baystation12.dme index f72742a15ae..ad973ce8273 100644 --- a/baystation12.dme +++ b/baystation12.dme @@ -889,6 +889,7 @@ #include "code\modules\cciaa\cciaa_items.dm" #include "code\modules\client\client defines.dm" #include "code\modules\client\client procs.dm" +#include "code\modules\client\client_saveSQL.dm" #include "code\modules\client\preferences.dm" #include "code\modules\client\preferences_ambience.dm" #include "code\modules\client\preferences_factions.dm" diff --git a/code/modules/client/client_saveSQL.dm b/code/modules/client/client_saveSQL.dm index 43ee0565f30..90c61003dc7 100644 --- a/code/modules/client/client_saveSQL.dm +++ b/code/modules/client/client_saveSQL.dm @@ -14,8 +14,8 @@ var/char_slot char_slot = cslot for(var/ckey in preferences_datums) var/datum/preferences/D = preferences_datums[ckey] - log_debug("Ckey is [ckey]") if(D == src) + log_debug("Ckey is [ckey]") establish_db_connection() if(!dbcon.IsConnected()) return 0 @@ -26,18 +26,17 @@ var/char_slot query = dbcon.NewQuery("INSERT INTO ss13_characters (ckey, slot) VALUES ('[ckey]', '[cslot]')") query.Execute() log_debug(dbcon.ErrorMsg()) - getCharId() + getCharId(ckey) InsertCharData() InsertJobsData() InsertFlavourData() InsertRobotFlavourData() InsertMiscData() + InsertSkillsData() + InsertGearData() + InsertOrgansData() log_debug(dbcon.ErrorMsg()) - TextQuery = "UPDATE SS13_characters SET Character_key = (SELECT id FROM characters_data WHERE char_id = [char_id]), " - TextQuery += "Jobs_key = (SELECT id FROM characters_jobs WHERE char_id = [char_id]), " - TextQuery += "Flavour_key = (SELECT id FROM characters_flavour WHERE char_id = [char_id]), " - TextQuery += "Misc_key = (SELECT id FROM characters_misc WHERE char_id = [char_id]), " - TextQuery += "Robot_key = (SELECT id FROM characters_robot_flavour WHERE char_id = [char_id]) WHERE id = [char_id] " + TextQuery = "UPDATE SS13_characters SET Character_Name = (SELECT name FROM characters_data WHERE char_id = '[char_id]')" query = dbcon.NewQuery(TextQuery) query.Execute() log_debug(dbcon.ErrorMsg()) @@ -49,14 +48,25 @@ var/char_slot UpdateFlavourData() UpdateRobotFlavourData() UpdateMiscData() + UpdateSkillsData() + UpdateGearData() + UpdateOrgansData() log_debug("Save query executed") return 1 log_debug("No ckey in datums") return 0 /datum/preferences/proc/SQLload_character(slot) + var/pckey + for(var/ckey in preferences_datums) + var/datum/preferences/D = preferences_datums[ckey] + if(D == src) + pckey = ckey + establish_db_connection() + if(!dbcon.IsConnected()) + return 0 char_slot = slot - if(!getCharId()) + if(!getCharId(pckey)) return 0 log_debug("Loading character ID [char_id] from slot [char_slot]") if(LoadCharData()) @@ -64,25 +74,30 @@ var/char_slot if(LoadFlavourData()) if(LoadRobotFlavourData()) if(LoadMiscData()) - return 1 + if(LoadSkillsData()) + if(LoadGearData()) + if(LoadOrgansData()) + return 1 return 0 /datum/preferences/proc/getCharId(var/ckey) TextQuery = "SELECT id FROM ss13_characters WHERE ckey='[ckey]' AND slot = '[char_slot]'" log_debug(TextQuery) - query = dbcon.NewQuery("SELECT id FROM ss13_characters WHERE ckey='[ckey]' AND slot = '[char_slot]'") + query = dbcon.NewQuery(TextQuery) log_debug("Query ready") query.Execute() + log_debug(dbcon.ErrorMsg()) var/rowDebug = query.RowCount() log_debug("Query executed, [rowDebug] rows") if(!query.RowCount()) - return null + return 0 query.NextRow() char_id = query.item[1] log_debug("GetCharId : [char_id]") return char_id /datum/preferences/proc/InsertCharData() + log_debug("Insert Char Data") TextQuery = "INSERT INTO characters_data (age, backbag, b_type, char_id, eyes_B, eyes_G, eyes_R, facial_B, facial_G, facial_R, facial_style, " TextQuery += "gender, hair_B, hair_G, hair_R, hair_style, isRandom, language, name, OOC,skin_B, skin_G, skin_R, skin_tone, spawnpoint, species, undershirt, underwear) VALUES " TextQuery += "('[age]', '[backbag]', '[b_type]', '[char_id]', '[b_eyes]', '[g_eyes]', '[r_eyes]', '[b_facial]', '[g_facial]', '[r_facial]', '[f_style]', " @@ -91,9 +106,11 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/UpdateCharData() + log_debug("Update Char Data") TextQuery = "UPDATE characters_data SET age = '[age]', backbag='[backbag]', b_type='[b_type]', eyes_B = '[b_eyes]', eyes_G='[g_eyes]', eyes_R='[r_eyes]'," TextQuery += "facial_B='[b_facial]', facial_G='[g_facial]', facial_R='[r_facial]', facial_style='[f_style]', gender = '[gender]', hair_B='[b_hair]', hair_G='[g_hair]'," TextQuery += "hair_R='[r_hair]', hair_style='[h_style]', isRandom='[be_random_name]', language='[language]', name='[real_name]', OOC='[metadata]',skin_B='[b_skin]', skin_G='[g_skin]'," @@ -102,15 +119,18 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/LoadCharData() + log_debug("Load char data") TextQuery = "SELECT age, backbag, b_type, eyes_B, eyes_G, eyes_R, facial_B, facial_G, facial_R, facial_style, gender, " TextQuery += "hair_B, hair_G, hair_R, hair_style, isRandom, language, name, OOC, skin_B, skin_G, skin_R, skin_tone, spawnpoint, species, undershirt, underwear " TextQuery += "FROM character_data WHERE char_id = [char_id]" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) if(!query.RowCount()) return 0 log_debug("Load query executed successfully") @@ -145,28 +165,34 @@ var/char_slot return 1 /datum/preferences/proc/InsertJobsData() + log_debug("Insert jobs") TextQuery = "INSERT INTO characters_jobs (char_id, Alternate, civ_high, civ_med, civ_low, medsci_high, medsci_med, medsci_low, engsec_high, engsec_med, engsec_low) " - TextQuery += " VALUES ('[alternate_option]', '[job_civilian_high]', '[job_civilian_med]', '[job_civilian_low]', '[job_medsci_high]', '[job_medsci_med]', '[job_medsci_low]', " + TextQuery += " VALUES ('[char_id]','[alternate_option]', '[job_civilian_high]', '[job_civilian_med]', '[job_civilian_low]', '[job_medsci_high]', '[job_medsci_med]', '[job_medsci_low]', " TextQuery += "'[job_engsec_high]', '[job_engsec_med]', '[job_engsec_low]')" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/UpdateJobsData() + log_debug("update jobs") TextQuery = "UPDATE characters_jobs SET Alternate='[alternate_option]', civ_high='[job_civilian_high]', civ_med='[job_civilian_med]', civ_low='[job_civilian_low]', " TextQuery += "medsci_high='[job_medsci_high]', medsci_med='[job_medsci_med]', medsci_low='[job_medsci_low]', " TextQuery += "engsec_high='[job_engsec_high]', engsec_med='[job_engsec_med]', engsec_low='[job_engsec_low]' WHERE char_id = [char_id] " log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/LoadJobsData() + log_debug("load_jobs") TextQuery = "SELECT * FROM characters_jobs WHERE char_id = [char_id]" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) if(!query.RowCount()) return 0 log_debug("Load query executed successfully") @@ -184,28 +210,34 @@ var/char_slot return 1 /datum/preferences/proc/InsertFlavourData() + log_debug("insert flavour") TextQuery = "INSERT INTO characters_flavour (char_id, generals, head, face, eyes, torso, arms, hands, legs, feet) " TextQuery += " VALUES ('[char_id]','[flavor_texts["general"]]', '[flavor_texts["head"]]', '[flavor_texts["face"]]', '[flavor_texts["eyes"]]', '[flavor_texts["torso"]]', " TextQuery += "'[flavor_texts["arms"]]', '[flavor_texts["hands"]]', '[flavor_texts["legs"]]', '[flavor_texts["feet"]]')" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/UpdateFlavourData() + log_debug("update flavour") TextQuery = "UPDATE characters_flavour SET generals='[flavor_texts["general"]]', head='[flavor_texts["head"]]', face='[flavor_texts["face"]]', eyes='[flavor_texts["eyes"]]', " TextQuery += "torso='[flavor_texts["torso"]]', arms='[flavor_texts["arms"]]', hands='[flavor_texts["hands"]]', legs='[flavor_texts["legs"]]', feet='[flavor_texts["feet"]]' " TextQuery += "WHERE char_id = [char_id]" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/LoadFlavourData() + log_debug("load flavour") TextQuery = "SELECT * FROM characters_flavour WHERE char_id = [char_id]" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) if(!query.RowCount()) return 0 log_debug("Load query executed successfully") @@ -222,6 +254,7 @@ var/char_slot return 1 /datum/preferences/proc/InsertRobotFlavourData() + log_debug("insert robot") TextQuery = "INSERT INTO characters_robot_flavour (char_id, Default_Robot, Standard, Engineering, Construction, Surgeon, Crisis, Miner, Janitor, Service, Clerical, Security, Research) " TextQuery += " VALUES ('[char_id]','[flavour_texts_robot["Default"]]', '[flavour_texts_robot["Standard"]]', '[flavour_texts_robot["Engineering"]]', '[flavour_texts_robot["Construction"]]', " TextQuery += "'[flavour_texts_robot["Surgeon"]]', '[flavour_texts_robot["Crisis"]]', '[flavour_texts_robot["Miner"]]', '[flavour_texts_robot["Janitor"]]', '[flavour_texts_robot["Service"]]', " @@ -229,9 +262,11 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/UpdateRobotFlavourData() + log_debug("update robot") TextQuery = "UPDATE characters_robot_flavour SET Default_Robot='[flavour_texts_robot["Default"]]', Standard='[flavour_texts_robot["Standard"]]', Engineering='[flavour_texts_robot["Engineering"]]', " TextQuery += "Construction='[flavour_texts_robot["Construction"]]', Surgeon='[flavour_texts_robot["Surgeon"]]', Crisis='[flavour_texts_robot["Crisis"]]', Miner='[flavour_texts_robot["Miner"]]', " TextQuery += "Janitor='[flavour_texts_robot["Janitor"]]', Service='[flavour_texts_robot["Service"]]', Clerical='[flavour_texts_robot["Clerical"]]', " @@ -239,13 +274,16 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/LoadRobotFlavourData() + log_debug("load robot") TextQuery = "SELECT * FROM characters_robot_flavour WHERE char_id = [char_id]" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) if(!query.RowCount()) return 0 log_debug("Load query executed successfully") @@ -265,32 +303,38 @@ var/char_slot return 1 /datum/preferences/proc/InsertMiscData() + log_debug("insert misc") sanitizePrefs() - TextQuery = "INSERT INTO characters_misc (char_id, med_rec, sec_rec, gen_rec, alt_titles, disab, used_skill, skills, skills_spec, organ_dat, limb_dat, gear," + TextQuery = "INSERT INTO characters_misc (char_id, med_rec, sec_rec, gen_rec, disab, used_skill, skills_spec, " TextQuery += "home_sys, citizen, faction, religion, NT_relation, uplink_loc, exploit_rec) VALUES (" - TextQuery += "'[char_id]', '[med_record]', '[sec_record]', '[gen_record]', '[player_alt_titles]', '[disabilities]', '[used_skillpoints]', '[skills]', " - TextQuery += "'[skill_specialization]', '[organ_data]', '[rlimb_data]', '[gear]', '[home_system]', '[citizenship]', '[faction]', '[religion]', '[nanotrasen_relation]', " + TextQuery += "'[char_id]', '[med_record]', '[sec_record]', '[gen_record]', '[disabilities]', '[used_skillpoints]', " + TextQuery += "'[skill_specialization]', '[home_system]', '[citizenship]', '[faction]', '[religion]', '[nanotrasen_relation]', " TextQuery += "'[uplinklocation]', '[exploit_record]')" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/UpdateMiscData() - TextQuery = "UPDATE characters_misc SET med_rec='[med_record]', sec_rec='[sec_record]', gen_rec='[gen_record]', alt_titles='[player_alt_titles]', disab='[disabilities]', " - TextQuery += "used_skill='[used_skillpoints]', skills='[skills]', skills_spec='[skill_specialization]', organ_dat='[organ_data]', limb_dat='[rlimb_data]', gear='[gear]', " + log_debug("update misc") + TextQuery = "UPDATE characters_misc SET med_rec='[med_record]', sec_rec='[sec_record]', gen_rec='[gen_record]', disab='[disabilities]', " + TextQuery += "used_skill='[used_skillpoints]', skills_spec='[skill_specialization]', " TextQuery += "home_sys='[home_system]', citizen='[citizenship]', faction='[faction]', religion='[religion]', NT_relation='[nanotrasen_relation]', uplink_loc='[uplinklocation]', " TextQuery += "exploit_rec='[exploit_record]' WHERE char_id = [char_id]" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/LoadMiscData() + log_debug("load_misc") TextQuery = "SELECT * FROM characters_misc WHERE char_id = [char_id]" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) if(!query.RowCount()) return 0 log_debug("Load query executed successfully") @@ -298,37 +342,256 @@ var/char_slot med_record = query.item[3] sec_record = query.item[4] gen_record = query.item[5] - player_alt_titles = query.item[6] - disabilities = query.item[7] - used_skillpoints = query.item[8] - skills = query.item[9] - skill_specialization = query.item[10] - organ_data = query.item[11] - rlimb_data = query.item[12] - gear = query.item[13] - home_system = query.item[14] - citizenship = query.item[15] - faction = query.item[16] - religion = query.item[17] - nanotrasen_relation = query.item[18] - uplinklocation = query.item[19] - exploit_record = query.item[20] + disabilities = query.item[6] + used_skillpoints = query.item[7] + skill_specialization = query.item[8] + home_system = query.item[9] + citizenship = query.item[10] + faction = query.item[11] + religion = query.item[12] + nanotrasen_relation = query.item[13] + uplinklocation = query.item[14] + exploit_record = query.item[15] + return 1 + +/datum/preferences/proc/InsertSkillsData() + log_debug("insert skills") + TextQuery = "INSERT INTO characters_skills (char_id, Command, Botany, Cooking, Close_Combat, Weapons_Expertise, Forensics, NanoTrasen_Law, EVA, " + TextQuery += "Construction, Electrical, Atmos, Engines, Heavy_Mach, Complex_Devices, Information_Tech, Genetics, Chemistry, Science, Medicine, Anatomy, Virology) VALUES " + TextQuery += "('[char_id]', '[skills["management"]]', '[skills["botany"]]', '[skills["cooking"]]', '[skills["combat"]]', '[skills["weapons"]]', '[skills["forensics"]]', '[skills["law"]]', '[skills["EVA"]]'," + TextQuery += " '[skills["construction"]]', '[skills["electrical"]]', '[skills["atmos"]]', '[skills["engines"]]', '[skills["pilot"]]', '[skills["devices"]]', '[skills["computer"]]', '[skills["genetics"]]'," + TextQuery += " '[skills["chemistry"]]', '[skills["science"]]', '[skills["medical"]]', '[skills["anatomy"]]', '[skills["virology"]]')" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) + return 1 + +/datum/preferences/proc/UpdateSkillsData() + log_debug("update skills") + TextQuery = "UPDATE characters_skills SET Command='[skills["management"]]', Botany='[skills["botany"]]', Cooking='[skills["cooking"]]', Close_Combat='[skills["combat"]]', " + TextQuery += "Weapons_Expertise='[skills["weapons"]]', Forensics='[skills["forensics"]]', NanoTrasen_Law='[skills["law"]]', EVA='[skills["EVA"]]', " + TextQuery += "Construction='[skills["construction"]]', Electrical='[skills["electrical"]]', Atmos='[skills["atmos"]]', Engines, Heavy_Mach='[skills["pilot"]]', Complex_Devices='[skills["devices"]]', " + TextQuery += "Information_Tech='[skills["computer"]]', Genetics='[skills["genetics"]]', Chemistry='[skills["chemistry"]]', Science='[skills["science"]]', Medicine='[skills["medical"]]', " + TextQuery += "Anatomy='[skills["anatomy"]]', Virology='[skills["virology"]]' WHERE char_id = '[char_id]'" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) + return 1 + +/datum/preferences/proc/LoadSkillsData() + log_debug("load skills") + TextQuery = "SELECT * FROM characters_skills WHERE char_id = '[char_id]'" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) + if(!query.RowCount()) + return 0 + log_debug("Load query executed successfully") + query.NextRow() + skills["management"] = query.item[3] + skills["botany"] = query.item[4] + skills["cooking"] = query.item[5] + skills["combat"] = query.item[6] + skills["weapons"] = query.item[7] + skills["forensics"] = query.item[8] + skills["law"] = query.item[9] + skills["EVA"] = query.item[10] + skills["construction"] = query.item[11] + skills["electrical"] = query.item[12] + skills["atmos"] = query.item[13] + skills["engines"] = query.item[14] + skills["pilot"] = query.item[15] + skills["devices"] = query.item[16] + skills["computer"] = query.item[17] + skills["genetics"] = query.item[18] + skills["chemistry"] = query.item[19] + skills["science"] = query.item[20] + skills["medical"] = query.item[21] + skills["anatomy"] = query.item[22] + skills["virology"] = query.item[23] + return 1 + +/datum/preferences/proc/InsertGearData() + log_debug("insert gear") + var/loop_id = 0 + for(var/gear_name in gear) + if(gear_name) + loop_id += 1 + switch(loop_id) + if(1) TextQuery = "INSERT INTO characters_gear (char_id, gear1) VALUES ('[char_id]', '[gear_name]')" + if(2) TextQuery = "UPDATE characters_gear SET gear2='[gear_name]' WHERE char_id = '[char_id]'" + if(3) TextQuery = "UPDATE characters_gear SET gear3='[gear_name]' WHERE char_id = '[char_id]'" + if(4) TextQuery = "UPDATE characters_gear SET gear4='[gear_name]' WHERE char_id = '[char_id]'" + if(5) TextQuery = "UPDATE characters_gear SET gear5='[gear_name]' WHERE char_id = '[char_id]'" + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) + else + TextQuery = "INSERT INTO characters_gear (char_id) VALUES ('[char_id]')" + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) + return 1 + +/datum/preferences/proc/UpdateGearData() + log_debug("update gear") + var/loop_id = 0 + for(var/gear_name in gear) + if(gear_name) + loop_id += 1 + switch(loop_id) + if(1) TextQuery = "UPDATE characters_gear SET gear1='[gear_name]' WHERE char_id = '[char_id]'" + if(2) TextQuery = "UPDATE characters_gear SET gear2='[gear_name]' WHERE char_id = '[char_id]'" + if(3) TextQuery = "UPDATE characters_gear SET gear3='[gear_name]' WHERE char_id = '[char_id]'" + if(4) TextQuery = "UPDATE characters_gear SET gear4='[gear_name]' WHERE char_id = '[char_id]'" + if(5) TextQuery = "UPDATE characters_gear SET gear5='[gear_name]' WHERE char_id = '[char_id]'" + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) + while(loop_id<5) + loop_id += 1 + switch(loop_id) + if(1) TextQuery = "UPDATE characters_gear SET gear1=NULL WHERE char_id = '[char_id]'" + if(2) TextQuery = "UPDATE characters_gear SET gear2=NULL WHERE char_id = '[char_id]'" + if(3) TextQuery = "UPDATE characters_gear SET gear3=NULL WHERE char_id = '[char_id]'" + if(4) TextQuery = "UPDATE characters_gear SET gear4=NULL WHERE char_id = '[char_id]'" + if(5) TextQuery = "UPDATE characters_gear SET gear5=NULL WHERE char_id = '[char_id]'" + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) + return 1 + +/datum/preferences/proc/LoadGearData() + log_debug("load gear") + TextQuery = "SELECT * FROM characters_gear WHERE char_id = '[char_id]'" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) + if(!query.RowCount()) + return 0 + log_debug("Load query executed successfully") + query.NextRow() + gear = list() + for(var/gear_name in query.item) + if(gear_name!=0) + gear += gear_name + return 1 + +/datum/preferences/proc/InsertOrgansData() + log_debug("insert organs") + sanitizePrefs() + TextQuery = "INSERT INTO characters_organs (char_id, l_leg, r_leg, l_arm, r_arm, l_foot, r_foot, l_hand, r_hand, heart, eyes) VALUES (" + TextQuery += "'[char_id]', '[organ_data["l_leg"]]', '[organ_data["r_leg"]]', '[organ_data["l_arm"]]', '[organ_data["r_arm"]]', '[organ_data["l_foot"]]', '[organ_data["r_foot"]]', " + TextQuery += "'[organ_data["l_hand"]]', '[organ_data["r_hand"]]', '[organ_data["heart"]]', '[organ_data["eyes"]]')" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) + InsertRorgansData() + return 1 + +/datum/preferences/proc/UpdateOrgansData() + log_debug("update organs") + sanitizePrefs() + TextQuery = "UPDATE characters_organs SET char_id='[char_id]', l_leg='[organ_data["l_leg"]]', r_leg='[organ_data["r_leg"]]', l_arm='[organ_data["l_arm"]]', r_arm='[organ_data["r_arm"]]', " + TextQuery += "l_foot='[organ_data["l_foot"]]', r_foot='[organ_data["r_foot"]]', l_hand='[organ_data["l_hand"]]', r_hand='[organ_data["r_hand"]]', heart='[organ_data["heart"]]', eyes='[organ_data["eyes"]]')" + TextQuery += " WHERE char_id = '[char_id]'" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) + UpdateRorgansData() + return 1 + +/datum/preferences/proc/LoadOrgansData() + log_debug("load organs") + TextQuery = "SELECT * FROM characters_organs WHERE char_id = '[char_id]'" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) + if(!query.RowCount()) + return 0 + log_debug("Load query executed successfully") + query.NextRow() + organ_data["l_leg"] = query.item[3] + organ_data["r_leg"] = query.item[4] + organ_data["l_arm"] = query.item[5] + organ_data["r_arm"] = query.item[6] + organ_data["l_foot"] = query.item[7] + organ_data["r_foot"] = query.item[8] + organ_data["l_hand"] = query.item[9] + organ_data["r_hand"] = query.item[10] + organ_data["heart"] = query.item[11] + organ_data["eyes"] = query.item[12] + LoadRorgansData() + return 1 + +/datum/preferences/proc/InsertRorgansData() + log_debug("insert robotics organs") + sanitizePrefs() + TextQuery = "INSERT INTO characters_rlimb (char_id, l_leg, r_leg, l_arm, r_arm, l_foot, r_foot, l_hand, r_hand) VALUES (" + TextQuery += "'[char_id]', '[rlimb_data["l_leg"]]', '[rlimb_data["r_leg"]]', '[rlimb_data["l_arm"]]', '[rlimb_data["r_arm"]]', '[rlimb_data["l_foot"]]', '[rlimb_data["r_foot"]]', " + TextQuery += "'[rlimb_data["l_hand"]]', '[rlimb_data["r_hand"]]')" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) + return 1 + +/datum/preferences/proc/UpdateRorgansData() + log_debug("update robotics organs") + sanitizePrefs() + TextQuery = "UPDATE characters_rlimb SET char_id='[char_id]', l_leg='[rlimb_data["l_leg"]]', r_leg='[rlimb_data["r_leg"]]', l_arm='[rlimb_data["l_arm"]]', r_arm='[rlimb_data["r_arm"]]', " + TextQuery += "l_foot='[rlimb_data["l_foot"]]', r_foot='[rlimb_data["r_foot"]]', l_hand='[rlimb_data["l_hand"]]', r_hand='[rlimb_data["r_hand"]]', heart='[rlimb_data["heart"]]', eyes='[rlimb_data["eyes"]]')" + TextQuery += " WHERE char_id = '[char_id]'" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) + return 1 + +/datum/preferences/proc/LoadRorgansData() + log_debug("load robotics organs") + TextQuery = "SELECT * FROM characters_rlimb WHERE char_id = '[char_id]'" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) + if(!query.RowCount()) + return 0 + log_debug("Load query executed successfully") + query.NextRow() + rlimb_data["l_leg"] = query.item[3] + rlimb_data["r_leg"] = query.item[4] + rlimb_data["l_arm"] = query.item[5] + rlimb_data["r_arm"] = query.item[6] + rlimb_data["l_foot"] = query.item[7] + rlimb_data["r_foot"] = query.item[8] + rlimb_data["l_hand"] = query.item[9] + rlimb_data["r_hand"] = query.item[10] return 1 /datum/preferences/proc/SavePrefData(var/ckey) - TextQuery = "SELECT * FROM characters_misc WHERE ckey = [ckey]" + TextQuery = "SELECT * FROM player_preferences WHERE ckey = [ckey]" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - if(query.RowCount()) + if(!query.RowCount()) + sanitizePrefs() + TextQuery = "INSERT INTO player_preferences (ckey, ooccolor, lastchangelog, UI_style, default_slot, toggles, UI_style_color, UI_style_alpha, be_special) " + TextQuery += "VALUES ('[ckey]', '[ooccolor]','[lastchangelog]', '[UI_style]', '[default_slot]', '[toggles]', '[UI_style_color]', '[UI_style_alpha]','[be_special]')" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) + return 1 + else return UpdatePrefData(ckey) - sanitizePrefs() - TextQuery = "INSERT INTO player_preferences (ckey, ooccolor, lastchangelog, UI_style, default_slot, toggles, UI_style_color, UI_style_alpha, be_special) " - TextQuery += "VALUES ('[ckey]', '[ooccolor]','[lastchangelog]', '[UI_style]', '[default_slot]', '[toggles]', '[UI_style_color]', '[UI_style_alpha]','[be_special]')" - log_debug(TextQuery) - query = dbcon.NewQuery(TextQuery) - query.Execute() - return 1 /datum/preferences/proc/UpdatePrefData(var/ckey) sanitizePrefs() @@ -337,15 +600,20 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/LoadPrefData(var/ckey) - TextQuery = "SELECT * FROM characters_misc WHERE ckey = [ckey]" + establish_db_connection() + if(!dbcon.IsConnected()) + return 0 + TextQuery = "SELECT * FROM player_preferences WHERE ckey = '[ckey]'" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() + log_debug(dbcon.ErrorMsg()) if(!query.RowCount()) - return SavePrefData(ckey) + return 0 log_debug("Load query executed successfully") query.NextRow() ooccolor = query.item[3] diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm index fc2f9bcb6cd..111b0677c98 100644 --- a/code/modules/client/preferences.dm +++ b/code/modules/client/preferences.dm @@ -140,10 +140,15 @@ datum/preferences if(istype(C)) if(!IsGuestKey(C.key)) load_path(C.ckey) - if(load_preferences()) - if(load_character()) + if(LoadPrefData(C.ckey)) + if(SQLload_character(default_slot)) current_slot = getCharSlot() return + /*if(load_preferences()) + if(load_character()) + current_slot = getCharSlot_File() + return*/ + //this ensure that if db fail the file system is used*/ gender = pick(MALE, FEMALE) real_name = random_name(gender,species) @@ -1595,16 +1600,29 @@ datum/preferences toggles ^= CHAT_GHOSTRADIO if("save") - save_preferences() - SQLsave_character(current_slot) - save_character() + for(var/ckey in preferences_datums) + var/datum/preferences/D = preferences_datums[ckey] + if(D == src) + //switch comment to switch to file save system + SavePrefData(ckey) + SQLsave_character(current_slot) + //save_preferences() + //save_character() if("reload") - load_preferences() - load_character() + for(var/ckey in preferences_datums) + var/datum/preferences/D = preferences_datums[ckey] + if(D == src) + //switch comment to switch to file save system + LoadPrefData(ckey) + SQLload_character(current_slot) + //load_preferences() + //load_character() if("open_load_dialog") if(!IsGuestKey(user.key)) + //file system preferences + //open_load_dialog_file(user) open_load_dialog(user) if("close_load_dialog") @@ -1612,7 +1630,10 @@ datum/preferences if("changeslot") current_slot = text2num(href_list["num"]) - load_character(current_slot) + SQLload_character(current_slot) + //file system load + //load_character() + close_load_dialog(user) ShowChoices(user) @@ -1730,6 +1751,42 @@ datum/preferences var/dat = "" dat += "
" + for(var/ckey in preferences_datums) + var/datum/preferences/D = preferences_datums[ckey] + if(D == src) + var/TextQuery = "SELECT Character_Name FROM SS13_characters WHERE ckey = '[ckey]' ORDER BY slot" + var/DBQuery/query + establish_db_connection() + if(!dbcon.IsConnected()) + open_load_dialog_file(user) + query = dbcon.NewQuery(TextQuery) + query.Execute() + var/rows + if(!query.RowCount()) + rows = 0 + else + rows = query.RowCount() + dat += "Select a character slot to load (SQL Edition !)
" + var/name + for(var/i=1, i<= config.character_slots, i++) + if(i<=rows) + query.NextRow() + name = query.item[i] + else name = "Character[i]" + if(i==default_slot) + name = "[name]" + dat += "[name]
" + + dat += "
" + dat += "Close
" + dat += "
" + user << browse(dat, "window=saves;size=300x390") + + +/datum/preferences/proc/open_load_dialog_file(mob/user) + var/dat = "" + dat += "
" + var/savefile/S = new /savefile(path) if(S) dat += "Select a character slot to load
" @@ -1747,7 +1804,25 @@ datum/preferences dat += "
" user << browse(dat, "window=saves;size=300x390") -/datum/preferences/proc/getCharSlot() //get character slot from savefile +/datum/preferences/proc/getCharSlot() + for(var/ckey in preferences_datums) + var/datum/preferences/D = preferences_datums[ckey] + if(D == src) + var/TextQuery = "SELECT slot FROM SS13_characters WHERE ckey = '[ckey]' AND name = '[real_name]'" + var/DBQuery/query + establish_db_connection() + if(!dbcon.IsConnected()) + getCharSlot_File() + query = dbcon.NewQuery(TextQuery) + query.Execute() + if(!query.RowCount()) + return 1 + query.NextRow() + return query.item[1] + return 1 + + +/datum/preferences/proc/getCharSlot_File() //get character slot from savefile var/savefile/S = new /savefile(path) if(S) var/name From 2f4c772d8ccd4363a71f4e69b8923493e2b026c0 Mon Sep 17 00:00:00 2001 From: Mahzel Date: Wed, 16 Mar 2016 22:40:47 +0100 Subject: [PATCH 4/7] Debugging SQL characters Fixed runtime errors while loading the game Fixed runtime errors while changing characters Fixed gear not being updated correctly. --- code/__HELPERS/logging.dm | 4 +- code/modules/client/client_saveSQL.dm | 161 +++++++++++++------------- code/modules/client/preferences.dm | 26 +++-- code/modules/mob/new_player/skill.dm | 5 - 4 files changed, 97 insertions(+), 99 deletions(-) diff --git a/code/__HELPERS/logging.dm b/code/__HELPERS/logging.dm index 23119c69ad5..1ae634f146a 100644 --- a/code/__HELPERS/logging.dm +++ b/code/__HELPERS/logging.dm @@ -31,6 +31,8 @@ diary << "\[[time_stamp()]]DEBUG: [text][log_end]" for(var/client/C in admins) + if(!C.prefs) //This is to avoid null.toggles runtime error while still initialyzing players preferences + return if(C.prefs.toggles & CHAT_DEBUGLOGS) C << "DEBUG: [text]" @@ -91,7 +93,7 @@ if(dir & WEST) comps += "WEST" if(dir & UP) comps += "UP" if(dir & DOWN) comps += "DOWN" - + return english_list(comps, nothing_text="0", and_text="|", comma_text="|") //more or less a logging utility diff --git a/code/modules/client/client_saveSQL.dm b/code/modules/client/client_saveSQL.dm index 90c61003dc7..00479f45313 100644 --- a/code/modules/client/client_saveSQL.dm +++ b/code/modules/client/client_saveSQL.dm @@ -36,7 +36,7 @@ var/char_slot InsertGearData() InsertOrgansData() log_debug(dbcon.ErrorMsg()) - TextQuery = "UPDATE SS13_characters SET Character_Name = (SELECT name FROM characters_data WHERE char_id = '[char_id]')" + TextQuery = "UPDATE SS13_characters SET Character_Name = (SELECT name FROM characters_data WHERE char_id = '[char_id]') WHERE id = '[char_id]'" query = dbcon.NewQuery(TextQuery) query.Execute() log_debug(dbcon.ErrorMsg()) @@ -56,12 +56,7 @@ var/char_slot log_debug("No ckey in datums") return 0 -/datum/preferences/proc/SQLload_character(slot) - var/pckey - for(var/ckey in preferences_datums) - var/datum/preferences/D = preferences_datums[ckey] - if(D == src) - pckey = ckey +/datum/preferences/proc/SQLload_character(var/slot, var/pckey) establish_db_connection() if(!dbcon.IsConnected()) return 0 @@ -77,6 +72,7 @@ var/char_slot if(LoadSkillsData()) if(LoadGearData()) if(LoadOrgansData()) + SanitizeCharacter() return 1 return 0 @@ -114,8 +110,8 @@ var/char_slot TextQuery = "UPDATE characters_data SET age = '[age]', backbag='[backbag]', b_type='[b_type]', eyes_B = '[b_eyes]', eyes_G='[g_eyes]', eyes_R='[r_eyes]'," TextQuery += "facial_B='[b_facial]', facial_G='[g_facial]', facial_R='[r_facial]', facial_style='[f_style]', gender = '[gender]', hair_B='[b_hair]', hair_G='[g_hair]'," TextQuery += "hair_R='[r_hair]', hair_style='[h_style]', isRandom='[be_random_name]', language='[language]', name='[real_name]', OOC='[metadata]',skin_B='[b_skin]', skin_G='[g_skin]'," - TextQuery += "skin_R='[r_skin]', skin_tone='[s_tone]', spawnpoint='[spawnpoint]', species='[species]', undershirt='[undershirt]', underwear='[underwear]' " - TextQuery += "WHERE char_id = [char_id]" + TextQuery += "skin_R='[r_skin]', skin_tone='[s_tone]', spawnpoint='[spawnpoint]', species='[species]', undershirt='[undershirt]', underwear='[underwear]'" + TextQuery += "WHERE char_id = '[char_id]'" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() @@ -126,7 +122,7 @@ var/char_slot log_debug("Load char data") TextQuery = "SELECT age, backbag, b_type, eyes_B, eyes_G, eyes_R, facial_B, facial_G, facial_R, facial_style, gender, " TextQuery += "hair_B, hair_G, hair_R, hair_style, isRandom, language, name, OOC, skin_B, skin_G, skin_R, skin_tone, spawnpoint, species, undershirt, underwear " - TextQuery += "FROM character_data WHERE char_id = [char_id]" + TextQuery += "FROM characters_data WHERE char_id = [char_id]" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() @@ -135,29 +131,29 @@ var/char_slot return 0 log_debug("Load query executed successfully") query.NextRow() - age = query.item[1] - backbag = query.item[2] - b_type = query.item[3] - b_eyes = query.item[4] - g_eyes = query.item[5] - r_eyes = query.item[6] - b_facial = query.item[7] - g_facial = query.item[8] - r_facial = query.item[9] + age = text2num(query.item[1]) + backbag = text2num(query.item[2]) + b_type = text2num(query.item[3]) + b_eyes = text2num(query.item[4]) + g_eyes = text2num(query.item[5]) + r_eyes = text2num(query.item[6]) + b_facial = text2num(query.item[7]) + g_facial = text2num(query.item[8]) + r_facial = text2num(query.item[9]) f_style = query.item[10] gender = query.item[11] - b_hair = query.item[12] - g_hair = query.item[13] - r_hair = query.item[14] + b_hair = text2num(query.item[12]) + g_hair = text2num(query.item[13]) + r_hair = text2num(query.item[14]) h_style = query.item[15] - be_random_name = query.item[16] + be_random_name = text2num(query.item[16]) language = query.item[17] real_name = query.item[18] metadata = query.item[19] - b_skin = query.item[20] - g_skin = query.item[21] - r_skin = query.item[22] - s_tone = query.item[23] + b_skin = text2num(query.item[20]) + g_skin = text2num(query.item[21]) + r_skin = text2num(query.item[22]) + s_tone = text2num(query.item[23]) spawnpoint = query.item[24] species = query.item[25] undershirt = query.item[26] @@ -197,16 +193,16 @@ var/char_slot return 0 log_debug("Load query executed successfully") query.NextRow() - alternate_option = query.item[3] - job_civilian_high = query.item[4] - job_civilian_med = query.item[5] - job_civilian_low = query.item[6] - job_medsci_high = query.item[7] - job_medsci_med = query.item[8] - job_medsci_low = query.item[9] - job_engsec_high = query.item[10] - job_engsec_med = query.item[11] - job_engsec_low = query.item[12] + alternate_option = text2num(query.item[3]) + job_civilian_high = text2num(query.item[4]) + job_civilian_med = text2num(query.item[5]) + job_civilian_low = text2num(query.item[6]) + job_medsci_high = text2num(query.item[7]) + job_medsci_med = text2num(query.item[8]) + job_medsci_low = text2num(query.item[9]) + job_engsec_high = text2num(query.item[10]) + job_engsec_med = text2num(query.item[11]) + job_engsec_low = text2num(query.item[12]) return 1 /datum/preferences/proc/InsertFlavourData() @@ -342,8 +338,8 @@ var/char_slot med_record = query.item[3] sec_record = query.item[4] gen_record = query.item[5] - disabilities = query.item[6] - used_skillpoints = query.item[7] + disabilities = text2num(query.item[6]) + used_skillpoints = text2num(query.item[7]) skill_specialization = query.item[8] home_system = query.item[9] citizenship = query.item[10] @@ -371,7 +367,7 @@ var/char_slot log_debug("update skills") TextQuery = "UPDATE characters_skills SET Command='[skills["management"]]', Botany='[skills["botany"]]', Cooking='[skills["cooking"]]', Close_Combat='[skills["combat"]]', " TextQuery += "Weapons_Expertise='[skills["weapons"]]', Forensics='[skills["forensics"]]', NanoTrasen_Law='[skills["law"]]', EVA='[skills["EVA"]]', " - TextQuery += "Construction='[skills["construction"]]', Electrical='[skills["electrical"]]', Atmos='[skills["atmos"]]', Engines, Heavy_Mach='[skills["pilot"]]', Complex_Devices='[skills["devices"]]', " + TextQuery += "Construction='[skills["construction"]]', Electrical='[skills["electrical"]]', Atmos='[skills["atmos"]]', Engines='[skills["engines"]]', Heavy_Mach='[skills["pilot"]]', Complex_Devices='[skills["devices"]]', " TextQuery += "Information_Tech='[skills["computer"]]', Genetics='[skills["genetics"]]', Chemistry='[skills["chemistry"]]', Science='[skills["science"]]', Medicine='[skills["medical"]]', " TextQuery += "Anatomy='[skills["anatomy"]]', Virology='[skills["virology"]]' WHERE char_id = '[char_id]'" log_debug(TextQuery) @@ -391,27 +387,27 @@ var/char_slot return 0 log_debug("Load query executed successfully") query.NextRow() - skills["management"] = query.item[3] - skills["botany"] = query.item[4] - skills["cooking"] = query.item[5] - skills["combat"] = query.item[6] - skills["weapons"] = query.item[7] - skills["forensics"] = query.item[8] - skills["law"] = query.item[9] - skills["EVA"] = query.item[10] - skills["construction"] = query.item[11] - skills["electrical"] = query.item[12] - skills["atmos"] = query.item[13] - skills["engines"] = query.item[14] - skills["pilot"] = query.item[15] - skills["devices"] = query.item[16] - skills["computer"] = query.item[17] - skills["genetics"] = query.item[18] - skills["chemistry"] = query.item[19] - skills["science"] = query.item[20] - skills["medical"] = query.item[21] - skills["anatomy"] = query.item[22] - skills["virology"] = query.item[23] + skills["management"] = text2num(query.item[3]) + skills["botany"] = text2num(query.item[4]) + skills["cooking"] = text2num(query.item[5]) + skills["combat"] = text2num(query.item[6]) + skills["weapons"] = text2num(query.item[7]) + skills["forensics"] = text2num(query.item[8]) + skills["law"] = text2num(query.item[9]) + skills["EVA"] = text2num(query.item[10]) + skills["construction"] = text2num(query.item[11]) + skills["electrical"] = text2num(query.item[12]) + skills["atmos"] = text2num(query.item[13]) + skills["engines"] = text2num(query.item[14]) + skills["pilot"] = text2num(query.item[15]) + skills["devices"] = text2num(query.item[16]) + skills["computer"] = text2num(query.item[17]) + skills["genetics"] = text2num(query.item[18]) + skills["chemistry"] = text2num(query.item[19]) + skills["science"] = text2num(query.item[20]) + skills["medical"] = text2num(query.item[21]) + skills["anatomy"] = text2num(query.item[22]) + skills["virology"] = text2num(query.item[23]) return 1 /datum/preferences/proc/InsertGearData() @@ -429,11 +425,6 @@ var/char_slot query = dbcon.NewQuery(TextQuery) query.Execute() log_debug(dbcon.ErrorMsg()) - else - TextQuery = "INSERT INTO characters_gear (char_id) VALUES ('[char_id]')" - query = dbcon.NewQuery(TextQuery) - query.Execute() - log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/UpdateGearData() @@ -454,11 +445,11 @@ var/char_slot while(loop_id<5) loop_id += 1 switch(loop_id) - if(1) TextQuery = "UPDATE characters_gear SET gear1=NULL WHERE char_id = '[char_id]'" - if(2) TextQuery = "UPDATE characters_gear SET gear2=NULL WHERE char_id = '[char_id]'" - if(3) TextQuery = "UPDATE characters_gear SET gear3=NULL WHERE char_id = '[char_id]'" - if(4) TextQuery = "UPDATE characters_gear SET gear4=NULL WHERE char_id = '[char_id]'" - if(5) TextQuery = "UPDATE characters_gear SET gear5=NULL WHERE char_id = '[char_id]'" + if(1) TextQuery = "UPDATE characters_gear SET gear1='NULL' WHERE char_id = '[char_id]'" + if(2) TextQuery = "UPDATE characters_gear SET gear2='NULL' WHERE char_id = '[char_id]'" + if(3) TextQuery = "UPDATE characters_gear SET gear3='NULL' WHERE char_id = '[char_id]'" + if(4) TextQuery = "UPDATE characters_gear SET gear4='NULL' WHERE char_id = '[char_id]'" + if(5) TextQuery = "UPDATE characters_gear SET gear5='NULL' WHERE char_id = '[char_id]'" query = dbcon.NewQuery(TextQuery) query.Execute() log_debug(dbcon.ErrorMsg()) @@ -476,9 +467,12 @@ var/char_slot log_debug("Load query executed successfully") query.NextRow() gear = list() + var/count = 1 for(var/gear_name in query.item) - if(gear_name!=0) - gear += gear_name + if(!(count>2)) + if(gear_name!=0) + gear += gear_name + count += 1 return 1 /datum/preferences/proc/InsertOrgansData() @@ -498,8 +492,8 @@ var/char_slot log_debug("update organs") sanitizePrefs() TextQuery = "UPDATE characters_organs SET char_id='[char_id]', l_leg='[organ_data["l_leg"]]', r_leg='[organ_data["r_leg"]]', l_arm='[organ_data["l_arm"]]', r_arm='[organ_data["r_arm"]]', " - TextQuery += "l_foot='[organ_data["l_foot"]]', r_foot='[organ_data["r_foot"]]', l_hand='[organ_data["l_hand"]]', r_hand='[organ_data["r_hand"]]', heart='[organ_data["heart"]]', eyes='[organ_data["eyes"]]')" - TextQuery += " WHERE char_id = '[char_id]'" + TextQuery += "l_foot='[organ_data["l_foot"]]', r_foot='[organ_data["r_foot"]]', l_hand='[organ_data["l_hand"]]', r_hand='[organ_data["r_hand"]]', heart='[organ_data["heart"]]', eyes='[organ_data["eyes"]]'" + TextQuery += " WHERE char_id='[char_id]'" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() @@ -547,7 +541,7 @@ var/char_slot log_debug("update robotics organs") sanitizePrefs() TextQuery = "UPDATE characters_rlimb SET char_id='[char_id]', l_leg='[rlimb_data["l_leg"]]', r_leg='[rlimb_data["r_leg"]]', l_arm='[rlimb_data["l_arm"]]', r_arm='[rlimb_data["r_arm"]]', " - TextQuery += "l_foot='[rlimb_data["l_foot"]]', r_foot='[rlimb_data["r_foot"]]', l_hand='[rlimb_data["l_hand"]]', r_hand='[rlimb_data["r_hand"]]', heart='[rlimb_data["heart"]]', eyes='[rlimb_data["eyes"]]')" + TextQuery += "l_foot='[rlimb_data["l_foot"]]', r_foot='[rlimb_data["r_foot"]]', l_hand='[rlimb_data["l_hand"]]', r_hand='[rlimb_data["r_hand"]]'" TextQuery += " WHERE char_id = '[char_id]'" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) @@ -577,7 +571,7 @@ var/char_slot return 1 /datum/preferences/proc/SavePrefData(var/ckey) - TextQuery = "SELECT * FROM player_preferences WHERE ckey = [ckey]" + TextQuery = "SELECT * FROM player_preferences WHERE ckey = '[ckey]'" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() @@ -596,7 +590,7 @@ var/char_slot /datum/preferences/proc/UpdatePrefData(var/ckey) sanitizePrefs() TextQuery = "UPDATE player_preferences SET ooccolor='[ooccolor]', lastchangelog='[lastchangelog]', UI_style='[UI_style]', default_slot='[default_slot]', toggles='[toggles]', " - TextQuery += "UI_style_color='[UI_style_color]', UI_style_alpha='[UI_style_alpha]', be_special='[be_special]') WHERE ckey = [ckey]" + TextQuery += "UI_style_color='[UI_style_color]', UI_style_alpha='[UI_style_alpha]', be_special='[be_special]' WHERE ckey = '[ckey]'" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() @@ -617,13 +611,14 @@ var/char_slot log_debug("Load query executed successfully") query.NextRow() ooccolor = query.item[3] - lastchangelog = query.item[4] + lastchangelog = text2num(query.item[4]) UI_style = query.item[5] - default_slot = query.item[6] - toggles = query.item[7] + default_slot = text2num(query.item[6]) + toggles = text2num(query.item[7]) UI_style_color = query.item[8] - UI_style_alpha = query.item[9] - be_special = query.item[10] + UI_style_alpha = text2num(query.item[9]) + be_special = text2num(query.item[10]) + sanitizePrefs() return 1 /datum/preferences/proc/sanitizePrefs() diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm index 111b0677c98..879ec709911 100644 --- a/code/modules/client/preferences.dm +++ b/code/modules/client/preferences.dm @@ -140,15 +140,16 @@ datum/preferences if(istype(C)) if(!IsGuestKey(C.key)) load_path(C.ckey) + log_debug("loading data for [C.ckey]") if(LoadPrefData(C.ckey)) - if(SQLload_character(default_slot)) + if(SQLload_character(default_slot, C.ckey)) current_slot = getCharSlot() return - /*if(load_preferences()) - if(load_character()) + if(load_preferences()) + if(load_character(default_slot)) current_slot = getCharSlot_File() - return*/ - //this ensure that if db fail the file system is used*/ + return + //this ensure that if db fail the file system is used gender = pick(MALE, FEMALE) real_name = random_name(gender,species) @@ -1605,7 +1606,7 @@ datum/preferences if(D == src) //switch comment to switch to file save system SavePrefData(ckey) - SQLsave_character(current_slot) + SQLsave_character(current_slot, ckey) //save_preferences() //save_character() @@ -1615,7 +1616,7 @@ datum/preferences if(D == src) //switch comment to switch to file save system LoadPrefData(ckey) - SQLload_character(current_slot) + SQLload_character(current_slot, ckey) //load_preferences() //load_character() @@ -1629,8 +1630,11 @@ datum/preferences close_load_dialog(user) if("changeslot") - current_slot = text2num(href_list["num"]) - SQLload_character(current_slot) + for(var/ckey in preferences_datums) + var/datum/preferences/D = preferences_datums[ckey] + if(D == src) + current_slot = text2num(href_list["num"]) + SQLload_character(current_slot, ckey) //file system load //load_character() @@ -1769,9 +1773,11 @@ datum/preferences dat += "Select a character slot to load (SQL Edition !)
" var/name for(var/i=1, i<= config.character_slots, i++) + log_debug("[rows] rows queried, i = [i]") if(i<=rows) query.NextRow() - name = query.item[i] + name = query.item[1] + log_debug("adding [query.item[1]] to list") else name = "Character[i]" if(i==default_slot) name = "[name]" diff --git a/code/modules/mob/new_player/skill.dm b/code/modules/mob/new_player/skill.dm index 1d6fbf01a42..66244e1d1f6 100644 --- a/code/modules/mob/new_player/skill.dm +++ b/code/modules/mob/new_player/skill.dm @@ -54,11 +54,6 @@ datum/skill/construction desc = "Your ability to construct various buildings, such as walls, floors, tables and so on. Note that constructing devices such as APCs additionally requires the Electronics skill. A low level of this skill is typical for janitors, a high level of this skill is typical for engineers." field = "Engineering" -datum/skill/management - ID = "management" - name = "Command" - desc = "Your ability to manage and commandeer other crew members." - datum/skill/knowledge/law ID = "law" name = "NanoTrasen Law" From ad7bbb25bce787f89955817edd97acbfdd3c47cc Mon Sep 17 00:00:00 2001 From: Mahzel Date: Fri, 18 Mar 2016 23:48:50 +0100 Subject: [PATCH 5/7] Characters DB R3 Corrected a bug when creating a new character Corrected gear management issues (SQL is so annoyed by NULL things :( ) Corrected a slot detection issue --- code/modules/client/client_saveSQL.dm | 69 +++++++++++++++++++++------ code/modules/client/preferences.dm | 21 +++++--- 2 files changed, 68 insertions(+), 22 deletions(-) diff --git a/code/modules/client/client_saveSQL.dm b/code/modules/client/client_saveSQL.dm index 00479f45313..60d7045015a 100644 --- a/code/modules/client/client_saveSQL.dm +++ b/code/modules/client/client_saveSQL.dm @@ -12,6 +12,9 @@ var/char_id var/char_slot /datum/preferences/proc/SQLsave_character(var/cslot) char_slot = cslot + if(!cslot) + log_debug("invalid slot") + return 0 for(var/ckey in preferences_datums) var/datum/preferences/D = preferences_datums[ckey] if(D == src) @@ -36,10 +39,6 @@ var/char_slot InsertGearData() InsertOrgansData() log_debug(dbcon.ErrorMsg()) - TextQuery = "UPDATE SS13_characters SET Character_Name = (SELECT name FROM characters_data WHERE char_id = '[char_id]') WHERE id = '[char_id]'" - query = dbcon.NewQuery(TextQuery) - query.Execute() - log_debug(dbcon.ErrorMsg()) else log_debug("ID = [char_id]") log_debug("Update entry") @@ -51,6 +50,10 @@ var/char_slot UpdateSkillsData() UpdateGearData() UpdateOrgansData() + TextQuery = "UPDATE SS13_characters SET Character_Name = (SELECT name FROM characters_data WHERE char_id = '[char_id]') WHERE id = '[char_id]'" + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) log_debug("Save query executed") return 1 log_debug("No ckey in datums") @@ -107,6 +110,10 @@ var/char_slot /datum/preferences/proc/UpdateCharData() log_debug("Update Char Data") + query = dbcon.NewQuery("SELECT id FROM characters_data WHERE char_id = '[char_id]'") + query.Execute() + if(!query.RowCount()) + InsertCharData() TextQuery = "UPDATE characters_data SET age = '[age]', backbag='[backbag]', b_type='[b_type]', eyes_B = '[b_eyes]', eyes_G='[g_eyes]', eyes_R='[r_eyes]'," TextQuery += "facial_B='[b_facial]', facial_G='[g_facial]', facial_R='[r_facial]', facial_style='[f_style]', gender = '[gender]', hair_B='[b_hair]', hair_G='[g_hair]'," TextQuery += "hair_R='[r_hair]', hair_style='[h_style]', isRandom='[be_random_name]', language='[language]', name='[real_name]', OOC='[metadata]',skin_B='[b_skin]', skin_G='[g_skin]'," @@ -118,6 +125,7 @@ var/char_slot log_debug(dbcon.ErrorMsg()) return 1 + /datum/preferences/proc/LoadCharData() log_debug("Load char data") TextQuery = "SELECT age, backbag, b_type, eyes_B, eyes_G, eyes_R, facial_B, facial_G, facial_R, facial_style, gender, " @@ -173,6 +181,10 @@ var/char_slot /datum/preferences/proc/UpdateJobsData() log_debug("update jobs") + query = dbcon.NewQuery("SELECT id FROM characters_jobs WHERE char_id = '[char_id]'") + query.Execute() + if(!query.RowCount()) + InsertJobsData() TextQuery = "UPDATE characters_jobs SET Alternate='[alternate_option]', civ_high='[job_civilian_high]', civ_med='[job_civilian_med]', civ_low='[job_civilian_low]', " TextQuery += "medsci_high='[job_medsci_high]', medsci_med='[job_medsci_med]', medsci_low='[job_medsci_low]', " TextQuery += "engsec_high='[job_engsec_high]', engsec_med='[job_engsec_med]', engsec_low='[job_engsec_low]' WHERE char_id = [char_id] " @@ -218,6 +230,10 @@ var/char_slot /datum/preferences/proc/UpdateFlavourData() log_debug("update flavour") + query = dbcon.NewQuery("SELECT id FROM characters_data WHERE char_id = '[char_id]'") + query.Execute() + if(!query.RowCount()) + InsertFlavourData() TextQuery = "UPDATE characters_flavour SET generals='[flavor_texts["general"]]', head='[flavor_texts["head"]]', face='[flavor_texts["face"]]', eyes='[flavor_texts["eyes"]]', " TextQuery += "torso='[flavor_texts["torso"]]', arms='[flavor_texts["arms"]]', hands='[flavor_texts["hands"]]', legs='[flavor_texts["legs"]]', feet='[flavor_texts["feet"]]' " TextQuery += "WHERE char_id = [char_id]" @@ -263,6 +279,10 @@ var/char_slot /datum/preferences/proc/UpdateRobotFlavourData() log_debug("update robot") + query = dbcon.NewQuery("SELECT id FROM characters_robot_flavour WHERE char_id = '[char_id]'") + query.Execute() + if(!query.RowCount()) + InsertRobotFlavourData() TextQuery = "UPDATE characters_robot_flavour SET Default_Robot='[flavour_texts_robot["Default"]]', Standard='[flavour_texts_robot["Standard"]]', Engineering='[flavour_texts_robot["Engineering"]]', " TextQuery += "Construction='[flavour_texts_robot["Construction"]]', Surgeon='[flavour_texts_robot["Surgeon"]]', Crisis='[flavour_texts_robot["Crisis"]]', Miner='[flavour_texts_robot["Miner"]]', " TextQuery += "Janitor='[flavour_texts_robot["Janitor"]]', Service='[flavour_texts_robot["Service"]]', Clerical='[flavour_texts_robot["Clerical"]]', " @@ -314,6 +334,10 @@ var/char_slot /datum/preferences/proc/UpdateMiscData() log_debug("update misc") + query = dbcon.NewQuery("SELECT id FROM characters_misc WHERE char_id = '[char_id]'") + query.Execute() + if(!query.RowCount()) + InsertMiscData() TextQuery = "UPDATE characters_misc SET med_rec='[med_record]', sec_rec='[sec_record]', gen_rec='[gen_record]', disab='[disabilities]', " TextQuery += "used_skill='[used_skillpoints]', skills_spec='[skill_specialization]', " TextQuery += "home_sys='[home_system]', citizen='[citizenship]', faction='[faction]', religion='[religion]', NT_relation='[nanotrasen_relation]', uplink_loc='[uplinklocation]', " @@ -365,6 +389,10 @@ var/char_slot /datum/preferences/proc/UpdateSkillsData() log_debug("update skills") + query = dbcon.NewQuery("SELECT id FROM characters_skills WHERE char_id = '[char_id]'") + query.Execute() + if(!query.RowCount()) + InsertSkillsData() TextQuery = "UPDATE characters_skills SET Command='[skills["management"]]', Botany='[skills["botany"]]', Cooking='[skills["cooking"]]', Close_Combat='[skills["combat"]]', " TextQuery += "Weapons_Expertise='[skills["weapons"]]', Forensics='[skills["forensics"]]', NanoTrasen_Law='[skills["law"]]', EVA='[skills["EVA"]]', " TextQuery += "Construction='[skills["construction"]]', Electrical='[skills["electrical"]]', Atmos='[skills["atmos"]]', Engines='[skills["engines"]]', Heavy_Mach='[skills["pilot"]]', Complex_Devices='[skills["devices"]]', " @@ -376,6 +404,7 @@ var/char_slot log_debug(dbcon.ErrorMsg()) return 1 + /datum/preferences/proc/LoadSkillsData() log_debug("load skills") TextQuery = "SELECT * FROM characters_skills WHERE char_id = '[char_id]'" @@ -422,6 +451,7 @@ var/char_slot if(3) TextQuery = "UPDATE characters_gear SET gear3='[gear_name]' WHERE char_id = '[char_id]'" if(4) TextQuery = "UPDATE characters_gear SET gear4='[gear_name]' WHERE char_id = '[char_id]'" if(5) TextQuery = "UPDATE characters_gear SET gear5='[gear_name]' WHERE char_id = '[char_id]'" + log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() log_debug(dbcon.ErrorMsg()) @@ -429,6 +459,10 @@ var/char_slot /datum/preferences/proc/UpdateGearData() log_debug("update gear") + query = dbcon.NewQuery("SELECT id FROM characters_gear WHERE char_id = '[char_id]'") + query.Execute() + if(!query.RowCount()) + InsertGearData() var/loop_id = 0 for(var/gear_name in gear) if(gear_name) @@ -439,17 +473,19 @@ var/char_slot if(3) TextQuery = "UPDATE characters_gear SET gear3='[gear_name]' WHERE char_id = '[char_id]'" if(4) TextQuery = "UPDATE characters_gear SET gear4='[gear_name]' WHERE char_id = '[char_id]'" if(5) TextQuery = "UPDATE characters_gear SET gear5='[gear_name]' WHERE char_id = '[char_id]'" + log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() log_debug(dbcon.ErrorMsg()) while(loop_id<5) loop_id += 1 switch(loop_id) - if(1) TextQuery = "UPDATE characters_gear SET gear1='NULL' WHERE char_id = '[char_id]'" - if(2) TextQuery = "UPDATE characters_gear SET gear2='NULL' WHERE char_id = '[char_id]'" - if(3) TextQuery = "UPDATE characters_gear SET gear3='NULL' WHERE char_id = '[char_id]'" - if(4) TextQuery = "UPDATE characters_gear SET gear4='NULL' WHERE char_id = '[char_id]'" - if(5) TextQuery = "UPDATE characters_gear SET gear5='NULL' WHERE char_id = '[char_id]'" + if(1) TextQuery = "UPDATE characters_gear SET gear1='none' WHERE char_id = '[char_id]'" + if(2) TextQuery = "UPDATE characters_gear SET gear2='none' WHERE char_id = '[char_id]'" + if(3) TextQuery = "UPDATE characters_gear SET gear3='none' WHERE char_id = '[char_id]'" + if(4) TextQuery = "UPDATE characters_gear SET gear4='none' WHERE char_id = '[char_id]'" + if(5) TextQuery = "UPDATE characters_gear SET gear5='none' WHERE char_id = '[char_id]'" + log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() log_debug(dbcon.ErrorMsg()) @@ -469,15 +505,14 @@ var/char_slot gear = list() var/count = 1 for(var/gear_name in query.item) - if(!(count>2)) - if(gear_name!=0) + if(count>2) + if(gear_name!="none") gear += gear_name count += 1 return 1 /datum/preferences/proc/InsertOrgansData() log_debug("insert organs") - sanitizePrefs() TextQuery = "INSERT INTO characters_organs (char_id, l_leg, r_leg, l_arm, r_arm, l_foot, r_foot, l_hand, r_hand, heart, eyes) VALUES (" TextQuery += "'[char_id]', '[organ_data["l_leg"]]', '[organ_data["r_leg"]]', '[organ_data["l_arm"]]', '[organ_data["r_arm"]]', '[organ_data["l_foot"]]', '[organ_data["r_foot"]]', " TextQuery += "'[organ_data["l_hand"]]', '[organ_data["r_hand"]]', '[organ_data["heart"]]', '[organ_data["eyes"]]')" @@ -490,7 +525,10 @@ var/char_slot /datum/preferences/proc/UpdateOrgansData() log_debug("update organs") - sanitizePrefs() + query = dbcon.NewQuery("SELECT id FROM characters_organs WHERE char_id = '[char_id]'") + query.Execute() + if(!query.RowCount()) + InsertOrgansData() TextQuery = "UPDATE characters_organs SET char_id='[char_id]', l_leg='[organ_data["l_leg"]]', r_leg='[organ_data["r_leg"]]', l_arm='[organ_data["l_arm"]]', r_arm='[organ_data["r_arm"]]', " TextQuery += "l_foot='[organ_data["l_foot"]]', r_foot='[organ_data["r_foot"]]', l_hand='[organ_data["l_hand"]]', r_hand='[organ_data["r_hand"]]', heart='[organ_data["heart"]]', eyes='[organ_data["eyes"]]'" TextQuery += " WHERE char_id='[char_id]'" @@ -527,7 +565,6 @@ var/char_slot /datum/preferences/proc/InsertRorgansData() log_debug("insert robotics organs") - sanitizePrefs() TextQuery = "INSERT INTO characters_rlimb (char_id, l_leg, r_leg, l_arm, r_arm, l_foot, r_foot, l_hand, r_hand) VALUES (" TextQuery += "'[char_id]', '[rlimb_data["l_leg"]]', '[rlimb_data["r_leg"]]', '[rlimb_data["l_arm"]]', '[rlimb_data["r_arm"]]', '[rlimb_data["l_foot"]]', '[rlimb_data["r_foot"]]', " TextQuery += "'[rlimb_data["l_hand"]]', '[rlimb_data["r_hand"]]')" @@ -539,7 +576,6 @@ var/char_slot /datum/preferences/proc/UpdateRorgansData() log_debug("update robotics organs") - sanitizePrefs() TextQuery = "UPDATE characters_rlimb SET char_id='[char_id]', l_leg='[rlimb_data["l_leg"]]', r_leg='[rlimb_data["r_leg"]]', l_arm='[rlimb_data["l_arm"]]', r_arm='[rlimb_data["r_arm"]]', " TextQuery += "l_foot='[rlimb_data["l_foot"]]', r_foot='[rlimb_data["r_foot"]]', l_hand='[rlimb_data["l_hand"]]', r_hand='[rlimb_data["r_hand"]]'" TextQuery += " WHERE char_id = '[char_id]'" @@ -571,6 +607,7 @@ var/char_slot return 1 /datum/preferences/proc/SavePrefData(var/ckey) + log_debug("Save pref data") TextQuery = "SELECT * FROM player_preferences WHERE ckey = '[ckey]'" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) @@ -588,6 +625,7 @@ var/char_slot return UpdatePrefData(ckey) /datum/preferences/proc/UpdatePrefData(var/ckey) + log_debug("Update pref data") sanitizePrefs() TextQuery = "UPDATE player_preferences SET ooccolor='[ooccolor]', lastchangelog='[lastchangelog]', UI_style='[UI_style]', default_slot='[default_slot]', toggles='[toggles]', " TextQuery += "UI_style_color='[UI_style_color]', UI_style_alpha='[UI_style_alpha]', be_special='[be_special]' WHERE ckey = '[ckey]'" @@ -598,6 +636,7 @@ var/char_slot return 1 /datum/preferences/proc/LoadPrefData(var/ckey) + log_debug("load pref data") establish_db_connection() if(!dbcon.IsConnected()) return 0 diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm index 879ec709911..0cff4c0ad8a 100644 --- a/code/modules/client/preferences.dm +++ b/code/modules/client/preferences.dm @@ -142,8 +142,10 @@ datum/preferences load_path(C.ckey) log_debug("loading data for [C.ckey]") if(LoadPrefData(C.ckey)) + log_debug("Default slot loaded : [default_slot]") if(SQLload_character(default_slot, C.ckey)) - current_slot = getCharSlot() + current_slot = default_slot + log_debug("Character [real_name] loaded, slot is [current_slot]") return if(load_preferences()) if(load_character(default_slot)) @@ -1605,6 +1607,7 @@ datum/preferences var/datum/preferences/D = preferences_datums[ckey] if(D == src) //switch comment to switch to file save system + default_slot = current_slot SavePrefData(ckey) SQLsave_character(current_slot, ckey) //save_preferences() @@ -1634,10 +1637,14 @@ datum/preferences var/datum/preferences/D = preferences_datums[ckey] if(D == src) current_slot = text2num(href_list["num"]) - SQLload_character(current_slot, ckey) + if(!SQLload_character(current_slot, ckey)) + gender = pick(MALE, FEMALE) + real_name = random_name(gender,species) + gear.Cut() + ZeroSkills(1) + ResetJobs() //file system load //load_character() - close_load_dialog(user) ShowChoices(user) @@ -1790,7 +1797,7 @@ datum/preferences /datum/preferences/proc/open_load_dialog_file(mob/user) - var/dat = "" +/* var/dat = "" dat += "
" var/savefile/S = new /savefile(path) @@ -1808,13 +1815,13 @@ datum/preferences dat += "
" dat += "Close
" dat += "
" - user << browse(dat, "window=saves;size=300x390") + user << browse(dat, "window=saves;size=300x390")*/ /datum/preferences/proc/getCharSlot() for(var/ckey in preferences_datums) var/datum/preferences/D = preferences_datums[ckey] if(D == src) - var/TextQuery = "SELECT slot FROM SS13_characters WHERE ckey = '[ckey]' AND name = '[real_name]'" + var/TextQuery = "SELECT slot FROM SS13_characters WHERE ckey = '[ckey]' AND Character_Name = '[real_name]'" var/DBQuery/query establish_db_connection() if(!dbcon.IsConnected()) @@ -1824,7 +1831,7 @@ datum/preferences if(!query.RowCount()) return 1 query.NextRow() - return query.item[1] + return text2num(query.item[1]) return 1 From 9de0a7e04abdf188d23d01678825503a34d171ca Mon Sep 17 00:00:00 2001 From: Mahzel Date: Tue, 22 Mar 2016 23:42:45 +0100 Subject: [PATCH 6/7] Characters continued Alt_titles finally added Gear bug at first insertion corrected --- SQL/aurora_characters_db.sql | 229 +++++--------------------- code/modules/client/client_saveSQL.dm | 21 ++- 2 files changed, 57 insertions(+), 193 deletions(-) diff --git a/SQL/aurora_characters_db.sql b/SQL/aurora_characters_db.sql index 4b89f730ca1..df573aa3da3 100644 --- a/SQL/aurora_characters_db.sql +++ b/SQL/aurora_characters_db.sql @@ -1,30 +1,10 @@ --- phpMyAdmin SQL Dump --- version 4.5.3.1 --- http://www.phpmyadmin.net --- --- Host: 127.0.0.1 --- Generation Time: Mar 15, 2016 at 10:38 PM --- Server version: 5.7.10 --- PHP Version: 5.6.17 - SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; -SET time_zone = "+00:00"; - /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; --- --- Database: `aurora_test` --- - --- -------------------------------------------------------- - --- --- Table structure for table `characters_data` --- CREATE TABLE `characters_data` ( `Id` int(11) NOT NULL, @@ -58,12 +38,6 @@ CREATE TABLE `characters_data` ( `spawnpoint` varchar(32) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; --- -------------------------------------------------------- - --- --- Table structure for table `characters_flavour` --- - CREATE TABLE `characters_flavour` ( `id` int(11) NOT NULL, `char_id` int(11) NOT NULL, @@ -78,28 +52,16 @@ CREATE TABLE `characters_flavour` ( `feet` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT; --- -------------------------------------------------------- - --- --- Table structure for table `characters_gear` --- - CREATE TABLE `characters_gear` ( `id` int(11) NOT NULL, `char_id` int(11) NOT NULL, - `gear1` text, - `gear2` text, - `gear3` text, - `gear4` text, - `gear5` text + `gear1` varchar(64) DEFAULT 'none', + `gear2` varchar(64) DEFAULT 'none', + `gear3` varchar(64) DEFAULT 'none', + `gear4` varchar(64) DEFAULT 'none', + `gear5` varchar(64) DEFAULT 'none' ) ENGINE=InnoDB DEFAULT CHARSET=latin1; --- -------------------------------------------------------- - --- --- Table structure for table `characters_jobs` --- - CREATE TABLE `characters_jobs` ( `id` int(11) NOT NULL, `char_id` int(11) NOT NULL, @@ -112,15 +74,10 @@ CREATE TABLE `characters_jobs` ( `medsci_low` int(11) NOT NULL, `engsec_high` int(11) NOT NULL, `engsec_med` int(11) NOT NULL, - `engsec_low` int(11) NOT NULL + `engsec_low` int(11) NOT NULL, + `alt_titles` mediumtext NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT; --- -------------------------------------------------------- - --- --- Table structure for table `characters_misc` --- - CREATE TABLE `characters_misc` ( `id` int(11) NOT NULL, `char_id` int(11) NOT NULL, @@ -128,7 +85,7 @@ CREATE TABLE `characters_misc` ( `sec_rec` text NOT NULL, `gen_rec` text NOT NULL, `disab` text NOT NULL, - `used_skill` text NOT NULL, + `used_skill` int(11) NOT NULL, `skills_spec` text NOT NULL, `home_sys` text NOT NULL, `citizen` text NOT NULL, @@ -139,12 +96,6 @@ CREATE TABLE `characters_misc` ( `exploit_rec` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; --- -------------------------------------------------------- - --- --- Table structure for table `characters_organs` --- - CREATE TABLE `characters_organs` ( `id` int(11) NOT NULL, `char_id` int(11) NOT NULL, @@ -160,12 +111,6 @@ CREATE TABLE `characters_organs` ( `eyes` text ) ENGINE=InnoDB DEFAULT CHARSET=latin1; --- -------------------------------------------------------- - --- --- Table structure for table `characters_rlimb` --- - CREATE TABLE `characters_rlimb` ( `id` int(11) NOT NULL, `char_id` int(11) NOT NULL, @@ -179,12 +124,6 @@ CREATE TABLE `characters_rlimb` ( `r_hand` text ) ENGINE=InnoDB DEFAULT CHARSET=latin1; --- -------------------------------------------------------- - --- --- Table structure for table `characters_robot_flavour` --- - CREATE TABLE `characters_robot_flavour` ( `id` int(11) NOT NULL, `char_id` int(11) DEFAULT NULL, @@ -202,44 +141,32 @@ CREATE TABLE `characters_robot_flavour` ( `Research` text ) ENGINE=InnoDB DEFAULT CHARSET=latin1; --- -------------------------------------------------------- - --- --- Table structure for table `characters_skills` --- - CREATE TABLE `characters_skills` ( `id` int(11) NOT NULL, `char_id` int(11) NOT NULL, - `Command` int(11) NOT NULL, - `Botany` int(11) NOT NULL, - `Cooking` int(11) NOT NULL, - `Close_Combat` int(11) NOT NULL, - `Weapons_Expertise` int(11) NOT NULL, - `Forensics` int(11) NOT NULL, - `NanoTrasen_Law` int(11) NOT NULL, - `EVA` int(11) NOT NULL, - `Construction` int(11) NOT NULL, - `Electrical` int(11) NOT NULL, - `Atmos` int(11) NOT NULL, - `Engines` int(11) NOT NULL, - `Heavy_Mach` int(11) NOT NULL, - `Complex_Devices` int(11) NOT NULL, - `Information_Tech` int(11) NOT NULL, - `Genetics` int(11) NOT NULL, - `Chemistry` int(11) NOT NULL, - `Science` int(11) NOT NULL, - `Medicine` int(11) NOT NULL, - `Anatomy` int(11) NOT NULL, - `Virology` int(11) NOT NULL + `Command` int(11) DEFAULT NULL, + `Botany` int(11) DEFAULT NULL, + `Cooking` int(11) DEFAULT NULL, + `Close_Combat` int(11) DEFAULT NULL, + `Weapons_Expertise` int(11) DEFAULT NULL, + `Forensics` int(11) DEFAULT NULL, + `NanoTrasen_Law` int(11) DEFAULT NULL, + `EVA` int(11) DEFAULT NULL, + `Construction` int(11) DEFAULT NULL, + `Electrical` int(11) DEFAULT NULL, + `Atmos` int(11) DEFAULT NULL, + `Engines` int(11) DEFAULT NULL, + `Heavy_Mach` int(11) DEFAULT NULL, + `Complex_Devices` int(11) DEFAULT NULL, + `Information_Tech` int(11) DEFAULT NULL, + `Genetics` int(11) DEFAULT NULL, + `Chemistry` int(11) DEFAULT NULL, + `Science` int(11) DEFAULT NULL, + `Medicine` int(11) DEFAULT NULL, + `Anatomy` int(11) DEFAULT NULL, + `Virology` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; --- -------------------------------------------------------- - --- --- Table structure for table `player_preferences` --- - CREATE TABLE `player_preferences` ( `id` int(11) NOT NULL, `ckey` text NOT NULL, @@ -253,12 +180,6 @@ CREATE TABLE `player_preferences` ( `be_special` int(11) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; --- -------------------------------------------------------- - --- --- Table structure for table `ss13_characters` --- - CREATE TABLE `ss13_characters` ( `id` int(11) NOT NULL, `ckey` varchar(32) DEFAULT NULL, @@ -266,135 +187,63 @@ CREATE TABLE `ss13_characters` ( `Character_Name` text ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT; --- --- Indexes for dumped tables --- --- --- Indexes for table `characters_data` --- ALTER TABLE `characters_data` ADD PRIMARY KEY (`Id`); --- --- Indexes for table `characters_flavour` --- ALTER TABLE `characters_flavour` ADD PRIMARY KEY (`id`); --- --- Indexes for table `characters_gear` --- ALTER TABLE `characters_gear` ADD PRIMARY KEY (`id`); --- --- Indexes for table `characters_jobs` --- ALTER TABLE `characters_jobs` ADD PRIMARY KEY (`id`); --- --- Indexes for table `characters_misc` --- ALTER TABLE `characters_misc` ADD PRIMARY KEY (`id`); --- --- Indexes for table `characters_organs` --- ALTER TABLE `characters_organs` ADD PRIMARY KEY (`id`); --- --- Indexes for table `characters_rlimb` --- ALTER TABLE `characters_rlimb` ADD PRIMARY KEY (`id`); --- --- Indexes for table `characters_robot_flavour` --- ALTER TABLE `characters_robot_flavour` ADD PRIMARY KEY (`id`); --- --- Indexes for table `characters_skills` --- ALTER TABLE `characters_skills` ADD PRIMARY KEY (`id`); --- --- Indexes for table `player_preferences` --- ALTER TABLE `player_preferences` ADD PRIMARY KEY (`id`); --- --- Indexes for table `ss13_characters` --- ALTER TABLE `ss13_characters` ADD PRIMARY KEY (`id`); --- --- AUTO_INCREMENT for dumped tables --- --- --- AUTO_INCREMENT for table `characters_data` --- ALTER TABLE `characters_data` - MODIFY `Id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; --- --- AUTO_INCREMENT for table `characters_flavour` --- + MODIFY `Id` int(11) NOT NULL AUTO_INCREMENT; ALTER TABLE `characters_flavour` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; --- --- AUTO_INCREMENT for table `characters_gear` --- + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; ALTER TABLE `characters_gear` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6; --- --- AUTO_INCREMENT for table `characters_jobs` --- + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; ALTER TABLE `characters_jobs` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; --- --- AUTO_INCREMENT for table `characters_misc` --- + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; ALTER TABLE `characters_misc` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; --- --- AUTO_INCREMENT for table `characters_organs` --- + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; ALTER TABLE `characters_organs` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2; --- --- AUTO_INCREMENT for table `characters_rlimb` --- + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; ALTER TABLE `characters_rlimb` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2; --- --- AUTO_INCREMENT for table `characters_robot_flavour` --- + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; ALTER TABLE `characters_robot_flavour` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; --- --- AUTO_INCREMENT for table `characters_skills` --- + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; ALTER TABLE `characters_skills` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; --- --- AUTO_INCREMENT for table `player_preferences` --- + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; ALTER TABLE `player_preferences` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; --- --- AUTO_INCREMENT for table `ss13_characters` --- ALTER TABLE `ss13_characters` - MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8; + MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; diff --git a/code/modules/client/client_saveSQL.dm b/code/modules/client/client_saveSQL.dm index 60d7045015a..9c4147d7f94 100644 --- a/code/modules/client/client_saveSQL.dm +++ b/code/modules/client/client_saveSQL.dm @@ -170,9 +170,10 @@ var/char_slot /datum/preferences/proc/InsertJobsData() log_debug("Insert jobs") - TextQuery = "INSERT INTO characters_jobs (char_id, Alternate, civ_high, civ_med, civ_low, medsci_high, medsci_med, medsci_low, engsec_high, engsec_med, engsec_low) " + var/alt_titles_list = list2params(player_alt_titles) + TextQuery = "INSERT INTO characters_jobs (char_id, Alternate, civ_high, civ_med, civ_low, medsci_high, medsci_med, medsci_low, engsec_high, engsec_med, engsec_low, alt_titles) " TextQuery += " VALUES ('[char_id]','[alternate_option]', '[job_civilian_high]', '[job_civilian_med]', '[job_civilian_low]', '[job_medsci_high]', '[job_medsci_med]', '[job_medsci_low]', " - TextQuery += "'[job_engsec_high]', '[job_engsec_med]', '[job_engsec_low]')" + TextQuery += "'[job_engsec_high]', '[job_engsec_med]', '[job_engsec_low]', '[alt_titles_list]')" log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() @@ -185,9 +186,10 @@ var/char_slot query.Execute() if(!query.RowCount()) InsertJobsData() + var/alt_titles_list = list2params(player_alt_titles) TextQuery = "UPDATE characters_jobs SET Alternate='[alternate_option]', civ_high='[job_civilian_high]', civ_med='[job_civilian_med]', civ_low='[job_civilian_low]', " TextQuery += "medsci_high='[job_medsci_high]', medsci_med='[job_medsci_med]', medsci_low='[job_medsci_low]', " - TextQuery += "engsec_high='[job_engsec_high]', engsec_med='[job_engsec_med]', engsec_low='[job_engsec_low]' WHERE char_id = [char_id] " + TextQuery += "engsec_high='[job_engsec_high]', engsec_med='[job_engsec_med]', engsec_low='[job_engsec_low]', alt_titles = '[alt_titles_list]' WHERE char_id = [char_id] " log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() @@ -215,6 +217,7 @@ var/char_slot job_engsec_high = text2num(query.item[10]) job_engsec_med = text2num(query.item[11]) job_engsec_low = text2num(query.item[12]) + player_alt_titles = params2list(query.item[13]) return 1 /datum/preferences/proc/InsertFlavourData() @@ -455,6 +458,18 @@ var/char_slot query = dbcon.NewQuery(TextQuery) query.Execute() log_debug(dbcon.ErrorMsg()) + while(loop_id<5) + loop_id += 1 + switch(loop_id) + if(1) TextQuery = "INSERT INTO characters_gear (char_id, gear1) VALUES ('[char_id]', 'none')" + if(2) TextQuery = "UPDATE characters_gear SET gear2='none' WHERE char_id = '[char_id]'" + if(3) TextQuery = "UPDATE characters_gear SET gear3='none' WHERE char_id = '[char_id]'" + if(4) TextQuery = "UPDATE characters_gear SET gear4='none' WHERE char_id = '[char_id]'" + if(5) TextQuery = "UPDATE characters_gear SET gear5='none' WHERE char_id = '[char_id]'" + log_debug(TextQuery) + query = dbcon.NewQuery(TextQuery) + query.Execute() + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/UpdateGearData() From 3b383ad315a4255644887486d2d4683b682e3be9 Mon Sep 17 00:00:00 2001 From: Mahzel Date: Wed, 23 Mar 2016 18:04:52 +0100 Subject: [PATCH 7/7] #109 update moved variables inside preferences datum switched gear to the list2params trick (cleaner, faster, easier) enabled intial character file system --- SQL/aurora_characters_db.sql | 7 +- code/modules/client/client_saveSQL.dm | 174 ++++++++++++-------------- code/modules/client/preferences.dm | 18 ++- 3 files changed, 92 insertions(+), 107 deletions(-) diff --git a/SQL/aurora_characters_db.sql b/SQL/aurora_characters_db.sql index df573aa3da3..b9eedf52a70 100644 --- a/SQL/aurora_characters_db.sql +++ b/SQL/aurora_characters_db.sql @@ -1,4 +1,5 @@ SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; +SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; @@ -55,11 +56,7 @@ CREATE TABLE `characters_flavour` ( CREATE TABLE `characters_gear` ( `id` int(11) NOT NULL, `char_id` int(11) NOT NULL, - `gear1` varchar(64) DEFAULT 'none', - `gear2` varchar(64) DEFAULT 'none', - `gear3` varchar(64) DEFAULT 'none', - `gear4` varchar(64) DEFAULT 'none', - `gear5` varchar(64) DEFAULT 'none' + `gear` mediumtext ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE `characters_jobs` ( diff --git a/code/modules/client/client_saveSQL.dm b/code/modules/client/client_saveSQL.dm index 9c4147d7f94..6e988ccdf59 100644 --- a/code/modules/client/client_saveSQL.dm +++ b/code/modules/client/client_saveSQL.dm @@ -2,14 +2,7 @@ //MAKE SURE YOU KEEP THIS UP TO DATE! //if the db can't be updated, return 0 //if the db was updated, return 1 -var/chardata[] -var/jobsdata[] -var/flavourdata[] -var/miscdata[] -var/DBQuery/query -var/TextQuery -var/char_id -var/char_slot + /datum/preferences/proc/SQLsave_character(var/cslot) char_slot = cslot if(!cslot) @@ -28,7 +21,8 @@ var/char_slot log_debug("New Character") query = dbcon.NewQuery("INSERT INTO ss13_characters (ckey, slot) VALUES ('[ckey]', '[cslot]')") query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) getCharId(ckey) InsertCharData() InsertJobsData() @@ -38,7 +32,6 @@ var/char_slot InsertSkillsData() InsertGearData() InsertOrgansData() - log_debug(dbcon.ErrorMsg()) else log_debug("ID = [char_id]") log_debug("Update entry") @@ -53,7 +46,8 @@ var/char_slot TextQuery = "UPDATE SS13_characters SET Character_Name = (SELECT name FROM characters_data WHERE char_id = '[char_id]') WHERE id = '[char_id]'" query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) log_debug("Save query executed") return 1 log_debug("No ckey in datums") @@ -85,7 +79,8 @@ var/char_slot query = dbcon.NewQuery(TextQuery) log_debug("Query ready") query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) var/rowDebug = query.RowCount() log_debug("Query executed, [rowDebug] rows") if(!query.RowCount()) @@ -105,7 +100,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/UpdateCharData() @@ -122,7 +118,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) return 1 @@ -134,7 +131,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) if(!query.RowCount()) return 0 log_debug("Load query executed successfully") @@ -177,7 +175,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/UpdateJobsData() @@ -193,7 +192,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/LoadJobsData() @@ -202,7 +202,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) if(!query.RowCount()) return 0 log_debug("Load query executed successfully") @@ -228,7 +229,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/UpdateFlavourData() @@ -243,7 +245,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/LoadFlavourData() @@ -252,7 +255,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) if(!query.RowCount()) return 0 log_debug("Load query executed successfully") @@ -277,7 +281,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/UpdateRobotFlavourData() @@ -293,7 +298,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/LoadRobotFlavourData() @@ -302,7 +308,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) if(!query.RowCount()) return 0 log_debug("Load query executed successfully") @@ -332,7 +339,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/UpdateMiscData() @@ -348,7 +356,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/LoadMiscData() @@ -357,7 +366,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) if(!query.RowCount()) return 0 log_debug("Load query executed successfully") @@ -387,7 +397,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/UpdateSkillsData() @@ -404,7 +415,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) return 1 @@ -414,7 +426,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) if(!query.RowCount()) return 0 log_debug("Load query executed successfully") @@ -444,31 +457,13 @@ var/char_slot /datum/preferences/proc/InsertGearData() log_debug("insert gear") - var/loop_id = 0 - for(var/gear_name in gear) - if(gear_name) - loop_id += 1 - switch(loop_id) - if(1) TextQuery = "INSERT INTO characters_gear (char_id, gear1) VALUES ('[char_id]', '[gear_name]')" - if(2) TextQuery = "UPDATE characters_gear SET gear2='[gear_name]' WHERE char_id = '[char_id]'" - if(3) TextQuery = "UPDATE characters_gear SET gear3='[gear_name]' WHERE char_id = '[char_id]'" - if(4) TextQuery = "UPDATE characters_gear SET gear4='[gear_name]' WHERE char_id = '[char_id]'" - if(5) TextQuery = "UPDATE characters_gear SET gear5='[gear_name]' WHERE char_id = '[char_id]'" - log_debug(TextQuery) - query = dbcon.NewQuery(TextQuery) - query.Execute() - log_debug(dbcon.ErrorMsg()) - while(loop_id<5) - loop_id += 1 - switch(loop_id) - if(1) TextQuery = "INSERT INTO characters_gear (char_id, gear1) VALUES ('[char_id]', 'none')" - if(2) TextQuery = "UPDATE characters_gear SET gear2='none' WHERE char_id = '[char_id]'" - if(3) TextQuery = "UPDATE characters_gear SET gear3='none' WHERE char_id = '[char_id]'" - if(4) TextQuery = "UPDATE characters_gear SET gear4='none' WHERE char_id = '[char_id]'" - if(5) TextQuery = "UPDATE characters_gear SET gear5='none' WHERE char_id = '[char_id]'" - log_debug(TextQuery) - query = dbcon.NewQuery(TextQuery) - query.Execute() + //var/loop_id = 0 + var/gear_list = list2params(gear) + //test + TextQuery = "INSERT INTO characters_gear (char_id, gear) VALUES ('[char_id]', '[gear_list]')" + query = dbcon.NewQuery(TextQuery) + query.Execute() + if(dbcon.ErrorMsg()) log_debug(dbcon.ErrorMsg()) return 1 @@ -478,31 +473,12 @@ var/char_slot query.Execute() if(!query.RowCount()) InsertGearData() - var/loop_id = 0 - for(var/gear_name in gear) - if(gear_name) - loop_id += 1 - switch(loop_id) - if(1) TextQuery = "UPDATE characters_gear SET gear1='[gear_name]' WHERE char_id = '[char_id]'" - if(2) TextQuery = "UPDATE characters_gear SET gear2='[gear_name]' WHERE char_id = '[char_id]'" - if(3) TextQuery = "UPDATE characters_gear SET gear3='[gear_name]' WHERE char_id = '[char_id]'" - if(4) TextQuery = "UPDATE characters_gear SET gear4='[gear_name]' WHERE char_id = '[char_id]'" - if(5) TextQuery = "UPDATE characters_gear SET gear5='[gear_name]' WHERE char_id = '[char_id]'" - log_debug(TextQuery) - query = dbcon.NewQuery(TextQuery) - query.Execute() - log_debug(dbcon.ErrorMsg()) - while(loop_id<5) - loop_id += 1 - switch(loop_id) - if(1) TextQuery = "UPDATE characters_gear SET gear1='none' WHERE char_id = '[char_id]'" - if(2) TextQuery = "UPDATE characters_gear SET gear2='none' WHERE char_id = '[char_id]'" - if(3) TextQuery = "UPDATE characters_gear SET gear3='none' WHERE char_id = '[char_id]'" - if(4) TextQuery = "UPDATE characters_gear SET gear4='none' WHERE char_id = '[char_id]'" - if(5) TextQuery = "UPDATE characters_gear SET gear5='none' WHERE char_id = '[char_id]'" - log_debug(TextQuery) - query = dbcon.NewQuery(TextQuery) - query.Execute() + //var/loop_id = 0 + var/gear_list = list2params(gear) + TextQuery = "UPDATE characters_gear SET gear='[gear_list]' WHERE char_id = '[char_id]'" + query = dbcon.NewQuery(TextQuery) + query.Execute() + if(dbcon.ErrorMsg()) log_debug(dbcon.ErrorMsg()) return 1 @@ -512,18 +488,13 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) if(!query.RowCount()) return 0 log_debug("Load query executed successfully") query.NextRow() - gear = list() - var/count = 1 - for(var/gear_name in query.item) - if(count>2) - if(gear_name!="none") - gear += gear_name - count += 1 + gear = params2list(query.item[3]) return 1 /datum/preferences/proc/InsertOrgansData() @@ -534,7 +505,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) InsertRorgansData() return 1 @@ -550,7 +522,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) UpdateRorgansData() return 1 @@ -560,7 +533,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) if(!query.RowCount()) return 0 log_debug("Load query executed successfully") @@ -586,7 +560,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/UpdateRorgansData() @@ -597,7 +572,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/LoadRorgansData() @@ -606,7 +582,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) if(!query.RowCount()) return 0 log_debug("Load query executed successfully") @@ -634,7 +611,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) return 1 else return UpdatePrefData(ckey) @@ -647,7 +625,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) return 1 /datum/preferences/proc/LoadPrefData(var/ckey) @@ -659,7 +638,8 @@ var/char_slot log_debug(TextQuery) query = dbcon.NewQuery(TextQuery) query.Execute() - log_debug(dbcon.ErrorMsg()) + if(dbcon.ErrorMsg()) + log_debug(dbcon.ErrorMsg()) if(!query.RowCount()) return 0 log_debug("Load query executed successfully") diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm index 0cff4c0ad8a..d23cab6a979 100644 --- a/code/modules/client/preferences.dm +++ b/code/modules/client/preferences.dm @@ -135,6 +135,16 @@ datum/preferences var/metadata = "" var/slot_name = "" + //SQL Save system vars + var/chardata[] + var/jobsdata[] + var/flavourdata[] + var/miscdata[] + var/DBQuery/query + var/TextQuery + var/char_id + var/char_slot + /datum/preferences/New(client/C) b_type = pick(4;"O-", 36;"O+", 3;"A-", 28;"A+", 1;"B-", 20;"B+", 1;"AB-", 5;"AB+") if(istype(C)) @@ -151,10 +161,9 @@ datum/preferences if(load_character(default_slot)) current_slot = getCharSlot_File() return - //this ensure that if db fail the file system is used + //this ensure that if db fail the file system is used to load an initial character gender = pick(MALE, FEMALE) real_name = random_name(gender,species) - gear = list() /datum/preferences/proc/ZeroSkills(var/forced = 0) @@ -1797,7 +1806,7 @@ datum/preferences /datum/preferences/proc/open_load_dialog_file(mob/user) -/* var/dat = "" + var/dat = "" dat += "
" var/savefile/S = new /savefile(path) @@ -1811,11 +1820,10 @@ datum/preferences if(i==default_slot) name = "[name]" dat += "[name]
" - dat += "
" dat += "Close
" dat += "
" - user << browse(dat, "window=saves;size=300x390")*/ + user << browse(dat, "window=saves;size=300x390") /datum/preferences/proc/getCharSlot() for(var/ckey in preferences_datums)