From 26258bd21bc93012d0bd1bbc9cdca8a2e9d3deab Mon Sep 17 00:00:00 2001
From: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com>
Date: Sat, 30 Sep 2023 12:41:16 +0100
Subject: [PATCH] Logs playtime history for ALL departments (#22446)
---
SQL/paradise_schema.sql | 10 +++++++
SQL/updates/51-52.sql | 13 +++++++++
code/__DEFINES/misc_defines.dm | 2 +-
code/controllers/subsystem/SSjobs.dm | 43 ++++++++++++++++++++++------
config/example/config.toml | 2 +-
5 files changed, 59 insertions(+), 11 deletions(-)
create mode 100644 SQL/updates/51-52.sql
diff --git a/SQL/paradise_schema.sql b/SQL/paradise_schema.sql
index 909f3fa0544..2a7c07d0cdd 100644
--- a/SQL/paradise_schema.sql
+++ b/SQL/paradise_schema.sql
@@ -474,7 +474,17 @@ CREATE TABLE `playtime_history` (
`ckey` varchar(32) NOT NULL,
`date` DATE NOT NULL,
`time_living` SMALLINT NOT NULL,
+ `time_crew` SMALLINT NOT NULL,
+ `time_special` SMALLINT NOT NULL,
`time_ghost` SMALLINT NOT NULL,
+ `time_command` SMALLINT NOT NULL,
+ `time_engineering` SMALLINT NOT NULL,
+ `time_medical` SMALLINT NOT NULL,
+ `time_science` SMALLINT NOT NULL,
+ `time_supply` SMALLINT NOT NULL,
+ `time_security` SMALLINT NOT NULL,
+ `time_silicon` SMALLINT NOT NULL,
+ `time_service` SMALLINT NOT NULL,
PRIMARY KEY (`ckey`, `date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
diff --git a/SQL/updates/51-52.sql b/SQL/updates/51-52.sql
new file mode 100644
index 00000000000..3ecf3b46dfc
--- /dev/null
+++ b/SQL/updates/51-52.sql
@@ -0,0 +1,13 @@
+# Updating SQL from 51 to 52 -AffectedArc07
+# Adding all department columns to playtime_history
+ALTER TABLE `playtime_history`
+ ADD COLUMN `time_crew` SMALLINT NOT NULL AFTER `time_living`,
+ ADD COLUMN `time_special` SMALLINT NOT NULL AFTER `time_crew`,
+ ADD COLUMN `time_command` SMALLINT NOT NULL AFTER `time_ghost`,
+ ADD COLUMN `time_engineering` SMALLINT NOT NULL AFTER `time_command`,
+ ADD COLUMN `time_medical` SMALLINT NOT NULL AFTER `time_engineering`,
+ ADD COLUMN `time_science` SMALLINT NOT NULL AFTER `time_medical`,
+ ADD COLUMN `time_supply` SMALLINT NOT NULL AFTER `time_science`,
+ ADD COLUMN `time_security` SMALLINT NOT NULL AFTER `time_supply`,
+ ADD COLUMN `time_silicon` SMALLINT NOT NULL AFTER `time_security`,
+ ADD COLUMN `time_service` SMALLINT NOT NULL AFTER `time_silicon`;
diff --git a/code/__DEFINES/misc_defines.dm b/code/__DEFINES/misc_defines.dm
index 544e499beea..fc5b7201621 100644
--- a/code/__DEFINES/misc_defines.dm
+++ b/code/__DEFINES/misc_defines.dm
@@ -375,7 +375,7 @@
#define INVESTIGATE_BOMB "bombs"
// The SQL version required by this version of the code
-#define SQL_VERSION 51
+#define SQL_VERSION 52
// Vending machine stuff
#define CAT_NORMAL 1
diff --git a/code/controllers/subsystem/SSjobs.dm b/code/controllers/subsystem/SSjobs.dm
index e23b25a0741..d49321a9f23 100644
--- a/code/controllers/subsystem/SSjobs.dm
+++ b/code/controllers/subsystem/SSjobs.dm
@@ -825,11 +825,24 @@ SUBSYSTEM_DEF(jobs)
else if(C.mob.mind.assigned_role)
myrole = C.mob.mind.assigned_role
- var/added_living = 0
- var/added_ghost = 0
+ // Track all the added ammounts for a mega update query
+ var/list/added_differential = list(
+ EXP_TYPE_LIVING = 0,
+ EXP_TYPE_CREW = 0,
+ EXP_TYPE_SPECIAL = 0,
+ EXP_TYPE_GHOST = 0,
+ EXP_TYPE_COMMAND = 0,
+ EXP_TYPE_ENGINEERING = 0,
+ EXP_TYPE_MEDICAL = 0,
+ EXP_TYPE_SCIENCE = 0,
+ EXP_TYPE_SUPPLY = 0,
+ EXP_TYPE_SECURITY = 0,
+ EXP_TYPE_SILICON = 0,
+ EXP_TYPE_SERVICE = 0
+ )
if(C.mob.stat == CONSCIOUS && myrole)
play_records[C.ckey][EXP_TYPE_LIVING] += minutes
- added_living += minutes
+ added_differential[EXP_TYPE_LIVING] += minutes
if(announce)
to_chat(C.mob, "You got: [minutes] Living EXP!")
@@ -838,6 +851,7 @@ SUBSYSTEM_DEF(jobs)
if(GLOB.exp_jobsmap[category]["titles"])
if(myrole in GLOB.exp_jobsmap[category]["titles"])
play_records[C.ckey][category] += minutes
+ added_differential[category] += minutes
if(announce)
to_chat(C.mob, "You got: [minutes] [category] EXP!")
@@ -848,7 +862,7 @@ SUBSYSTEM_DEF(jobs)
else if(isobserver(C.mob))
play_records[C.ckey][EXP_TYPE_GHOST] += minutes
- added_ghost += minutes
+ added_differential[EXP_TYPE_GHOST] += minutes
if(announce)
to_chat(C.mob, "You got: [minutes] Ghost EXP!")
else
@@ -868,14 +882,25 @@ SUBSYSTEM_DEF(jobs)
player_update_queries += update_query
+ // This gets hellish
var/datum/db_query/update_query_history = SSdbcore.NewQuery({"
- INSERT INTO playtime_history (ckey, date, time_living, time_ghost)
- VALUES (:ckey, CURDATE(), :addedliving, :addedghost)
- ON DUPLICATE KEY UPDATE time_living=time_living + VALUES(time_living), time_ghost=time_ghost + VALUES(time_ghost)"},
+ INSERT INTO playtime_history (ckey, date, time_living, time_crew, time_special, time_ghost, time_command, time_engineering, time_medical, time_science, time_supply, time_security, time_silicon, time_service)
+ VALUES (:ckey, CURDATE(), :addedliving, :addedcrew, :addedspecial, :addedghost, :addedcommand, :addedengineering, :addedmedical, :addedscience, :addedsupply, :addedsecurity, :addedsilicon, :addedservice)
+ ON DUPLICATE KEY UPDATE time_living=time_living + VALUES(time_living), time_crew=time_crew + VALUES(time_crew), time_crew=time_special + VALUES(time_special), time_ghost=time_ghost + VALUES(time_ghost), time_command=time_command + VALUES(time_command), time_engineering=time_engineering + VALUES(time_engineering), time_medical=time_medical + VALUES(time_medical), time_science=time_science + VALUES(time_science), time_supply=time_supply + VALUES(time_supply), time_security=time_security + VALUES(time_security), time_silicon=time_silicon + VALUES(time_silicon), time_service=time_service + VALUES(time_service)"},
list(
"ckey" = C.ckey,
- "addedliving" = added_living,
- "addedghost" = added_ghost
+ "addedliving" = added_differential[EXP_TYPE_LIVING],
+ "addedcrew" = added_differential[EXP_TYPE_CREW],
+ "addedspecial" = added_differential[EXP_TYPE_SPECIAL],
+ "addedghost" = added_differential[EXP_TYPE_GHOST],
+ "addedcommand" = added_differential[EXP_TYPE_COMMAND],
+ "addedengineering" = added_differential[EXP_TYPE_ENGINEERING],
+ "addedmedical" = added_differential[EXP_TYPE_MEDICAL],
+ "addedscience" = added_differential[EXP_TYPE_SCIENCE],
+ "addedsupply" = added_differential[EXP_TYPE_SUPPLY],
+ "addedsecurity" = added_differential[EXP_TYPE_SECURITY],
+ "addedsilicon" = added_differential[EXP_TYPE_SILICON],
+ "addedservice" = added_differential[EXP_TYPE_SERVICE]
)
)
diff --git a/config/example/config.toml b/config/example/config.toml
index 4c20d93672f..63ed6f030ea 100644
--- a/config/example/config.toml
+++ b/config/example/config.toml
@@ -144,7 +144,7 @@ ipc_screens = [
# Enable/disable the database on a whole
sql_enabled = false
# SQL version. If this is a mismatch, round start will be delayed
-sql_version = 51
+sql_version = 52
# SQL server address. Can be an IP or DNS name
sql_address = "127.0.0.1"
# SQL server port