forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrates admin memos to use database
- Loading branch information
1 parent
81145ea
commit f7b66ed
Showing
8 changed files
with
151 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,92 @@ | ||
#define MEMOFILE "data/memo.sav" //where the memos are saved | ||
#define ENABLE_MEMOS 1 //using a define because screw making a config variable for it. This is more efficient and purty. | ||
|
||
//switch verb so we don't spam up the verb lists with like, 3 verbs for this feature. | ||
/client/proc/admin_memo(task in list("write","show","delete")) | ||
/client/proc/admin_memo(task in list("Show","Write","Edit","Remove")) | ||
set name = "Memo" | ||
set category = "Server" | ||
if(!ENABLE_MEMOS) return | ||
if(!check_rights(0)) return | ||
if(!dbcon.IsConnected()) | ||
usr << "<span class='danger'>Failed to establish database connection.</span>" | ||
return | ||
var/sql_ckey = sanitizeSQL(src.ckey) | ||
switch(task) | ||
if("write") admin_memo_write() | ||
if("show") admin_memo_show() | ||
if("delete") admin_memo_delete() | ||
|
||
//write a message | ||
/client/proc/admin_memo_write() | ||
var/savefile/F = new(MEMOFILE) | ||
if(F) | ||
var/memo = input(src,"Type your memo\n(Leaving it blank will delete your current memo):","Write Memo",null) as null|message | ||
switch(memo) | ||
if(null) | ||
if("Write") | ||
var/memotext = input(src,"Write your Memo","Memo") as text|null | ||
if(!memotext) | ||
return | ||
if("") | ||
message_admins("<span class='admin'>[src.ckey] removed their own Memo</span>") | ||
log_admin("[src.ckey] removed their own Memo") | ||
F.dir.Remove(ckey) | ||
memotext = sanitizeSQL(memotext) | ||
var/timestamp = SQLtime() | ||
var/DBQuery/query_memoadd = dbcon.NewQuery("INSERT INTO [format_table_name("memo")] (ckey, memotext, timestamp) VALUES ('[sql_ckey]', '[memotext]', '[timestamp]')") | ||
if(!query_memoadd.Execute()) | ||
var/err = query_memoadd.ErrorMsg() | ||
log_game("SQL ERROR adding new memo. Error : \[[err]\]\n") | ||
return | ||
if( findtext(memo,"<script",1,0) ) | ||
return | ||
F[ckey] << "[key] on [time2text(world.realtime,"(DDD) DD MMM hh:mm")]<br>[memo]" | ||
message_admins("[key] set an admin memo:<br>[memo]") | ||
log_admin("[key] set an admin memo:[memo]") | ||
|
||
//show all memos | ||
/client/proc/admin_memo_show() | ||
if(ENABLE_MEMOS) | ||
var/savefile/F = new(MEMOFILE) | ||
if(F) | ||
for(var/ckey in F.dir) | ||
src << "<center><span class='motd'><span class='prefix'>Admin Memo</span><span class='emote'> by [F[ckey]]</span></span></center>" | ||
|
||
//delete your own or somebody else's memo | ||
/client/proc/admin_memo_delete() | ||
var/savefile/F = new(MEMOFILE) | ||
if(F) | ||
var/ckey | ||
if(check_rights(R_SERVER,0)) //high ranking admins can delete other admin's memos | ||
ckey = input(src,"Whose memo shall we remove?","Remove Memo",null) as null|anything in F.dir | ||
else | ||
ckey = src.ckey | ||
if(ckey) | ||
message_admins("<span class='admin'>[src.ckey] removed [ckey]'s Memo.</span>") | ||
log_admin("[src.ckey] removed Memo created by [ckey].") | ||
for(var/memo in F.dir) | ||
F.dir.Remove(ckey) | ||
|
||
#undef MEMOFILE | ||
#undef ENABLE_MEMOS | ||
log_admin("[key_name(src)] has set a memo: [memotext]") | ||
message_admins("[key_name_admin(src)] has set a memo:<br>[memotext]") | ||
if("Edit") | ||
var/DBQuery/query_memolist = dbcon.NewQuery("SELECT ckey FROM [format_table_name("memo")])") //should select all memos there are | ||
query_memolist.Execute() | ||
var/list/memolist = list() | ||
while(query_memolist.NextRow()) | ||
var/ckey = query_memolist.item[2] | ||
memolist += "[ckey]" | ||
if(!memolist.len) | ||
src << "No memos found in database." | ||
return | ||
var/target_ckey = input(src, "Select whose memo to edit", "Select memo") as null|anything in memolist | ||
if(!target_ckey) | ||
return | ||
var/target_sql_ckey = sanitizeSQL(target_ckey) | ||
var/DBQuery/query_memofind = dbcon.NewQuery("SELECT ckey, memotext FROM [format_table_name("memo")] WHERE (ckey = '[target_sql_ckey]')") | ||
query_memofind.Execute() | ||
if(query_memofind.NextRow()) | ||
var/old_memo = query_memofind.item[3] | ||
var/new_memo = input("Input new memo", "New Memo", "[old_memo]", null) as null|text | ||
if(!new_memo) | ||
return | ||
new_memo = sanitizeSQL(new_memo) | ||
var/edit_text = "Edited by [sql_ckey] on [SQLtime()] from<br>[old_memo]<br>to<br>[new_memo]<hr>" | ||
edit_text = sanitizeSQL(edit_text) | ||
var/DBQuery/update_query = dbcon.NewQuery("UPDATE [format_table_name("memo")] SET memotext = '[new_memo]', last_editor = '[sql_ckey]', edits = CONCAT(edits,'[edit_text]') WHERE (ckey = '[target_sql_ckey]')") | ||
if(!update_query.Execute()) | ||
var/err = update_query.ErrorMsg() | ||
log_game("SQL ERROR editing memo. Error : \[[err]\]\n") | ||
return | ||
if(target_sql_ckey == sql_ckey) | ||
log_admin("[key_name(src)] has edited their memo from [old_memo] to [new_memo]") | ||
message_admins("[key_name_admin(src)] has edited their memo from<br>[old_memo]<br>to<br>[new_memo]") | ||
else | ||
log_admin("[key_name(src)] has edited [target_sql_ckey]'s memo from [old_memo] to [new_memo]") | ||
message_admins("[key_name_admin(src)] has edited [target_sql_ckey]'s memo from<br>[old_memo]<br>to<br>[new_memo]") | ||
if("Show") | ||
var/DBQuery/query_memoshow = dbcon.NewQuery("SELECT id, ckey, memotext, timestamp, last_editor FROM [format_table_name("memo")])") | ||
while(query_memoshow.NextRow()) | ||
var/output | ||
var/id = query_memoshow.item[1] | ||
var/ckey = query_memoshow.item[2] | ||
var/memotext = query_memoshow.item[3] | ||
var/timestamp = query_memoshow.item[4] | ||
var/last_editor = query_memoshow.item[5] | ||
output += "<span class='memo'>Memo by <span class='prefix'>[ckey]</span> on [timestamp]:" | ||
if(last_editor) | ||
output += "<br><span class='memoedit'>Last edit by [last_editor] <A href='?_src_=holder;memoeditlist=[id]'>(Click here to see edit log)</A></span>" | ||
output += "<br>[memotext]</span>" | ||
src << output | ||
if("Remove") | ||
var/DBQuery/query_memolist = dbcon.NewQuery("SELECT ckey FROM [format_table_name("memo")])") //should select all memos there are | ||
query_memolist.Execute() | ||
if(!query_memolist.NextRow()) | ||
src << "No memos found in database." | ||
return | ||
var/target_ckey = input(src, "Select whose memo to delete", "Select memo") as null|anything in query_memolist //does this work? it's not initialized as an actual list | ||
if(!target_ckey) | ||
return | ||
var/target_sql_ckey = sanitizeSQL(target_ckey) | ||
var/DBQuery/query_memodel = dbcon.NewQuery("DELETE FROM [format_table_name("memo")] WHERE ckey = '[target_sql_ckey]'") | ||
if(!query_memodel.Execute()) | ||
var/err = query_memodel.ErrorMsg() | ||
log_game("SQL ERROR removing memo. Error : \[[err]\]\n") | ||
return | ||
if(target_sql_ckey == sql_ckey) | ||
log_admin("[key_name(src)] has removed their memo.") | ||
message_admins("[key_name_admin(src)] has removed their memo.") | ||
else | ||
log_admin("[key_name(src)] has removed [target_sql_ckey]'s memo.") | ||
message_admins("[key_name_admin(src)] has removed [target_sql_ckey]'s memo.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters