diff --git a/SQL/database_changelog.txt b/SQL/database_changelog.txt index 653a7679a8a..4f6246cca5f 100644 --- a/SQL/database_changelog.txt +++ b/SQL/database_changelog.txt @@ -1,13 +1,33 @@ 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 5.20; The query to update the schema revision table is: +Make sure to also update `DB_MAJOR_VERSION` and `DB_MINOR_VERSION`, which can be found in `code/__DEFINES/subsystem.dm`. -INSERT INTO `schema_revision` (`major`, `minor`) VALUES (5, 20); +The latest database version is 5.21; The query to update the schema revision table is: + +INSERT INTO `schema_revision` (`major`, `minor`) VALUES (5, 21); or -INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (5, 20); +INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (5, 21); In any query remember to add a prefix to the table names if you use one. +Version 5.21, 15 December 2021, by Mothblocks +Adds `telemetry_connections` table for tracking tgui telemetry. + +``` +CREATE TABLE `telemetry_connections` ( + `id` INT NOT NULL AUTO_INCREMENT, + `ckey` VARCHAR(32) NOT NULL, + `telemetry_ckey` VARCHAR(32) NOT NULL, + `address` INT(10) NOT NULL, + `computer_id` VARCHAR(32) NOT NULL, + `first_round_id` INT(11) UNSIGNED NULL, + `latest_round_id` INT(11) UNSIGNED NULL, + PRIMARY KEY (`id`), + UNIQUE INDEX `unique_constraints` (`ckey` , `telemetry_ckey` , `address` , `computer_id`) +); +``` +----------------------------------------------------- + Version 5.20, 11 November 2021, by Mothblocks Adds `admin_ckey` field to the `known_alts` table to track who added what. diff --git a/SQL/tgstation_schema.sql b/SQL/tgstation_schema.sql index 11187db7a8a..a65adc2167e 100644 --- a/SQL/tgstation_schema.sql +++ b/SQL/tgstation_schema.sql @@ -677,6 +677,22 @@ CREATE TABLE `known_alts` ( UNIQUE INDEX `unique_contraints` (`ckey1` , `ckey2`) ); +-- +-- Table structure for table `telemetry_connections` +-- +DROP TABLE IF EXISTS `telemetry_connections`; +CREATE TABLE `telemetry_connections` ( + `id` INT NOT NULL AUTO_INCREMENT, + `ckey` VARCHAR(32) NOT NULL, + `telemetry_ckey` VARCHAR(32) NOT NULL, + `address` INT(10) NOT NULL, + `computer_id` VARCHAR(32) NOT NULL, + `first_round_id` INT(11) UNSIGNED NULL, + `latest_round_id` INT(11) UNSIGNED NULL, + PRIMARY KEY (`id`), + UNIQUE INDEX `unique_constraints` (`ckey` , `telemetry_ckey` , `address` , `computer_id`) +); + /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; diff --git a/SQL/tgstation_schema_prefixed.sql b/SQL/tgstation_schema_prefixed.sql index 703163b6205..141ffe90b3a 100644 --- a/SQL/tgstation_schema_prefixed.sql +++ b/SQL/tgstation_schema_prefixed.sql @@ -677,6 +677,22 @@ CREATE TABLE `SS13_known_alts` ( UNIQUE INDEX `unique_contraints` (`ckey1` , `ckey2`) ); +-- +-- Table structure for table `telemetry_connections` +-- +DROP TABLE IF EXISTS `SS13_telemetry_connections`; +CREATE TABLE `SS13_telemetry_connections` ( + `id` INT NOT NULL AUTO_INCREMENT, + `ckey` VARCHAR(32) NOT NULL, + `telemetry_ckey` VARCHAR(32) NOT NULL, + `address` INT(10) NOT NULL, + `computer_id` VARCHAR(32) NOT NULL, + `first_round_id` INT(11) UNSIGNED NULL, + `latest_round_id` INT(11) UNSIGNED NULL, + PRIMARY KEY (`id`), + UNIQUE INDEX `unique_constraints` (`ckey` , `telemetry_ckey` , `address` , `computer_id`) +); + /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm index 21414bee02f..589fdd2c3e1 100644 --- a/code/__DEFINES/subsystems.dm +++ b/code/__DEFINES/subsystems.dm @@ -20,7 +20,7 @@ * * make sure you add an update to the schema_version stable in the db changelog */ -#define DB_MINOR_VERSION 20 +#define DB_MINOR_VERSION 21 //! ## Timing subsystem diff --git a/code/modules/tgui_panel/telemetry.dm b/code/modules/tgui_panel/telemetry.dm index 7d08fc997a7..63d175b06ce 100644 --- a/code/modules/tgui_panel/telemetry.dm +++ b/code/modules/tgui_panel/telemetry.dm @@ -61,16 +61,23 @@ qdel(client) return + var/ckey = client?.ckey + if (!ckey) + return + var/list/all_known_alts = GLOB.known_alts.load_known_alts() var/list/our_known_alts = list() for (var/known_alt in all_known_alts) - if (known_alt[1] == client?.ckey) + if (known_alt[1] == ckey) our_known_alts += known_alt[2] - else if (known_alt[2] == client?.ckey) + else if (known_alt[2] == ckey) our_known_alts += known_alt[1] var/list/found + + var/list/insert_queries = list() + for(var/i in 1 to len) if(QDELETED(client)) // He got cleaned up before we were done @@ -81,6 +88,31 @@ if (!row || row.len < 3 || (!row["ckey"] || !row["address"] || !row["computer_id"])) return + if (!isnull(GLOB.round_id)) + insert_queries += SSdbcore.NewQuery({" + INSERT INTO [format_table_name("telemetry_connections")] ( + ckey, + telemetry_ckey, + address, + computer_id, + first_round_id, + latest_round_id + ) VALUES( + :ckey, + :telemetry_ckey, + INET_ATON(:address), + :computer_id, + :round_id, + :round_id + ) ON DUPLICATE KEY UPDATE latest_round_id = :round_id + "}, list( + "ckey" = ckey, + "telemetry_ckey" = row["ckey"], + "address" = row["address"], + "computer_id" = row["computer_id"], + "round_id" = GLOB.round_id, + )) + if (row["ckey"] in our_known_alts) continue @@ -89,9 +121,16 @@ break CHECK_TICK + // This fucker has a history of playing on a banned account. if(found) var/msg = "[key_name(client)] has a banned account in connection history! (Matched: [found["ckey"]], [found["address"]], [found["computer_id"]])" message_admins(msg) log_admin_private(msg) log_suspicious_login(msg, access_log_mirror = FALSE) + + // Only log them all at the end, since it's not as important as reporting an evader + for (var/datum/db_query/insert_query as anything in insert_queries) + insert_query.Execute() + + QDEL_LIST(insert_queries)