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 += "