diff --git a/SQL/database_changelog.txt b/SQL/database_changelog.txt index bf305298ce2..dfd4b30dad3 100644 --- a/SQL/database_changelog.txt +++ b/SQL/database_changelog.txt @@ -1,3 +1,15 @@ +14 August 2015, by Jordie0608 + +Added new table 'notes' to replace BYOND's .sav note system. + +To create this new table run the following command: + +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, PRIMARY KEY (`id`)) + +Remember to add prefix to the table name if you use them. + +---------------------------------------------------- + 28 July 2015, by Jordie0608 Modified table 'memo', removing 'id' column and making 'ckey' primary. diff --git a/SQL/tgstation_schema.sql b/SQL/tgstation_schema.sql index caeec1c432c..ae8bf1859d6 100644 --- a/SQL/tgstation_schema.sql +++ b/SQL/tgstation_schema.sql @@ -338,5 +338,25 @@ CREATE TABLE `memo` ( ) 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, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + -- Dump completed on 2013-03-24 18:02:35 diff --git a/SQL/tgstation_schema_prefixed.sql b/SQL/tgstation_schema_prefixed.sql index 93ba765835d..b49032a7ee1 100644 --- a/SQL/tgstation_schema_prefixed.sql +++ b/SQL/tgstation_schema_prefixed.sql @@ -333,5 +333,25 @@ CREATE TABLE `SS13_memo` ( ) 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, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; +/*!40101 SET character_set_client = @saved_cs_client */; + -- Dump completed on 2013-03-24 18:02:35 diff --git a/code/game/verbs/ooc.dm b/code/game/verbs/ooc.dm index eb9bbc56c0f..3a5b8178aae 100644 --- a/code/game/verbs/ooc.dm +++ b/code/game/verbs/ooc.dm @@ -137,4 +137,4 @@ var/global/normal_ooc_colour = "#002eb8" usr << "Sorry, that function is not enabled on this server." return - see_own_notes() + show_note(usr, null, 1) diff --git a/code/modules/admin/NewBan.dm b/code/modules/admin/NewBan.dm index c1716c470de..7fb18b8e55f 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) - notes_add(ckey, "Permanently banned - [reason]") + add_note(ckey, "Permanently banned - [reason]", null, bannedby, 0) else - notes_add(ckey, "Banned for [minutes] minutes - [reason]") + add_note(ckey, "Banned for [minutes] minutes - [reason]", null, bannedby, 0) return 1 /proc/RemoveBan(foldername) diff --git a/code/modules/admin/admin_investigate.dm b/code/modules/admin/admin_investigate.dm index b542204bd23..103d7eac30d 100644 --- a/code/modules/admin/admin_investigate.dm +++ b/code/modules/admin/admin_investigate.dm @@ -45,4 +45,4 @@ src << "Error: admin_investigate: Href Logging is not on." return if("notes") - holder.notes_show() + show_note() diff --git a/code/modules/admin/player_panel.dm b/code/modules/admin/player_panel.dm index 7fdf3adb2d7..027541007f5 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_notes.dm b/code/modules/admin/sql_notes.dm new file mode 100644 index 00000000000..ab14a73e799 --- /dev/null +++ b/code/modules/admin/sql_notes.dm @@ -0,0 +1,169 @@ +proc/add_note(target_ckey, notetext, timestamp, adminckey, logged = 1) + 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|null) + if(!new_ckey) + return + 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 notes table. Error : \[[err]\]\n") + return + if(!query_find_ckey.NextRow()) + usr << "[new_ckey] has not been seen before, you can only add notes to unknown players." + else + target_ckey = new_ckey + var/target_sql_ckey = sanitizeSQL(target_ckey) + if(!notetext) + notetext = input(usr,"Write your Note","Add Note") as message + if(!notetext) + return + notetext = sanitizeSQL(notetext) + if(!timestamp) + timestamp = SQLtime() + if(!adminckey) + adminckey = usr.ckey + if(!adminckey) + return + var/server + if (config && config.server_name) + server = config.server_name + var/admin_sql_ckey = sanitizeSQL(adminckey) + var/DBQuery/query_noteadd = dbcon.NewQuery("INSERT INTO [format_table_name("notes")] (ckey, timestamp, notetext, adminckey, server) VALUES ('[target_sql_ckey]', '[timestamp]', '[notetext]', '[admin_sql_ckey]', '[server]')") + 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 + 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 + 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 message + if(!new_note) + return + 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/show_note(target_ckey, index, linkless = 0) + var/output + var/navbar + var/ruler + ruler = "
" + navbar = "\[All\]|\[#\]" + for(var/letter in alphabet) + navbar += "|\[[letter]\]" + navbar += "
\ + \ + \ +
" + if(!linkless) + output = navbar + if(target_ckey) + world << "target_ckey: [target_ckey]" + var/DBQuery/query_get_notes = dbcon.NewQuery("SELECT id, timestamp, notetext, adminckey, last_editor, server FROM [format_table_name("notes")] WHERE ckey = '[target_ckey]'") + if(!query_get_notes.Execute()) + var/err = query_get_notes.ErrorMsg() + log_game("SQL ERROR obtaining ckey, notetext, adminckey, last_editor, server from notes table. Error : \[[err]\]\n") + return + output += "

Notes of [target_ckey]

" + if(!linkless) + output += "
\[Add Note\]
" + output += ruler + while(query_get_notes.NextRow()) + var/id = query_get_notes.item[1] + 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] + output += "[timestamp] | [server] | [adminckey]" + if(!linkless) + output += " \[Remove Note\] \[Edit Note\]" + if(last_editor) + output += " Last edit by [last_editor] (Click here to see edit log)" + output += "
[notetext]
" + else if(index) + world << "index: [index]" + var/index_ckey + var/search + output += "
\[Add Note\]
" + output += ruler + switch(index) + if(1) + search = "^." + if(2) + search = "^\[^\[:alpha:\]\]" + else + search = "^[index]" + world << "search: [search]" + if(!search) + world << "null search" + return + var/DBQuery/query_list_notes = dbcon.NewQuery("SELECT DISTINCT ckey FROM [format_table_name("notes")] WHERE ckey REGEXP '[search]'") + 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] + world << "index_ckey: [index_ckey]" + output += "[index_ckey]
" + else + output += "
\[Add Note\]
" + output += ruler + usr << browse(output, "window=show_notes;size=900x500") \ No newline at end of file diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm index b1ce38e14d7..5bfd15f4c67 100644 --- a/code/modules/admin/topic.dm +++ b/code/modules/admin/topic.dm @@ -505,7 +505,7 @@ feedback_inc("ban_appearance",1) DB_ban_record(BANTYPE_APPEARANCE, M, -1, reason) appearance_fullban(M, "[reason]; By [usr.ckey] on [time2text(world.realtime)]") - notes_add(M.ckey, "Appearance banned - [reason]") + add_note(M.ckey, "Appearance banned - [reason]", null, usr, 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]" @@ -921,7 +921,7 @@ msg = job else msg += ", [job]" - notes_add(M.ckey, "Banned from [msg] - [reason]") + add_note(M.ckey, "Banned from [msg] - [reason]", null, usr, 0) message_admins("[key_name_admin(usr)] banned [key_name_admin(M)] from [msg] for [mins] minutes") M << "You have been jobbanned by [usr.client.ckey] from: [msg]." M << "The reason is: [reason]" @@ -941,7 +941,7 @@ jobban_fullban(M, job, "[reason]; By [usr.ckey] on [time2text(world.realtime)]") if(!msg) msg = job else msg += ", [job]" - notes_add(M.ckey, "Banned from [msg] - [reason]") + add_note(M.ckey, "Banned from [msg] - [reason]", null, usr, 0) message_admins("[key_name_admin(usr)] banned [key_name_admin(M)] from [msg]") M << "You have been jobbanned by [usr.client.ckey] from: [msg]." M << "The reason is: [reason]" @@ -994,17 +994,49 @@ del(M.client) //Player Notes - else if(href_list["notes"]) - var/ckey = href_list["ckey"] - switch(href_list["notes"]) - if("show") - notes_show(ckey) - if("add") - notes_add(ckey,href_list["text"], 1) - notes_show(ckey) - if("remove") - notes_remove(ckey,text2num(href_list["from"]),text2num(href_list["to"])) - notes_show(ckey) + else if(href_list["addnote"]) + var/target_ckey = href_list["addnote"] + world << "addnote: [target_ckey]" + add_note(target_ckey) + + else if(href_list["addnoteempty"]) + add_note() + + else if(href_list["removenote"]) + var/note_id = href_list["removenote"] + remove_note(note_id) + + else if(href_list["editnote"]) + var/note_id = href_list["editnote"] + edit_note(note_id) + + else if(href_list["shownote"]) + var/target = href_list["shownote"] + show_note(index = target) + + else if(href_list["nonalpha"]) + var/target = href_list["nonalpha"] + target = text2num(target) + show_note(index = target) + + else if(href_list["shownoteckey"]) + var/target_ckey = href_list["shownoteckey"] + show_note(target_ckey) + + else if(href_list["notessearch"]) + var/target = href_list["notessearch"] + show_note(index = target) + + 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") + return + if(query_noteedits.NextRow()) + var/edit_log = query_noteedits.item[1] + usr << browse(edit_log,"window=noteedits") else if(href_list["removejobban"]) if(!check_rights(R_BAN)) return @@ -2089,4 +2121,4 @@ message_admins("[key_name_admin(usr)] has kicked [afkonly ? "all AFK" : "all"] clients from the lobby. [length(listkicked)] clients kicked: [strkicked ? strkicked : "--"]") log_admin("[key_name(usr)] has kicked [afkonly ? "all AFK" : "all"] clients from the lobby. [length(listkicked)] clients kicked: [strkicked ? strkicked : "--"]") else - usr << "You may only use this when the game is running" + usr << "You may only use this when the game is running" \ No newline at end of file diff --git a/tgstation.dme b/tgstation.dme index 75cb814a0aa..9b1ff3e38d6 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -815,9 +815,9 @@ #include "code\modules\admin\IsBanned.dm" #include "code\modules\admin\NewBan.dm" #include "code\modules\admin\newbanjob.dm" -#include "code\modules\admin\player_notes.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\topic.dm" #include "code\modules\admin\DB ban\functions.dm" #include "code\modules\admin\permissionverbs\permissionedit.dm"