Files
Bubberstation/code/modules/modular_computers/file_system/programs/signalcommander.dm
SkyratBot 807846f7d6 [MIRROR] Updates signaler investigate code | Adds some nice QOL changes for signalers | Enforces cooldown on signaler circuitry [MDB IGNORE] (#24500)
* Updates signaler investigate code | Adds some nice QOL changes for signalers | Enforces cooldown on signaler circuitry (#78974)

## About The Pull Request

See title.
If someone was abusing signalers previously to cause server lag, going
into list signalers would actually cause even worse lag as byond sat
there and processed thousands of items into a string over and over,
which would cause string format operations on longer and longer strings,
resulting in more and more overhead. This is bad.
So instead there is now a limit to the size of the list, currently I
have that set to 500 although I am open to increasing and even reducing
the number.

I have also made signalers slightly more intuitive by having the
cooldown actually displayed in the ui as a tooltip instead of just being
a secret feature you didnt know about unless you code dived. Also made
the cooldown actually respected by things such as circuitry where it
didnt even implement the cooldown and would happily send as many signals
as you had items connected to your proximity circuit.
## Why It's Good For The Game

Admins won't accidentally kill the server by trying to parse a lag
machines signal list. Players lagging the server? No, how about the
admins trying to fix it!

## Changelog

🆑
qol: signalers now tell you their cooldown and also use balloon alerts
/🆑

* Updates signaler investigate code | Adds some nice QOL changes for signalers | Enforces cooldown on signaler circuitry

---------

Co-authored-by: Zephyr <12817816+ZephyrTFA@users.noreply.github.com>
2023-10-21 18:20:44 -04:00

83 lines
2.8 KiB
Plaintext

/datum/computer_file/program/signal_commander
filename = "signaler"
filedesc = "SignalCommander"
category = PROGRAM_CATEGORY_MISC
program_icon_state = "signal"
extended_desc = "A small built-in frequency app that sends out signaller signals with the appropriate hardware."
size = 2
tgui_id = "NtosSignaler"
program_icon = "satellite-dish"
usage_flags = PROGRAM_TABLET | PROGRAM_LAPTOP
///What is the saved signal frequency?
var/signal_frequency = FREQ_SIGNALER
/// What is the saved signal code?
var/signal_code = DEFAULT_SIGNALER_CODE
/// Radio connection datum used by signalers.
var/datum/radio_frequency/radio_connection
/// How long do we cooldown before we can send another signal?
var/signal_cooldown_time = 1 SECONDS
/// Cooldown store
COOLDOWN_DECLARE(signal_cooldown)
/datum/computer_file/program/signal_commander/on_start(mob/living/user)
. = ..()
set_frequency(signal_frequency)
/datum/computer_file/program/signal_commander/kill_program(mob/user)
. = ..()
SSradio.remove_object(computer, signal_frequency)
/datum/computer_file/program/signal_commander/ui_data(mob/user)
var/list/data = list()
data["frequency"] = signal_frequency
data["cooldown"] = signal_cooldown_time
data["code"] = signal_code
data["minFrequency"] = MIN_FREE_FREQ
data["maxFrequency"] = MAX_FREE_FREQ
return data
/datum/computer_file/program/signal_commander/ui_act(action, list/params)
switch(action)
if("signal")
INVOKE_ASYNC(src, PROC_REF(signal))
. = TRUE
if("freq")
var/new_signal_frequency = sanitize_frequency(unformat_frequency(params["freq"]), TRUE)
set_frequency(new_signal_frequency)
. = TRUE
if("code")
signal_code = text2num(params["code"])
signal_code = round(signal_code)
. = TRUE
if("reset")
if(params["reset"] == "freq")
signal_frequency = initial(signal_frequency)
else
signal_code = initial(signal_code)
. = TRUE
/datum/computer_file/program/signal_commander/proc/signal()
if(!radio_connection)
return
if(!COOLDOWN_FINISHED(src, signal_cooldown))
computer.balloon_alert(usr, "cooling down!")
return
COOLDOWN_START(src, signal_cooldown, signal_cooldown_time)
computer.balloon_alert(usr, "signaled")
var/time = time2text(world.realtime,"hh:mm:ss")
var/turf/T = get_turf(computer)
var/logging_data = "[time] <B>:</B> [key_name(usr)] used the computer '[initial(computer.name)]' @ location ([T.x],[T.y],[T.z]) <B>:</B> [format_frequency(signal_frequency)]/[signal_code]"
add_to_signaler_investigate_log(logging_data)
var/datum/signal/signal = new(list("code" = signal_code), logging_data = logging_data)
radio_connection.post_signal(computer, signal)
/datum/computer_file/program/signal_commander/proc/set_frequency(new_frequency)
SSradio.remove_object(computer, signal_frequency)
signal_frequency = new_frequency
radio_connection = SSradio.add_object(computer, signal_frequency, RADIO_SIGNALER)