autoconvert notes to sql procs

This commit is contained in:
Jordie0608
2015-08-17 15:24:50 +10:00
parent 9e2c59ca24
commit e4b21e30d3
6 changed files with 72 additions and 128 deletions

View File

@@ -163,6 +163,8 @@
var/reactionary_explosions = 0 //If we use reactionary explosions, explosions that react to walls and doors
var/autoconvert_notes = 0 //if all connecting player's notes should attempt to be converted to the database
/datum/configuration/New()
var/list/L = typesof(/datum/game_mode) - /datum/game_mode
for(var/T in L)
@@ -343,6 +345,8 @@
if (world.log != newlog)
world.log << "Now logging runtimes to data/logs/runtimes/runtime-[time2text(world.realtime, "YYYY-MM-DD")].log"
world.log = newlog
if("autoconvert_notes")
config.autoconvert_notes = 1
else
diary << "Unknown setting in configuration: '[name]'"

View File

@@ -47,7 +47,7 @@ var/global/floorIsLava = 0
body += "<A href='?_src_=holder;newban=\ref[M]'>Ban</A> | "
body += "<A href='?_src_=holder;jobban2=\ref[M]'>Jobban</A> | "
body += "<A href='?_src_=holder;appearanceban=\ref[M]'>Identity Ban</A> | "
body += "<A href='?_src_=holder;notes=show;ckey=[M.ckey]'>Notes</A> | "
body += "<A href='?_src_=holder;shownoteckey=[M.ckey]'>Notes</A> | "
body += "<A href='?_src_=holder;watchlist=\ref[M]'>Watchlist Flag</A> "
if(M.client)

View File

@@ -1,117 +0,0 @@
//This stuff was originally intended to be integrated into the ban-system I was working on
//but it's safe to say that'll never be finished. So I've merged it into the current player panel.
//enjoy ~Carn
#define NOTESFILE "data/player_notes.sav" //where the player notes are saved
/proc/see_own_notes()
if(!config.see_own_notes)
return
var/ckey = usr.client.ckey
if(!ckey)
usr << "<span class='warning'>Error: No ckey found.</span>"
return
var/savefile/notesfile = new(NOTESFILE)
if(!notesfile)
usr << "<span class='warning'>Error: Cannot access [NOTESFILE]</span>"
return
notesfile.cd = "/[ckey]"
var/dat = "<b>Notes for [ckey]:</b><br>"
while(!notesfile.eof)
var/note
notesfile >> note
dat += note + "<br>"
var/datum/browser/popup = new(usr, "player_notes", "Player Notes", 700, 400)
popup.set_content(dat)
popup.open()
/datum/admins/proc/notes_show(ckey)
usr << browse("<head><title>Player Notes</title></head><body>[notes_gethtml(ckey)]</body>","window=player_notes;size=700x400")
/datum/admins/proc/notes_gethtml(ckey)
var/savefile/notesfile = new(NOTESFILE)
if(!notesfile) return "<span class='warning'>Error: Cannot access [NOTESFILE]</span>"
if(ckey)
. = "<b>Notes for <a href='?_src_=holder;notes=show'>[ckey]</a>:</b> <a href='?_src_=holder;notes=add;ckey=[ckey]'>\[+\]</a><br>"
notesfile.cd = "/[ckey]"
var/index = 1
while( !notesfile.eof )
var/note
notesfile >> note
. += "[note] <a href='?_src_=holder;notes=remove;ckey=[ckey];from=[index]'>\[-\]</a><br>"
index++
else
. = "<b>All Notes:</b> <a href='?_src_=holder;notes=add'>\[+\]</a><br>"
notesfile.cd = "/"
for(var/dir in notesfile.dir)
. += "<a href='?_src_=holder;notes=show;ckey=[dir]'>[dir]</a><br>"
return
//handles adding notes to the end of a ckey's buffer
//originally had seperate entries such as var/by to record who left the note and when
//but the current bansystem is a heap of dung.
/proc/notes_add(ckey, note, lognote = 0)
if(!ckey)
ckey = ckey(input(usr,"Who would you like to add notes for?","Enter a ckey",null) as text|null)
if(!ckey) return
if(!note)
note = html_encode(input(usr,"Enter your note:","Enter some text",null) as message|null)
if(!note) return
var/savefile/notesfile = new(NOTESFILE)
if(!notesfile) return
notesfile.cd = "/[ckey]"
notesfile.eof = 1 //move to the end of the buffer
notesfile << "[time2text(world.realtime,"DD-MMM-YYYY")] | [note][(usr && usr.ckey)?" ~[usr.ckey]":""]"
if(lognote)//don't need an admin log for the notes applied automatically during bans.
message_admins("[key_name(usr)] added note '[note]' to [ckey]")
log_admin("[key_name(usr)] added note '[note]' to [ckey]")
return
//handles removing entries from the buffer, or removing the entire directory if no start_index is given
/proc/notes_remove(ckey, start_index, end_index)
var/savefile/notesfile = new(NOTESFILE)
var/admin_msg
if(!notesfile) return
if(!ckey)
notesfile.cd = "/"
ckey = ckey(input(usr,"Who would you like to remove notes for?","Enter a ckey",null) as null|anything in notesfile.dir)
if(!ckey) return
if(start_index)
notesfile.cd = "/[ckey]"
var/list/noteslist = list()
if(!end_index) end_index = start_index
var/index = 0
while( !notesfile.eof )
index++
var/temp
notesfile >> temp
if( (start_index <= index) && (index <= end_index) )
admin_msg = temp
continue
noteslist += temp
notesfile.eof = -2 //Move to the start of the buffer and then erase.
for( var/note in noteslist )
notesfile << note
message_admins("[key_name(usr)] removed a note '[admin_msg]' from [ckey]")
log_admin("[key_name(usr)] removed a note '[admin_msg]' from [ckey]")
if(noteslist.len == 0)
notesfile.cd = "/"
notesfile.dir.Remove(ckey)
message_admins("[ckey] has no notes and was removed from the notes list.")
return
#undef NOTESFILE

View File

@@ -1,4 +1,4 @@
proc/add_note(target_ckey, notetext, timestamp, adminckey, logged = 1)
/proc/add_note(target_ckey, notetext, timestamp, adminckey, logged = 1, server)
if(!dbcon.IsConnected())
usr << "<span class='danger'>Failed to establish database connection.</span>"
return
@@ -28,10 +28,10 @@ proc/add_note(target_ckey, notetext, timestamp, adminckey, logged = 1)
adminckey = usr.ckey
if(!adminckey)
return
var/server
if (config && config.server_name)
server = config.server_name
var/admin_sql_ckey = sanitizeSQL(adminckey)
if(!server)
if (config && config.server_name)
server = config.server_name
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()
@@ -40,9 +40,9 @@ proc/add_note(target_ckey, notetext, timestamp, adminckey, logged = 1)
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)
show_note(target_ckey)
proc/remove_note(note_id)
/proc/remove_note(note_id)
var/ckey
var/notetext
var/adminckey
@@ -69,7 +69,7 @@ proc/remove_note(note_id)
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)
/proc/edit_note(note_id)
if(!dbcon.IsConnected())
usr << "<span class='danger'>Failed to establish database connection.</span>"
return
@@ -100,7 +100,7 @@ proc/edit_note(note_id)
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)
/proc/show_note(target_ckey, index, linkless = 0)
var/output
var/navbar
var/ruler
@@ -160,4 +160,55 @@ proc/show_note(target_ckey, index, linkless = 0)
else
output += "<center><a href='?_src_=holder;addnoteempty=1'>\[Add Note\]</a></center>"
output += ruler
usr << browse(output, "window=show_notes;size=900x500")
usr << browse(output, "window=show_notes;size=900x500")
/proc/regex_note_sql_extract(str, exp)
return new /datum/regex(str, exp, call(LIBREGEX_LIBRARY, "regEx_find")(str, exp))
#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 = "^(\\d{2}-\\w{3}-\\d{4}) \\| (.+) ~(\\w+)$"
var/datum/regex/results = regex_note_sql_extract(notetext, regex)
var/timestamp = results.str(2)
notetext = results.str(3)
var/adminckey = results.str(4)
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)
else
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

View File

@@ -175,6 +175,9 @@ var/next_external_rsc = 0
else
winset(src, "rpane.changelogb", "background-color=#eaeaea;font-style=bold")
if (config && config.autoconvert_notes)
convert_notes_sql(ckey)
//////////////
//DISCONNECT//
//////////////

View File

@@ -193,4 +193,7 @@ NOTIFY_NEW_PLAYER_AGE 0
#AGGRESSIVE_CHANGELOG
## Uncomment to have the game log runtimes to the log folder. (Note: this disables normal output in dd/ds, so it should be left off for testing.
#LOG_RUNTIMES
#LOG_RUNTIMES
##Comment this out if you've used the mass conversion sql proc for notes or want to stop converting notes
AUTOCONVERT_NOTES