From 0a974b3c0e4cd53c6e88ee2fafd8976002b7173f Mon Sep 17 00:00:00 2001 From: "baloh.matevz" Date: Sun, 11 Sep 2011 19:18:04 +0000 Subject: [PATCH] Edit variables and view variables combined. Screenshot: http://www.kamletos.si/view%20vars3.JPG What C and E mean is written on the window itself. git-svn-id: http://tgstation13.googlecode.com/svn/trunk@2178 316c924e-a436-60f5-8080-3fe189b3f50e --- code/datums/datumvars.dm | 54 +++++- code/modules/admin/verbs/modifyvariables.dm | 201 +++++++++++++------- 2 files changed, 180 insertions(+), 75 deletions(-) diff --git a/code/datums/datumvars.dm b/code/datums/datumvars.dm index d754f785a8f..25d8a216777 100644 --- a/code/datums/datumvars.dm +++ b/code/datums/datumvars.dm @@ -1,3 +1,6 @@ + +// reference: /client/proc/modify_variables(var/atom/O, var/param_var_name = null, var/autodetect_class = 0) + client proc/debug_variables(datum/D in world) set category = "Debug" @@ -19,6 +22,12 @@ client #endif title = "[D] (\ref[D]) = [D.type]" + body += "
" + + body += "
[D]
[D.type]

" + + body += "E - Edit, tries to determine the variable type by itself.
" + body += "C - Change, asks you for the var type first.
" body += "
    " @@ -29,7 +38,7 @@ client names = sortList(names) for (var/V in names) - body += debug_variable(V, D.vars[V], 0) + body += debug_variable(V, D.vars[V], 0, D) body += "
" @@ -56,13 +65,13 @@ client return - - - - proc/debug_variable(name, value, level) + proc/debug_variable(name, value, level, var/datum/DA = null) var/html = "" - html += "
  • " + if(DA) + html += "
  • (E) (C) " + else + html += "
  • " if (isnull(value)) html += "[name] = null" @@ -130,6 +139,39 @@ client if (href_list["Vars"]) debug_variables(locate(href_list["Vars"])) + else if (href_list["varnameedit"]) + if(!href_list["datumedit"] || !href_list["varnameedit"]) + usr << "Varedit error: Not all information has been sent Contact a coder." + return + var/datum/DAT = locate(href_list["datumedit"]) + if(!DAT) + usr << "Item not found" + return + if(!istype(DAT,/datum)) + usr << "Can't edit an item of this type. Type must be /datum, so anything except simple variables. [DAT]" + return + modify_variables(DAT, href_list["varnameedit"], 1) + else if (href_list["varnamechange"]) + if(!href_list["datumchange"] || !href_list["varnamechange"]) + usr << "Varedit error: Not all information has been sent. Contact a coder." + return + var/datum/DAT = locate(href_list["datumchange"]) + if(!DAT) + usr << "Item not found" + return + if(!istype(DAT,/datum)) + usr << "Can't edit an item of this type. Type must be /datum, so anything except simple variables. [DAT]" + return + modify_variables(DAT, href_list["varnamechange"], 0) + else if (href_list["refresh"]) + if(!href_list["datumrefresh"]) + return + var/datum/DAT = locate(href_list["datumrefresh"]) + if(!DAT) + return + if(!istype(DAT,/datum)) + return + src.debug_variables(DAT) else ..() diff --git a/code/modules/admin/verbs/modifyvariables.dm b/code/modules/admin/verbs/modifyvariables.dm index 6d8439a5b75..d0cbcbfb323 100644 --- a/code/modules/admin/verbs/modifyvariables.dm +++ b/code/modules/admin/verbs/modifyvariables.dm @@ -227,99 +227,162 @@ variable = input("Pick icon:","Icon",variable) \ as icon - -/client/proc/modify_variables(var/atom/O) +/client/proc/modify_variables(var/atom/O, var/param_var_name = null, var/autodetect_class = 0) var/list/locked = list("vars", "key", "ckey", "client", "firemut", "ishulk", "telekinesis", "xray", "virus", "cuffed", "ka", "last_eaten", "urine", "poo", "icon", "icon_state") if(!src.authenticated || !src.holder) src << "Only administrators may use this command." return - var/list/names = list() - for (var/V in O.vars) - names += V + var/class + var/variable + var/var_value - names = sortList(names) + if(param_var_name) + if(!param_var_name in O.vars) + src << "A variable with this name ([param_var_name]) doesn't exist in this atom ([O])" + return - var/variable = input("Which var?","Var") as null|anything in names - if(!variable) - return - var/default - var/var_value = O.vars[variable] - var/dir + if (param_var_name == "holder" && holder.rank != "Game Master") + src << "No. Stop being stupid." + return - if (locked.Find(variable) && !(src.holder.rank in list("Game Master", "Game Admin"))) - return + if (locked.Find(param_var_name) && !(src.holder.rank in list("Game Master", "Game Admin"))) + src << "Editing this variable requires you to be a game master or game admin." + return - if (variable == "holder" && holder.rank != "Game Master") //Hotfix, a bit ugly but that exploit has been there for ages and now somebody just had to go and tell everyone of it bluh bluh - U - return + variable = param_var_name - if(isnull(var_value)) - usr << "Unable to determine variable type." + var_value = O.vars[variable] - else if(isnum(var_value)) - usr << "Variable appears to be NUM." - default = "num" - dir = 1 + if(autodetect_class) + if(isnull(var_value)) + usr << "Unable to determine variable type." + class = null + autodetect_class = null + else if(isnum(var_value)) + usr << "Variable appears to be NUM." + class = "num" + dir = 1 - else if(istext(var_value)) - usr << "Variable appears to be TEXT." - default = "text" + else if(istext(var_value)) + usr << "Variable appears to be TEXT." + class = "text" - else if(isloc(var_value)) - usr << "Variable appears to be REFERENCE." - default = "reference" + else if(isloc(var_value)) + usr << "Variable appears to be REFERENCE." + class = "reference" - else if(isicon(var_value)) - usr << "Variable appears to be ICON." - var_value = "\icon[var_value]" - default = "icon" + else if(isicon(var_value)) + usr << "Variable appears to be ICON." + var_value = "\icon[var_value]" + class = "icon" - else if(istype(var_value,/atom) || istype(var_value,/datum)) - usr << "Variable appears to be TYPE." - default = "type" + else if(istype(var_value,/atom) || istype(var_value,/datum)) + usr << "Variable appears to be TYPE." + class = "type" - else if(istype(var_value,/list)) - usr << "Variable appears to be LIST." - default = "list" + else if(istype(var_value,/list)) + usr << "Variable appears to be LIST." + class = "list" - else if(istype(var_value,/client)) - usr << "Variable appears to be CLIENT." - default = "cancel" + else if(istype(var_value,/client)) + usr << "Variable appears to be CLIENT." + class = "cancel" + + else + usr << "Variable appears to be FILE." + class = "file" else - usr << "Variable appears to be FILE." - default = "file" - usr << "Variable contains: [var_value]" - if(dir) - switch(var_value) - if(1) - dir = "NORTH" - if(2) - dir = "SOUTH" - if(4) - dir = "EAST" - if(8) - dir = "WEST" - if(5) - dir = "NORTHEAST" - if(6) - dir = "SOUTHEAST" - if(9) - dir = "NORTHWEST" - if(10) - dir = "SOUTHWEST" - else - dir = null + var/list/names = list() + for (var/V in O.vars) + names += V + + names = sortList(names) + + variable = input("Which var?","Var") as null|anything in names + if(!variable) + return + var_value = O.vars[variable] + + if (locked.Find(variable) && !(src.holder.rank in list("Game Master", "Game Admin"))) + return + + if (variable == "holder" && holder.rank != "Game Master") //Hotfix, a bit ugly but that exploit has been there for ages and now somebody just had to go and tell everyone of it bluh bluh - U + return + + if(!autodetect_class) + + var/dir + var/default + if(isnull(var_value)) + usr << "Unable to determine variable type." + + else if(isnum(var_value)) + usr << "Variable appears to be NUM." + default = "num" + dir = 1 + + else if(istext(var_value)) + usr << "Variable appears to be TEXT." + default = "text" + + else if(isloc(var_value)) + usr << "Variable appears to be REFERENCE." + default = "reference" + + else if(isicon(var_value)) + usr << "Variable appears to be ICON." + var_value = "\icon[var_value]" + default = "icon" + + else if(istype(var_value,/atom) || istype(var_value,/datum)) + usr << "Variable appears to be TYPE." + default = "type" + + else if(istype(var_value,/list)) + usr << "Variable appears to be LIST." + default = "list" + + else if(istype(var_value,/client)) + usr << "Variable appears to be CLIENT." + default = "cancel" + + else + usr << "Variable appears to be FILE." + default = "file" + + usr << "Variable contains: [var_value]" if(dir) - usr << "If a direction, direction is: [dir]" + switch(var_value) + if(1) + dir = "NORTH" + if(2) + dir = "SOUTH" + if(4) + dir = "EAST" + if(8) + dir = "WEST" + if(5) + dir = "NORTHEAST" + if(6) + dir = "SOUTHEAST" + if(9) + dir = "NORTHWEST" + if(10) + dir = "SOUTHWEST" + else + dir = null + if(dir) + usr << "If a direction, direction is: [dir]" - var/class = input("What kind of variable?","Variable Type",default) as null|anything in list("text", - "num","type","reference","mob reference", "icon","file","list","edit referenced object","restore to default") + class = input("What kind of variable?","Variable Type",default) as null|anything in list("text", + "num","type","reference","mob reference", "icon","file","list","edit referenced object","restore to default") - if(!class) - return + if(!class) + return var/original_name