mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-15 12:11:45 +00:00
* 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 * Adds SIGNAL_HANDLER and SIGNAL_HANDLER_DOES_SLEEP to prevent signal callbacks from blocking Co-authored-by: Jared-Fogle <35135081+Jared-Fogle@users.noreply.github.com>
63 lines
1.6 KiB
Plaintext
63 lines
1.6 KiB
Plaintext
/datum/component/beetlejuice
|
|
var/keyword
|
|
var/list/first_heard
|
|
var/list/count
|
|
var/max_delay = 3 SECONDS //How fast they need to be said
|
|
var/min_count = 3
|
|
var/cooldown = 30 SECONDS //Delay between teleports
|
|
var/active = TRUE
|
|
var/case_sensitive = FALSE
|
|
var/regex/R
|
|
|
|
/datum/component/beetlejuice/Initialize()
|
|
if(!ismovable(parent))
|
|
return COMPONENT_INCOMPATIBLE
|
|
|
|
first_heard = list()
|
|
count = list()
|
|
|
|
var/atom/movable/O = parent
|
|
keyword = O.name
|
|
if(ismob(O))
|
|
var/mob/M = parent
|
|
keyword = M.real_name
|
|
update_regex()
|
|
|
|
RegisterSignal(SSdcs, COMSIG_GLOB_LIVING_SAY_SPECIAL, .proc/say_react)
|
|
|
|
/datum/component/beetlejuice/proc/update_regex()
|
|
R = regex("[REGEX_QUOTE(keyword)]","g[case_sensitive ? "" : "i"]")
|
|
|
|
/datum/component/beetlejuice/vv_edit_var(var_name, var_value)
|
|
. = ..()
|
|
if (var_name == NAMEOF(src, keyword) || var_name == NAMEOF(src, case_sensitive))
|
|
update_regex()
|
|
|
|
/datum/component/beetlejuice/proc/say_react(datum/source, mob/speaker,message)
|
|
SIGNAL_HANDLER
|
|
|
|
if(!speaker || speaker == parent || !message || !active)
|
|
return
|
|
var/found = R.Find(message)
|
|
if(found)
|
|
var/occurences = 1
|
|
while(R.Find(message))
|
|
occurences++
|
|
R.next = 1
|
|
|
|
if(!first_heard[speaker] || (first_heard[speaker] + max_delay < world.time))
|
|
first_heard[speaker] = world.time
|
|
count[speaker] = 0
|
|
count[speaker] += occurences
|
|
if(count[speaker] >= min_count)
|
|
first_heard -= speaker
|
|
count -= speaker
|
|
apport(speaker)
|
|
|
|
|
|
/datum/component/beetlejuice/proc/apport(atom/target)
|
|
var/atom/movable/AM = parent
|
|
do_teleport(AM,get_turf(target))
|
|
active = FALSE
|
|
addtimer(VARSET_CALLBACK(src, active, TRUE), cooldown)
|