mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-23 13:10:02 +01:00
Refactors machine_stat and is_processing() to process on demand (#53150)
This commit is contained in:
@@ -128,7 +128,7 @@
|
||||
var/obj/machinery/ntnet_relay/n = i
|
||||
if(zlevel && n.z != zlevel)
|
||||
continue
|
||||
if(n.is_operational())
|
||||
if(n.is_operational)
|
||||
return TRUE
|
||||
return FALSE
|
||||
|
||||
|
||||
@@ -11,8 +11,10 @@
|
||||
circuit = /obj/item/circuitboard/machine/ntnet_relay
|
||||
|
||||
var/datum/ntnet/NTNet = null // This is mostly for backwards reference and to allow varedit modifications from ingame.
|
||||
var/enabled = 1 // Set to 0 if the relay was turned off
|
||||
var/dos_failure = 0 // Set to 1 if the relay failed due to (D)DoS attack
|
||||
///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
|
||||
@@ -23,24 +25,47 @@
|
||||
var/dos_dissipate = 1 // Amount of DoS "packets" dissipated over time.
|
||||
|
||||
|
||||
// TODO: Implement more logic here. For now it's only a placeholder.
|
||||
/obj/machinery/ntnet_relay/is_operational()
|
||||
if(machine_stat & (BROKEN | NOPOWER | EMPED))
|
||||
return FALSE
|
||||
if(dos_failure)
|
||||
return FALSE
|
||||
if(!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
|
||||
if(.) //Turned off
|
||||
set_is_operational(FALSE)
|
||||
else if(!dos_failure && !(machine_stat & (NOPOWER|BROKEN|MAINT))) //Turned on
|
||||
set_is_operational(TRUE)
|
||||
|
||||
|
||||
///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
|
||||
if(.) //Failure ended
|
||||
if(relay_enabled && !(machine_stat & (NOPOWER|BROKEN|MAINT)))
|
||||
set_is_operational(TRUE)
|
||||
else //Failure started
|
||||
set_is_operational(FALSE)
|
||||
|
||||
|
||||
/obj/machinery/ntnet_relay/on_set_machine_stat(old_value)
|
||||
if(old_value & (NOPOWER|BROKEN|MAINT))
|
||||
if(relay_enabled && !dos_failure && !(machine_stat & (NOPOWER|BROKEN|MAINT))) //From off to on.
|
||||
set_is_operational(TRUE)
|
||||
else if(machine_stat & (NOPOWER|BROKEN|MAINT)) //From on to off.
|
||||
set_is_operational(FALSE)
|
||||
|
||||
|
||||
/obj/machinery/ntnet_relay/update_icon_state()
|
||||
if(is_operational())
|
||||
if(is_operational)
|
||||
icon_state = "bus"
|
||||
else
|
||||
icon_state = "bus_off"
|
||||
|
||||
/obj/machinery/ntnet_relay/process()
|
||||
if(is_operational())
|
||||
if(is_operational)
|
||||
use_power = ACTIVE_POWER_USE
|
||||
else
|
||||
use_power = IDLE_POWER_USE
|
||||
@@ -52,12 +77,12 @@
|
||||
|
||||
// If DoS traffic exceeded capacity, crash.
|
||||
if((dos_overload > dos_capacity) && !dos_failure)
|
||||
dos_failure = 1
|
||||
set_dos_failure(TRUE)
|
||||
update_icon()
|
||||
SSnetworks.station_network.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)
|
||||
dos_failure = 0
|
||||
set_dos_failure(FALSE)
|
||||
update_icon()
|
||||
SSnetworks.station_network.add_log("Quantum relay switched from overload recovery mode to normal operation mode.")
|
||||
..()
|
||||
@@ -70,7 +95,7 @@
|
||||
|
||||
/obj/machinery/ntnet_relay/ui_data(mob/user)
|
||||
var/list/data = list()
|
||||
data["enabled"] = enabled
|
||||
data["enabled"] = relay_enabled
|
||||
data["dos_capacity"] = dos_capacity
|
||||
data["dos_overload"] = dos_overload
|
||||
data["dos_crashed"] = dos_failure
|
||||
@@ -82,13 +107,13 @@
|
||||
switch(action)
|
||||
if("restart")
|
||||
dos_overload = 0
|
||||
dos_failure = 0
|
||||
set_dos_failure(FALSE)
|
||||
update_icon()
|
||||
SSnetworks.station_network.add_log("Quantum relay manually restarted from overload recovery mode to normal operation mode.")
|
||||
return TRUE
|
||||
if("toggle")
|
||||
enabled = !enabled
|
||||
SSnetworks.station_network.add_log("Quantum relay manually [enabled ? "enabled" : "disabled"].")
|
||||
set_relay_enabled(!relay_enabled)
|
||||
SSnetworks.station_network.add_log("Quantum relay manually [relay_enabled ? "enabled" : "disabled"].")
|
||||
update_icon()
|
||||
return TRUE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user