From 4a1adbad5f84b260bb21d703b32f1cc48c0cdcaa Mon Sep 17 00:00:00 2001 From: Jordie Date: Fri, 3 Feb 2017 17:02:24 +1100 Subject: [PATCH] Unifed SQL message system (#23327) * unifed sql message system to supersede notes, watchlist and memos and adds messages * a neserseree change --- SQL/database_changelog.txt | 25 ++ SQL/tgstation_schema.sql | 79 ++--- SQL/tgstation_schema_prefixed.sql | 79 ++--- code/controllers/subsystem/minimap.dm | 1 - code/modules/admin/NewBan.dm | 4 +- code/modules/admin/admin.dm | 8 +- code/modules/admin/admin_investigate.dm | 8 +- code/modules/admin/admin_memo.dm | 131 -------- code/modules/admin/admin_verbs.dm | 1 - code/modules/admin/player_panel.dm | 2 +- code/modules/admin/sql_message_system.dm | 371 +++++++++++++++++++++++ code/modules/admin/sql_notes.dm | 260 ---------------- code/modules/admin/topic.dm | 159 +++++----- code/modules/admin/watchlist.dm | 119 -------- code/modules/client/client_procs.dm | 22 +- code/modules/client/verbs/ooc.dm | 2 +- tgstation.dme | 4 +- 17 files changed, 529 insertions(+), 746 deletions(-) delete mode 100644 code/modules/admin/admin_memo.dm create mode 100644 code/modules/admin/sql_message_system.dm delete mode 100644 code/modules/admin/sql_notes.dm delete mode 100644 code/modules/admin/watchlist.dm diff --git a/SQL/database_changelog.txt b/SQL/database_changelog.txt index 2840d2c54f2..bf765a0806d 100644 --- a/SQL/database_changelog.txt +++ b/SQL/database_changelog.txt @@ -8,6 +8,31 @@ Remember to add a prefix to the table name if you use them ---------------------------------------------------- +25 January 2017, by Jordie0608 + +Created table 'messages' to supersede the 'notes', 'memos', and 'watchlist' tables; they must be collated into this new table + +To create this new table run the following command: + +CREATE TABLE `feedback`.`messages` (`id` INT(11) NOT NULL AUTO_INCREMENT , `type` VARCHAR(32) NOT NULL , `targetckey` VARCHAR(32) NOT NULL , `adminckey` VARCHAR(32) NOT NULL , `text` TEXT NOT NULL , `timestamp` DATETIME NOT NULL , `server` VARCHAR(32) NULL , `secret` TINYINT(1) NULL DEFAULT 1 , `lasteditor` VARCHAR(32) NULL , `edits` TEXT NULL , PRIMARY KEY (`id`) ) + +To copy the contents of the 'notes', 'memos', and 'watchlist' tables to this new table run the following commands: + +INSERT INTO `feedback`.`messages` +(`id`,`type`,`targetckey`,`adminckey`,`text`,`timestamp`,`server`,`secret`,`lasteditor`,`edits`) SELECT `id`, "note", `ckey`, `adminckey`, `notetext`, `timestamp`, `server`, `secret`, `last_editor`, `edits` FROM `feedback`.`notes` + +INSERT INTO `feedback`.`messages` +(`type`,`targetckey`,`adminckey`,`text`,`timestamp`,`lasteditor`,`edits`) SELECT "memo", `ckey`, `ckey`, `memotext`, `timestamp`, `last_editor`, `edits` FROM `feedback`.`memo` + +INSERT INTO `feedback`.`messages` +(`type`,`targetckey`,`adminckey`,`text`,`timestamp`,`lasteditor`,`edits`) SELECT "watchlist entry", `ckey`, `adminckey`, `reason`, `timestamp`, `last_editor`, `edits` FROM `feedback`.`watch` + +It's not necessary to delete the 'notes', 'memos', and 'watchlist' tables but they will no longer be used. + +Remember to add a prefix to the table names if you use them + +---------------------------------------------------- + 1 September 2016, by Jordie0608 Modified table 'notes', adding column 'secret'. diff --git a/SQL/tgstation_schema.sql b/SQL/tgstation_schema.sql index a0a56c5ab40..e751b130890 100644 --- a/SQL/tgstation_schema.sql +++ b/SQL/tgstation_schema.sql @@ -314,69 +314,38 @@ CREATE TABLE `poll_vote` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `watch` +-- Table structure for table `ipintel` -- -DROP TABLE IF EXISTS `watch`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `watch` ( - `ckey` varchar(32) NOT NULL, - `reason` text NOT NULL, - `timestamp` datetime NOT NULL, - `adminckey` varchar(32) NOT NULL, - `last_editor` varchar(32), - `edits` text, - PRIMARY KEY (`ckey`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `memo` --- - -DROP TABLE IF EXISTS `memo`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `memo` ( - `ckey` varchar(32) NOT NULL, - `memotext` text NOT NULL, - `timestamp` datetime NOT NULL, - `last_editor` varchar(32), - `edits` text, - PRIMARY KEY (`ckey`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `notes` --- - -DROP TABLE IF EXISTS `notes`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `notes` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `ckey` varchar(32) NOT NULL, - `notetext` text NOT NULL, - `timestamp` datetime NOT NULL, - `adminckey` varchar(32) NOT NULL, - `last_editor` varchar(32), - `edits` text, - `server` varchar(50) NOT NULL, - `secret` tinyint(1) NOT NULL DEFAULT '1', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - DROP TABLE IF EXISTS `ipintel`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `ipintel` ( +CREATE TABLE `ipintel` ( `ip` INT UNSIGNED NOT NULL , `date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL , `intel` REAL NOT NULL DEFAULT '0', PRIMARY KEY ( `ip` ) ) ENGINE = INNODB; /*!40101 SET character_set_client = @saved_cs_client */; --- Dump completed on 2013-03-24 18:02:35 + +-- +-- Table structure for table `messages` +-- + +DROP TABLE IF EXISTS `messages`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `messages` ( + `id` int(11) NOT NULL AUTO_INCREMENT , + `type` varchar(32) NOT NULL , + `targetckey` varchar(32) NOT NULL , + `adminckey` varchar(32) NOT NULL , + `text` text NOT NULL , + `timestamp` datetime NOT NULL , + `server` varchar(32) NULL , + `secret` tinyint(1) NULL DEFAULT 1 , + `lasteditor` varchar(32) NULL , + `edits` text NULL , + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; diff --git a/SQL/tgstation_schema_prefixed.sql b/SQL/tgstation_schema_prefixed.sql index 2faf92bb44c..63d32eed08e 100644 --- a/SQL/tgstation_schema_prefixed.sql +++ b/SQL/tgstation_schema_prefixed.sql @@ -308,69 +308,38 @@ CREATE TABLE `SS13_poll_vote` ( /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `SS13_watch` +-- Table structure for table `SS13_ipintel` -- -DROP TABLE IF EXISTS `SS13_watch`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `SS13_watch` ( - `ckey` varchar(32) NOT NULL, - `reason` text NOT NULL, - `timestamp` datetime NOT NULL, - `adminckey` varchar(32) NOT NULL, - `last_editor` varchar(32), - `edits` text, - PRIMARY KEY (`ckey`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `SS13_memo` --- - -DROP TABLE IF EXISTS `SS13_memo`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `SS13_memo` ( - `ckey` varchar(32) NOT NULL, - `memotext` text NOT NULL, - `timestamp` datetime NOT NULL, - `last_editor` varchar(32), - `edits` text, - PRIMARY KEY (`ckey`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `SS13_notes` --- - -DROP TABLE IF EXISTS `SS13_notes`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `SS13_notes` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `ckey` varchar(32) NOT NULL, - `notetext` text NOT NULL, - `timestamp` datetime NOT NULL, - `adminckey` varchar(32) NOT NULL, - `last_editor` varchar(32), - `edits` text, - `server` varchar(50) NOT NULL, - `secret` tinyint(1) NOT NULL DEFAULT '1', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; - DROP TABLE IF EXISTS `SS13_ipintel`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `SS13_ipintel` ( +CREATE TABLE `SS13_ipintel` ( `ip` INT UNSIGNED NOT NULL , `date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NOT NULL , `intel` REAL NOT NULL DEFAULT '0', PRIMARY KEY ( `ip` ) ) ENGINE = INNODB; /*!40101 SET character_set_client = @saved_cs_client */; --- Dump completed on 2013-03-24 18:02:35 + +-- +-- Table structure for table `SS13_messages` +-- + +DROP TABLE IF EXISTS `SS13_messages`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `SS13_messages` ( + `id` int(11) NOT NULL AUTO_INCREMENT , + `type` varchar(32) NOT NULL , + `targetckey` varchar(32) NOT NULL , + `adminckey` varchar(32) NOT NULL , + `text` text NOT NULL , + `timestamp` datetime NOT NULL , + `server` varchar(32) NULL , + `secret` tinyint(1) NULL DEFAULT 1 , + `lasteditor` varchar(32) NULL , + `edits` text NULL , + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; diff --git a/code/controllers/subsystem/minimap.dm b/code/controllers/subsystem/minimap.dm index 1687cb1b2b8..6170185cede 100644 --- a/code/controllers/subsystem/minimap.dm +++ b/code/controllers/subsystem/minimap.dm @@ -28,7 +28,6 @@ var/datum/subsystem/minimap/SSminimap world << "Minimap generation disabled. Loading from cache..." var/fileloc = 0 if(check_files(0)) //Let's first check if we have maps cached in the data folder. NOTE: This will override the backup files even if this map is older. - world.log << "cache" if(hash != trim(file2text(hash_path()))) world << "Loaded cached minimap is outdated. There may be minor discrepancies in layout." //Disclaimer against players saying map is wrong. fileloc = 0 diff --git a/code/modules/admin/NewBan.dm b/code/modules/admin/NewBan.dm index 279de52a4c2..6b71181ca7f 100644 --- a/code/modules/admin/NewBan.dm +++ b/code/modules/admin/NewBan.dm @@ -117,9 +117,9 @@ var/savefile/Banlist if (temp) Banlist["minutes"] << bantimestamp if(!temp) - add_note(ckey, "Permanently banned - [reason]", null, bannedby, 0, null, 0) + create_message("note", ckey, bannedby, "Permanently banned - [reason]", null, null, 0, 0) else - add_note(ckey, "Banned for [minutes] minutes - [reason]", null, bannedby, 0, null, 0) + create_message("note", ckey, bannedby, "Banned for [minutes] minutes - [reason]", null, null, 0, 0) return 1 /proc/RemoveBan(foldername) diff --git a/code/modules/admin/admin.dm b/code/modules/admin/admin.dm index 4129039cf73..5202913b845 100644 --- a/code/modules/admin/admin.dm +++ b/code/modules/admin/admin.dm @@ -61,14 +61,8 @@ var/global/BSACooldown = 0 else body+= "Emoteban | " - body += "Notes | " + body += "Notes | Messages | Watchlist | " if(M.client) - if(M.client.check_watchlist(M.client.ckey)) - body += "Remove from Watchlist | " - body += "Edit Watchlist reason " - else - body += "Add to Watchlist " - body += "| Prison | " body += "\ Send back to Lobby | " var/muted = M.client.prefs.muted diff --git a/code/modules/admin/admin_investigate.dm b/code/modules/admin/admin_investigate.dm index 656238f46fd..d8b1faf43e2 100644 --- a/code/modules/admin/admin_investigate.dm +++ b/code/modules/admin/admin_investigate.dm @@ -25,7 +25,7 @@ F << "[time_stamp()] \ref[src] ([x],[y],[z]) || [src] [message]
" //ADMINVERBS -/client/proc/investigate_show( subject in list("hrefs","notes","watchlist","singulo","wires","telesci", "gravity", "records", "cargo", "supermatter", "atmos", "experimentor", "kudzu") ) +/client/proc/investigate_show( subject in list("hrefs","notes, memos, watchlist","singulo","wires","telesci", "gravity", "records", "cargo", "supermatter", "atmos", "experimentor", "kudzu") ) set name = "Investigate" set category = "Admin" if(!holder) @@ -46,7 +46,5 @@ else src << "No href logfile was found." return - if("notes") - show_note() - if("watchlist") - watchlist_show() + if("notes, memos, watchlist") + browse_messages() diff --git a/code/modules/admin/admin_memo.dm b/code/modules/admin/admin_memo.dm deleted file mode 100644 index 403f744925c..00000000000 --- a/code/modules/admin/admin_memo.dm +++ /dev/null @@ -1,131 +0,0 @@ -/client/proc/admin_memo() - set name = "Memo" - set category = "Server" - if(!check_rights(0)) - return - if(!dbcon.IsConnected()) - src << "Failed to establish database connection." - return - var/memotask = input(usr,"Choose task.","Memo") in list("Show","Write","Edit","Remove") - if(!memotask) - return - admin_memo_output(memotask) - -/client/proc/admin_memo_output(task) - if(!task) - return - if(!dbcon.IsConnected()) - src << "Failed to establish database connection." - return - var/sql_ckey = sanitizeSQL(src.ckey) - switch(task) - if("Write") - var/DBQuery/query_memocheck = dbcon.NewQuery("SELECT ckey FROM [format_table_name("memo")] WHERE ckey = '[sql_ckey]'") - if(!query_memocheck.Execute()) - var/err = query_memocheck.ErrorMsg() - log_game("SQL ERROR obtaining ckey from memo table. Error : \[[err]\]\n") - return - if(query_memocheck.NextRow()) - src << "You already have set a memo." - return - var/memotext = input(src,"Write your Memo","Memo") as message - if(!memotext) - return - memotext = sanitizeSQL(memotext) - var/timestamp = SQLtime() - var/DBQuery/query_memoadd = dbcon.NewQuery("INSERT INTO [format_table_name("memo")] (ckey, memotext, timestamp) VALUES ('[sql_ckey]', '[memotext]', '[timestamp]')") - if(!query_memoadd.Execute()) - var/err = query_memoadd.ErrorMsg() - log_game("SQL ERROR adding new memo. Error : \[[err]\]\n") - return - log_admin("[key_name(src)] has set a memo: [memotext]") - message_admins("[key_name_admin(src)] has set a memo:
[memotext]") - if("Edit") - var/DBQuery/query_memolist = dbcon.NewQuery("SELECT ckey FROM [format_table_name("memo")]") - if(!query_memolist.Execute()) - var/err = query_memolist.ErrorMsg() - log_game("SQL ERROR obtaining ckey from memo table. Error : \[[err]\]\n") - return - var/list/memolist = list() - while(query_memolist.NextRow()) - var/lkey = query_memolist.item[1] - memolist += "[lkey]" - if(!memolist.len) - src << "No memos found in database." - return - var/target_ckey = input(src, "Select whose memo to edit", "Select memo") as null|anything in memolist - if(!target_ckey) - return - var/target_sql_ckey = sanitizeSQL(target_ckey) - var/DBQuery/query_memofind = dbcon.NewQuery("SELECT memotext FROM [format_table_name("memo")] WHERE ckey = '[target_sql_ckey]'") - if(!query_memofind.Execute()) - var/err = query_memofind.ErrorMsg() - log_game("SQL ERROR obtaining memotext from memo table. Error : \[[err]\]\n") - return - if(query_memofind.NextRow()) - var/old_memo = query_memofind.item[1] - var/new_memo = input("Input new memo", "New Memo", "[old_memo]", null) as message - if(!new_memo) - return - new_memo = sanitizeSQL(new_memo) - var/edit_text = "Edited by [sql_ckey] on [SQLtime()] from
[old_memo]
to
[new_memo]
" - edit_text = sanitizeSQL(edit_text) - var/DBQuery/update_query = dbcon.NewQuery("UPDATE [format_table_name("memo")] SET memotext = '[new_memo]', last_editor = '[sql_ckey]', edits = CONCAT(IFNULL(edits,''),'[edit_text]') WHERE ckey = '[target_sql_ckey]'") - if(!update_query.Execute()) - var/err = update_query.ErrorMsg() - log_game("SQL ERROR editing memo. Error : \[[err]\]\n") - return - if(target_sql_ckey == sql_ckey) - log_admin("[key_name(src)] has edited their memo from [old_memo] to [new_memo]") - message_admins("[key_name_admin(src)] has edited their memo from
[old_memo]
to
[new_memo]") - else - log_admin("[key_name(src)] has edited [target_sql_ckey]'s memo from [old_memo] to [new_memo]") - message_admins("[key_name_admin(src)] has edited [target_sql_ckey]'s memo from
[old_memo]
to
[new_memo]") - if("Show") - var/DBQuery/query_memoshow = dbcon.NewQuery("SELECT ckey, memotext, timestamp, last_editor FROM [format_table_name("memo")]") - if(!query_memoshow.Execute()) - var/err = query_memoshow.ErrorMsg() - log_game("SQL ERROR obtaining ckey, memotext, timestamp, last_editor from memo table. Error : \[[err]\]\n") - return - var/output = null - while(query_memoshow.NextRow()) - var/ckey = query_memoshow.item[1] - var/memotext = query_memoshow.item[2] - var/timestamp = query_memoshow.item[3] - var/last_editor = query_memoshow.item[4] - output += "Memo by [ckey] on [timestamp]" - if(last_editor) - output += "
Last edit by [last_editor] (Click here to see edit log)" - output += "
[memotext]

" - if(!output) - src << "No memos found in database." - return - src << output - if("Remove") - var/DBQuery/query_memodellist = dbcon.NewQuery("SELECT ckey FROM [format_table_name("memo")]") - if(!query_memodellist.Execute()) - var/err = query_memodellist.ErrorMsg() - log_game("SQL ERROR obtaining ckey from memo table. Error : \[[err]\]\n") - return - var/list/memolist = list() - while(query_memodellist.NextRow()) - var/ckey = query_memodellist.item[1] - memolist += "[ckey]" - if(!memolist.len) - src << "No memos found in database." - return - var/target_ckey = input(src, "Select whose memo to delete", "Select memo") as null|anything in memolist - if(!target_ckey) - return - var/target_sql_ckey = sanitizeSQL(target_ckey) - var/DBQuery/query_memodel = dbcon.NewQuery("DELETE FROM [format_table_name("memo")] WHERE ckey = '[target_sql_ckey]'") - if(!query_memodel.Execute()) - var/err = query_memodel.ErrorMsg() - log_game("SQL ERROR removing memo. Error : \[[err]\]\n") - return - if(target_sql_ckey == sql_ckey) - log_admin("[key_name(src)] has removed their memo.") - message_admins("[key_name_admin(src)] has removed their memo.") - else - log_admin("[key_name(src)] has removed [target_sql_ckey]'s memo.") - message_admins("[key_name_admin(src)] has removed [target_sql_ckey]'s memo.") \ No newline at end of file diff --git a/code/modules/admin/admin_verbs.dm b/code/modules/admin/admin_verbs.dm index 22534a3320b..88ed6297f1a 100644 --- a/code/modules/admin/admin_verbs.dm +++ b/code/modules/admin/admin_verbs.dm @@ -7,7 +7,6 @@ var/list/admin_verbs_default = list( /client/proc/hide_verbs, /*hides all our adminverbs*/ /client/proc/hide_most_verbs, /*hides all our hideable adminverbs*/ /client/proc/debug_variables, /*allows us to -see- the variables of any instance in the game. +VAREDIT needed to modify*/ - /client/proc/admin_memo, /*admin memo system. show/delete/write. +SERVER needed to delete admin memos of others*/ /client/proc/deadchat, /*toggles deadchat on/off*/ /client/proc/dsay, /*talk in deadchat using our ckey/fakekey*/ /client/proc/toggleprayers, /*toggles prayers on/off*/ diff --git a/code/modules/admin/player_panel.dm b/code/modules/admin/player_panel.dm index 168c0ac1bba..396bbaafcfb 100644 --- a/code/modules/admin/player_panel.dm +++ b/code/modules/admin/player_panel.dm @@ -76,7 +76,7 @@ body += ""; body += "PP - " - body += "N - " + body += "N - " body += "VV - " body += "TP - " body += "PM - " diff --git a/code/modules/admin/sql_message_system.dm b/code/modules/admin/sql_message_system.dm new file mode 100644 index 00000000000..6edeb66c776 --- /dev/null +++ b/code/modules/admin/sql_message_system.dm @@ -0,0 +1,371 @@ +/proc/create_message(type, target_ckey, admin_ckey, text, timestamp, server, secret, logged = 1, browse) + if(!dbcon.IsConnected()) + usr << "Failed to establish database connection." + return + if(!type) + return + if(!target_ckey && (type == "note" || type == "message" || type == "watchlist entry")) + var/new_ckey = ckey(input(usr,"Who would you like to create a [type] for?","Enter a ckey",null) as null|text) + if(!new_ckey) + return + new_ckey = sanitizeSQL(new_ckey) + var/DBQuery/query_find_ckey = dbcon.NewQuery("SELECT ckey FROM [format_table_name("player")] WHERE ckey = '[new_ckey]'") + if(!query_find_ckey.Execute()) + var/err = query_find_ckey.ErrorMsg() + log_game("SQL ERROR obtaining ckey from player table. Error : \[[err]\]\n") + return + if(!query_find_ckey.NextRow()) + if(alert(usr, "[new_ckey] has not been seen before, are you sure you want to create a [type] for them?", "Unknown ckey", "Yes", "No", "Cancel") != "Yes") + return + target_ckey = new_ckey + if(target_ckey) + target_ckey = sanitizeSQL(target_ckey) + if(!admin_ckey) + admin_ckey = usr.ckey + if(!admin_ckey) + return + admin_ckey = sanitizeSQL(admin_ckey) + if(!target_ckey) + target_ckey = admin_ckey + if(!text) + text = input(usr,"Write your [type]","Create [type]") as null|message + if(!text) + return + text = sanitizeSQL(text) + if(!timestamp) + timestamp = SQLtime() + if(!server) + if (config && config.server_name) + server = config.server_name + server = sanitizeSQL(server) + if(isnull(secret)) + switch(alert("Hide note from being viewed by players?", "Secret note?","Yes","No","Cancel")) + if("Yes") + secret = 1 + if("No") + secret = 0 + else + return + var/DBQuery/query_create_message = dbcon.NewQuery("INSERT INTO [format_table_name("messages")] (type, targetckey, adminckey, text, timestamp, server, secret) VALUES ('[type]', '[target_ckey]', '[admin_ckey]', '[text]', '[timestamp]', '[server]', '[secret]')") + if(!query_create_message.Execute()) + var/err = query_create_message.ErrorMsg() + log_game("SQL ERROR creating new [type] in messages table. Error : \[[err]\]\n") + return + if(logged) + log_admin("[key_name(usr)] has created a [type][type == ("note"||"message"||"watchlist entry") ? " for [target_ckey]" : ""]: [text]") + message_admins("[key_name_admin(usr)] has created a [type][type == ("note"||"message"||"watchlist entry") ? " for [target_ckey]" : ""]:
[text]") + if(browse) + browse_messages("[type]") + else + browse_messages(target_ckey = target_ckey) + +/proc/delete_message(message_id, logged = 1, browse) + if(!dbcon.IsConnected()) + usr << "Failed to establish database connection." + return + message_id = text2num(message_id) + if(!message_id) + return + var/type + var/target_ckey + var/text + var/DBQuery/query_find_del_message = dbcon.NewQuery("SELECT type, targetckey, adminckey, text FROM [format_table_name("messages")] WHERE id = [message_id]") + if(!query_find_del_message.Execute()) + var/err = query_find_del_message.ErrorMsg() + log_game("SQL ERROR obtaining type, targetckey, adminckey text from messages table. Error : \[[err]\]\n") + return + if(query_find_del_message.NextRow()) + type = query_find_del_message.item[1] + target_ckey = query_find_del_message.item[2] + text = query_find_del_message.item[4] + var/DBQuery/query_del_message = dbcon.NewQuery("DELETE FROM [format_table_name("messages")] WHERE id = [message_id]") + if(!query_del_message.Execute()) + var/err = query_del_message.ErrorMsg() + log_game("SQL ERROR deleting [type] from messages table. Error : \[[err]\]\n") + return + if(logged) + log_admin("[key_name(usr)] has deleted a [type][type == ("note"||"message"||"watchlist entry") ? " for" : " made by"] [target_ckey]: [text]") + message_admins("[key_name_admin(usr)] has deleted a [type][type == ("note"||"message"||"watchlist entry") ? " for" : " made by"] [target_ckey]:
[text]") + if(browse) + browse_messages("[type]") + else + browse_messages(target_ckey = target_ckey) + +/proc/edit_message(message_id, browse) + if(!dbcon.IsConnected()) + usr << "Failed to establish database connection." + return + message_id = text2num(message_id) + if(!message_id) + return + var/DBQuery/query_find_edit_message = dbcon.NewQuery("SELECT type, targetckey, adminckey, text FROM [format_table_name("messages")] WHERE id = [message_id]") + if(!query_find_edit_message.Execute()) + var/err = query_find_edit_message.ErrorMsg() + log_game("SQL ERROR obtaining type, targetckey, adminckey, text from messages table. Error : \[[err]\]\n") + return + if(query_find_edit_message.NextRow()) + var/type = query_find_edit_message.item[1] + var/target_ckey = query_find_edit_message.item[2] + var/admin_ckey = query_find_edit_message.item[3] + var/old_text = query_find_edit_message.item[4] + var/editor_ckey = sanitizeSQL(usr.ckey) + var/new_text = input("Input new [type]", "New [type]", "[old_text]") as null|message + if(!new_text) + return + new_text = sanitizeSQL(new_text) + var/edit_text = sanitizeSQL("Edited by [editor_ckey] on [SQLtime()] from
[old_text]
to
[new_text]
") + var/DBQuery/query_edit_message = dbcon.NewQuery("UPDATE [format_table_name("messages")] SET text = '[new_text]', lasteditor = '[editor_ckey]', edits = CONCAT(IFNULL(edits,''),'[edit_text]') WHERE id = [message_id]") + if(!query_edit_message.Execute()) + var/err = query_edit_message.ErrorMsg() + log_game("SQL ERROR editing messages table. Error : \[[err]\]\n") + return + log_admin("[key_name(usr)] has edited a [type] [type == ("note"||"message"||"watchlist entry") ? " for [target_ckey]" : ""] made by [admin_ckey] from [old_text] to [new_text]") + message_admins("[key_name_admin(usr)] has edited a [type] [type == ("note"||"message"||"watchlist entry") ? " for [target_ckey]" : ""] made by [admin_ckey] from
[old_text]
to
[new_text]") + if(browse) + browse_messages("[type]") + else + browse_messages(target_ckey = target_ckey) + +/proc/toggle_message_secrecy(message_id) + if(!dbcon.IsConnected()) + usr << "Failed to establish database connection." + return + message_id = text2num(message_id) + if(!message_id) + return + var/DBQuery/query_find_message_secret = dbcon.NewQuery("SELECT type, targetckey, adminckey, secret FROM [format_table_name("messages")] WHERE id = [message_id]") + if(!query_find_message_secret.Execute()) + var/err = query_find_message_secret.ErrorMsg() + log_game("SQL ERROR obtaining type, targetckey, adminckey, secret from messages table. Error : \[[err]\]\n") + return + if(query_find_message_secret.NextRow()) + var/type = query_find_message_secret.item[1] + var/target_ckey = query_find_message_secret.item[2] + var/admin_ckey = query_find_message_secret.item[3] + var/secret = text2num(query_find_message_secret.item[4]) + var/editor_ckey = sanitizeSQL(usr.ckey) + var/edit_text = "Made [secret ? "not secret" : "secret"] by [editor_ckey] on [SQLtime()]
" + var/DBQuery/query_message_secret = dbcon.NewQuery("UPDATE [format_table_name("messages")] SET secret = NOT secret, lasteditor = '[editor_ckey]', edits = CONCAT(IFNULL(edits,''),'[edit_text]') WHERE id = [message_id]") + if(!query_message_secret.Execute()) + var/err = query_message_secret.ErrorMsg() + log_game("SQL ERROR toggling message secrecy. Error : \[[err]\]\n") + return + log_admin("[key_name(usr)] has toggled [target_ckey]'s [type] made by [admin_ckey] to [secret ? "not secret" : "secret"]") + message_admins("[key_name_admin(usr)] has toggled [target_ckey]'s [type] made by [admin_ckey] to [secret ? "not secret" : "secret"]") + browse_messages(target_ckey = target_ckey) + +/proc/browse_messages(type, target_ckey, index, linkless = 0) + if(!dbcon.IsConnected()) + usr << "Failed to establish database connection." + return + var/output + var/ruler = "
" + var/navbar = "\[All\]|\[#\]" + for(var/letter in alphabet) + navbar += "|\[[letter]\]" + navbar += "|\[Memos\]|\[Watchlist\]" + navbar += "
\ + \ + \ +
" + if(!linkless) + output = navbar + if(type == "memo" || type == "watchlist entry") + if(type == "memo") + output += "

Admin memos

" + output += "\[Add memo\]" + else if(type == "watchlist entry") + output += "

Watchlist entries

" + output += "\[Add watchlist entry\]" + output += ruler + var/DBQuery/query_get_type_messages = dbcon.NewQuery("SELECT id, targetckey, adminckey, text, timestamp, server, lasteditor FROM [format_table_name("messages")] WHERE type = '[type]'") + if(!query_get_type_messages.Execute()) + var/err = query_get_type_messages.ErrorMsg() + log_game("SQL ERROR obtaining id, targetckey, adminckey, text, timestamp, server, lasteditor from messages table. Error : \[[err]\]\n") + return + while(query_get_type_messages.NextRow()) + var/id = query_get_type_messages.item[1] + var/t_ckey = query_get_type_messages.item[2] + var/admin_ckey = query_get_type_messages.item[3] + var/text = query_get_type_messages.item[4] + var/timestamp = query_get_type_messages.item[5] + var/server = query_get_type_messages.item[6] + var/editor_ckey = query_get_type_messages.item[7] + output += "" + if(type == "watchlist entry") + output += "[t_ckey] | " + output += "[timestamp] | [server] | [admin_ckey]" + output += " \[Delete\]" + output += " \[Edit\]" + if(editor_ckey) + output += " Last edit by [editor_ckey] (Click here to see edit log)" + output += "
[text]
" + if(target_ckey) + target_ckey = sanitizeSQL(target_ckey) + var/DBQuery/query_get_messages = dbcon.NewQuery("SELECT type, secret, id, adminckey, text, timestamp, server, lasteditor FROM [format_table_name("messages")] WHERE type <> 'memo' AND targetckey = '[target_ckey]' ORDER BY timestamp") + if(!query_get_messages.Execute()) + var/err = query_get_messages.ErrorMsg() + log_game("SQL ERROR obtaining type, secret, id, adminckey, text, timestamp, server, lasteditor from messages table. Error : \[[err]\]\n") + return + var/messagedata + var/watchdata + var/notedata + while(query_get_messages.NextRow()) + type = query_get_messages.item[1] + if(type == "memo") + continue + var/secret = text2num(query_get_messages.item[2]) + if(linkless && secret) + continue + var/id = query_get_messages.item[3] + var/admin_ckey = query_get_messages.item[4] + var/text = query_get_messages.item[5] + var/timestamp = query_get_messages.item[6] + var/server = query_get_messages.item[7] + var/editor_ckey = query_get_messages.item[8] + var/data + data += "[timestamp] | [server] | [admin_ckey]" + if(!linkless) + data += " \[Delete\]" + if(type == "note") + data += " [secret ? "\[Secret\]" : "\[Not secret\]"]" + data += " \[Edit\]" + if(editor_ckey) + data += " Last edit by [editor_ckey] (Click here to see edit log)" + data += "
[text]
" + switch(type) + if("message") + messagedata += data + if("watchlist entry") + watchdata += data + if("note") + notedata += data + output += "

[target_ckey]

" + if(!linkless) + output += "\[Add message\]" + output += " \[Add to watchlist\]" + output += " \[Add note\]" + output += " \[Refresh page\]
" + else + output += " \[Refresh page\]" + output += ruler + if(messagedata) + output += "

Messages

" + output += messagedata + if(watchdata) + output += "

Watchlist

" + output += watchdata + if(notedata) + output += "

Notes

" + output += notedata + if(index) + var/index_ckey + var/search + output += "
\[Add message\]\[Add watchlist entry\]\[Add note\]
" + output += ruler + if(!isnum(index)) + index = sanitizeSQL(index) + switch(index) + if(1) + search = "^." + if(2) + search = "^\[^\[:alpha:\]\]" + else + search = "^[index]" + var/DBQuery/query_list_messages = dbcon.NewQuery("SELECT DISTINCT targetckey FROM [format_table_name("messages")] WHERE type <> 'memo' AND targetckey REGEXP '[search]' ORDER BY targetckey") + if(!query_list_messages.Execute()) + var/err = query_list_messages.ErrorMsg() + log_game("SQL ERROR obtaining distinct targetckey from messages table. Error : \[[err]\]\n") + return + while(query_list_messages.NextRow()) + index_ckey = query_list_messages.item[1] + output += "[index_ckey]
" + else if(!type && !target_ckey && !index) + output += "
\[Add message\]\[Add watchlist entry\]\[Add note\]
" + output += ruler + usr << browse(output, "window=browse_messages;size=900x500") + +proc/get_message_output(type, target_ckey) + if(!dbcon.IsConnected()) + usr << "Failed to establish database connection." + return + if(!type) + return + var/output + if(target_ckey) + target_ckey = sanitizeSQL(target_ckey) + var/query = "SELECT id, adminckey, text, timestamp, lasteditor FROM [format_table_name("messages")] WHERE type = '[type]'" + if(type == "message" || type == "watchlist entry") + query += " AND targetckey = '[target_ckey]'" + var/DBQuery/query_get_message_output = dbcon.NewQuery(query) + if(!query_get_message_output.Execute()) + var/err = query_get_message_output.ErrorMsg() + log_game("SQL ERROR obtaining id, adminckey, text, timestamp, lasteditor from messages table. Error : \[[err]\]\n") + return + while(query_get_message_output.NextRow()) + var/id = query_get_message_output.item[1] + var/admin_ckey = query_get_message_output.item[2] + var/text = query_get_message_output.item[3] + var/timestamp = query_get_message_output.item[4] + var/editor_ckey = query_get_message_output.item[5] + switch(type) + if("message") + output += "Admin message left by [admin_ckey] on [timestamp]" + output += "
[text]" + delete_message(id, 0) + if("watchlist entry") + message_admins("Notice: [key_name_admin(target_ckey)] is on the watchlist and has just connected - Reason: [text]") + send2irc_adminless_only("Watchlist", "[key_name(target_ckey)] is on the watchlist and has just connected - Reason: [text]") + if("memo") + output += "Memo by [admin_ckey] on [timestamp]" + if(editor_ckey) + output += "
Last edit by [editor_ckey] (Click here to see edit log)" + output += "
[text]

" + return output + +#define NOTESFILE "data/player_notes.sav" +//if the AUTOCONVERT_NOTES is turned on, anytime a player connects this will be run to try and add all their notes to the databas +/proc/convert_notes_sql(ckey) + var/savefile/notesfile = new(NOTESFILE) + if(!notesfile) + log_game("Error: Cannot access [NOTESFILE]") + return + notesfile.cd = "/[ckey]" + while(!notesfile.eof) + var/notetext + notesfile >> notetext + var/server + if(config && config.server_name) + server = config.server_name + var/regex/note = new("^(\\d{2}-\\w{3}-\\d{4}) \\| (.+) ~(\\w+)$", "i") + note.Find(notetext) + var/timestamp = note.group[1] + notetext = note.group[2] + var/admin_ckey = note.group[3] + var/DBQuery/query_convert_time = dbcon.NewQuery("SELECT ADDTIME(STR_TO_DATE('[timestamp]','%d-%b-%Y'), '0')") + if(!query_convert_time.Execute()) + var/err = query_convert_time.ErrorMsg() + log_game("SQL ERROR converting timestamp. Error : \[[err]\]\n") + return + if(query_convert_time.NextRow()) + timestamp = query_convert_time.item[1] + if(ckey && notetext && timestamp && admin_ckey && server) + create_message("note", ckey, admin_ckey, notetext, timestamp, server, 1, 0) + notesfile.cd = "/" + notesfile.dir.Remove(ckey) + +/*alternatively this proc can be run once to pass through every note and attempt to convert it before deleting the file, if done then AUTOCONVERT_NOTES should be turned off +this proc can take several minutes to execute fully if converting and cause DD to hang if converting a lot of notes; it's not advised to do so while a server is live +/proc/mass_convert_notes() + world << "Beginning mass note conversion" + var/savefile/notesfile = new(NOTESFILE) + if(!notesfile) + log_game("Error: Cannot access [NOTESFILE]") + return + notesfile.cd = "/" + for(var/ckey in notesfile.dir) + convert_notes_sql(ckey) + world << "Deleting NOTESFILE" + fdel(NOTESFILE) + world << "Finished mass note conversion, remember to turn off AUTOCONVERT_NOTES"*/ +#undef NOTESFILE \ No newline at end of file diff --git a/code/modules/admin/sql_notes.dm b/code/modules/admin/sql_notes.dm deleted file mode 100644 index 44244d36f38..00000000000 --- a/code/modules/admin/sql_notes.dm +++ /dev/null @@ -1,260 +0,0 @@ -/proc/add_note(target_ckey, notetext, timestamp, adminckey, logged = 1, server, secret) - if(!dbcon.IsConnected()) - usr << "Failed to establish database connection." - return - if(!target_ckey) - var/new_ckey = ckey(input(usr,"Who would you like to add a note for?","Enter a ckey",null) as text) - if(!new_ckey) - return - new_ckey = sanitizeSQL(new_ckey) - var/DBQuery/query_find_ckey = dbcon.NewQuery("SELECT ckey FROM [format_table_name("player")] WHERE ckey = '[new_ckey]'") - if(!query_find_ckey.Execute()) - var/err = query_find_ckey.ErrorMsg() - log_game("SQL ERROR obtaining ckey from player table. Error : \[[err]\]\n") - return - if(!query_find_ckey.NextRow()) - if(alert(usr, "[new_ckey] has not been seen before, are you sure you want to add a note for them?", "Unknown ckey", "Yes", "No", "Cancel") != "Yes") - return - target_ckey = new_ckey - var/target_sql_ckey = sanitizeSQL(target_ckey) - if(!notetext) - notetext = input(usr,"Write your Note","Add Note") as null|message - if(!notetext) - return - notetext = sanitizeSQL(notetext) - if(!timestamp) - timestamp = SQLtime() - if(!adminckey) - adminckey = usr.ckey - if(!adminckey) - return - var/admin_sql_ckey = sanitizeSQL(adminckey) - if(!server) - if (config && config.server_name) - server = config.server_name - server = sanitizeSQL(server) - if(isnull(secret)) - switch(alert("Hide note from being viewed by players?", "Secret Note?","Yes","No","Cancel")) - if("Yes") - secret = 1 - if("No") - secret = 0 - else - return - var/DBQuery/query_noteadd = dbcon.NewQuery("INSERT INTO [format_table_name("notes")] (ckey, timestamp, notetext, adminckey, server, secret) VALUES ('[target_sql_ckey]', '[timestamp]', '[notetext]', '[admin_sql_ckey]', '[server]', '[secret]')") - if(!query_noteadd.Execute()) - var/err = query_noteadd.ErrorMsg() - log_game("SQL ERROR adding new note to table. Error : \[[err]\]\n") - return - if(logged) - log_admin("[key_name(usr)] has added a note to [target_ckey]: [notetext]") - message_admins("[key_name_admin(usr)] has added a note to [target_ckey]:
[notetext]") - show_note(target_ckey) - -/proc/remove_note(note_id) - var/ckey - var/notetext - var/adminckey - if(!dbcon.IsConnected()) - usr << "Failed to establish database connection." - return - if(!note_id) - return - note_id = text2num(note_id) - var/DBQuery/query_find_note_del = dbcon.NewQuery("SELECT ckey, notetext, adminckey FROM [format_table_name("notes")] WHERE id = [note_id]") - if(!query_find_note_del.Execute()) - var/err = query_find_note_del.ErrorMsg() - log_game("SQL ERROR obtaining ckey, notetext, adminckey from notes table. Error : \[[err]\]\n") - return - if(query_find_note_del.NextRow()) - ckey = query_find_note_del.item[1] - notetext = query_find_note_del.item[2] - adminckey = query_find_note_del.item[3] - var/DBQuery/query_del_note = dbcon.NewQuery("DELETE FROM [format_table_name("notes")] WHERE id = [note_id]") - if(!query_del_note.Execute()) - var/err = query_del_note.ErrorMsg() - log_game("SQL ERROR removing note from table. Error : \[[err]\]\n") - return - log_admin("[key_name(usr)] has removed a note made by [adminckey] from [ckey]: [notetext]") - message_admins("[key_name_admin(usr)] has removed a note made by [adminckey] from [ckey]:
[notetext]") - show_note(ckey) - -/proc/edit_note(note_id) - if(!dbcon.IsConnected()) - usr << "Failed to establish database connection." - return - if(!note_id) - return - note_id = text2num(note_id) - var/target_ckey - var/sql_ckey = sanitizeSQL(usr.ckey) - var/DBQuery/query_find_note_edit = dbcon.NewQuery("SELECT ckey, notetext, adminckey FROM [format_table_name("notes")] WHERE id = [note_id]") - if(!query_find_note_edit.Execute()) - var/err = query_find_note_edit.ErrorMsg() - log_game("SQL ERROR obtaining notetext from notes table. Error : \[[err]\]\n") - return - if(query_find_note_edit.NextRow()) - target_ckey = query_find_note_edit.item[1] - var/old_note = query_find_note_edit.item[2] - var/adminckey = query_find_note_edit.item[3] - var/new_note = input("Input new note", "New Note", "[old_note]") as null|message - if(!new_note) - return - new_note = sanitizeSQL(new_note) - var/edit_text = "Edited by [sql_ckey] on [SQLtime()] from
[old_note]
to
[new_note]
" - edit_text = sanitizeSQL(edit_text) - var/DBQuery/query_update_note = dbcon.NewQuery("UPDATE [format_table_name("notes")] SET notetext = '[new_note]', last_editor = '[sql_ckey]', edits = CONCAT(IFNULL(edits,''),'[edit_text]') WHERE id = [note_id]") - if(!query_update_note.Execute()) - var/err = query_update_note.ErrorMsg() - log_game("SQL ERROR editing note. Error : \[[err]\]\n") - return - log_admin("[key_name(usr)] has edited [target_ckey]'s note made by [adminckey] from [old_note] to [new_note]") - message_admins("[key_name_admin(usr)] has edited [target_ckey]'s note made by [adminckey] from
[old_note]
to
[new_note]") - show_note(target_ckey) - -/proc/toggle_note_secrecy(note_id) - if(!dbcon.IsConnected()) - usr << "Failed to establish database connection." - return - if(!note_id) - return - note_id = text2num(note_id) - var/DBQuery/query_find_note_secret = dbcon.NewQuery("SELECT ckey, adminckey, secret FROM [format_table_name("notes")] WHERE id = [note_id]") - if(!query_find_note_secret.Execute()) - var/err = query_find_note_secret.ErrorMsg() - log_game("SQL ERROR obtaining ckey, adminckey, secret from notes table. Error : \[[err]\]\n") - return - if(query_find_note_secret.NextRow()) - var/target_ckey = query_find_note_secret.item[1] - var/adminckey = query_find_note_secret.item[2] - var/secret = text2num(query_find_note_secret.item[3]) - var/sql_ckey = sanitizeSQL(usr.ckey) - var/edit_text = "Made [secret ? "not secret" : "secret"] by [sql_ckey] on [SQLtime()]
" - var/DBQuery/query_update_note = dbcon.NewQuery("UPDATE [format_table_name("notes")] SET secret = NOT secret, last_editor = '[sql_ckey]', edits = CONCAT(IFNULL(edits,''),'[edit_text]') WHERE id = [note_id]") - if(!query_update_note.Execute()) - var/err = query_update_note.ErrorMsg() - log_game("SQL ERROR toggling note secrecy. Error : \[[err]\]\n") - return - log_admin("[key_name(usr)] has toggled [target_ckey]'s note made by [adminckey] to [secret ? "not secret" : "secret"]") - message_admins("[key_name_admin(usr)] has toggled [target_ckey]'s note made by [adminckey] to [secret ? "not secret" : "secret"]") - show_note(target_ckey) - -/proc/show_note(target_ckey, index, linkless = 0) - if(!dbcon.IsConnected()) - usr << "Failed to establish database connection." - return - var/output - var/ruler = "
" - var/navbar = "\[All\]|\[#\]" - for(var/letter in alphabet) - navbar += "|\[[letter]\]" - navbar += "
\ - \ - \ -
" - if(!linkless) - output = navbar - if(target_ckey) - var/target_sql_ckey = sanitizeSQL(target_ckey) - var/DBQuery/query_get_notes = dbcon.NewQuery("SELECT secret, timestamp, notetext, adminckey, last_editor, server, id FROM [format_table_name("notes")] WHERE ckey = '[target_sql_ckey]' ORDER BY timestamp") - if(!query_get_notes.Execute()) - var/err = query_get_notes.ErrorMsg() - usr << "SQL ERROR: Failed to obtain DB records. Error : \[[err]\]\" - log_game("SQL ERROR obtaining secret, timestamp, notetext, adminckey, last_editor, server, id from notes table. Error : \[[err]\]\n") - return - output += "

Notes of [target_ckey]

" - if(!linkless) - output += "
\[Add Note\]" - output += " \[Refresh Page\]
" - else - output += " \[Refresh Page\]" - output += ruler - while(query_get_notes.NextRow()) - var/secret = text2num(query_get_notes.item[1]) - if(linkless && secret) - continue - var/timestamp = query_get_notes.item[2] - var/notetext = query_get_notes.item[3] - var/adminckey = query_get_notes.item[4] - var/last_editor = query_get_notes.item[5] - var/server = query_get_notes.item[6] - var/id = query_get_notes.item[7] - output += "[timestamp] | [server] | [adminckey]" - if(!linkless) - output += " \[Remove Note\] [secret ? "\[Secret\]" : "\[Not Secret\]"] \[Edit Note\]" - if(last_editor) - output += " Last edit by [last_editor] (Click here to see edit log)" - output += "
[notetext]
" - else if(index) - var/index_ckey - var/search - output += "
\[Add Note\]
" - output += ruler - if(!isnum(index)) - index = sanitizeSQL(index) - switch(index) - if(1) - search = "^." - if(2) - search = "^\[^\[:alpha:\]\]" - else - search = "^[index]" - var/DBQuery/query_list_notes = dbcon.NewQuery("SELECT DISTINCT ckey FROM [format_table_name("notes")] WHERE ckey REGEXP '[search]' ORDER BY ckey") - if(!query_list_notes.Execute()) - var/err = query_list_notes.ErrorMsg() - log_game("SQL ERROR obtaining ckey from notes table. Error : \[[err]\]\n") - return - while(query_list_notes.NextRow()) - index_ckey = query_list_notes.item[1] - output += "[index_ckey]
" - else - output += "
\[Add Note\]
" - output += ruler - usr << browse(output, "window=show_notes;size=900x500") - -#define NOTESFILE "data/player_notes.sav" -//if the AUTOCONVERT_NOTES is turned on, anytime a player connects this will be run to try and add all their notes to the databas -/proc/convert_notes_sql(ckey) - var/savefile/notesfile = new(NOTESFILE) - if(!notesfile) - log_game("Error: Cannot access [NOTESFILE]") - return - notesfile.cd = "/[ckey]" - while(!notesfile.eof) - var/notetext - notesfile >> notetext - var/server - if(config && config.server_name) - server = config.server_name - var/regex/note = new("^(\\d{2}-\\w{3}-\\d{4}) \\| (.+) ~(\\w+)$", "i") - note.Find(notetext) - var/timestamp = note.group[1] - notetext = note.group[2] - var/adminckey = note.group[3] - var/DBQuery/query_convert_time = dbcon.NewQuery("SELECT ADDTIME(STR_TO_DATE('[timestamp]','%d-%b-%Y'), '0')") - if(!query_convert_time.Execute()) - var/err = query_convert_time.ErrorMsg() - log_game("SQL ERROR converting timestamp. Error : \[[err]\]\n") - return - if(query_convert_time.NextRow()) - timestamp = query_convert_time.item[1] - if(ckey && notetext && timestamp && adminckey && server) - add_note(ckey, notetext, timestamp, adminckey, 0, server, 1) - notesfile.cd = "/" - notesfile.dir.Remove(ckey) - -/*alternatively this proc can be run once to pass through every note and attempt to convert it before deleting the file, if done then AUTOCONVERT_NOTES should be turned off -this proc can take several minutes to execute fully if converting and cause DD to hang if converting a lot of notes; it's not advised to do so while a server is live -/proc/mass_convert_notes() - world << "Beginning mass note conversion" - var/savefile/notesfile = new(NOTESFILE) - if(!notesfile) - log_game("Error: Cannot access [NOTESFILE]") - return - notesfile.cd = "/" - for(var/ckey in notesfile.dir) - convert_notes_sql(ckey) - world << "Deleting NOTESFILE" - fdel(NOTESFILE) - world << "Finished mass note conversion, remember to turn off AUTOCONVERT_NOTES"*/ -#undef NOTESFILE diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm index 00a3202b1fe..5032bb69de1 100644 --- a/code/modules/admin/topic.dm +++ b/code/modules/admin/topic.dm @@ -238,7 +238,7 @@ if(!DB_ban_record(bantype, playermob, banduration, banreason, banjob, null, banckey, banip, bancid )) usr << "Failed to apply ban." return - add_note(banckey, banreason, null, usr.ckey, 0, null, 0) + create_message("note", banckey, null, banreason, null, null, 0, 0) else if(href_list["editrights"]) edit_rights_topic(href_list) @@ -543,7 +543,7 @@ ban_unban_log_save("[key_name(usr)] appearance banned [key_name(M)]. reason: [reason]") log_admin("[key_name(usr)] appearance banned [key_name(M)]. \nReason: [reason]") feedback_inc("ban_appearance",1) - add_note(M.ckey, "Appearance banned - [reason]", null, usr.ckey, 0, null, 0) + create_message("note", M.ckey, null, "Appearance banned - [reason]", null, null, 0, 0) message_admins("[key_name_admin(usr)] appearance banned [key_name_admin(M)].") M << "You have been appearance banned by [usr.client.ckey]." M << "The reason is: [reason]" @@ -933,7 +933,7 @@ msg = job else msg += ", [job]" - add_note(M.ckey, "Banned from [msg] - [reason]", null, usr.ckey, 0, null, 0) + create_message("note", M.ckey, null, "Banned from [msg] - [reason]", null, null, 0, 0) message_admins("[key_name_admin(usr)] banned [key_name_admin(M)] from [msg] for [mins] minutes.") M << "You have been [(msg == ("ooc" || "appearance")) ? "banned" : "jobbanned"] by [usr.client.ckey] from: [msg]." M << "The reason is: [reason]" @@ -958,7 +958,7 @@ msg = job else msg += ", [job]" - add_note(M.ckey, "Banned from [msg] - [reason]", null, usr.ckey, 0, null, 0) + create_message("note", M.ckey, null, "Banned from [msg] - [reason]", null, null, 0, 0) message_admins("[key_name_admin(usr)] banned [key_name_admin(M)] from [msg].") M << "You have been [(msg == ("ooc" || "appearance")) ? "banned" : "jobbanned"] by [usr.client.ckey] from: [msg]." M << "The reason is: [reason]" @@ -1010,58 +1010,88 @@ //M.client = null qdel(M.client) - //Player Notes + else if(href_list["addmessage"]) + var/target_ckey = href_list["addmessage"] + create_message("message", target_ckey, secret = 0) + else if(href_list["addnote"]) var/target_ckey = href_list["addnote"] - add_note(target_ckey) + create_message("note", target_ckey) + + else if(href_list["addwatch"]) + var/target_ckey = href_list["addwatch"] + create_message("watchlist entry", target_ckey, secret = 1) + + else if(href_list["addmemo"]) + create_message("memo", secret = 0, browse = 1) + + else if(href_list["addmessageempty"]) + create_message("message", secret = 0) else if(href_list["addnoteempty"]) - add_note() + create_message("note") - else if(href_list["removenote"]) - var/note_id = href_list["removenote"] - remove_note(note_id) + else if(href_list["addwatchempty"]) + create_message("watchlist entry", secret = 1) - else if(href_list["editnote"]) - var/note_id = href_list["editnote"] - edit_note(note_id) + else if(href_list["deletemessage"]) + var/message_id = href_list["deletemessage"] + delete_message(message_id) - else if(href_list["shownote"]) - var/target = href_list["shownote"] - show_note(index = target) + else if(href_list["deletemessageempty"]) + var/message_id = href_list["deletemessageempty"] + delete_message(message_id, browse = 1) + + else if(href_list["editmessage"]) + var/message_id = href_list["editmessage"] + edit_message(message_id) + + else if(href_list["editmessageempty"]) + var/message_id = href_list["editmessageempty"] + edit_message(message_id, browse = 1) + + else if(href_list["secretmessage"]) + var/message_id = href_list["secretmessage"] + toggle_message_secrecy(message_id) + + else if(href_list["searchmessages"]) + var/target = href_list["searchmessages"] + browse_messages(index = target) else if(href_list["nonalpha"]) var/target = href_list["nonalpha"] target = text2num(target) - show_note(index = target) + browse_messages(index = target) - else if(href_list["shownoteckey"]) - var/target_ckey = href_list["shownoteckey"] - show_note(target_ckey) + else if(href_list["showmessages"]) + var/target = href_list["showmessages"] + browse_messages(index = target) - else if(href_list["shownoteckeylinkless"]) - var/target_ckey = href_list["shownoteckeylinkless"] - show_note(target_ckey, null, 1) + else if(href_list["showmemo"]) + browse_messages("memo") - else if(href_list["notessearch"]) - var/target = href_list["notessearch"] - show_note(index = target) + else if(href_list["showwatch"]) + browse_messages("watchlist entry") - else if(href_list["noteedits"]) - var/note_id = sanitizeSQL("[href_list["noteedits"]]") - var/DBQuery/query_noteedits = dbcon.NewQuery("SELECT edits FROM [format_table_name("notes")] WHERE id = '[note_id]'") - if(!query_noteedits.Execute()) - var/err = query_noteedits.ErrorMsg() - log_game("SQL ERROR obtaining edits from notes table. Error : \[[err]\]\n") + else if(href_list["showmessageckey"]) + var/target = href_list["showmessageckey"] + browse_messages(target_ckey = target) + + else if(href_list["showmessageckeylinkless"]) + var/target = href_list["showmessageckeylinkless"] + browse_messages(target_ckey = target, linkless = 1) + + else if(href_list["messageedits"]) + var/message_id = sanitizeSQL("[href_list["messageedits"]]") + var/DBQuery/query_get_message_edits = dbcon.NewQuery("SELECT edits FROM [format_table_name("messages")] WHERE id = '[message_id]'") + if(!query_get_message_edits.Execute()) + var/err = query_get_message_edits.ErrorMsg() + log_game("SQL ERROR obtaining edits from messages table. Error : \[[err]\]\n") return - if(query_noteedits.NextRow()) - var/edit_log = query_noteedits.item[1] + if(query_get_message_edits.NextRow()) + var/edit_log = query_get_message_edits.item[1] usr << browse(edit_log,"window=noteedits") - else if(href_list["secretnote"]) - var/note_id = href_list["secretnote"] - toggle_note_secrecy(note_id) - else if(href_list["newban"]) if(!check_rights(R_BAN)) return @@ -1126,48 +1156,6 @@ if("Cancel") return - //Watchlist - else if(href_list["watchadd"]) - var/target_ckey = locate(href_list["watchadd"]) - usr.client.watchlist_add(target_ckey) - - else if(href_list["watchremove"]) - var/target_ckey = href_list["watchremove"] - usr.client.watchlist_remove(target_ckey) - - else if(href_list["watchedit"]) - var/target_ckey = href_list["watchedit"] - usr.client.watchlist_edit(target_ckey) - - else if(href_list["watchaddbrowse"]) - usr.client.watchlist_add(null, 1) - - else if(href_list["watchremovebrowse"]) - var/target_ckey = href_list["watchremovebrowse"] - usr.client.watchlist_remove(target_ckey, 1) - - else if(href_list["watcheditbrowse"]) - var/target_ckey = href_list["watcheditbrowse"] - usr.client.watchlist_edit(target_ckey, 1) - - else if(href_list["watchsearch"]) - var/target_ckey = href_list["watchsearch"] - usr.client.watchlist_show(target_ckey) - - else if(href_list["watchshow"]) - usr.client.watchlist_show() - - else if(href_list["watcheditlog"]) - var/target_ckey = sanitizeSQL("[href_list["watcheditlog"]]") - var/DBQuery/query_watchedits = dbcon.NewQuery("SELECT edits FROM [format_table_name("watch")] WHERE ckey = '[target_ckey]'") - if(!query_watchedits.Execute()) - var/err = query_watchedits.ErrorMsg() - log_game("SQL ERROR obtaining edits from watch table. Error : \[[err]\]\n") - return - if(query_watchedits.NextRow()) - var/edit_log = query_watchedits.item[1] - usr << browse(edit_log,"window=watchedits") - else if(href_list["mute"]) if(!check_rights(R_ADMIN)) return @@ -2132,17 +2120,6 @@ FM.locked ^= 1 src.access_news_network() - else if(href_list["memoeditlist"]) - var/sql_key = sanitizeSQL("[href_list["memoeditlist"]]") - var/DBQuery/query_memoedits = dbcon.NewQuery("SELECT edits FROM [format_table_name("memo")] WHERE (ckey = '[sql_key]')") - if(!query_memoedits.Execute()) - var/err = query_memoedits.ErrorMsg() - log_game("SQL ERROR obtaining edits from memo table. Error : \[[err]\]\n") - return - if(query_memoedits.NextRow()) - var/edit_log = query_memoedits.item[1] - usr << browse(edit_log,"window=memoeditlist") - else if(href_list["check_antagonist"]) if(!check_rights(R_ADMIN)) return diff --git a/code/modules/admin/watchlist.dm b/code/modules/admin/watchlist.dm deleted file mode 100644 index d5ac928272f..00000000000 --- a/code/modules/admin/watchlist.dm +++ /dev/null @@ -1,119 +0,0 @@ -/client/proc/watchlist_add(target_ckey, browse = 0) - if(!target_ckey) - var/new_ckey = ckey(input(usr,"Who would you like to add to the watchlist?","Enter a ckey",null) as text) - if(!new_ckey) - return - new_ckey = sanitizeSQL(new_ckey) - var/DBQuery/query_watchfind = dbcon.NewQuery("SELECT ckey FROM [format_table_name("player")] WHERE ckey = '[new_ckey]'") - if(!query_watchfind.Execute()) - var/err = query_watchfind.ErrorMsg() - log_game("SQL ERROR obtaining ckey from player table. Error : \[[err]\]\n") - return - if(!query_watchfind.NextRow()) - if(alert(usr, "[new_ckey] has not been seen before, are you sure you want to add them to the watchlist?", "Unknown ckey", "Yes", "No", "Cancel") != "Yes") - return - target_ckey = new_ckey - var/target_sql_ckey = sanitizeSQL(target_ckey) - if(check_watchlist(target_sql_ckey)) - usr << "[target_sql_ckey] is already on the watchlist." - return - var/reason = input(usr,"Please State Reason","Reason") as message - if(!reason) - return - reason = sanitizeSQL(reason) - var/timestamp = SQLtime() - var/adminckey = usr.ckey - if(!adminckey) - return - var/admin_sql_ckey = sanitizeSQL(adminckey) - var/DBQuery/query_watchadd = dbcon.NewQuery("INSERT INTO [format_table_name("watch")] (ckey, reason, adminckey, timestamp) VALUES ('[target_sql_ckey]', '[reason]', '[admin_sql_ckey]', '[timestamp]')") - if(!query_watchadd.Execute()) - var/err = query_watchadd.ErrorMsg() - log_game("SQL ERROR during adding new watch entry. Error : \[[err]\]\n") - return - log_admin("[key_name(usr)] has added [target_ckey] to the watchlist - Reason: [reason]") - message_admins("[key_name_admin(usr)] has added [target_ckey] to the watchlist - Reason: [reason]", 1) - if(browse) - watchlist_show(target_sql_ckey) - - add_note(target_ckey, "Added to Watchlist - [reason]", null, usr.ckey, 0, null, 1) - -/client/proc/watchlist_remove(target_ckey, browse = 0) - var/target_sql_ckey = sanitizeSQL(target_ckey) - var/DBQuery/query_watchdel = dbcon.NewQuery("DELETE FROM [format_table_name("watch")] WHERE ckey = '[target_sql_ckey]'") - if(!query_watchdel.Execute()) - var/err = query_watchdel.ErrorMsg() - log_game("SQL ERROR during removing watch entry. Error : \[[err]\]\n") - return - log_admin("[key_name(usr)] has removed [target_ckey] from the watchlist") - message_admins("[key_name_admin(usr)] has removed [target_ckey] from the watchlist", 1) - if(browse) - watchlist_show() - -/client/proc/watchlist_edit(target_ckey, browse = 0) - var/target_sql_ckey = sanitizeSQL(target_ckey) - var/DBQuery/query_watchreason = dbcon.NewQuery("SELECT reason FROM [format_table_name("watch")] WHERE ckey = '[target_sql_ckey]'") - if(!query_watchreason.Execute()) - var/err = query_watchreason.ErrorMsg() - log_game("SQL ERROR obtaining reason from watch table. Error : \[[err]\]\n") - return - if(query_watchreason.NextRow()) - var/watch_reason = query_watchreason.item[1] - var/new_reason = input("Input new reason", "New Reason", "[watch_reason]") as message - new_reason = sanitizeSQL(new_reason) - if(!new_reason) - return - var/sql_ckey = sanitizeSQL(usr.ckey) - var/edit_text = "Edited by [sql_ckey] on [SQLtime()] from
[watch_reason]
to
[new_reason]
" - edit_text = sanitizeSQL(edit_text) - var/DBQuery/query_watchupdate = dbcon.NewQuery("UPDATE [format_table_name("watch")] SET reason = '[new_reason]', last_editor = '[sql_ckey]', edits = CONCAT(IFNULL(edits,''),'[edit_text]') WHERE ckey = '[target_sql_ckey]'") - if(!query_watchupdate.Execute()) - var/err = query_watchupdate.ErrorMsg() - log_game("SQL ERROR editing watchlist reason. Error : \[[err]\]\n") - return - log_admin("[key_name(usr)] has edited [target_ckey]'s watchlist reason from [watch_reason] to [new_reason]") - message_admins("[key_name_admin(usr)] has edited [target_ckey]'s watchlist reason from
[watch_reason]
to
[new_reason]") - if(browse) - watchlist_show(target_sql_ckey) - -/client/proc/watchlist_show(search) - var/output - output += "
\ - \ - \ -
" - output += "\[Clear Search\] \[Add Ckey\]" - output += "
" - if(search) - search = "^[search]" - else - search = "^." - search = sanitizeSQL(search) - var/DBQuery/query_watchlist = dbcon.NewQuery("SELECT ckey, reason, adminckey, timestamp, last_editor FROM [format_table_name("watch")] WHERE ckey REGEXP '[search]' ORDER BY ckey") - if(!query_watchlist.Execute()) - var/err = query_watchlist.ErrorMsg() - log_game("SQL ERROR obtaining ckey, reason, adminckey, timestamp, last_editor from watch table. Error : \[[err]\]\n") - return - while(query_watchlist.NextRow()) - var/ckey = query_watchlist.item[1] - var/reason = query_watchlist.item[2] - var/adminckey = query_watchlist.item[3] - var/timestamp = query_watchlist.item[4] - var/last_editor = query_watchlist.item[5] - output += "[ckey] | Added by [adminckey] on [timestamp] \[Remove\] \[Edit Reason\]" - if(last_editor) - output += " Last edit by [last_editor] (Click here to see edit log)" - output += "
[reason]
" - usr << browse(output, "window=watchwin;size=900x500") - -/client/proc/check_watchlist(target_ckey) - var/target_sql_ckey = sanitizeSQL(target_ckey) - var/DBQuery/query_watch = dbcon.NewQuery("SELECT reason FROM [format_table_name("watch")] WHERE ckey = '[target_sql_ckey]'") - if(!query_watch.Execute()) - var/err = query_watch.ErrorMsg() - log_game("SQL ERROR obtaining reason from watch table. Error : \[[err]\]\n") - return - if(query_watch.NextRow()) - return query_watch.item[1] - else - return 0 diff --git a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm index cd5d28757fb..de00b830923 100644 --- a/code/modules/client/client_procs.dm +++ b/code/modules/client/client_procs.dm @@ -234,7 +234,7 @@ var/next_external_rsc = 0 if(holder) add_admin_verbs() - admin_memo_output("Show") + src << get_message_output("memo") adminGreet() if((global.comms_key == "default_pwd" || length(global.comms_key) <= 6) && global.comms_allowed) //It's the default value or less than 6 characters long, but it somehow didn't disable comms. src << "The server's API key is either too short or is the default value! Consider changing it immediately!" @@ -268,7 +268,7 @@ var/next_external_rsc = 0 findJoinDate() sync_client_with_db(tdata) - + get_message_output("watchlist entry", ckey) check_ip_intel() send_resources() @@ -292,7 +292,7 @@ var/next_external_rsc = 0 if(config && config.autoconvert_notes) convert_notes_sql(ckey) - + src << get_message_output("message", ckey) if(!winexists(src, "asset_cache_browser")) // The client is using a custom skin, tell them. src << "Unable to access asset cache browser, if you are using a custom skin file, please allow DS to download the updated version, if you are not, then make a bug report. This is not a critical issue but can cause issues with resource downloading, as it is impossible to know when extra resources arrived to you." @@ -372,12 +372,6 @@ var/next_external_rsc = 0 if (check_randomizer(connectiontopic)) return - var/watchreason = check_watchlist(sql_ckey) - if(watchreason) - current_watchlist[sql_ckey] = watchreason - message_admins("Notice: [key_name_admin(src)] is on the watchlist and has just connected - Reason: [watchreason]") - send2irc_adminless_only("Watchlist", "[key_name(src)] is on the watchlist and has just connected - Reason: [watchreason]") - var/sql_ip = sanitizeSQL(src.address) var/sql_computerid = sanitizeSQL(src.computer_id) var/sql_admin_rank = sanitizeSQL(admin_rank) @@ -472,24 +466,24 @@ var/next_external_rsc = 0 var/const/adminckey = "CID-Error" var/sql_ckey = sanitizeSQL(ckey) //check to see if we noted them in the last day. - var/DBQuery/query_get_notes = dbcon.NewQuery("SELECT id FROM [format_table_name("notes")] WHERE ckey = '[sql_ckey]' AND adminckey = '[adminckey]' AND timestamp + INTERVAL 1 DAY < NOW()") + var/DBQuery/query_get_notes = dbcon.NewQuery("SELECT id FROM [format_table_name("messages")] WHERE type = 'note' AND targetckey = '[sql_ckey]' AND adminckey = '[adminckey]' AND timestamp + INTERVAL 1 DAY < NOW()") if(!query_get_notes.Execute()) var/err = query_get_notes.ErrorMsg() - log_game("SQL ERROR obtaining id from notes table. Error : \[[err]\]\n") + log_game("SQL ERROR obtaining id from messages table. Error : \[[err]\]\n") return if (query_get_notes.NextRow()) return //regardless of above, make sure their last note is not from us, as no point in repeating the same note over and over. - query_get_notes = dbcon.NewQuery("SELECT adminckey FROM [format_table_name("notes")] WHERE ckey = '[sql_ckey]' ORDER BY timestamp DESC LIMIT 1") + query_get_notes = dbcon.NewQuery("SELECT adminckey FROM [format_table_name("messages")] WHERE targetckey = '[sql_ckey]' ORDER BY timestamp DESC LIMIT 1") if(!query_get_notes.Execute()) var/err = query_get_notes.ErrorMsg() - log_game("SQL ERROR obtaining id from notes table. Error : \[[err]\]\n") + log_game("SQL ERROR obtaining adminckey from notes table. Error : \[[err]\]\n") return if (query_get_notes.NextRow()) if (query_get_notes.item[1] == adminckey) return - add_note(ckey, "Detected as using a cid randomizer.", null, adminckey, 0, null, 0) + create_message("note", sql_ckey, adminckey, "Detected as using a cid randomizer.", null, null, 0, 0) /client/proc/check_ip_intel() diff --git a/code/modules/client/verbs/ooc.dm b/code/modules/client/verbs/ooc.dm index 89e1314176a..bbbf67e9fe2 100644 --- a/code/modules/client/verbs/ooc.dm +++ b/code/modules/client/verbs/ooc.dm @@ -152,7 +152,7 @@ var/global/normal_ooc_colour = OOC_COLOR usr << "Sorry, that function is not enabled on this server." return - show_note(usr.ckey, null, 1) + browse_messages(null, usr.ckey, null, 1) /client/proc/ignore_key(client) var/client/C = client diff --git a/tgstation.dme b/tgstation.dme index 77c6868f7d7..39470d551cb 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -933,7 +933,6 @@ #include "code\js\menus.dm" #include "code\modules\admin\admin.dm" #include "code\modules\admin\admin_investigate.dm" -#include "code\modules\admin\admin_memo.dm" #include "code\modules\admin\admin_ranks.dm" #include "code\modules\admin\admin_verbs.dm" #include "code\modules\admin\banjob.dm" @@ -948,10 +947,9 @@ #include "code\modules\admin\NewBan.dm" #include "code\modules\admin\player_panel.dm" #include "code\modules\admin\secrets.dm" -#include "code\modules\admin\sql_notes.dm" +#include "code\modules\admin\sql_message_system.dm" #include "code\modules\admin\stickyban.dm" #include "code\modules\admin\topic.dm" -#include "code\modules\admin\watchlist.dm" #include "code\modules\admin\whitelist.dm" #include "code\modules\admin\DB_ban\functions.dm" #include "code\modules\admin\permissionverbs\permissionedit.dm"