From 781af013d79daf79b5a6a1f230e77416f5bcfef7 Mon Sep 17 00:00:00 2001 From: Gurkenglas Date: Thu, 19 Aug 2021 05:46:24 +0200 Subject: [PATCH] fix ntnet circuit components (#60917) * fix ntnet * fix typos and switcheroos * whoops, tracked a test circuit json. --- code/__DEFINES/networks.dm | 1 - .../subsystem/processing/networks.dm | 3 ++- code/datums/components/ntnet_interface.dm | 7 +++---- code/modules/NTNet/network.dm | 21 +++++++------------ .../research/designs/wiremod_designs.dm | 4 ++-- .../{ntnet_reciever.dm => ntnet_receive.dm} | 9 ++++---- .../ntnet/{ntnet_request.dm => ntnet_send.dm} | 14 +++---------- tgstation.dme | 4 ++-- 8 files changed, 24 insertions(+), 39 deletions(-) rename code/modules/wiremod/components/ntnet/{ntnet_reciever.dm => ntnet_receive.dm} (91%) rename code/modules/wiremod/components/ntnet/{ntnet_request.dm => ntnet_send.dm} (54%) diff --git a/code/__DEFINES/networks.dm b/code/__DEFINES/networks.dm index 2d2a1e1acfd..2b692e757f2 100644 --- a/code/__DEFINES/networks.dm +++ b/code/__DEFINES/networks.dm @@ -91,5 +91,4 @@ #define NETWORK_ERROR_BAD_NETWORK "network_error_bad_network" #define NETWORK_ERROR_BAD_RECEIVER_ID "network_error_bad_receiver_id" #define NETWORK_ERROR_UNAUTHORIZED "network_error_bad_unauthorized" -#define NETWORK_ERROR_BAD_TARGET_ID "network_error_bad_target_id" diff --git a/code/controllers/subsystem/processing/networks.dm b/code/controllers/subsystem/processing/networks.dm index 0030552e848..0ccb2344146 100644 --- a/code/controllers/subsystem/processing/networks.dm +++ b/code/controllers/subsystem/processing/networks.dm @@ -140,7 +140,8 @@ SUBSYSTEM_DEF(networks) /// Check if we are a list. If so process the list if(islist(current.receiver_id)) // are we a broadcast list var/list/receivers = current.receiver_id - var/receiver_id = receivers[receivers.len--] // pop it + var/receiver_id = receivers[receivers.len] // pop it + receivers.len-- _process_packet(receiver_id, current) if(receivers.len == 0) // pop it if done count_broadcasts_packets++ diff --git a/code/datums/components/ntnet_interface.dm b/code/datums/components/ntnet_interface.dm index 8c595252e14..719c693323c 100644 --- a/code/datums/components/ntnet_interface.dm +++ b/code/datums/components/ntnet_interface.dm @@ -14,20 +14,19 @@ */ /datum/proc/ntnet_send(packet_data, target_id = null, passkey = null) var/datum/netdata/data = packet_data - if(!data) // check for easy case - if(!islist(packet_data) || target_id == null) + if(!istype(data)) // construct netdata from list() + if(!islist(packet_data)) stack_trace("ntnet_send: Bad packet creation") // hard fail as its runtime fault return data = new(packet_data) data.receiver_id = target_id data.passkey = passkey - if(data.receiver_id == null) - return NETWORK_ERROR_BAD_TARGET_ID var/datum/component/ntnet_interface/NIC = GetComponent(/datum/component/ntnet_interface) if(!NIC) return NETWORK_ERROR_NOT_ON_NETWORK data.sender_id = NIC.hardware_id data.network_id = NIC.network.network_id + data.receiver_id ||= data.network_id return SSnetworks.transmit(data) /* diff --git a/code/modules/NTNet/network.dm b/code/modules/NTNet/network.dm index c66da9b97fc..141ad73fe52 100644 --- a/code/modules/NTNet/network.dm +++ b/code/modules/NTNet/network.dm @@ -56,11 +56,12 @@ parent.children[network_node_id] = src root_devices = parent.root_devices networks = parent.networks + networks[network_id] = src else network_node_id = net_id parent = null networks = list() - root_devices = list() + root_devices = linked_devices SSnetworks.root_networks[network_id] = src SSnetworks.networks[network_id] = src @@ -72,6 +73,7 @@ /// A network should NEVER be deleted. If you don't want to show it exists just check if its /// empty /datum/ntnet/Destroy() + networks -= network_id if(children.len > 0 || linked_devices.len > 0) CRASH("Trying to delete a network with devices still in them") @@ -142,19 +144,10 @@ */ /datum/ntnet/proc/add_interface(datum/component/ntnet_interface/interface) if(interface.network) - if(!networks[interface.network.network_id]) - /// If we are doing a hard jump to a new network, log it - log_telecomms("The device {[interface.hardware_id]} is jumping networks from '[interface.network.network_id]' to '[network_id]'") - interface.network.remove_interface(interface, TRUE) - else // we are on the same network so we just want to be aliased to another branch - if(!interface.alias[network_id]) - interface.alias[network_id] = src // add to the alias list - linked_devices[interface.hardware_id] = interface - else - log_telecomms("The device {[interface.hardware_id]} is trying to join '[network_id]' for a second time!") - return - // we have no network - interface.network = src // now we do! + /// If we are doing a hard jump to a new network, log it + log_telecomms("The device {[interface.hardware_id]} is jumping networks from '[interface.network.network_id]' to '[network_id]'") + interface.network.remove_interface(interface, TRUE) + interface.network ||= src interface.alias[network_id] = src // add to the alias just to make removing easier. linked_devices[interface.hardware_id] = interface root_devices[interface.hardware_id] = interface diff --git a/code/modules/research/designs/wiremod_designs.dm b/code/modules/research/designs/wiremod_designs.dm index e333aa2d599..41a49c6ea58 100644 --- a/code/modules/research/designs/wiremod_designs.dm +++ b/code/modules/research/designs/wiremod_designs.dm @@ -234,12 +234,12 @@ build_path = /obj/item/circuit_component/module /datum/design/component/ntnet_receive - name = "Pressure NTNet Transmitter" + name = "NTNet Receiver" id = "comp_ntnet_receive" build_path = /obj/item/circuit_component/ntnet_receive /datum/design/component/ntnet_send - name = "NTNet Request Component" + name = "NTNet Transmitter" id = "comp_ntnet_send" build_path = /obj/item/circuit_component/ntnet_send diff --git a/code/modules/wiremod/components/ntnet/ntnet_reciever.dm b/code/modules/wiremod/components/ntnet/ntnet_receive.dm similarity index 91% rename from code/modules/wiremod/components/ntnet/ntnet_reciever.dm rename to code/modules/wiremod/components/ntnet/ntnet_receive.dm index 9539e214103..0bcb1c5ed00 100644 --- a/code/modules/wiremod/components/ntnet/ntnet_reciever.dm +++ b/code/modules/wiremod/components/ntnet/ntnet_receive.dm @@ -1,12 +1,12 @@ /** - * # NTNet Reciever Component + * # NTNet Receiver Component * - * Recieves data through NTNet. + * Receives data through NTNet. */ /obj/item/circuit_component/ntnet_receive display_name = "NTNet Receiver" - desc = "Recieves data packages through NTNet. If Encryption Key is set then only signals with the same Encryption Key will be received." + desc = "Receives data packages through NTNet. If Encryption Key is set then only signals with the same Encryption Key will be received." circuit_flags = CIRCUIT_FLAG_OUTPUT_SIGNAL //trigger_output @@ -22,7 +22,6 @@ /obj/item/circuit_component/ntnet_receive/Initialize() . = ..() - AddComponent(/datum/component/ntnet_interface) data_package = add_output_port("Data Package", PORT_TYPE_ANY) secondary_package = add_output_port("Secondary Package", PORT_TYPE_ANY) enc_key = add_input_port("Encryption Key", PORT_TYPE_STRING) @@ -50,6 +49,8 @@ if(COMPONENT_TRIGGERED_BY(secondary_data_type_options, port)) secondary_package.set_datatype(secondary_data_type_options.value) + return TRUE + /obj/item/circuit_component/ntnet_receive/proc/ntnet_receive(datum/source, datum/netdata/data) SIGNAL_HANDLER diff --git a/code/modules/wiremod/components/ntnet/ntnet_request.dm b/code/modules/wiremod/components/ntnet/ntnet_send.dm similarity index 54% rename from code/modules/wiremod/components/ntnet/ntnet_request.dm rename to code/modules/wiremod/components/ntnet/ntnet_send.dm index 8a81a338e9a..33d9370fae3 100644 --- a/code/modules/wiremod/components/ntnet/ntnet_request.dm +++ b/code/modules/wiremod/components/ntnet/ntnet_send.dm @@ -6,7 +6,7 @@ /obj/item/circuit_component/ntnet_send display_name = "NTNet Transmitter" - desc = "Sends a data package through NTNet when triggered. If target HID is not provided, data will be sent to all circuits in the network. If Encryption Key is set then transmitted data will be only picked up by receivers with the same Encryption Key." + desc = "Sends a data package through NTNet. If Encryption Key is set then transmitted data will be only picked up by receivers with the same Encryption Key." circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL @@ -24,14 +24,6 @@ /obj/item/circuit_component/ntnet_send/input_received(datum/port/input/port) . = ..() - if(. || !data_package.value) + if(.) return - - var/list/datalist = list("data" = data_package.value) - if(secondary_package.value) - datalist["data_secondary"] = secondary_package.value - if(enc_key.value) - datalist["enc_key"] = enc_key.value - var/datum/netdata/data = new(datalist) - data.network_id = __NETWORK_CIRCUITS - ntnet_send(data) + ntnet_send(list("data" = data_package.value, "data_secondary" = secondary_package.value, "enc_key" = enc_key.value)) diff --git a/tgstation.dme b/tgstation.dme index 5e5b953f2f2..1b5d1172a66 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -3736,8 +3736,8 @@ #include "code\modules\wiremod\components\math\logic.dm" #include "code\modules\wiremod\components\math\not.dm" #include "code\modules\wiremod\components\math\random.dm" -#include "code\modules\wiremod\components\ntnet\ntnet_reciever.dm" -#include "code\modules\wiremod\components\ntnet\ntnet_request.dm" +#include "code\modules\wiremod\components\ntnet\ntnet_receive.dm" +#include "code\modules\wiremod\components\ntnet\ntnet_send.dm" #include "code\modules\wiremod\components\sensors\pressuresensor.dm" #include "code\modules\wiremod\components\sensors\tempsensor.dm" #include "code\modules\wiremod\components\string\concat.dm"