[MIRROR] [NO GBP] Fixing issues with modular computer and circuits. (#26247)

* [NO GBP] Fixing issues with modular computer and circuits. (#81076)

## About The Pull Request
It turns out the messenger circuit wasn't working as intended, because
list components tend to convert datum keys into weakrefs, creating
incoherence between composite datum/atom and simple datum/atom
datatypes, which at least just spares us from the headache of clearing
the refs on del from lists too.

So, taking the shortest path, I decided to adapt the messenger to the
weak ref usage.

Another thing, instead of refusing altogether to send message that
trigger the pda filter regexes, the messenger circuit will instead
replace the matches with grawlix, since we have no way to inform
whoever's responsible for said message about the filters in an orthodox
way.

Beside that, I've noticed several of the circuits from my PR were
lacking trigger outputs or similar when needed, pretty making them only
as half as functional, at least to a noob like me.

And another small issue with missing ports from the status display
circuit.

One more suggestion from moocow is to add a cooldown to the ringtone
trigger for the messenger circuit, because he said it's pretty spammy
and some admins are fickle.

## Why It's Good For The Game
Bugfixing and improvements.

## Changelog

🆑
fix: Fixed the messenger circuit not sending messages.
fix: Added several ports to modpc circuits that were missing or needing
them.
fix: Fixes ever-expanding ports whenever circuits are re-inserted in a
modular computer.
/🆑

* [NO GBP] Fixing issues with modular computer and circuits.

---------

Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
This commit is contained in:
SkyratBot
2024-01-25 23:08:34 -05:00
committed by GitHub
co-authored by Ghom
parent 309da5fd76
commit f768fab6c9
16 changed files with 210 additions and 85 deletions
@@ -1,6 +1,7 @@
#define MESSENGER_CIRCUIT_MIN_COOLDOWN 5 SECONDS
#define MESSENGER_CIRCUIT_MAX_COOLDOWN 45 SECONDS
#define MESSENGER_CIRCUIT_CD_PER_RECIPIENT 1.5 SECONDS
#define MESSENGER_CIRCUIT_RINGTONE_CD 1.5 SECONDS
/obj/item/circuit_component/mod_program/messenger
associated_program = /datum/computer_file/program/messenger
@@ -14,6 +15,8 @@
var/datum/port/output/sender_job
///Reference to the device that sent the message. Usually a PDA.
var/datum/port/output/sender_device
///Pinged whenever a message is received.
var/datum/port/output/received
///A message to be sent when triggered
var/datum/port/input/message
@@ -25,12 +28,16 @@
///Set the ringtone to the input
var/datum/port/input/set_ring
///the cooldown of the ringtone.
COOLDOWN_DECLARE(ring_cd)
/obj/item/circuit_component/mod_program/messenger/populate_ports()
. = ..()
received_message = add_output_port("Received Message", PORT_TYPE_STRING)
received_message = add_output_port("Message", PORT_TYPE_STRING)
sender_name = add_output_port("Sender Name", PORT_TYPE_STRING)
sender_job = add_output_port("Sender Job", PORT_TYPE_STRING)
sender_device = add_output_port("Sender Device", PORT_TYPE_ATOM)
received = add_output_port("Received", PORT_TYPE_SIGNAL)
message = add_input_port("Message", PORT_TYPE_STRING)
targets = add_input_port("Targets", PORT_TYPE_LIST(PORT_TYPE_ATOM))
@@ -38,25 +45,22 @@
ring = add_input_port("Play Ringtone", PORT_TYPE_SIGNAL, trigger = PROC_REF(play_ringtone))
set_ring = add_input_port("Set Ringtone", PORT_TYPE_STRING, trigger = PROC_REF(set_ringtone))
///Sanitize the targets list so it doesn't contain duplicate targets and our own computer.
/obj/item/circuit_component/mod_program/messenger/pre_input_received(datum/port/port)
if(COMPONENT_TRIGGERED_BY(targets, port))
targets.value = unique_list(targets.value) - associated_program.computer
/obj/item/circuit_component/mod_program/messenger/input_received(datum/port/port)
var/list/messenger_targets = list()
for(var/obj/item/modular_computer/modpc in targets.value)
for(var/datum/weakref/ref as anything in targets.value)
var/obj/item/modular_computer/modpc = ref?.resolve() //entity ports are hardrefs, entity list ports are weakref. :thonking:
if(!istype(modpc))
continue
var/datum/computer_file/program/messenger/messenger = locate() in modpc.stored_files
if(messenger)
messenger_targets |= messenger
var/messenger_length = length(messenger_targets)
if(!messenger_length)
if(!length(messenger_targets))
return
var/datum/computer_file/program/messenger/messenger = associated_program
if(is_ic_filtered_for_pdas(message.value) || is_soft_ic_filtered_for_pdas(message.value))
return
var/filterd_message = censor_ic_filter_for_pdas(message.value)
///We need to async send_message() because some tcomms devices might sleep. Also because of (non-existent) user tgui alerts.
INVOKE_ASYNC(messenger, TYPE_PROC_REF(/datum/computer_file/program/messenger, send_message), src, message.value, messenger_targets)
INVOKE_ASYNC(messenger, TYPE_PROC_REF(/datum/computer_file/program/messenger, send_message), src, filterd_message, messenger_targets)
/obj/item/circuit_component/mod_program/messenger/register_shell(atom/movable/shell)
. = ..()
@@ -76,8 +80,8 @@
/obj/item/circuit_component/mod_program/messenger/proc/message_received(datum/source, datum/signal/subspace/messaging/tablet_message/signal, message_job, message_name)
SIGNAL_HANDLER
received_message.set_value(signal.data["message"])
sender_name.set_value(message_name)
sender_job.set_value(message_job)
sender_name.set_output(message_name)
sender_job.set_output(message_job)
var/atom/source_device
if(istype(signal.source, /datum/computer_file/program/messenger))
@@ -86,7 +90,8 @@
else if(isatom(signal.source))
source_device = signal.source
sender_device.set_value(source_device)
sender_device.set_output(source_device)
received.set_output(COMPONENT_SIGNAL)
///Set the cooldown after the message was sent (by us)
/obj/item/circuit_component/mod_program/messenger/proc/message_sent(datum/source, atom/origin, datum/signal/subspace/messaging/tablet_message/signal)
@@ -103,9 +108,13 @@
messenger.set_ringtone(set_ring.value)
/obj/item/circuit_component/mod_program/messenger/proc/play_ringtone(datum/port/port)
if(!COOLDOWN_FINISHED(src, ring_cd))
return
COOLDOWN_START(src, ring_cd, MESSENGER_CIRCUIT_RINGTONE_CD)
var/datum/computer_file/program/messenger/messenger = associated_program
messenger.computer.ring(messenger.ringtone)
#undef MESSENGER_CIRCUIT_MIN_COOLDOWN
#undef MESSENGER_CIRCUIT_MAX_COOLDOWN
#undef MESSENGER_CIRCUIT_CD_PER_RECIPIENT
#undef MESSENGER_CIRCUIT_RINGTONE_CD
@@ -470,8 +470,6 @@
var/mob/living/sender
if(isliving(source))
sender = source
else if(is_ic_filtered_for_pdas(message) || is_soft_ic_filtered_for_pdas(message))
return FALSE
message = sanitize_pda_message(message, sender)
if(!message)
return FALSE
@@ -571,8 +569,8 @@
var/mob/sender
if(ismob(source))
sender = source
if(sender && !sender.can_perform_action(computer, ALLOW_RESTING))
return FALSE
if(!sender.can_perform_action(computer, ALLOW_RESTING))
return FALSE
if(!COOLDOWN_FINISHED(src, last_text))
return FALSE