-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathntnet_relay.dm
133 lines (117 loc) · 4.82 KB
/
ntnet_relay.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
///Checks whether NTNet is available by ensuring at least one relay exists and is operational.
/proc/find_functional_ntnet_relay()
// Check all relays. If we have at least one working relay, ntos is up.
for(var/obj/machinery/ntnet_relay/relays as anything in SSmachines.get_machines_by_type(/obj/machinery/ntnet_relay))
if(!relays.is_operational())
continue
return TRUE
return FALSE
// Relays don't handle any actual communication. Global NTNet datum does that, relays only tell the datum if it should or shouldn't work.
/obj/machinery/ntnet_relay
name = "NTNet Quantum Relay"
desc = "A very complex router and transmitter capable of connecting electronic devices together. Looks fragile."
use_power = ACTIVE_POWER_USE
active_power_usage = 10000 //10kW, apropriate for machine that keeps massive cross-Zlevel wireless network operational. Used to be 20 but that actually drained the smes one round
idle_power_usage = 100
icon = 'icons/obj/machines/telecomms.dmi'
icon_state = "bus"
density = TRUE
circuit = /obj/item/circuitboard/machine/ntnet_relay
///On / off status for the relay machine, toggleable by the user.
var/relay_enabled = TRUE
///(D)DoS-attack-related failure causing it not to be operational any longer.
var/dos_failure = FALSE
var/list/dos_sources = list() // Backwards reference for qdel() stuff
var/uid
var/static/gl_uid = 1
// Denial of Service attack variables
var/dos_overload = 0 // Amount of DoS "packets" in this relay's buffer
var/dos_capacity = 500 // Amount of DoS "packets" in buffer required to crash the relay
var/dos_dissipate = 0.5 // Amount of DoS "packets" dissipated over time.
/obj/machinery/ntnet_relay/Initialize(mapload)
. = ..()
uid = gl_uid++
var/list/current_machines = SSmachines.get_machines_by_type(/obj/machinery/ntnet_relay)
SSmodular_computers.add_log("New quantum relay activated. Current amount of linked relays: [current_machines.len]")
/obj/machinery/ntnet_relay/Destroy()
. = ..()
var/list/machines_left = SSmachines.get_machines_by_type(/obj/machinery/ntnet_relay)
SSmodular_computers.add_log("Quantum relay connection severed. Current amount of linked relays: [machines_left.len]")
for(var/datum/computer_file/program/ntnet_dos/D in dos_sources)
D.target = null
D.error = "Connection to quantum relay severed"
// TODO: Implement more logic here. For now it's only a placeholder.
/obj/machinery/ntnet_relay/is_operational()
if(stat & (BROKEN | NOPOWER | EMPED))
return FALSE
if(dos_failure)
return FALSE
if(!relay_enabled)
return FALSE
return TRUE
///Proc called to change the value of the `relay_enabled` variable and append behavior related to its change.
/obj/machinery/ntnet_relay/proc/set_relay_enabled(new_value)
if(new_value == relay_enabled)
return
. = relay_enabled
relay_enabled = new_value
///Proc called to change the value of the `dos_failure` variable and append behavior related to its change.
/obj/machinery/ntnet_relay/proc/set_dos_failure(new_value)
if(new_value == dos_failure)
return
. = dos_failure
dos_failure = new_value
/obj/machinery/ntnet_relay/update_overlays()
. = ..()
if(!is_operational())
return
var/mutable_appearance/on_overlay
on_overlay = mutable_appearance(icon, "[initial(icon_state)]_on")
. += on_overlay
/obj/machinery/ntnet_relay/process(seconds_per_tick)
if(is_operational())
use_power = ACTIVE_POWER_USE
else
use_power = IDLE_POWER_USE
update_appearance()
if(dos_overload > 0)
dos_overload = max(0, dos_overload - dos_dissipate * seconds_per_tick)
// If DoS traffic exceeded capacity, crash.
if((dos_overload > dos_capacity) && !dos_failure)
set_dos_failure(TRUE)
update_appearance()
SSmodular_computers.add_log("Quantum relay switched from normal operation mode to overload recovery mode.")
// If the DoS buffer reaches 0 again, restart.
if((dos_overload == 0) && dos_failure)
set_dos_failure(FALSE)
update_appearance()
SSmodular_computers.add_log("Quantum relay switched from overload recovery mode to normal operation mode.")
return TRUE
/obj/machinery/ntnet_relay/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "NtnetRelay")
ui.open()
/obj/machinery/ntnet_relay/ui_data(mob/user)
var/list/data = list()
data["enabled"] = relay_enabled
data["dos_capacity"] = dos_capacity
data["dos_overload"] = dos_overload
data["dos_crashed"] = dos_failure
return data
/obj/machinery/ntnet_relay/ui_act(action, params)
. = ..()
if(.)
return
switch(action)
if("restart")
dos_overload = 0
set_dos_failure(FALSE)
update_appearance()
SSmodular_computers.add_log("Quantum relay manually restarted from overload recovery mode to normal operation mode.")
return TRUE
if("toggle")
set_relay_enabled(!relay_enabled)
SSmodular_computers.add_log("Quantum relay manually [relay_enabled ? "enabled" : "disabled"].")
update_appearance()
return TRUE