diff --git a/code/__DEFINES/dcs/signals/signals_circuit.dm b/code/__DEFINES/dcs/signals/signals_circuit.dm index 3fe4e80fdb2..08d5f675b28 100644 --- a/code/__DEFINES/dcs/signals/signals_circuit.dm +++ b/code/__DEFINES/dcs/signals/signals_circuit.dm @@ -82,6 +82,9 @@ /// Called when an equipment action component is removed from a shell (/obj/item/circuit_component/equipment_action/action_comp) #define COMSIG_CIRCUIT_ACTION_COMPONENT_UNREGISTERED "circuit_action_component_unregistered" +/// Called when an NFC sender sends data to this circuit +#define COMSIG_CIRCUIT_NFC_DATA_SENT "circuit_nfc_data_receive" + ///Sent to the shell component when a circuit is attached. #define COMSIG_SHELL_CIRCUIT_ATTACHED "shell_circuit_attached" ///Sent to the shell component when a circuit is removed. diff --git a/code/modules/research/designs/wiremod_designs.dm b/code/modules/research/designs/wiremod_designs.dm index e848356359d..418dec186e9 100644 --- a/code/modules/research/designs/wiremod_designs.dm +++ b/code/modules/research/designs/wiremod_designs.dm @@ -347,6 +347,16 @@ id = "comp_ntnet_send" build_path = /obj/item/circuit_component/ntnet_send +/datum/design/component/nfc_send + name = "NFC Transmitter" + id = "comp_nfc_send" + build_path = /obj/item/circuit_component/nfc_send + +/datum/design/component/nfc_receive + name = "NFC Receiver" + id = "comp_nfc_receive" + build_path = /obj/item/circuit_component/nfc_receive + /datum/design/component/list_literal/ntnet_send name = "NTNet Transmitter List Literal" id = "comp_ntnet_send_list_literal" diff --git a/code/modules/research/techweb/nodes/circuit_nodes.dm b/code/modules/research/techweb/nodes/circuit_nodes.dm index e654abbf4df..554e9997c04 100644 --- a/code/modules/research/techweb/nodes/circuit_nodes.dm +++ b/code/modules/research/techweb/nodes/circuit_nodes.dm @@ -59,6 +59,8 @@ "comp_ntnet_receive", "comp_ntnet_send", "comp_ntnet_send_list_literal", + "comp_nfc_send", + "comp_nfc_receive", "comp_pinpointer", "comp_pressuresensor", "comp_radio", diff --git a/code/modules/wiremod/components/utility/nfc_receive.dm b/code/modules/wiremod/components/utility/nfc_receive.dm new file mode 100644 index 00000000000..03e8d3ff2e4 --- /dev/null +++ b/code/modules/wiremod/components/utility/nfc_receive.dm @@ -0,0 +1,80 @@ +/** + * # NFC Receiver Component + * + * Sends a data package through NFC directly to a shell + * if we ever get more shells like BCI's that are nested, keep in mind this may not work correctly unless adjusted + */ + + +/obj/item/circuit_component/nfc_receive + display_name = "NFC Receiver" + desc = "Receives data packages through NFC. If Encryption Key is set then only signals with the same Encryption Key will be received." + category = "Utility" + + circuit_flags = CIRCUIT_FLAG_OUTPUT_SIGNAL //trigger_output + + /// The list type + var/datum/port/input/option/list_options + + /// Data being received + var/datum/port/output/data_package + + /// Encryption key + var/datum/port/input/enc_key + +/obj/item/circuit_component/nfc_receive/populate_options() + list_options = add_option_port("List Type", GLOB.wiremod_basic_types) + +/obj/item/circuit_component/nfc_receive/populate_ports() + data_package = add_output_port("Data Package", PORT_TYPE_LIST(PORT_TYPE_ANY)) + enc_key = add_input_port("Encryption Key", PORT_TYPE_STRING) + +/obj/item/circuit_component/nfc_receive/register_shell(atom/movable/shell) + RegisterSignal(shell, COMSIG_CIRCUIT_NFC_DATA_SENT, PROC_REF(nfc_receive)) + RegisterSignal(shell, COMSIG_ORGAN_IMPLANTED, PROC_REF(on_organ_implanted)) + RegisterSignal(shell, COMSIG_ORGAN_REMOVED, PROC_REF(on_organ_removed)) + +/obj/item/circuit_component/nfc_receive/unregister_shell(atom/movable/shell) + UnregisterSignal(shell, list( + COMSIG_CIRCUIT_NFC_DATA_SENT, + COMSIG_ORGAN_IMPLANTED, + COMSIG_ORGAN_REMOVED, + )) + +/obj/item/circuit_component/nfc_receive/proc/on_organ_implanted(datum/source, mob/living/carbon/owner) + SIGNAL_HANDLER + + RegisterSignal(owner, COMSIG_CIRCUIT_NFC_DATA_SENT, PROC_REF(nfc_receive)) + +/obj/item/circuit_component/nfc_receive/proc/on_organ_removed(datum/source, mob/living/carbon/owner) + SIGNAL_HANDLER + + UnregisterSignal(owner, COMSIG_CIRCUIT_NFC_DATA_SENT) + + +/obj/item/circuit_component/nfc_receive/pre_input_received(datum/port/input/port) + if(port == list_options) + var/new_datatype = list_options.value + data_package.set_datatype(PORT_TYPE_LIST(new_datatype)) + + +/obj/item/circuit_component/nfc_receive/proc/nfc_receive(obj/item/circuit_component/source,obj/sender, list/data) + SIGNAL_HANDLER + + if(get_dist(sender,parent) >= 10) + return + + if(data["enc_key"] != enc_key.value) + return + + var/datum/weakref/ref = data["port"] + var/datum/port/input/port = ref?.resolve() + if(!port) + return + + var/datum/circuit_datatype/datatype_handler = data_package.datatype_handler + if(!datatype_handler?.can_receive_from_datatype(port.datatype)) + return + + data_package.set_output(data["data"]) + trigger_output.set_output(COMPONENT_SIGNAL) diff --git a/code/modules/wiremod/components/utility/nfc_send.dm b/code/modules/wiremod/components/utility/nfc_send.dm new file mode 100644 index 00000000000..437e6a4b198 --- /dev/null +++ b/code/modules/wiremod/components/utility/nfc_send.dm @@ -0,0 +1,48 @@ +/** + * # NFC Transmitter Component + * + * Sends a data package through NFC + * Only the targeted shell will receive the message + */ + +/obj/item/circuit_component/nfc_send + display_name = "NFC Transmitter" + 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." + category = "Utility" + + circuit_flags = CIRCUIT_FLAG_INPUT_SIGNAL + + /// The list type + var/datum/port/input/option/list_options + + /// The targeted circuit + var/datum/port/input/target + + /// Data being sent + var/datum/port/input/data_package + + /// Encryption key + var/datum/port/input/enc_key + +/obj/item/circuit_component/nfc_send/populate_options() + list_options = add_option_port("List Type", GLOB.wiremod_basic_types) + +/obj/item/circuit_component/nfc_send/populate_ports() + data_package = add_input_port("Data Package", PORT_TYPE_LIST(PORT_TYPE_ANY)) + enc_key = add_input_port("Encryption Key", PORT_TYPE_STRING) + target = add_input_port("Target", PORT_TYPE_ATOM) + +/obj/item/circuit_component/nfc_send/should_receive_input(datum/port/input/port) + . = ..() + if(!.) + return FALSE + +/obj/item/circuit_component/nfc_send/pre_input_received(datum/port/input/port) + if(port == list_options) + var/new_datatype = list_options.value + data_package.set_datatype(PORT_TYPE_LIST(new_datatype)) + +/obj/item/circuit_component/nfc_send/input_received(datum/port/input/port) + if(isatom(target.value)) + var/atom/target_enty = target.value + SEND_SIGNAL(target_enty, COMSIG_CIRCUIT_NFC_DATA_SENT, parent, list("data" = data_package.value, "enc_key" = enc_key.value, "port" = WEAKREF(data_package))) diff --git a/code/modules/wiremod/components/utility/nfc_send_literal.dm b/code/modules/wiremod/components/utility/nfc_send_literal.dm new file mode 100644 index 00000000000..c56104ebeb0 --- /dev/null +++ b/code/modules/wiremod/components/utility/nfc_send_literal.dm @@ -0,0 +1,36 @@ +/** + * # NFC Transmitter List Literal Component + * + * Create a list literal and send a data package through NFC + * + * This file is based off of nfc_sendl.dm + * Any changes made to those files should be copied over with discretion + */ +/obj/item/circuit_component/list_literal/nfc_send + display_name = "NFC Transmitter List Literal" + desc = "Creates a list literal data package and sends it through NFC. If Encryption Key is set then transmitted data will be only picked up by receivers with the same Encryption Key." + category = "Utility" + + /// Encryption key + var/datum/port/input/enc_key + + /// The targeted circuit + var/datum/port/input/target + +/obj/item/circuit_component/list_literal/nfc_send/populate_ports() + . = ..() + enc_key = add_input_port("Encryption Key", PORT_TYPE_STRING) + target = add_input_port("Target", PORT_TYPE_ATOM) + +/obj/item/circuit_component/list_literal/nfc_send/should_receive_input(datum/port/input/port) + . = ..() + if(!.) + return FALSE + /// If the server is down, don't use power or attempt to send data + return find_functional_ntnet_relay() + +/obj/item/circuit_component/list_literal/nfc_send/input_received(datum/port/input/port) + . = ..() + if(isatom(target.value)) + var/atom/target_enty = target.value + SEND_SIGNAL(target_enty, COMSIG_CIRCUIT_NFC_DATA_SENT, list("data" = list_output.value, "enc_key" = enc_key.value, "port" = WEAKREF(list_output))) diff --git a/tgstation.dme b/tgstation.dme index aa62e44aa74..2fcc53ac455 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -6407,6 +6407,9 @@ #include "code\modules\wiremod\components\table\select.dm" #include "code\modules\wiremod\components\utility\clock.dm" #include "code\modules\wiremod\components\utility\delay.dm" +#include "code\modules\wiremod\components\utility\nfc_receive.dm" +#include "code\modules\wiremod\components\utility\nfc_send.dm" +#include "code\modules\wiremod\components\utility\nfc_send_literal.dm" #include "code\modules\wiremod\components\utility\router.dm" #include "code\modules\wiremod\components\utility\timepiece.dm" #include "code\modules\wiremod\components\utility\typecast.dm"