Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] NTnet and modpc changes #11907

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion beestation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
#include "code\__DEFINES\dcs\signals\signals_atom\signals_atom_attack.dm"
#include "code\__DEFINES\dcs\signals\signals_datum\signals_circuit.dm"
#include "code\__DEFINES\dcs\signals\signals_datum\signals_datum.dm"
#include "code\__DEFINES\dcs\signals\signals_datum\signals_modpc.dm"
#include "code\__DEFINES\dcs\signals\signals_datum\signals_moveloop.dm"
#include "code\__DEFINES\dcs\signals\signals_datum\signals_nanite.dm"
#include "code\__DEFINES\dcs\signals\signals_datum\signals_ntnet.dm"
Expand Down Expand Up @@ -466,6 +467,7 @@
#include "code\controllers\subsystem\mobs.dm"
#include "code\controllers\subsystem\moods.dm"
#include "code\controllers\subsystem\natural_light_cycle.dm"
#include "code\controllers\subsystem\networks.dm"
#include "code\controllers\subsystem\nightshift.dm"
#include "code\controllers\subsystem\npcpool.dm"
#include "code\controllers\subsystem\overlays.dm"
Expand Down Expand Up @@ -522,7 +524,6 @@
#include "code\controllers\subsystem\processing\greyscale.dm"
#include "code\controllers\subsystem\processing\instruments.dm"
#include "code\controllers\subsystem\processing\nanites.dm"
#include "code\controllers\subsystem\processing\networks.dm"
#include "code\controllers\subsystem\processing\obj.dm"
#include "code\controllers\subsystem\processing\orbits.dm"
#include "code\controllers\subsystem\processing\processing.dm"
Expand Down
1 change: 1 addition & 0 deletions code/__DEFINES/dcs/signals/signals_datum/signals_modpc.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define COMSIG_MODPC_PROGRAM_STATE_CHANGED "modpc_program_state_changed"
3 changes: 3 additions & 0 deletions code/__DEFINES/networks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#define __NETWORK_SERVER "SERVER"
#define __NETWORK_CARDS "CARDS"
#define __NETWORK_CIRCUITS "CIRCUITS"
#define __NETWORK_CHAT "CHAT"

/// Various combined subnetworks

Expand All @@ -61,6 +62,7 @@
#define NETWORK_ATMOS_SCUBBERS NETWORK_NAME_COMBINE(__NETWORK_ATMOS, __NETWORK_SCUBBERS)
#define NETWORK_CARDS NETWORK_NAME_COMBINE(__NETWORK_COMPUTER, __NETWORK_CARDS)
#define NETWORK_BOTS_CARGO NETWORK_NAME_COMBINE(__NETWORK_CARGO, __NETWORK_BOTS)
#define NETWORK_COMPUTER_CHAT NETWORK_NAME_COMBINE(__NETWORK_COMPUTER, __NETWORK_CHAT)

// Finally turn eveything into strings

Expand Down Expand Up @@ -136,3 +138,4 @@

// Packet types
#define PACKET_TYPE_PING "ping"
#define PACKET_TYPE_SERVER_STATUS "server_status"
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
SUBSYSTEM_DEF(networks)
name = "Networks"
priority = FIRE_PRIORITY_NETWORKS
wait = 5
flags = SS_KEEP_TIMING
flags = SS_NO_FIRE
init_order = INIT_ORDER_NETWORKS

var/list/relays = list()
Expand All @@ -27,12 +26,6 @@ SUBSYSTEM_DEF(networks)
/// network tress
var/list/root_networks = list()



// Why not list? Because its a Copy() every time we add a packet, and thats stupid.
var/datum/netdata/first = null // start of the queue. Pulled off in fire.
var/datum/netdata/last = null // end of the queue. pushed on by transmit
var/packet_count = 0
// packet stats
var/count_broadcasts_packets = 0 // count of broadcast packets sent
var/count_failed_packets = 0 // count of message fails
Expand Down Expand Up @@ -60,7 +53,7 @@ SUBSYSTEM_DEF(networks)


/datum/controller/subsystem/networks/stat_entry(msg)
msg = "NET: QUEUE([packet_count]) FAILS([count_failed_packets]) BROADCAST([count_broadcasts_packets])"
msg = "NET: FAILS([count_failed_packets]) BROADCAST([count_broadcasts_packets])"
return ..()

/datum/controller/subsystem/networks/Initialize()
Expand Down Expand Up @@ -129,45 +122,6 @@ SUBSYSTEM_DEF(networks)
SEND_SIGNAL(sending_interface.parent, COMSIG_COMPONENT_NTNET_ACK, data)
count_good_packets++

/// Helper define to make sure we pop the packet and qdel it
#define POP_PACKET(CURRENT) first = CURRENT.next; packet_count--; if(!first) { last = null; packet_count = 0; }; qdel(CURRENT);

/datum/controller/subsystem/networks/fire(resumed = 0)
var/datum/netdata/current
var/datum/component/ntnet_interface/target_interface
while(first)
current = first
/// 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
if (length(receivers))
var/receiver_id = receivers[receivers.len] // pop it
receivers.len--
_process_packet(receiver_id, current)
if(!length(receivers)) // pop it if done
count_broadcasts_packets++
POP_PACKET(current)
else // else set up a broadcast or send a single targete
// check if we are sending to a network or to a single target
target_interface = interfaces_by_hardware_id[current.receiver_id]
if(target_interface) // a single sender id
_process_packet(current.receiver_id, current) // single target
POP_PACKET(current)
else // ok so lets find the network to send it too
var/datum/ntnet/net = networks[current.network_id] // get the sending network
net = net?.networks[current.receiver_id] // find the target network to broadcast
if(net) // we found it
current.receiver_id = net.collect_interfaces() // make a list of all the sending targets
else
// We got an error, the network is bad so send a NAK
target_interface = interfaces_by_hardware_id[current.sender_id]
if(!QDELETED(target_interface))
SEND_SIGNAL(target_interface.parent, COMSIG_COMPONENT_NTNET_NAK, current , NETWORK_ERROR_BAD_NETWORK)
POP_PACKET(current) // and get rid of it
if (MC_TICK_CHECK)
return

#undef POP_PACKET

/*
* Main function to queue a packet. As long as we have valid receiver_id and network_id we will take it
Expand All @@ -177,17 +131,38 @@ SUBSYSTEM_DEF(networks)
* Arguments:
* * data - packet to be sent
*/
/datum/controller/subsystem/networks/proc/transmit(datum/netdata/data)
data.next = null // sanity check
// dm
// filepath: /d:/ss13/BeeStation-Hornet/code/controllers/subsystem/processing/networks.dm

if(!last)
first = last = data
else
last.next = data
last = data
packet_count++
// We do error checking when the packet is sent
return NETWORK_ERROR_OK
/datum/controller/subsystem/networks/proc/transmit(datum/netdata/data)
// Instead of queuing the packet, process it immediately
// data.receiver_id can be a single receiver or a list for broadcasts

var/datum/component/ntnet_interface/sending_interface = interfaces_by_hardware_id[data.sender_id]

if(islist(data.receiver_id))
// Handle broadcast packets
for(var/receiver_id in data.receiver_id)
_process_packet(receiver_id, data)
else
// Check if we're sending to a single device or broadcasting to a network
var/datum/component/ntnet_interface/target_interface = interfaces_by_hardware_id[data.receiver_id]
if(target_interface)
// Send to a single device
_process_packet(data.receiver_id, data)
else
// Attempt to broadcast to a network
var/datum/ntnet/net = networks[data.network_id]
net = net?.networks[data.receiver_id]
if(net)
var/list/receivers = net.collect_interfaces()
for(var/receiver_id in receivers)
_process_packet(receiver_id, data)
else
// Invalid target network, send NAK to sender
if(!QDELETED(sending_interface))
SEND_SIGNAL(sending_interface.parent, COMSIG_COMPONENT_NTNET_NAK, data, NETWORK_ERROR_BAD_NETWORK)
return NETWORK_ERROR_OK


/datum/controller/subsystem/networks/proc/check_relay_operation(zlevel=0) //can be expanded later but right now it's true/false.
Expand Down
1 change: 1 addition & 0 deletions code/game/area/areas/ruins/_ruins.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
name = "\improper Unexplored Location"
icon_state = "away"
has_gravity = STANDARD_GRAVITY
network_root_id = LIMBO_NETWORK_ROOT
area_flags = HIDDEN_AREA | BLOBS_ALLOWED
dynamic_lighting = DYNAMIC_LIGHTING_ENABLED
ambience_index = AMBIENCE_RUINS
Expand Down
3 changes: 0 additions & 3 deletions code/game/machinery/doors/windowdoor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ CREATION_TEST_IGNORE_SUBTYPES(/obj/machinery/door/window)
AddElement(/datum/element/connect_loc, loc_connections)
RegisterSignal(src, COMSIG_COMPONENT_NTNET_RECEIVE, PROC_REF(ntnet_receive))

/obj/machinery/door/window/ComponentInitialize()
. = ..()
AddComponent(/datum/component/ntnet_interface)

/obj/machinery/door/window/Destroy()
set_density(FALSE)
Expand Down
8 changes: 3 additions & 5 deletions code/game/machinery/telecomms/computers/telemonitor.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
network_id = __NETWORK_SERVER // if its connected to the default one we will ignore it
var/network = "NULL" // the network to probe
var/list/servers = list() // the servers in the network
var/hardware_id = ""


/obj/machinery/computer/telecomms/monitor/Initialize(mapload)
. = ..()
update_network()
RegisterSignal(src, COMSIG_COMPONENT_NTNET_RECEIVE, PROC_REF(ntnet_receive))
hardware_id = GetComponent(/datum/component/ntnet_interface).hardware_id

/obj/machinery/computer/telecomms/monitor/Destroy()
. = ..()
Expand Down Expand Up @@ -61,7 +63,7 @@
ntnet_send(data, network_id)

/obj/machinery/computer/telecomms/monitor/proc/ntnet_receive(datum/source, datum/netdata/data)
if(islist(data.receiver_id))
if(!data.type == PACKET_TYPE_SERVER_STATUS)
return // if its broadcasting we don't want that packet, its probably our ping
servers[data.sender_id] = data.data
servers[data.sender_id]["last_update"] = world.time
Expand All @@ -77,10 +79,6 @@
if(!A.network_root_id)
log_telecomms("Area '[A.name]([REF(A)])' has no network network_root_id, force assigning in object [src]([REF(src)])")
SSnetworks.lookup_area_root_id(A)
new_network_id = NETWORK_NAME_COMBINE(A.network_root_id, new_network_id) // should result in something like SS13.SERVER.TCOMMSAT
else
log_telecomms("Created [src]([REF(src)] in nullspace, assuming network to be in station")
new_network_id = NETWORK_NAME_COMBINE(STATION_NETWORK_ROOT, new_network_id) // should result in something like SS13.SERVER.TCOMMSAT
new_network_id = simple_network_name_fix(new_network_id) // make sure the network name is valid
var/datum/ntnet/new_network = SSnetworks.create_network_simple(new_network_id)
new_network.move_interface(GetComponent(/datum/component/ntnet_interface), new_network_id, network_id)
Expand Down
4 changes: 1 addition & 3 deletions code/game/machinery/telecomms/telecomunications.dm
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ GLOBAL_LIST_EMPTY(telecomms_list)
log_telecomms("Area '[A.name]([REF(A)])' has no network network_root_id, force assigning in object [src]([REF(src)])")
SSnetworks.lookup_area_root_id(A)
new_network_id = NETWORK_NAME_COMBINE(A.network_root_id, new_network_id) // should result in something like SS13.SERVER.TCOMMSAT
else
log_telecomms("Created [src]([REF(src)] in nullspace, assuming network to be in station")
new_network_id = NETWORK_NAME_COMBINE(STATION_NETWORK_ROOT, new_network_id) // should result in something like SS13.SERVER.TCOMMSAT
new_network_id = simple_network_name_fix(new_network_id) // make sure the network name is valid
var/datum/ntnet/new_network = SSnetworks.create_network_simple(new_network_id)
new_network.move_interface(GetComponent(/datum/component/ntnet_interface), new_network_id, network_id)
Expand All @@ -183,6 +180,7 @@ GLOBAL_LIST_EMPTY(telecomms_list)
switch(data.data["type"])
if(PACKET_TYPE_PING) // we respond to the ping with our status
var/list/send_data = list()
send_data["type"] = PACKET_TYPE_SERVER_STATUS
send_data["name"] = name
send_data["temperature"] = get_temperature()
send_data["overheat_temperature"] = get_overheat_temperature()
Expand Down
5 changes: 1 addition & 4 deletions code/game/objects/objs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ CREATION_TEST_IGNORE_SELF(/obj)
if(!A.network_root_id)
log_telecomms("Area '[A.name]([REF(A)])' has no network network_root_id, force assigning in object [src]([REF(src)])")
SSnetworks.lookup_area_root_id(A)
network_id = NETWORK_NAME_COMBINE(A.network_root_id, network_id) // I regret nothing!!
else
log_telecomms("Created [src]([REF(src)] in nullspace, assuming network to be in station")
network_id = NETWORK_NAME_COMBINE(STATION_NETWORK_ROOT, network_id) // I regret nothing!!
network_id = NETWORK_NAME_COMBINE(A.network_root_id, network_id) // I regret everything!!
AddComponent(/datum/component/ntnet_interface, network_id, id_tag)
/// Needs to run before as ComponentInitialize runs after this statement...why do we have ComponentInitialize again?

Expand Down
13 changes: 9 additions & 4 deletions code/modules/modular_computers/computers/item/computer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ GLOBAL_LIST_EMPTY(TabletMessengers) // a list of all active messengers, similar

var/datum/computer_file/program/emag_console/emag_console = new(src)
emag_console.computer = src
emag_console.program_state = PROGRAM_STATE_ACTIVE
emag_console.set_program_state(PROGRAM_STATE_ACTIVE)
active_program = emag_console
ui_interact(user)
update_icon()
Expand Down Expand Up @@ -500,7 +500,7 @@ GLOBAL_LIST_EMPTY(TabletMessengers) // a list of all active messengers, similar
// The program is already running. Resume it.
if(!in_background)
if(program in idle_threads)
program.program_state = PROGRAM_STATE_ACTIVE
program.set_program_state(PROGRAM_STATE_ACTIVE)
active_program = program
program.alert_pending = FALSE
idle_threads.Remove(program)
Expand All @@ -525,12 +525,17 @@ GLOBAL_LIST_EMPTY(TabletMessengers) // a list of all active messengers, similar
program.alert_pending = FALSE
ui_interact(user)
else
program.program_state = PROGRAM_STATE_BACKGROUND
program.set_program_state(PROGRAM_STATE_BACKGROUND)
idle_threads.Add(program)
update_icon()
return TRUE


// wrapper to send ntnet packets through the network card
/obj/item/modular_computer/ntnet_send(packet_data, target_id, passkey)
var/obj/item/computer_hardware/network_card/network_card = all_components[MC_NET]
if(!network_card)
return NETWORK_ERROR_NOT_ON_NETWORK
return network_card.ntnet_send(packet_data, target_id, passkey)

// Returns 0 for No Signal, 1 for Low Signal and 2 for Good Signal. 3 is for wired connection (always-on)
/obj/item/modular_computer/proc/get_ntnet_status(specific_action = 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
return

idle_threads.Add(active_program)
active_program.program_state = PROGRAM_STATE_BACKGROUND // Should close any existing UIs
active_program.set_program_state(PROGRAM_STATE_BACKGROUND) // Should close any existing UIs
active_program = null
if(ismob(usr))
ui_interact(usr) // Re-open the UI on this computer. It should show the main screen now.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
/obj/item/modular_computer/tablet/syndicate_contract_uplink/preset/uplink/Initialize(mapload)
. = ..()
var/obj/item/computer_hardware/hard_drive/small/syndicate/hard_drive = new
var/datum/computer_file/program/contract_uplink/uplink = new
var/datum/computer_file/program/contract_uplink/uplink = new(src)

active_program = uplink
uplink.program_state = PROGRAM_STATE_ACTIVE
uplink.set_program_state(PROGRAM_STATE_ACTIVE)
uplink.computer = src

hard_drive.store_file(uplink)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/modular_computers/file_system/computer_file.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
return ..()

// Returns independent copy of this file.
/datum/computer_file/proc/clone(rename = 0)
var/datum/computer_file/temp = new type
/datum/computer_file/proc/clone(rename = 0, comp = null)
var/datum/computer_file/temp = new type(comp)
temp.unsendable = unsendable
temp.undeletable = undeletable
temp.size = size
Expand Down
35 changes: 27 additions & 8 deletions code/modules/modular_computers/file_system/program.dm
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@
/// If this program should process attack_atom calls
var/use_attack_obj = FALSE

/datum/computer_file/program/New(obj/item/modular_computer/comp = null)
/datum/computer_file/program/New(var/comp = null)
..()
if(istype(comp))
computer = comp
else if(istype(holder?.holder, /obj/item/modular_computer))
computer = holder.holder
if(istype(comp, /obj/item/modular_computer))
var/obj/item/modular_computer/C = comp
computer = C
else if(istype(comp, /obj/item/computer_hardware/hard_drive))
var/obj/item/computer_hardware/hard_drive/HD = comp
computer = HD.holder

/datum/computer_file/program/Destroy()
computer = null
. = ..()

/datum/computer_file/program/clone()
var/datum/computer_file/program/temp = ..()
/datum/computer_file/program/clone(hard_drive)
var/datum/computer_file/program/temp = ..(comp = hard_drive)
temp.required_access = required_access
temp.filedesc = filedesc
temp.program_icon_state = program_icon_state
Expand All @@ -75,6 +77,18 @@
return 0
return 1

// wrapper to send a ntnet packet through the computer
/datum/computer_file/program/ntnet_send(packet_data, target_id, passkey)
if(!computer)
return NETWORK_ERROR_NOT_ON_NETWORK
return computer.ntnet_send(packet_data, target_id, passkey)

/datum/computer_file/program/proc/get_network_card()
if(computer)
var/obj/item/computer_hardware/network_card/NC = computer.all_components[MC_NET]
return NC
return null

/datum/computer_file/program/proc/get_signal(specific_action = 0)
if(computer)
return computer.get_ntnet_status(specific_action)
Expand Down Expand Up @@ -149,7 +163,7 @@
if(can_run(user, 1))
if(requires_ntnet && network_destination)
generate_network_log("Connection opened to [network_destination].")
program_state = PROGRAM_STATE_ACTIVE
set_program_state(PROGRAM_STATE_ACTIVE)
return TRUE
return FALSE

Expand Down Expand Up @@ -198,3 +212,8 @@
/// Called when ui_close is called on the computer while this program is active. Any behavior in this should also be in kill_program.
/datum/computer_file/program/proc/on_ui_close(mob/user, datum/tgui/tgui)
return

//
/datum/computer_file/program/proc/set_program_state(state)
program_state = state
SEND_SIGNAL(src, COMSIG_MODPC_PROGRAM_STATE_CHANGED, state)
Loading
Loading