Callback security and usr (#33599)

* Gonna regret writing this one day

* tmp -> temp

* Make PushUsr() a /world proc

* Callbacks now preserve usr

* Fixes PushUsr return value

* Fixes PushUsr invocations

* Update modifyvariables.dm

* Use weakrefs in callback user

* Further fixes

* Whoopsie
This commit is contained in:
Jordan Brown
2017-12-18 22:42:25 -05:00
committed by CitadelStationBot
parent d5708c981a
commit fabfad270f
3 changed files with 38 additions and 3 deletions

View File

@@ -1508,6 +1508,14 @@ GLOBAL_DATUM_INIT(dview_mob, /mob/dview, new)
return "\[[url_encode(thing.tag)]\]"
return "\ref[input]"
// Makes a call in the context of a different usr
// Use sparingly
/world/proc/PushUsr(mob/M, datum/callback/CB)
var/temp = usr
usr = M
. = CB.Invoke()
usr = temp
//Returns a list of all servants of Ratvar and observers.
/proc/servants_and_ghosts()
. = list()

View File

@@ -48,6 +48,7 @@
var/datum/object = GLOBAL_PROC
var/delegate
var/list/arguments
var/datum/weakref/user
/datum/callback/New(thingtocall, proctocall, ...)
if (thingtocall)
@@ -55,6 +56,8 @@
delegate = proctocall
if (length(args) > 2)
arguments = args.Copy(3)
if(usr)
user = WEAKREF(usr)
/world/proc/ImmediateInvokeAsync(thingtocall, proctocall, ...)
set waitfor = FALSE
@@ -70,8 +73,16 @@
call(thingtocall, proctocall)(arglist(calling_arguments))
/datum/callback/proc/Invoke(...)
if(!usr)
var/datum/weakref/W = user
if(W)
var/mob/M = W.resolve()
if(M)
return world.PushUsr(M, src)
if (!object)
return
var/list/calling_arguments = arguments
if (length(args))
if (length(arguments))
@@ -87,8 +98,17 @@
//copy and pasted because fuck proc overhead
/datum/callback/proc/InvokeAsync(...)
set waitfor = FALSE
if(!usr)
var/datum/weakref/W = user
if(W)
var/mob/M = W.resolve()
if(M)
return world.PushUsr(M, src)
if (!object)
return
var/list/calling_arguments = arguments
if (length(args))
if (length(arguments))

View File

@@ -213,7 +213,9 @@ GLOBAL_PROTECT(VVpixelmovement)
.["class"] = null
return
.["type"] = type
.["value"] = new type()
var/atom/newguy = new type()
newguy.var_edited = TRUE
.["value"] = newguy
if (VV_NEW_DATUM)
var/type = pick_closest_path(FALSE, get_fancy_list_of_datum_types())
@@ -221,7 +223,9 @@ GLOBAL_PROTECT(VVpixelmovement)
.["class"] = null
return
.["type"] = type
.["value"] = new type()
var/datum/newguy = new type()
newguy.var_edited = TRUE
.["value"] = newguy
if (VV_NEW_TYPE)
var/type = current_value
@@ -237,7 +241,10 @@ GLOBAL_PROTECT(VVpixelmovement)
.["class"] = null
return
.["type"] = type
.["value"] = new type()
var/datum/newguy = new type()
if(istype(newguy))
newguy.var_edited = TRUE
.["value"] = newguy
if (VV_NEW_LIST)