diff --git a/SQL/paradise_schema.sql b/SQL/paradise_schema.sql index 734a45ffbeb..e3e87c05b06 100644 --- a/SQL/paradise_schema.sql +++ b/SQL/paradise_schema.sql @@ -413,9 +413,11 @@ CREATE TABLE `notes` ( `automated` TINYINT(3) UNSIGNED NULL DEFAULT '0', `deleted` TINYINT(4) NOT NULL DEFAULT '0', `deletedby` VARCHAR(32) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci', + `public` TINYINT(4) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `ckey` (`ckey`), - KEY `deleted` (`deleted`) + KEY `deleted` (`deleted`), + KEY `public` (`public`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/SQL/updates/64-65.sql b/SQL/updates/64-65.sql new file mode 100644 index 00000000000..dbcbd20f327 --- /dev/null +++ b/SQL/updates/64-65.sql @@ -0,0 +1,5 @@ +# Updating DB from 64-65 ~Contrabang +# Adds a new column to the notes table for public notes +ALTER TABLE `notes` + ADD COLUMN `public` TINYINT NOT NULL DEFAULT 0 AFTER `deletedby`, + ADD INDEX `public` (`public`); diff --git a/code/__DEFINES/misc_defines.dm b/code/__DEFINES/misc_defines.dm index e3c12779e4f..a051c69320c 100644 --- a/code/__DEFINES/misc_defines.dm +++ b/code/__DEFINES/misc_defines.dm @@ -431,7 +431,7 @@ #define INVESTIGATE_HOTMIC "hotmic" // The SQL version required by this version of the code -#define SQL_VERSION 64 +#define SQL_VERSION 65 // Vending machine stuff #define CAT_NORMAL (1<<0) diff --git a/code/game/verbs/ooc.dm b/code/game/verbs/ooc.dm index b7a1ace80fb..65f445dcd8e 100644 --- a/code/game/verbs/ooc.dm +++ b/code/game/verbs/ooc.dm @@ -283,4 +283,52 @@ GLOBAL_VAR_INIT(admin_ooc_colour, "#b82e00") init_verbs() +/client/verb/show_own_notes() + set name = "Show My Notes" + set desc = "View your public notes." + set category = "OOC" + + if(!key) + return + if(!SSdbcore.IsConnected()) + to_chat(src, "Failed to establish database connection.") + return + var/list/output = list("") + var/datum/db_query/query_get_notes = SSdbcore.NewQuery({" + SELECT timestamp, notetext, adminckey, last_editor, server, crew_playtime, round_id + FROM notes WHERE ckey=:targetkey AND deleted=0 AND public=1 ORDER BY timestamp"}, list( + "targetkey" = ckey + )) + if(!query_get_notes.warn_execute()) + to_chat(src, "Unfortunately, we were not able to retrieve your notes.") + qdel(query_get_notes) + return + output += "

Notes of [ckey]


Don't discuss warnings or other punishments from the admins in Paradise Discord.
" + output += "
" + var/found_notes = FALSE + while(query_get_notes.NextRow()) + found_notes = TRUE + var/timestamp = query_get_notes.item[1] + var/notetext = query_get_notes.item[2] + var/adminckey = query_get_notes.item[3] + var/last_editor = query_get_notes.item[4] + var/server = query_get_notes.item[5] + var/mins = text2num(query_get_notes.item[6]) + var/round_id = text2num(query_get_notes.item[7]) + output += "[timestamp][round_id ? " (Round [round_id])" : ""] | [server] | [adminckey]" + if(mins) + var/playstring = get_exp_format(mins) + output += " | [playstring] as Crew" + output += "" + + if(last_editor) + output += " Last edit by [last_editor]." + output += "
[replacetext(notetext, "\n", "
")]
" + if(!found_notes) + output += "You have no public notes." + qdel(query_get_notes) + var/datum/browser/popup = new(mob, "show_public_notes", "Public Notes", 900, 500) + popup.set_content(output.Join("")) + popup.open() + #undef DEFAULT_PLAYER_OOC_COLOUR diff --git a/code/modules/admin/sql_notes.dm b/code/modules/admin/sql_notes.dm index 35da1e5dcbf..bcc40040043 100644 --- a/code/modules/admin/sql_notes.dm +++ b/code/modules/admin/sql_notes.dm @@ -1,4 +1,4 @@ -/proc/add_note(target_ckey, notetext, timestamp, adminckey, logged = 1, checkrights = 1, show_after = TRUE, automated = FALSE, sanitise_html = TRUE) // Dont you EVER disable this last param unless you know what you're doing +/proc/add_note(target_ckey, notetext, timestamp, adminckey, logged = 1, checkrights = 1, show_after = TRUE, automated = FALSE, sanitise_html = TRUE, public = FALSE) // Dont you EVER disable 'sanitise_html', only automated systems should use this if(checkrights && !check_rights(R_ADMIN|R_MOD)) return if(IsAdminAdvancedProcCall() && !sanitise_html) @@ -51,6 +51,7 @@ notetext = input(usr,"Write your note","Add Note") as message|null if(!notetext) return + public = (alert(usr, "Would you like to make this note public?", "Public Note?", "Private", "Public") == "Public") if(!adminckey) adminckey = usr.ckey @@ -66,8 +67,8 @@ notetext = html_encode(notetext) var/datum/db_query/query_noteadd = SSdbcore.NewQuery({" - INSERT INTO notes (ckey, timestamp, notetext, adminckey, server, crew_playtime, round_id, automated) - VALUES (:targetckey, NOW(), :notetext, :adminkey, :server, :crewnum, :roundid, :automated) + INSERT INTO notes (ckey, timestamp, notetext, adminckey, server, crew_playtime, round_id, automated, public) + VALUES (:targetckey, NOW(), :notetext, :adminkey, :server, :crewnum, :roundid, :automated, :public) "}, list( "targetckey" = target_ckey, "notetext" = notetext, @@ -75,15 +76,16 @@ "server" = GLOB.configuration.system.instance_id, "crewnum" = crew_number, "roundid" = GLOB.round_id, - "automated" = automated + "automated" = automated, + "public" = public )) if(!query_noteadd.warn_execute()) qdel(query_noteadd) return qdel(query_noteadd) if(logged) - log_admin("[usr ? key_name(usr) : adminckey] has added a note to [target_ckey]: [notetext]") - message_admins("[usr ? key_name_admin(usr) : adminckey] has added a note to [target_ckey]:
[notetext]") + log_admin("[usr ? key_name(usr) : adminckey] has added a [public ? "public" : "private"] note to [target_ckey]: [notetext]") + message_admins("[usr ? key_name_admin(usr) : adminckey] has added a [public ? "public" : "private"] note to [target_ckey]:
[notetext]") if(show_after) show_note(target_ckey) @@ -193,7 +195,7 @@ if(target_ckey) var/target_sql_ckey = ckey(target_ckey) var/datum/db_query/query_get_notes = SSdbcore.NewQuery({" - SELECT id, timestamp, notetext, adminckey, last_editor, server, crew_playtime, round_id, automated + SELECT id, timestamp, notetext, adminckey, last_editor, server, crew_playtime, round_id, automated, public FROM notes WHERE ckey=:targetkey AND deleted=0 ORDER BY timestamp"}, list( "targetkey" = target_sql_ckey )) @@ -214,6 +216,7 @@ var/mins = text2num(query_get_notes.item[7]) var/round_id = text2num(query_get_notes.item[8]) var/automated = text2num(query_get_notes.item[9]) // 0/1 bool stored in table + var/public = text2num(query_get_notes.item[10]) // 0/1 bool stored in table output += "[timestamp][round_id ? " (Round [round_id])" : ""] | [server] | [adminckey]" if(mins) var/playstring = get_exp_format(mins) @@ -221,7 +224,14 @@ output += "" if(!linkless) - output += " \[Remove Note\] [automated ? "\[Automated Note\]" : "\[Edit Note\]"]" + var/note_publicity = (public ? "Public Note" : "PRIVATE Note") + if(adminckey == usr.ckey) + note_publicity = "\[[note_publicity]]" + + output += " \[Remove Note\] \ + [automated ? "\[Automated Note\]" : "\[Edit Note\]"] \ + [note_publicity]" + if(last_editor) output += " Last edit by [last_editor] (Click here to see edit log)" output += "
[replacetext(notetext, "\n", "
")]
" @@ -257,3 +267,53 @@ output += ruler usr << browse(output.Join(""), "window=show_notes;size=900x500") +/proc/toggle_note_publicity(note_id) + if(!usr) + return + if(!check_rights(R_ADMIN|R_MOD)) + return + if(!SSdbcore.IsConnected()) + if(usr) + to_chat(usr, "Failed to establish database connection.") + return + if(!note_id) + return + note_id = text2num(note_id) + var/datum/db_query/query_find_note_edit = SSdbcore.NewQuery("SELECT ckey, notetext, adminckey, automated, public FROM notes WHERE id=:note_id", list( + "note_id" = note_id + )) + if(!query_find_note_edit.warn_execute()) + qdel(query_find_note_edit) + return + if(query_find_note_edit.NextRow()) + var/target_ckey = query_find_note_edit.item[1] + var/text = query_find_note_edit.item[2] + var/adminckey = query_find_note_edit.item[3] + var/automated = query_find_note_edit.item[4] + var/public = query_find_note_edit.item[5] + if((!adminckey || adminckey != usr.ckey) && !check_rights(R_PERMISSIONS)) + to_chat(usr, "You cannot toggle the publicity of notes created by other users.") + return + if(automated) + to_chat(usr, "That note is generated automatically. You can't edit it.") + return + + if(public) + if(alert(usr, "Are you sure you want to make this note private?", "Private Note?", "Yes", "No") != "Yes") + return + else + if(alert(usr, "Are you sure you want to make this note public?", "Public Note?", "Yes", "No") != "Yes") + return + + public = !public + var/datum/db_query/query_update_note = SSdbcore.NewQuery("UPDATE notes SET public=:new_public WHERE id=:note_id", list( + "new_public" = public, + "note_id" = note_id + )) + if(!query_update_note.warn_execute()) + qdel(query_update_note) + return + log_admin("[key_name(usr)] has made [target_ckey]'s note [public ? "public" : "private"], contents are \"[text]\".") + message_admins("[key_name_admin(usr)] has edited [target_ckey]'s note [public ? "public" : "private"], contents are \"[text]\".") + show_note(target_ckey) + qdel(query_update_note) diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm index aba62bccdb9..4f28cbb3e4a 100644 --- a/code/modules/admin/topic.dm +++ b/code/modules/admin/topic.dm @@ -866,6 +866,10 @@ var/note_id = href_list["editnote"] edit_note(note_id) + else if(href_list["toggle_note_publicity"]) + var/note_id = href_list["toggle_note_publicity"] + toggle_note_publicity(note_id) + else if(href_list["shownote"]) var/target = href_list["shownote"] show_note(index = target) diff --git a/config/example/config.toml b/config/example/config.toml index 4b1471b3e43..b8ff593e077 100644 --- a/config/example/config.toml +++ b/config/example/config.toml @@ -173,7 +173,7 @@ ipc_screens = [ # Enable/disable the database on a whole sql_enabled = false # SQL version. If this is a mismatch, round start will be delayed -sql_version = 64 +sql_version = 65 # SQL server address. Can be an IP or DNS name sql_address = "127.0.0.1" # SQL server port