From 37854a5489b64ea297d0c03bc1ed63912122774d Mon Sep 17 00:00:00 2001 From: Jordie <4343468+Jordie0608@users.noreply.github.com> Date: Tue, 15 May 2018 17:11:39 +1000 Subject: [PATCH] Splits up round table initialize, start, end and shutdown (#37665) For planned change to how TGS initializes server instances ahead of time so rounds aren't tracked as being far longer than they really would be. Similarly end time split for a more accurate round duration. --- SQL/database_changelog.txt | 19 ++++++++++++++++--- SQL/tgstation_schema.sql | 4 +++- SQL/tgstation_schema_prefixed.sql | 4 +++- code/__DEFINES/subsystems.dm | 2 +- code/__HELPERS/roundend.dm | 2 +- code/controllers/subsystem/dbcore.dm | 26 +++++++++++++++++++------- code/controllers/subsystem/ticker.dm | 1 + 7 files changed, 44 insertions(+), 14 deletions(-) diff --git a/SQL/database_changelog.txt b/SQL/database_changelog.txt index 742b887c973..d3339df1fb8 100644 --- a/SQL/database_changelog.txt +++ b/SQL/database_changelog.txt @@ -1,15 +1,28 @@ Any time you make a change to the schema files, remember to increment the database schema version. Generally increment the minor number, major should be reserved for significant changes to the schema. Both values go up to 255. -The latest database version is 4.3; The query to update the schema revision table is: +The latest database version is 4.4; The query to update the schema revision table is: -INSERT INTO `schema_revision` (`major`, `minor`) VALUES (4, 3); +INSERT INTO `schema_revision` (`major`, `minor`) VALUES (4, 4); or -INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (4, 3); +INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (4, 4); In any query remember to add a prefix to the table names if you use one. ---------------------------------------------------- +Version 4.4, 9 May 2018, by Jordie0608 +Modified table `round`, renaming column `start_datetime` to `initialize_datetime` and `end_datetime` to `shutdown_datetime` and adding columns to replace both under the same name in preparation for changes to TGS server initialization. + +ALTER TABLE `round` + ALTER `start_datetime` DROP DEFAULT; +ALTER TABLE `round` + CHANGE COLUMN `start_datetime` `initialize_datetime` DATETIME NOT NULL AFTER `id`, + ADD COLUMN `start_datetime` DATETIME NULL DEFAULT NULL AFTER `initialize_datetime`, + CHANGE COLUMN `end_datetime` `shutdown_datetime` DATETIME NULL DEFAULT NULL AFTER `start_datetime`, + ADD COLUMN `end_datetime` DATETIME NULL DEFAULT NULL AFTER `shutdown_datetime`; + +---------------------------------------------------- + Version 4.3, 9 May 2018, by MrStonedOne Added table `role_time_log` and triggers `role_timeTlogupdate`, `role_timeTloginsert` and `role_timeTlogdelete` to update it from changes to `role_time` diff --git a/SQL/tgstation_schema.sql b/SQL/tgstation_schema.sql index 917f863bdc3..682132e29e7 100644 --- a/SQL/tgstation_schema.sql +++ b/SQL/tgstation_schema.sql @@ -421,7 +421,9 @@ DROP TABLE IF EXISTS `round`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `round` ( `id` INT(11) NOT NULL AUTO_INCREMENT, - `start_datetime` DATETIME NOT NULL, + `initialize_datetime` DATETIME NOT NULL, + `start_datetime` DATETIME NULL, + `shutdown_datetime` DATETIME NULL, `end_datetime` DATETIME NULL, `server_ip` INT(10) UNSIGNED NOT NULL, `server_port` SMALLINT(5) UNSIGNED NOT NULL, diff --git a/SQL/tgstation_schema_prefixed.sql b/SQL/tgstation_schema_prefixed.sql index e69bafdb722..a1555cd9251 100644 --- a/SQL/tgstation_schema_prefixed.sql +++ b/SQL/tgstation_schema_prefixed.sql @@ -421,7 +421,9 @@ DROP TABLE IF EXISTS `SS13_round`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `SS13_round` ( `id` INT(11) NOT NULL AUTO_INCREMENT, - `start_datetime` DATETIME NOT NULL, + `initialize_datetime` DATETIME NOT NULL, + `start_datetime` DATETIME NULL, + `shutdown_datetime` DATETIME NULL, `end_datetime` DATETIME NULL, `server_ip` INT(10) UNSIGNED NOT NULL, `server_port` SMALLINT(5) UNSIGNED NOT NULL, diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm index d93d6395611..2fb681d1a39 100644 --- a/code/__DEFINES/subsystems.dm +++ b/code/__DEFINES/subsystems.dm @@ -1,7 +1,7 @@ //Update this whenever the db schema changes //make sure you add an update to the schema_version stable in the db changelog #define DB_MAJOR_VERSION 4 -#define DB_MINOR_VERSION 3 +#define DB_MINOR_VERSION 4 //Timing subsystem //Don't run if there is an identical unique timer active diff --git a/code/__HELPERS/roundend.dm b/code/__HELPERS/roundend.dm index fcf5a5dd4aa..b9db24e447d 100644 --- a/code/__HELPERS/roundend.dm +++ b/code/__HELPERS/roundend.dm @@ -220,7 +220,7 @@ log_game("[i]s[total_antagonists[i]].") CHECK_TICK - + SSdbcore.SetRoundEnd() //Collects persistence features if(mode.allow_persistence_save) SSpersistence.CollectData() diff --git a/code/controllers/subsystem/dbcore.dm b/code/controllers/subsystem/dbcore.dm index 0609b78d999..b026f8ad6fa 100644 --- a/code/controllers/subsystem/dbcore.dm +++ b/code/controllers/subsystem/dbcore.dm @@ -37,19 +37,18 @@ SUBSYSTEM_DEF(dbcore) message_admins("Database schema ([db_major].[db_minor]) doesn't match the latest schema version ([DB_MAJOR_VERSION].[DB_MINOR_VERSION]), this may lead to undefined behaviour or errors") if(2) message_admins("Could not get schema version from database") - + return ..() - + /datum/controller/subsystem/dbcore/Recover() _db_con = SSdbcore._db_con /datum/controller/subsystem/dbcore/Shutdown() //This is as close as we can get to the true round end before Disconnect() without changing where it's called, defeating the reason this is a subsystem if(SSdbcore.Connect()) - var/sql_station_name = sanitizeSQL(station_name()) - var/datum/DBQuery/query_round_end = SSdbcore.NewQuery("UPDATE [format_table_name("round")] SET end_datetime = Now(), game_mode_result = '[sanitizeSQL(SSticker.mode_result)]', end_state = '[sanitizeSQL(SSticker.end_state)]', station_name = '[sql_station_name]' WHERE id = [GLOB.round_id]") - query_round_end.Execute() + var/datum/DBQuery/query_round_shutdown = SSdbcore.NewQuery("UPDATE [format_table_name("round")] SET shutdown_datetime = Now(), end_state = '[sanitizeSQL(SSticker.end_state)]' WHERE id = [GLOB.round_id]") + query_round_shutdown.Execute() if(IsConnected()) Disconnect() @@ -107,13 +106,26 @@ SUBSYSTEM_DEF(dbcore) /datum/controller/subsystem/dbcore/proc/SetRoundID() if(CONFIG_GET(flag/sql_enabled)) if(SSdbcore.Connect()) - var/datum/DBQuery/query_round_start = SSdbcore.NewQuery("INSERT INTO [format_table_name("round")] (start_datetime, server_ip, server_port) VALUES (Now(), INET_ATON(IF('[world.internet_address]' LIKE '', '0', '[world.internet_address]')), '[world.port]')") - query_round_start.Execute() + var/datum/DBQuery/query_round_initialize = SSdbcore.NewQuery("INSERT INTO [format_table_name("round")] (initialize_datetime, server_ip, server_port) VALUES (Now(), INET_ATON(IF('[world.internet_address]' LIKE '', '0', '[world.internet_address]')), '[world.port]')") + query_round_initialize.Execute() var/datum/DBQuery/query_round_last_id = SSdbcore.NewQuery("SELECT LAST_INSERT_ID()") query_round_last_id.Execute() if(query_round_last_id.NextRow()) GLOB.round_id = query_round_last_id.item[1] +/datum/controller/subsystem/dbcore/proc/SetRoundStart() + if(CONFIG_GET(flag/sql_enabled)) + if(SSdbcore.Connect()) + var/datum/DBQuery/query_round_start = SSdbcore.NewQuery("UPDATE [format_table_name("round")] SET start_datetime = Now() WHERE id = [GLOB.round_id]") + query_round_start.Execute() + +/datum/controller/subsystem/dbcore/proc/SetRoundEnd() + if(CONFIG_GET(flag/sql_enabled)) + if(SSdbcore.Connect()) + var/sql_station_name = sanitizeSQL(station_name()) + var/datum/DBQuery/query_round_end = SSdbcore.NewQuery("UPDATE [format_table_name("round")] SET end_datetime = Now(), game_mode_result = '[sanitizeSQL(SSticker.mode_result)]', station_name = '[sql_station_name]' WHERE id = [GLOB.round_id]") + query_round_end.Execute() + /datum/controller/subsystem/dbcore/proc/Disconnect() failed_connections = 0 return _dm_db_close(_db_con) diff --git a/code/controllers/subsystem/ticker.dm b/code/controllers/subsystem/ticker.dm index 2966ae7d7c7..4c9920dc89c 100755 --- a/code/controllers/subsystem/ticker.dm +++ b/code/controllers/subsystem/ticker.dm @@ -282,6 +282,7 @@ SUBSYSTEM_DEF(ticker) log_world("Game start took [(world.timeofday - init_start)/10]s") round_start_time = world.time + SSdbcore.SetRoundStart() to_chat(world, "Welcome to [station_name()], enjoy your stay!") SEND_SOUND(world, sound('sound/ai/welcome.ogg'))