diff --git a/SQL/paradise_schema.sql b/SQL/paradise_schema.sql index 1e4692b7e3b..445de8b4d08 100644 --- a/SQL/paradise_schema.sql +++ b/SQL/paradise_schema.sql @@ -565,3 +565,18 @@ CREATE TABLE `oauth_tokens` ( PRIMARY KEY (`token`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; + + +-- +-- Table structure for table `playtime_history` +-- +DROP TABLE IF EXISTS `playtime_history`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `playtime_history` ( + `ckey` varchar(32) NOT NULL, + `date` DATE NOT NULL, + `time_living` SMALLINT NOT NULL, + `time_ghost` SMALLINT NOT NULL, + PRIMARY KEY (`ckey`, `date`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; \ No newline at end of file diff --git a/SQL/paradise_schema_prefixed.sql b/SQL/paradise_schema_prefixed.sql index aa5d5895e56..f70593fc1ac 100644 --- a/SQL/paradise_schema_prefixed.sql +++ b/SQL/paradise_schema_prefixed.sql @@ -564,3 +564,17 @@ CREATE TABLE `SS13_oauth_tokens` ( PRIMARY KEY (`token`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `SS13_playtime_history` +-- +DROP TABLE IF EXISTS `SS13_playtime_history`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `SS13_playtime_history` ( + `ckey` varchar(32) NOT NULL, + `date` DATE NOT NULL, + `time_living` SMALLINT NOT NULL, + `time_ghost` SMALLINT NOT NULL, + PRIMARY KEY (`ckey`, `date`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; \ No newline at end of file diff --git a/SQL/updates/9-10.sql b/SQL/updates/9-10.sql new file mode 100644 index 00000000000..f82e7c56830 --- /dev/null +++ b/SQL/updates/9-10.sql @@ -0,0 +1,11 @@ +# Updating SQL from ver 9 to 10 - Kyet + +# Add the 'playtime_history' table that tracks playtime per player per day +CREATE TABLE `playtime_history` ( + `ckey` varchar(32) NOT NULL, + `date` DATE NOT NULL, + `time_living` SMALLINT NOT NULL, + `time_ghost` SMALLINT NOT NULL, + PRIMARY KEY (`ckey`, `date`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + diff --git a/code/__DEFINES/misc.dm b/code/__DEFINES/misc.dm index 7dd5fc5a609..5a2c087e1fd 100644 --- a/code/__DEFINES/misc.dm +++ b/code/__DEFINES/misc.dm @@ -319,7 +319,7 @@ #define INVESTIGATE_BOMB "bombs" // The SQL version required by this version of the code -#define SQL_VERSION 9 +#define SQL_VERSION 10 // Vending machine stuff #define CAT_NORMAL 1 diff --git a/code/game/jobs/job_exp.dm b/code/game/jobs/job_exp.dm index 1b64b3e8aee..b69dbfd3ed4 100644 --- a/code/game/jobs/job_exp.dm +++ b/code/game/jobs/job_exp.dm @@ -263,8 +263,11 @@ var/global/list/role_playtime_requirements = list( myrole = mob.mind.playtime_role else if(mob.mind.assigned_role) myrole = mob.mind.assigned_role + var/added_living = 0 + var/added_ghost = 0 if(mob.stat == CONSCIOUS && myrole) play_records[EXP_TYPE_LIVING] += minutes + added_living += minutes if(announce_changes) to_chat(mob,"You got: [minutes] Living EXP!") for(var/category in exp_jobsmap) @@ -279,6 +282,7 @@ var/global/list/role_playtime_requirements = list( to_chat(mob,"You got: [minutes] Special EXP!") else if(isobserver(mob)) play_records[EXP_TYPE_GHOST] += minutes + added_ghost += minutes if(announce_changes) to_chat(mob,"You got: [minutes] Ghost EXP!") else @@ -289,6 +293,12 @@ var/global/list/role_playtime_requirements = list( var/DBQuery/update_query = dbcon.NewQuery("UPDATE [format_table_name("player")] SET exp = '[new_exp]',lastseen = Now() WHERE ckey='[ckey]'") if(!update_query.Execute()) var/err = update_query.ErrorMsg() - log_game("SQL ERROR during exp_update_client write. Error : \[[err]\]\n") - message_admins("SQL ERROR during exp_update_client write. Error : \[[err]\]\n") + log_game("SQL ERROR during exp_update_client write 1. Error : \[[err]\]\n") + message_admins("SQL ERROR during exp_update_client write 1. Error : \[[err]\]\n") + return + var/DBQuery/update_query_history = dbcon.NewQuery("INSERT INTO [format_table_name("playtime_history")] (ckey, date, time_living, time_ghost) VALUES ('[ckey]',CURDATE(),[added_living],[added_ghost]) ON DUPLICATE KEY UPDATE time_living=time_living+VALUES(time_living),time_ghost=time_ghost+VALUES(time_ghost)") + if(!update_query_history.Execute()) + var/err = update_query_history.ErrorMsg() + log_game("SQL ERROR during exp_update_client write 2. Error : \[[err]\]\n") + message_admins("SQL ERROR during exp_update_client write 2. Error : \[[err]\]\n") return \ No newline at end of file diff --git a/config/example/dbconfig.txt b/config/example/dbconfig.txt index ad859d92543..654a7e348d5 100644 --- a/config/example/dbconfig.txt +++ b/config/example/dbconfig.txt @@ -9,7 +9,7 @@ ## This value must be set to the version of the paradise schema in use. ## If this value does not match, the SQL database will not be loaded and an error will be generated. ## Roundstart will be delayed. -DB_VERSION 9 +DB_VERSION 10 ## Server the MySQL database can be found at. # Examples: localhost, 200.135.5.43, www.mysqldb.com, etc.