Skip to content

Commit

Permalink
NetworkInitialize support
Browse files Browse the repository at this point in the history
  • Loading branch information
francinum committed Dec 30, 2024
1 parent 1422a4f commit 3f21f30
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
23 changes: 23 additions & 0 deletions code/controllers/subsystem/packetnets.dm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ SUBSYSTEM_DEF(packets)
/// @everyone broadcast key
var/gprs_broadcast_packet

/// NetworkInitialize requesters
/// For objects that need the full network ready. You probably don't need this.
VAR_PRIVATE/list/atom/network_initializers

/// Generates a unique (at time of read) ID for an atom, It just plays silly with the ref.
/// Pass the target atom in as arg[1]
/datum/controller/subsystem/packets/proc/generate_net_id(invoker)
Expand All @@ -78,12 +82,23 @@ SUBSYSTEM_DEF(packets)
return ..()

/datum/controller/subsystem/packets/Initialize(start_timeofday)

//Calculate the stupid magic bullshit
detomatix_magic_packet = random_string(rand(16,32), GLOB.hex_characters)
clownvirus_magic_packet = random_string(rand(16,32), GLOB.hex_characters)
mimevirus_magic_packet = random_string(rand(16,32), GLOB.hex_characters)
framevirus_magic_packet = random_string(rand(16,32), GLOB.hex_characters)
gprs_broadcast_packet = random_string(rand(16,32), GLOB.hex_characters)
pda_exploitable_register = pick_list(PACKET_STRING_FILE, "packet_field_names")

// We're late enough in init order that all network devices have late initialized,
// so the network *should* be stable, we can now safely re-wake anything that has requested network readiness.
if(network_initializers) //...If there are any, of course
for(var/atom/initializer in network_initializers)
initializer.NetworkInitialize()
CHECK_TICK
network_initializers.Cut() //Drop the refs.

. = ..()

/datum/controller/subsystem/packets/Recover()
Expand Down Expand Up @@ -504,3 +519,11 @@ SUBSYSTEM_DEF(packets)
ASSOC_UNSETEMPTY(recursive_contents, RECURSIVE_CONTENTS_RADIO_NONATMOS)
UNSETEMPTY(location.important_recursive_contents)

/datum/controller/subsystem/packets/proc/request_network_initialize(atom/initializer)
if(initialized)
//Hi. If you're here, you might have tried to load a device that requests this as part of a
//post-roundstart map load. I apologize that the idea of touching the code required to support that
//at the current time of 02:09:24 EST is... Not on the table. Suck my dick.
CRASH("Attempted to request NetworkInitialize() after SSpackets has initialized!")

LAZYADD(network_initializers, initializer)
12 changes: 12 additions & 0 deletions code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,18 @@
/atom/proc/LateInitialize()
set waitfor = FALSE

/**
* 'Network' Intialization, for code that should run after the packet network has stabilized.
*
* To have your NetworkInitialize proc be called, you must call SSpackets.request_network_initialize(src)
* in your Initialize() or LateInitialize() procs.
*
* This has limited usefulness for most atoms, Mostly used for direct-access based autoconfiguration of
* major network equipment, such as telephone exchanges or packet routing equipment (some day, I promise)
*/
/atom/proc/NetworkInitialize()
set waitfor = FALSE

/**
* Top level of the destroy chain for most atoms
*
Expand Down

0 comments on commit 3f21f30

Please sign in to comment.