Files
Bubberstation/code/datums/components/tether.dm
Jared-Fogle 45c14f6330 Adds SIGNAL_HANDLER and SIGNAL_HANDLER_DOES_SLEEP to prevent signal callbacks from blocking (#52761)
Adds SIGNAL_HANDLER, a macro that sets SHOULD_NOT_SLEEP(TRUE). This should ideally be required on all new signal callbacks.

Adds BLOCKING_SIGNAL_HANDLER, a macro that does nothing except symbolize "this is an older signal that didn't necessitate a code rewrite". It should not be allowed for new work.

This comes from discussion around #52735, which yields by calling input, and (though it sets the return type beforehand) will not properly return the flag to prevent attack from slapping.

To fix 60% of the yielding cases, WrapAdminProcCall no longer waits for another admin's proc call to finish. I'm not an admin, so I don't know how many behinds this has saved, but if this is problematic for admins I can just make it so that it lets you do it anyway. I'm not sure what the point of this babysitting was anyway.

Requested by @optimumtact.
Changelog

cl
admin: Calling a proc while another admin is calling one will no longer wait for the first to finish. You will simply just have to call it again.
/cl
2020-08-20 09:11:28 +12:00

40 lines
1.3 KiB
Plaintext

/datum/component/tether
dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS
var/atom/tether_target
var/max_dist
var/tether_name
/datum/component/tether/Initialize(atom/tether_target, max_dist = 4, tether_name)
if(!isliving(parent) || !istype(tether_target) || !tether_target.loc)
return COMPONENT_INCOMPATIBLE
src.tether_target = tether_target
src.max_dist = max_dist
if (ispath(tether_name, /atom))
var/atom/tmp = tether_name
src.tether_name = initial(tmp.name)
else
src.tether_name = tether_name
RegisterSignal(parent, list(COMSIG_MOVABLE_PRE_MOVE), .proc/checkTether)
/datum/component/tether/proc/checkTether(mob/mover, newloc)
SIGNAL_HANDLER
if (get_dist(mover,newloc) > max_dist)
to_chat(mover, "<span class='userdanger'>The [tether_name] runs out of slack and prevents you from moving!</span>")
return COMPONENT_MOVABLE_BLOCK_PRE_MOVE
var/atom/blocker
out:
for(var/turf/T in getline(tether_target,newloc))
if (T.density)
blocker = T
break out
for(var/a in T)
var/atom/A = a
if(A.density && A != mover && A != tether_target)
blocker = A
break out
if (blocker)
to_chat(mover, "<span class='userdanger'>The [tether_name] catches on [blocker] and prevents you from moving!</span>")
return COMPONENT_MOVABLE_BLOCK_PRE_MOVE