Skip to content

Commit

Permalink
[Ready] Database Tickets (tgstation#48727)
Browse files Browse the repository at this point in the history
* DB ticket procs

* Schema changes for DB tickets

* Schema version update

* Fixes requested by Jordie

* SQL updates

Adds a recipient column

* Still one dangling issue where this DOESN'T WORK

* Alright, this should work

* Requested SQL fixes

* Rogue changes

* less bad defaults

* utf8 for the utf8 gods

* aaaaaa

* Update tgstation_schema_prefixed.sql

* Update tgstation_schema.sql

* Update database_changelog.txt

Co-authored-by: Jordie <[email protected]>
  • Loading branch information
nfreader and Jordie0608 committed Jan 16, 2020
1 parent 3195cea commit c758bdd
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 6 deletions.
25 changes: 22 additions & 3 deletions SQL/database_changelog.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
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.6; The query to update the schema revision table is:
The latest database version is 5.7; The query to update the schema revision table is:

INSERT INTO `schema_revision` (`major`, `minor`) VALUES (5, 6);
INSERT INTO `schema_revision` (`major`, `minor`) VALUES (5, 7);
or
INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (5, 6);
INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (5, 7);

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

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

Version 5.7, 10 January 2020 by Atlanta-Ned
Added ticket table for tracking ahelp tickets in the database.

DROP TABLE IF EXISTS `ticket`;
CREATE TABLE `ticket` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`server_ip` int(10) unsigned NOT NULL,
`server_port` smallint(5) unsigned NOT NULL,
`round_id` int(11) unsigned NOT NULL,
`ticket` smallint(11) unsigned NOT NULL,
`action` varchar(20) NOT NULL DEFAULT 'Message',
`message` text NOT NULL,
`timestamp` datetime NOT NULL,
`recipient` varchar(32) DEFAULT NULL,
`sender` varchar(32) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

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

Expand Down
18 changes: 18 additions & 0 deletions SQL/tgstation_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,24 @@ CREATE TABLE `achievement_metadata` (
PRIMARY KEY (`achievement_key`)
) ENGINE=InnoDB;

--
-- Table structure for table `ticket`
--
DROP TABLE IF EXISTS `ticket`;
CREATE TABLE `ticket` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`server_ip` int(10) unsigned NOT NULL,
`server_port` smallint(5) unsigned NOT NULL,
`round_id` int(11) unsigned NOT NULL,
`ticket` smallint(11) unsigned NOT NULL,
`action` varchar(20) NOT NULL DEFAULT 'Message',
`message` text NOT NULL,
`timestamp` datetime NOT NULL,
`recipient` varchar(32) DEFAULT NULL,
`sender` varchar(32) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
Expand Down
18 changes: 18 additions & 0 deletions SQL/tgstation_schema_prefixed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,24 @@ CREATE TABLE `SS13_achievement_metadata` (
PRIMARY KEY (`achievement_key`)
) ENGINE=InnoDB;

--
-- Table structure for table `SS13_ticket`
--
DROP TABLE IF EXISTS `SS13_ticket`;
CREATE TABLE `SS13_ticket` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`server_ip` int(10) unsigned NOT NULL,
`server_port` smallint(5) unsigned NOT NULL,
`round_id` int(11) unsigned NOT NULL,
`ticket` smallint(11) unsigned NOT NULL,
`action` varchar(20) NOT NULL DEFAULT 'Message',
`message` text NOT NULL,
`timestamp` datetime NOT NULL,
`recipient` varchar(32) DEFAULT NULL,
`sender` varchar(32) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
Expand Down
2 changes: 1 addition & 1 deletion code/__DEFINES/subsystems.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* make sure you add an update to the schema_version stable in the db changelog
*/
#define DB_MINOR_VERSION 6
#define DB_MINOR_VERSION 7


//! ## Timing subsystem
Expand Down
19 changes: 19 additions & 0 deletions code/controllers/subsystem/blackbox.dm
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,25 @@ Versioning
key = new_key
key_type = new_key_type

/datum/controller/subsystem/blackbox/proc/LogAhelp(ticket, action, message, recipient, sender)

if(!SSdbcore.Connect())
return

ticket = sanitizeSQL(ticket)
action = sanitizeSQL(action)
message = sanitizeSQL(message)
recipient = recipient ? "'sanitizeSQL(recipient)'" : "NULL"
sender = sender ? "'sanitizeSQL(sender)'" : "NULL"
var/server_ip = sanitizeSQL(world.internet_address)
var/server_port = sanitizeSQL(world.port)
var/round_id = sanitizeSQL(GLOB.round_id)

var/datum/DBQuery/query_log_ahelp = SSdbcore.NewQuery("INSERT INTO [format_table_name("ticket")] (ticket, action, message, recipient, sender, server_ip, server_port, round_id, timestamp) VALUES ('[ticket]', '[action]', '[message]', [recipient], [sender], INET_ATON(IF('[server_ip]' LIKE '', '0', '[server_ip]')), '[server_port]','[round_id]', '[SQLtime()]')")
query_log_ahelp.Execute()
qdel(query_log_ahelp)


/datum/controller/subsystem/blackbox/proc/ReportDeath(mob/living/L)
set waitfor = FALSE
if(sealed)
Expand Down
9 changes: 8 additions & 1 deletion code/modules/admin/verbs/adminhelp.dm
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
if(C.current_ticket)
C.current_ticket.initiator = C
C.current_ticket.AddInteraction("Client reconnected.")
SSblackbox.LogAhelp(C.current_ticket.id, "Reconnected", "Client reconnected", C.ckey)

//Dissasociate ticket
/datum/admin_help_tickets/proc/ClientLogout(client/C)
if(C.current_ticket)
C.current_ticket.AddInteraction("Client disconnected.")
SSblackbox.LogAhelp(C.current_ticket.id, "Disconnected", "Client disconnected", C.ckey)
C.current_ticket.initiator = null
C.current_ticket = null

Expand Down Expand Up @@ -201,7 +203,6 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
if(admin_number_present <= 0)
to_chat(C, "<span class='notice'>No active admins are online, your adminhelp was sent through TGS to admins who are available. This may use IRC or Discord.</span>")
heard_by_no_admins = TRUE

GLOB.ahelp_tickets.active_tickets += src

/datum/admin_help/Destroy()
Expand Down Expand Up @@ -269,6 +270,7 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)

//show it to the person adminhelping too
to_chat(initiator, "<span class='adminnotice'>PM to-<b>Admins</b>: <span class='linkify'>[msg]</span></span>")
SSblackbox.LogAhelp(id, "Ticket Opened", msg, null, initiator.ckey)

//Reopen a closed ticket
/datum/admin_help/proc/Reopen()
Expand Down Expand Up @@ -298,6 +300,7 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
var/msg = "<span class='adminhelp'>Ticket [TicketHref("#[id]")] reopened by [key_name_admin(usr)].</span>"
message_admins(msg)
log_admin_private(msg)
SSblackbox.LogAhelp(id, "Reopened", "Reopened by [usr.key]", usr.ckey)
SSblackbox.record_feedback("tally", "ahelp_stats", 1, "reopened")
TicketPanel() //can only be done from here, so refresh it

Expand All @@ -323,6 +326,7 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
SSblackbox.record_feedback("tally", "ahelp_stats", 1, "closed")
var/msg = "Ticket [TicketHref("#[id]")] closed by [key_name]."
message_admins(msg)
SSblackbox.LogAhelp(id, "Closed", "Closed by [usr.key]", null, usr.ckey)
log_admin_private(msg)

//Mark open ticket as resolved/legitimate, returns ahelp verb
Expand All @@ -341,6 +345,7 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
SSblackbox.record_feedback("tally", "ahelp_stats", 1, "resolved")
var/msg = "Ticket [TicketHref("#[id]")] resolved by [key_name]"
message_admins(msg)
SSblackbox.LogAhelp(id, "Resolved", "Resolved by [usr.key]", null, usr.ckey)
log_admin_private(msg)

//Close and return ahelp verb, use if ticket is incoherent
Expand All @@ -362,6 +367,7 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
message_admins(msg)
log_admin_private(msg)
AddInteraction("Rejected by [key_name].")
SSblackbox.LogAhelp(id, "Rejected", "Rejected by [usr.key]", null, usr.ckey)
Close(silent = TRUE)

//Resolve ticket with IC Issue message
Expand All @@ -380,6 +386,7 @@ GLOBAL_DATUM_INIT(ahelp_tickets, /datum/admin_help_tickets, new)
message_admins(msg)
log_admin_private(msg)
AddInteraction("Marked as IC issue by [key_name]")
SSblackbox.LogAhelp(id, "IC Issue", "Marked as IC issue by [usr.key]", null, usr.ckey)
Resolve(silent = TRUE)

//Show the ticket panel
Expand Down
10 changes: 9 additions & 1 deletion code/modules/admin/verbs/adminpm.dm
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,25 @@
admin_ticket_log(src, interaction_message)
if(recipient != src) //reeee
admin_ticket_log(recipient, interaction_message)

SSblackbox.LogAhelp(current_ticket.id, "Reply", msg, recipient.ckey, src.ckey)
else //recipient is an admin but sender is not
var/replymsg = "Reply PM from-<b>[key_name(src, recipient, 1)]</b>: <span class='linkify'>[keywordparsedmsg]</span>"
admin_ticket_log(src, "<font color='red'>[replymsg]</font>")
to_chat(recipient, "<span class='danger'>[replymsg]</span>")
to_chat(src, "<span class='notice'>PM to-<b>Admins</b>: <span class='linkify'>[msg]</span></span>")
SSblackbox.LogAhelp(current_ticket.id, "Reply", msg, recipient.ckey, src.ckey)

//play the receiving admin the adminhelp sound (if they have them enabled)
if(recipient.prefs.toggles & SOUND_ADMINHELP)
SEND_SOUND(recipient, sound('sound/effects/adminhelp.ogg'))

else
if(holder) //sender is an admin but recipient is not. Do BIG RED TEXT
var/already_logged = FALSE
if(!recipient.current_ticket)
new /datum/admin_help(msg, recipient, TRUE)
already_logged = TRUE
SSblackbox.LogAhelp(recipient.current_ticket.id, "Ticket Opened", msg, null, recipient.ckey)

to_chat(recipient, "<font color='red' size='4'><b>-- Administrator private message --</b></font>")
to_chat(recipient, "<span class='adminsay'>Admin PM from-<b>[key_name(src, recipient, 0)]</b>: <span class='linkify'>[msg]</span></span>")
Expand All @@ -182,6 +186,10 @@

admin_ticket_log(recipient, "<font color='purple'>PM From [key_name_admin(src)]: [keywordparsedmsg]</font>")

if(!already_logged) //Reply to an existing ticket
SSblackbox.LogAhelp(recipient.current_ticket.id, "Reply", msg, recipient.ckey, src.ckey)


//always play non-admin recipients the adminhelp sound
SEND_SOUND(recipient, sound('sound/effects/adminhelp.ogg'))

Expand Down

0 comments on commit c758bdd

Please sign in to comment.