From 7f9e50c33baef282246cba502d18316403b06239 Mon Sep 17 00:00:00 2001 From: Menshin Date: Fri, 8 Mar 2019 11:33:57 +0100 Subject: [PATCH] Fixes advanced proc calls not working + various code cleaning (#42952) * Fixes advanced proc calls not working + various code cleaning * Reverted Destroy() call protection. --- code/modules/admin/verbs/debug.dm | 86 ++++++++++++++----------------- 1 file changed, 40 insertions(+), 46 deletions(-) diff --git a/code/modules/admin/verbs/debug.dm b/code/modules/admin/verbs/debug.dm index 631e8cd6037..3b48439e81e 100644 --- a/code/modules/admin/verbs/debug.dm +++ b/code/modules/admin/verbs/debug.dm @@ -29,66 +29,62 @@ But you can call procs that are of type /mob/living/carbon/human/proc/ for that /client/proc/callproc() set category = "Debug" set name = "Advanced ProcCall" - set waitfor = 0 + set waitfor = FALSE if(!check_rights(R_DEBUG)) return var/datum/target = null - var/targetselected = 0 + var/targetselected = FALSE var/returnval = null - switch(alert("Proc owned by something?",,"Yes","No")) - if("Yes") - targetselected = 1 - var/list/value = vv_get_value(default_class = VV_ATOM_REFERENCE, classes = list(VV_ATOM_REFERENCE, VV_DATUM_REFERENCE, VV_MOB_REFERENCE, VV_CLIENT)) - if (!value["class"] || !value["value"]) - return - target = value["value"] - if("No") - target = null - targetselected = 0 + if(alert("Proc owned by something?",,"Yes","No") == "Yes") + targetselected = TRUE + var/list/value = vv_get_value(default_class = VV_ATOM_REFERENCE, classes = list(VV_ATOM_REFERENCE, VV_DATUM_REFERENCE, VV_MOB_REFERENCE, VV_CLIENT)) + if (!value["class"] || !value["value"]) + return + target = value["value"] - var/procname = input("Proc path, eg: /proc/fake_blood","Path:", null) as text|null - if(!procname) + var/procpath = input("Proc path, eg: /proc/fake_blood","Path:", null) as text|null + if(!procpath) return - + //strip away everything but the proc name - var/list/proclist = splittext(procname, "/") + var/list/proclist = splittext(procpath, "/") if (!length(proclist)) return - procname = proclist[proclist.len] - - var/proctype = "proc" - if ("verb" in proclist) - proctype = "verb" - - if(targetselected && !hascall(target, procname)) - to_chat(usr, "Error: callproc(): type [target.type] has no [proctype] named [procname].") - return - else - var/procpath = text2path("[proctype]/[procname]") - if (!procpath) - to_chat(usr, "Error: callproc(): proc [procname] does not exist. (Did you forget the /proc/ part?)") + + var/procname = proclist[proclist.len] + var/proctype = ("verb" in proclist) ? "verb" :"proc" + + if(targetselected) + if(!hascall(target, procname)) + to_chat(usr, "Error: callproc(): type [target.type] has no [proctype] named [procpath].") return + else + procpath = "/[proctype]/[procname]" + if(!text2path(procpath)) + to_chat(usr, "Error: callproc(): [procpath] does not exist.") + return + var/list/lst = get_callproc_args() if(!lst) return if(targetselected) if(!target) - to_chat(usr, "Error: callproc(): owner of proc no longer exists.") + to_chat(usr, "Error: callproc(): owner of proc no longer exists.") return - var/msg = "[key_name(src)] called [target]'s [procname]() with [lst.len ? "the arguments [list2params(lst)]":"no arguments"]." + var/msg = "[key_name(src)] called [target]'s [procname]() with [lst.len ? "the arguments [list2params(lst)]":"no argument"]." log_admin(msg) message_admins(msg) admin_ticket_log(target, msg) - returnval = WrapAdminProcCall(target, procname, lst) // Pass the lst as an argument list to the proc + returnval = WrapAdminProcCall(target, procname, lst) else - //this currently has no hascall protection. wasn't able to get it working. - log_admin("[key_name(src)] called [procname]() with [lst.len ? "the arguments [list2params(lst)]":"no arguments"].") - message_admins("[key_name(src)] called [procname]() with [lst.len ? "the arguments [list2params(lst)]":"no arguments"].") - returnval = WrapAdminProcCall(GLOBAL_PROC, procname, lst) // Pass the lst as an argument list to the proc + var/msg = "[key_name(src)] called [procname]() with [lst.len ? "the arguments [list2params(lst)]":"no argument"]." + log_admin(msg) + message_admins(msg) + returnval = WrapAdminProcCall(GLOBAL_PROC, procpath, lst) //calling globals needs full qualified name (e.g /proc/foo) . = get_callproc_returnval(returnval, procname) if(.) to_chat(usr, .) @@ -108,8 +104,8 @@ GLOBAL_LIST_EMPTY(AdminProcCallSpamPrevention) GLOBAL_PROTECT(AdminProcCallSpamPrevention) /proc/WrapAdminProcCall(datum/target, procname, list/arguments) - if(target && procname == "Del") - to_chat(usr, "Calling Del() is not allowed") + if(target != GLOBAL_PROC && procname == "Del") + to_chat(usr, "Calling Del() is not allowed") return if(target != GLOBAL_PROC && !target.CanProcCall(procname)) @@ -156,7 +152,7 @@ GLOBAL_PROTECT(AdminProcCallSpamPrevention) /client/proc/callproc_datum(datum/A as null|area|mob|obj|turf) set category = "Debug" set name = "Atom ProcCall" - set waitfor = 0 + set waitfor = FALSE if(!check_rights(R_DEBUG)) return @@ -165,7 +161,7 @@ GLOBAL_PROTECT(AdminProcCallSpamPrevention) if(!procname) return if(!hascall(A,procname)) - to_chat(usr, "Error: callproc_datum(): type [A.type] has no proc named [procname].") + to_chat(usr, "Error: callproc_datum(): type [A.type] has no proc named [procname].") return var/list/lst = get_callproc_args() if(!lst) @@ -174,8 +170,8 @@ GLOBAL_PROTECT(AdminProcCallSpamPrevention) if(!A || !IsValidSrc(A)) to_chat(usr, "Error: callproc_datum(): owner of proc no longer exists.") return - log_admin("[key_name(src)] called [A]'s [procname]() with [lst.len ? "the arguments [list2params(lst)]":"no arguments"].") var/msg = "[key_name(src)] called [A]'s [procname]() with [lst.len ? "the arguments [list2params(lst)]":"no arguments"]." + log_admin(msg) message_admins(msg) admin_ticket_log(A, msg) SSblackbox.record_feedback("tally", "admin_verb", 1, "Atom ProcCall") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! @@ -185,8 +181,6 @@ GLOBAL_PROTECT(AdminProcCallSpamPrevention) if(.) to_chat(usr, .) - - /client/proc/get_callproc_args() var/argnum = input("Number of arguments","Number:",0) as num|null if(isnull(argnum)) @@ -210,7 +204,7 @@ GLOBAL_PROTECT(AdminProcCallSpamPrevention) . = "" if(islist(returnval)) var/list/returnedlist = returnval - . = "" + . = "" if(returnedlist.len) var/assoc_check = returnedlist[1] if(istext(assoc_check) && (returnedlist[assoc_check] != null)) @@ -224,10 +218,10 @@ GLOBAL_PROTECT(AdminProcCallSpamPrevention) . += "\n[elem]" else . = "[procname] returned an empty list" - . += "" + . += "" else - . = "[procname] returned: [!isnull(returnval) ? returnval : "null"]" + . = "[procname] returned: [!isnull(returnval) ? returnval : "null"]" /client/proc/Cell()