Skip to content

Commit

Permalink
Security citations are now logged to the DB (tgstation#58827)
Browse files Browse the repository at this point in the history
Co-authored-by: Kyle Spier-Swenson <[email protected]>
  • Loading branch information
nfreader and MrStonedOne authored May 3, 2021
1 parent eb88cce commit e3b1e3c
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 5 deletions.
35 changes: 32 additions & 3 deletions SQL/database_changelog.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
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.12; The query to update the schema revision table is:
The latest database version is 5.13; The query to update the schema revision table is:

INSERT INTO `schema_revision` (`major`, `minor`) VALUES (5, 12);
INSERT INTO `schema_revision` (`major`, `minor`) VALUES (5, 13);
or
INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (5, 12);
INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (5, 13);

In any query remember to add a prefix to the table names if you use one.

-----------------------------------------------------

Version 5.13, 30 April 2021, by Atlanta Ned
Added the `citation` table for tracking security citations in the database.

```
CREATE TABLE `citation` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`round_id` INT(11) UNSIGNED NOT NULL,
`server_ip` INT(11) UNSIGNED NOT NULL,
`server_port` INT(11) UNSIGNED NOT NULL,
`citation` TEXT NOT NULL COLLATE 'utf8mb4_general_ci',
`action` VARCHAR(20) NOT NULL DEFAULT '' COLLATE 'utf8mb4_general_ci',
`sender` VARCHAR(32) NOT NULL DEFAULT '' COLLATE 'utf8mb4_general_ci',
`sender_ic` VARCHAR(64) NOT NULL DEFAULT '' COMMENT 'Longer because this is the character name, not the ckey' COLLATE 'utf8mb4_general_ci',
`recipient` VARCHAR(64) NOT NULL DEFAULT '' COMMENT 'Longer because this is the character name, not the ckey' COLLATE 'utf8mb4_general_ci',
`crime` TEXT NOT NULL COLLATE 'utf8mb4_general_ci',
`fine` INT(4) NULL DEFAULT NULL,
`paid` INT(4) NULL DEFAULT '0',
`timestamp` DATETIME NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
UNIQUE INDEX `idx_constraints` (`round_id`, `server_ip`, `server_port`, `citation`(100)) USING BTREE
)
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1
;
```

-----------------------------------------------------

Version 5.12, 29 December 2020, by Missfox
Modified table `messages`, adding column `playtime` to show the user's playtime when the note was created.

Expand Down
25 changes: 25 additions & 0 deletions SQL/tgstation_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,31 @@ CREATE TABLE `ban` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `citation`
--
DROP TABLE IF EXISTS `citation`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `citation` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`round_id` int(11) unsigned NOT NULL,
`server_ip` int(11) unsigned NOT NULL,
`server_port` int(11) unsigned NOT NULL,
`citation` text NOT NULL,
`action` varchar(20) NOT NULL DEFAULT '',
`sender` varchar(32) NOT NULL DEFAULT '',
`sender_ic` varchar(64) NOT NULL DEFAULT '' COMMENT 'Longer because this is the character name, not the ckey',
`recipient` varchar(64) NOT NULL DEFAULT '' COMMENT 'Longer because this is the character name, not the ckey',
`crime` text NOT NULL,
`fine` int(4) DEFAULT NULL,
`paid` int(4) DEFAULT 0,
`timestamp` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `idx_constraints` (`round_id`,`server_ip`,`server_port`,`citation`(100)) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `connection_log`
--
Expand Down
25 changes: 25 additions & 0 deletions SQL/tgstation_schema_prefixed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,31 @@ CREATE TABLE `SS13_ban` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `citation`
--
DROP TABLE IF EXISTS `SS13_citation`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE IF NOT EXISTS `SS13_citation` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`round_id` int(11) unsigned NOT NULL,
`server_ip` int(11) unsigned NOT NULL,
`server_port` int(11) unsigned NOT NULL,
`citation` text NOT NULL,
`action` varchar(20) NOT NULL DEFAULT '',
`sender` varchar(32) NOT NULL DEFAULT '',
`sender_ic` varchar(64) NOT NULL DEFAULT '' COMMENT 'Longer because this is the character name, not the ckey',
`recipient` varchar(64) NOT NULL DEFAULT '' COMMENT 'Longer because this is the character name, not the ckey',
`crime` text NOT NULL,
`fine` int(4) DEFAULT NULL,
`paid` int(4) DEFAULT 0,
`timestamp` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `idx_constraints` (`round_id`,`server_ip`,`server_port`,`citation`(100)) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Table structure for table `SS13_connection_log`
--
Expand Down
45 changes: 45 additions & 0 deletions code/controllers/subsystem/blackbox.dm
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,48 @@ Versioning
if(query_report_death)
query_report_death.Execute(async = TRUE)
qdel(query_report_death)

/datum/controller/subsystem/blackbox/proc/ReportCitation(citation, sender, sender_ic, recipient, message, fine = 0, paid = 0)
var/datum/db_query/query_report_citation = SSdbcore.NewQuery({"INSERT INTO [format_table_name("citation")]
(server_ip,
server_port,
round_id,
citation,
action,
sender,
sender_ic,
recipient,
crime,
fine,
paid,
timestamp) VALUES (
INET_ATON(:server_ip),
:port,
:round_id,
:citation,
:action,
:sender,
:sender_ic,
:recipient,
:message,
:fine,
:paid,
:timestamp
) ON DUPLICATE KEY UPDATE
paid = paid + VALUES(paid)"}, list(
"server_ip" = world.internet_address || "0",
"port" = "[world.port]",
"round_id" = GLOB.round_id,
"citation" = citation,
"action" = "Citation Created",
"sender" = sender,
"sender_ic" = sender_ic,
"recipient" = recipient,
"message" = message,
"fine" = fine,
"paid" = paid,
"timestamp" = SQLtime()
))
if(query_report_citation)
query_report_citation.Execute(async = TRUE)
qdel(query_report_citation)
4 changes: 3 additions & 1 deletion code/game/machinery/computer/security.dm
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ What a mess.*/
if (pay == diff || pay > diff || pay >= diff)
investigate_log("Citation Paid off: <strong>[p.crimeName]</strong> Fine: [p.fine] | Paid off by [key_name(usr)]", INVESTIGATE_RECORDS)
to_chat(usr, "<span class='notice'>The fine has been paid in full.</span>")
SSblackbox.ReportCitation(text2num(href_list["cdataid"]),"","","","", 0, pay)
qdel(C)
playsound(src, "terminal_type", 25, FALSE)
else
Expand Down Expand Up @@ -696,7 +697,7 @@ What a mess.*/
if(!canUseSecurityRecordsConsole(usr, t1, null, a2))
return

var/crime = GLOB.data_core.createCrimeEntry(t1, "", authenticated, station_time_timestamp(), fine)
var/datum/data/crime/crime = GLOB.data_core.createCrimeEntry(t1, "", authenticated, station_time_timestamp(), fine)
for (var/obj/item/pda/P in GLOB.PDAs)
if(P.owner == active1.fields["name"])
var/message = "You have been fined [fine] credits for '[t1]'. Fines may be paid at security."
Expand All @@ -711,6 +712,7 @@ What a mess.*/
usr.log_message("(PDA: Citation Server) sent \"[message]\" to [signal.format_target()]", LOG_PDA)
GLOB.data_core.addCitation(active1.fields["id"], crime)
investigate_log("New Citation: <strong>[t1]</strong> Fine: [fine] | Added to [active1.fields["name"]] by [key_name(usr)]", INVESTIGATE_RECORDS)
SSblackbox.ReportCitation(crime.dataId, usr.ckey, usr.real_name, active1.fields["name"], t1, fine)
if("citation_delete")
if(istype(active1, /datum/data/record))
if(href_list["cdataid"])
Expand Down
1 change: 1 addition & 0 deletions code/game/machinery/computer/warrant.dm
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
if (pay == diff || pay > diff || pay >= diff)
investigate_log("Citation Paid off: <strong>[p.crimeName]</strong> Fine: [p.fine] | Paid off by [key_name(usr)]", INVESTIGATE_RECORDS)
to_chat(M, "<span class='notice'>The fine has been paid in full.</span>")
SSblackbox.ReportCitation(text2num(href_list["cdataid"]),"","","","", 0, pay)
qdel(C)
playsound(src, "terminal_type", 25, FALSE)
else
Expand Down
3 changes: 2 additions & 1 deletion code/modules/mob/living/carbon/human/human.dm
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
return
fine = min(fine, maxFine)

var/crime = GLOB.data_core.createCrimeEntry(t1, "", allowed_access, station_time_timestamp(), fine)
var/datum/data/crime/crime = GLOB.data_core.createCrimeEntry(t1, "", allowed_access, station_time_timestamp(), fine)
for (var/obj/item/pda/P in GLOB.PDAs)
if(P.owner == R.fields["name"])
var/message = "You have been fined [fine] credits for '[t1]'. Fines may be paid at security."
Expand All @@ -302,6 +302,7 @@
usr.log_message("(PDA: Citation Server) sent \"[message]\" to [signal.format_target()]", LOG_PDA)
GLOB.data_core.addCitation(R.fields["id"], crime)
investigate_log("New Citation: <strong>[t1]</strong> Fine: [fine] | Added to [R.fields["name"]] by [key_name(usr)]", INVESTIGATE_RECORDS)
SSblackbox.ReportCitation(crime.dataId, usr.ckey, usr.real_name, R.fields["name"], t1, fine)
return

if(href_list["add_crime"])
Expand Down

0 comments on commit e3b1e3c

Please sign in to comment.