diff --git a/code/modules/admin/admin.dm b/code/modules/admin/admin.dm index 498c0647..8a405d72 100644 --- a/code/modules/admin/admin.dm +++ b/code/modules/admin/admin.dm @@ -246,7 +246,11 @@ var/global/floorIsLava = 0 */ if(!check_rights(R_ADMIN|R_MOD)) return - PlayerNotesPage(1) + + if(config.ban_legacy_system) + PlayerNotesPage(1) + else + show_notes_sql() /datum/admins/proc/PlayerNotesPage(page) var/dat = "Player notes
" @@ -303,38 +307,40 @@ var/global/floorIsLava = 0 if (!istype(src,/datum/admins)) usr << "Error: you are not an admin!" return - var/dat = "Info on [key]" - dat += "" - var/savefile/info = new("data/player_saves/[copytext(key, 1, 2)]/[key]/info.sav") - var/list/infos - info >> infos - if(!infos) - dat += "No information found on the given key.
" + if(config.ban_legacy_system) + var/dat = "Info on [key]" + dat += "" + + var/savefile/info = new("data/player_saves/[copytext(key, 1, 2)]/[key]/info.sav") + var/list/infos + info >> infos + if(!infos) + dat += "No information found on the given key.
" + else + var/update_file = 0 + var/i = 0 + for(var/datum/player_info/I in infos) + i += 1 + if(!I.timestamp) + I.timestamp = "Pre-4/3/2012" + update_file = 1 + if(!I.rank) + I.rank = "N/A" + update_file = 1 + dat += "[I.content] by [I.author] ([I.rank]) on [I.timestamp] " + if(I.author == usr.key || I.author == "Adminbot") + dat += "Remove" + dat += "

" + if(update_file) info << infos + + dat += "
" + dat += "Add Comment
" + + dat += "" + usr << browse(dat, "window=adminplayerinfo;size=480x480") else - var/update_file = 0 - var/i = 0 - for(var/datum/player_info/I in infos) - i += 1 - if(!I.timestamp) - I.timestamp = "Pre-4/3/2012" - update_file = 1 - if(!I.rank) - I.rank = "N/A" - update_file = 1 - dat += "[I.content] by [I.author] ([I.rank]) on [I.timestamp] " - if(I.author == usr.key || I.author == "Adminbot") - dat += "Remove" - dat += "

" - if(update_file) info << infos - - dat += "
" - dat += "Add Comment
" - - dat += "" - usr << browse(dat, "window=adminplayerinfo;size=480x480") - - + show_notes_sql(key) /datum/admins/proc/access_news_network() //MARKER set category = "Fun" diff --git a/code/modules/admin/player_notes.dm b/code/modules/admin/player_notes.dm index 3a74da5f..56c6aa65 100644 --- a/code/modules/admin/player_notes.dm +++ b/code/modules/admin/player_notes.dm @@ -89,6 +89,11 @@ datum/admins/proc/notes_gethtml(var/ckey) if (!key || !note) return + //Master safety and override for SQL based noting: + if(!config.ban_legacy_system) + notes_add_sql(key, note, usr) + return + //Loading list of notes for this key var/savefile/info = new("data/player_saves/[copytext(key, 1, 2)]/[key]/info.sav") var/list/infos diff --git a/code/modules/admin/player_notes_sql.dm b/code/modules/admin/player_notes_sql.dm new file mode 100644 index 00000000..9e59318e --- /dev/null +++ b/code/modules/admin/player_notes_sql.dm @@ -0,0 +1,273 @@ +//System will now support SQL pulls for fetching player notes. +//Yay! + +/proc/notes_add_sql(var/key, var/note, var/usr, var/IP, var/CID) + if(!key || !note) + return + + var/ckey = sanitizeSQL(key) + var/content = sanitizeSQL(note) + + var/a_ckey + if(usr) + a_ckey = sanitizeSQL(usr) + else + a_ckey = "Adminbot" + + establish_db_connection() + if(!dbcon.IsConnected()) + error("SQL connection failed while trying to add a note!") + return + + if(!IP || !CID) + var/DBQuery/initquery = dbcon.NewQuery("SELECT ip, computerid FROM erro_player WHERE ckey = '[ckey]'") + IP = initquery.item[1] + CID = initquery.item[2] + + var/querycontents + if(IP && CID) + querycontents = "INSERT INTO aurora_notes (id, adddate, ckey, ip, computerid, a_ckey, content) VALUES (null, Now(), '[ckey]', '[IP]', '[CID]', '[a_ckey]', '[content]')" + else + querycontents = "INSERT INTO aurora_notes (id, adddate, ckey, ip, computerid, a_ckey, content) VALUES (null, Now(), '[ckey]', null, null, '[a_ckey]', '[content]')" + + //We aren't suppose to end up here, but just in case. + if(!querycontents) + return + + var/DBQuery/insertquery = dbcon.NewQuery(querycontents) + insertquery.Execute() + if(insertquery.ErrorMsg()) + error("Inserting notes into SQL failed. Reason: [insertquery.ErrorMsg()].") + else + message_admins("\blue [key_name_admin(usr)] has edited [key]'s notes.") + log_admin("[key_name(usr)] has edited [key]'s notes.") + +/proc/notes_edit_sql(var/noteid, var/noteedit) + if(!noteid || !noteedit) + return + + establish_db_connection() + if(!dbcon.IsConnected()) + error("SQL connection failed while attempting to delete a note!") + return + + var/count = 0 //failsafe from unban procs + var/ackey = usr.ckey + var/ckey + var/content + + var/DBQuery/initquery = dbcon.NewQuery("SELECT ckey, content FROM aurora_notes WHERE id = '[noteid]'") + initquery.Execute() + while(initquery.NextRow()) + ckey = initquery.item[1] + content = initquery.item[2] + count++ + + if(count == 0) + usr << "\red Database update failed due to a note id not being present in the database." + error("Database update failed due to a note id not being present in the database.") + return + + if(count > 1) + usr << "\red Database update failed due to multiple notes having the same ID. Contact the database admin." + error("Database update failed due to multiple notes having the same ID. Contact the database admin.") + return + + switch(noteedit) + if("delete") + if(alert("Delete this note?", "Delete?", "Yes", "No") == "Yes") + var/DBQuery/deletequery = dbcon.NewQuery("UPDATE aurora_notes SET visible = 0 WHERE id = '[noteid]'") + deletequery.Execute() + + message_admins("\blue [key_name_admin(usr)] deleted one of [ckey]'s notes.") + log_admin("[key_name(usr)] deleted one of [ckey]'s notes.") + else + usr << "Cancelled" + return + if("content") + var/newcontent = input("Edit this note's contents.", "New Contents", "[content]", null) as null|text + newcontent = sql_sanitize_text(newcontent) + if(!newcontent) + usr << "Cancelled" + return + var/DBQuery/editquery = dbcon.NewQuery("UPDATE aurora_notes SET content = '[newcontent]', lasteditor = '[ackey]', lasteditdate = Now(), edited = 1 WHERE id = [noteid]") + editquery.Execute() + +/datum/admins/proc/show_notes_sql(var/playerckey = null, var/adminckey = null) + if(!check_rights(R_ADMIN|R_MOD)) + return + + if(adminckey == "Adminbot") + usr << "Adminbot is not an actual admin. You were lied to." + //The fucking size of this request would be astronomical. Please do not! + return + + establish_db_connection() + if(!dbcon.IsConnected()) + error("SQL connection failed while attempting to view a player's notes!") + return + + var/dat = "

Notes Look-up Panel


" + + //Totally not stealing code from the DB_ban_panel + + dat += "
Search: " + dat += "" + dat += "Ckey: " + dat += "Admin ckey: " + dat += "" + dat += "
" + + dat += "" + dat += "" + dat += "" + dat += "" + dat += "" + dat += "" + dat += "" + + if(playerckey) + + dat += "" + + var/ckey = sanitizeSQL(playerckey) + var/IP + var/CID + var/DBQuery/initquery = dbcon.NewQuery("SELECT ip, computerid FROM erro_player WHERE ckey = '[ckey]'") + initquery.Execute() + if(initquery.NextRow()) + IP = initquery.item[1] + CID = initquery.item[2] + + var/querycontent = "SELECT id, adddate, ckey, a_ckey, content, edited, lasteditor, lasteditdate FROM aurora_notes WHERE ckey = '[ckey]' AND visible = '1'" + + if(IP) + querycontent += " OR ip = '[IP]' AND visible = '1'" + if(CID) + querycontent += " OR computerid = '[CID]' AND visible = '1'" + + querycontent += " ORDER BY adddate ASC" + var/DBQuery/query = dbcon.NewQuery(querycontent) + query.Execute() + + while(query.NextRow()) + var/id = text2num(query.item[1]) + var/date = query.item[2] + var/p_ckey = query.item[3] + var/a_ckey = query.item[4] + var/content = query.item[5] + var/edited = text2num(query.item[6]) + + if(adminckey && ckey(a_ckey) != ckey(adminckey)) + continue + else + dat += "" + if(edited) + var/lasteditor = query.item[7] + var/editdate = query.item[8] + dat += "" + dat += "" + dat += "" + + else if(adminckey && !playerckey) + var/adminkey = sanitizeSQL(adminckey) + + var/aquerycontent = "SELECT id, adddate, ckey, content, edited, lasteditor, lasteditdate FROM aurora_notes WHERE a_ckey = '[ckey(adminkey)]' AND visible = '1' ORDER BY adddate ASC" + var/DBQuery/adminquery = dbcon.NewQuery(aquerycontent) + adminquery.Execute() + + while(adminquery.NextRow()) + var/id = text2num(adminquery.item[1]) + var/date = adminquery.item[2] + var/p_ckey = adminquery.item[3] + var/content = adminquery.item[4] + var/edited = text2num(adminquery.item[5]) + + dat += "" + if(edited) + var/lasteditor = adminquery.item[6] + var/editdate = adminquery.item[7] + dat += "" + dat += "" + dat += "" + + dat += "
ISSUED TOISSUED BYTIME ISSUEDCONTENT
Add Note
[p_ckey][a_ckey][date]
[content]
Note last edited: [editdate], by: [lasteditor].
(Delete) (Edit)
 
[p_ckey][adminckey][date]
[content]
Note last edited: [editdate], by: [lasteditor].
(Delete) (Edit)
 
" + usr << browse(dat,"window=lookupnotes;size=900x500") + +/proc/notes_transfer() + msg_scopes("Locating master list.") + var/savefile/note_list = new("data/player_notes.sav") + var/list/note_keys + note_list >> note_keys + + msg_scopes("Establishing DB connection!") + establish_db_connection() + if(!dbcon.IsConnected()) + msg_scopes("No DB connection!") + return + + for(var/t in note_keys) + var/IP = null + var/CID = null + var/DBQuery/query = dbcon.NewQuery("SELECT ip, computerid FROM erro_player WHERE ckey = '[t]'") + query.Execute() + if(query.NextRow()) + IP = query.item[1] + CID = query.item[2] + + var/savefile/info = new("data/player_saves/[copytext(t, 1, 2)]/[t]/info.sav") + var/list/infos + info >> infos + + for(var/datum/player_info/I in infos) + var/a_ckey = sanitizeSQL(I.author) + var/timeY = copytext(I.timestamp, findtext(I.timestamp, "of") + 3) + var/timeM + var/timeD = copytext(I.timestamp, findtext(I.timestamp, " ", 6) + 1, findtext(I.timestamp, " ", 6) + 3) + if(findtext(timeD, "s") || findtext(timeD, "n") || findtext(timeD, "r") || findtext(timeD, "t")) + timeD = "0[copytext(timeD, 1, 2)]" + +// msg_scopes("Timestamp: [I.timestamp].") + var/temp = copytext(I.timestamp, 6, findtext(I.timestamp, " ", 6)) +// msg_scopes("The day? [timeD].") +// msg_scopes("The month? [temp].") +// msg_scopes("The year? [timeY].") + switch(temp) + if("January") + timeM = "01" + if("February") + timeM = "02" + if("March") + timeM = "03" + if("April") + timeM = "04" + if("May") + timeM = "05" + if("June") + timeM = "06" + if("July") + timeM = "07" + if("August") + timeM = "08" + if("September") + timeM = "09" + if("October") + timeM = "10" + if("November") + timeM = "11" + if("December") + timeM = "12" + + var/DTG = "[timeY]-[timeM]-[timeD] 00:00:00" +// msg_scopes("Full DTG: [DTG]") + var/insertionstuff + if(IP && CID) + insertionstuff = "INSERT INTO aurora_notes (id, adddate, ckey, ip, computerid, a_ckey, content) VALUES (null, '[DTG]', '[t]', '[IP]', '[CID]', '[a_ckey]', '[I.content]')" + else + insertionstuff = "INSERT INTO aurora_notes (id, adddate, ckey, ip, computerid, a_ckey, content) VALUES (null, '[DTG]', '[t]', null, null, '[a_ckey]', '[I.content]')" + var/DBQuery/insertquery = dbcon.NewQuery(insertionstuff) + insertquery.Execute() + if(insertquery.ErrorMsg()) + msg_scopes(insertquery.ErrorMsg()) + else + msg_scopes("Transfer successful.") \ No newline at end of file diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm index 1156cc24..fe68382b 100644 --- a/code/modules/admin/topic.dm +++ b/code/modules/admin/topic.dm @@ -908,6 +908,9 @@ log_admin("[usr.client.ckey] has banned [M.ckey].\nReason: [reason]\nThis will be removed in [mins] minutes.") message_admins("\blue[usr.client.ckey] has banned [M.ckey].\nReason: [reason]\nThis will be removed in [mins] minutes.") + if(!config.ban_legacy_system) + notes_add_sql(M.ckey, "Banned for: [reason]. Duration: [mins] minutes.", usr.client.ckey, M.lastKnownIP, M.computer_id) + del(M.client) //del(M) // See no reason why to delete mob. Important stuff can be lost. And ban can be lifted before round ends. if("No") @@ -933,6 +936,9 @@ feedback_inc("ban_perma",1) DB_ban_record(BANTYPE_PERMA, M, -1, reason) + if(!config.ban_legacy_system) + notes_add_sql(M.ckey, "Banned for: [reason]. The ban is permanent.", usr.client.ckey, M.lastKnownIP, M.computer_id) + del(M.client) //del(M) if("Cancel") @@ -2763,7 +2769,17 @@ var/add = input("Add Player Info") as null|text if(!add) return - notes_add(key,add,usr) + if(config.ban_legacy_system) + notes_add(key,add,usr) + else + var/IP + var/CID + var/client/C = directory[key] + if(C) + IP = C.address + CID = C.computer_id + notes_add_sql(key, add, src.owner:ckey, IP, CID) + show_player_info(key) if(href_list["remove_player_info"]) @@ -2836,4 +2852,20 @@ M.client.adminhelped = 1 else usr << "The adminhelp has already been claimed." + return + + else if(href_list["dbnoteedit"]) + var/noteedit = href_list["dbnoteedit"] + var/noteid = text2num(href_list["dbnoteid"]) + if(!noteedit || !noteid) + return + + notes_edit_sql(noteid, noteedit) + return + + else if(href_list["notessearchckey"] || href_list["notessearchadmin"]) + var/adminckey = href_list["notessearchadmin"] + var/playerckey = href_list["notessearchckey"] + + show_notes_sql(playerckey, adminckey) return \ No newline at end of file diff --git a/code/modules/admin/verbs/warning.dm b/code/modules/admin/verbs/warning.dm index ae8b9b38..9334bc25 100644 --- a/code/modules/admin/verbs/warning.dm +++ b/code/modules/admin/verbs/warning.dm @@ -110,7 +110,12 @@ var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO aurora_warnings (id, time, severity, reason, notes, ckey, computerid, ip, a_ckey) VALUES (null, Now(), '[severity]', '[reason]', '[notes]', '[sqlkey]', '[computerid]', '[ip]', '[a_ckey]')") query_insert.Execute() - notes_add(warned_ckey, "Warning added by [a_ckey], for: [reason]. || Notes regarding the warning: [notes].") + + if(config.ban_legacy_system) + notes_add(warned_ckey, "Warning added by [a_ckey], for: [reason]. || Notes regarding the warning: [notes].") + else + notes_add_sql(warned_ckey, "Warning added by [a_ckey], for: [reason]. || Notes regarding the warning: [notes].", a_ckey, ip, computerid) + feedback_add_details("admin_verb","WARN-DB") if(C) C << "You have been formally warned by an administrator.
You can look up your warnings through the OOC panel, with the 'My Warnings' button.
"