database notes

This commit is contained in:
Jordie0608
2015-08-15 22:24:24 +10:00
parent fcbd841b60
commit e2d3488f7f
10 changed files with 274 additions and 21 deletions

View File

@@ -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.

View File

@@ -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

View File

@@ -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

View File

@@ -137,4 +137,4 @@ var/global/normal_ooc_colour = "#002eb8"
usr << "<span class='notice'>Sorry, that function is not enabled on this server.</span>"
return
see_own_notes()
show_note(usr, null, 1)

View File

@@ -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)

View File

@@ -45,4 +45,4 @@
src << "<font color='red'>Error: admin_investigate: Href Logging is not on.</font>"
return
if("notes")
holder.notes_show()
show_note()

View File

@@ -76,7 +76,7 @@
body += "</td><td align='center'>";
body += "<a href='?_src_=holder;adminplayeropts="+ref+"'>PP</a> - "
body += "<a href='?_src_=holder;notes=show;ckey="+ckey+"'>N</a> - "
body += "<a href='?_src_=holder;shownoteckey="+ckey+"'>N</a> - "
body += "<a href='?_src_=vars;Vars="+ref+"'>VV</a> - "
body += "<a href='?_src_=holder;traitor="+ref+"'>TP</a> - "
body += "<a href='?priv_msg="+ckey+"'>PM</a> - "

View File

@@ -0,0 +1,169 @@
proc/add_note(target_ckey, notetext, timestamp, adminckey, logged = 1)
if(!dbcon.IsConnected())
usr << "<span class='danger'>Failed to establish database connection.</span>"
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 << "<font color='red'>[new_ckey] has not been seen before, you can only add notes to unknown players.</font>"
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]:<br>[notetext]")
show_note(target_ckey)
proc/remove_note(note_id)
var/ckey
var/notetext
var/adminckey
if(!dbcon.IsConnected())
usr << "<span class='danger'>Failed to establish database connection.</span>"
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]:<br>[notetext]")
show_note(ckey)
proc/edit_note(note_id)
if(!dbcon.IsConnected())
usr << "<span class='danger'>Failed to establish database connection.</span>"
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<br>[old_note]<br>to<br>[new_note]<hr>"
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<br>[old_note]<br>to<br>[new_note]")
show_note(target_ckey)
proc/show_note(target_ckey, index, linkless = 0)
var/output
var/navbar
var/ruler
ruler = "<hr style='background:#000000; border:0; height:3px'>"
navbar = "<a href='?_src_=holder;nonalpha=1'>\[All\]</a>|<a href='?_src_=holder;nonalpha=2'>\[#\]</a>"
for(var/letter in alphabet)
navbar += "|<a href='?_src_=holder;shownote=[letter]'>\[[letter]\]</a>"
navbar += "<br><form method='GET' name='search' action='?'>\
<input type='hidden' name='_src_' value='holder'>\
<input type='text' name='notessearch' value='[index]'>\
<input type='submit' value='Search'></form>"
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 += "<h2><center>Notes of [target_ckey]</center></h2>"
if(!linkless)
output += "<center><a href='?_src_=holder;addnote=[target_ckey]'>\[Add Note\]</a></center>"
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 += "<b>[timestamp] | [server] | [adminckey]</b>"
if(!linkless)
output += " <a href='?_src_=holder;removenote=[id]'>\[Remove Note\]</a> <a href='?_src_=holder;editnote=[id]'>\[Edit Note\]</a>"
if(last_editor)
output += " <font size='2'>Last edit by [last_editor] <a href='?_src_=holder;noteedits=[id]'>(Click here to see edit log)</a></font>"
output += "<br>[notetext]<hr style='background:#000000; border:0; height:1px'>"
else if(index)
world << "index: [index]"
var/index_ckey
var/search
output += "<center><a href='?_src_=holder;addnoteempty=1'>\[Add Note\]</a></center>"
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 += "<a href='?_src_=holder;shownoteckey=[index_ckey]'>[index_ckey]</a><br>"
else
output += "<center><a href='?_src_=holder;addnoteempty=1'>\[Add Note\]</a></center>"
output += ruler
usr << browse(output, "window=show_notes;size=900x500")

View File

@@ -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("<span class='adminnotice'>[key_name_admin(usr)] appearance banned [key_name_admin(M)]</span>")
M << "<span class='boldannounce'><BIG>You have been appearance banned by [usr.client.ckey].</BIG></span>"
M << "<span class='boldannounce'>The reason is: [reason]</span>"
@@ -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("<span class='adminnotice'>[key_name_admin(usr)] banned [key_name_admin(M)] from [msg] for [mins] minutes</span>")
M << "<span class='boldannounce'><BIG>You have been jobbanned by [usr.client.ckey] from: [msg].</BIG></span>"
M << "<span class='boldannounce'>The reason is: [reason]</span>"
@@ -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("<span class='adminnotice'>[key_name_admin(usr)] banned [key_name_admin(M)] from [msg]</span>")
M << "<span class='boldannounce'><BIG>You have been jobbanned by [usr.client.ckey] from: [msg].</BIG></span>"
M << "<span class='boldannounce'>The reason is: [reason]</span>"
@@ -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

View File

@@ -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"