/
ntnet_receive.dm
53 lines (39 loc) · 1.65 KB
/
ntnet_receive.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* # NTNet Receiver Component
*
* Receives data through NTNet.
*/
/obj/item/circuit_component/ntnet_receive
display_name = "NTNet Receiver"
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
network_id = __NETWORK_CIRCUITS
/// 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/ntnet_receive/populate_options()
list_options = add_option_port("List Type", GLOB.wiremod_basic_types)
/obj/item/circuit_component/ntnet_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)
RegisterSignal(src, COMSIG_COMPONENT_NTNET_RECEIVE, .proc/ntnet_receive)
/obj/item/circuit_component/ntnet_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/ntnet_receive/proc/ntnet_receive(datum/source, datum/netdata/data)
SIGNAL_HANDLER
if(data.data["enc_key"] != enc_key.value)
return
var/datum/weakref/ref = data.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["data"])
trigger_output.set_output(COMPONENT_SIGNAL)