Files
Bubberstation/code/modules/NTNet/netdata.dm
Mothblocks 0f435d5dff Remove hideous inline tab indentation, and bans it in contributing guidelines (#56912)
Done using this command sed -Ei 's/(\s*\S+)\s*\t+/\1 /g' code/**/*.dm

We have countless examples in the codebase with this style gone wrong, and defines and such being on hideously different levels of indentation. Fixing this to keep the alignment involves tainting the blames of code your PR doesn't need to be touching at all. And ultimately, it's hideous.

There are some files that this sed makes uglier. I can fix these when they are pointed out, but I believe this is ultimately for the greater good of readability. I'm more concerned with if any strings relied on this.

Hi codeowners!

Co-authored-by: Jared-Fogle <35135081+Jared-Fogle@users.noreply.github.com>
2021-02-14 16:53:29 -08:00

127 lines
3.4 KiB
Plaintext

// This netlink class shares a list to two devices
// This allows skipping of sending many many packets
// just to update simple data
/datum/netlink
var/server_id
var/server_network
var/port
var/passkey = null // sends auth data used to check if we can connect or send data to a device
var/list/data
/datum/netlink/New(datum/component/ntnet_interface/conn, port)
data = conn.registered_sockets[port]
ASSERT(data != null)
server_id = conn.hardware_id
server_network = conn.network.network_id
src.port = port
RegisterSignal(conn, COMSIG_COMPONENT_NTNET_PORT_DESTROYED, .proc/_server_disconnected)
..()
/datum/netlink/proc/_server_disconnected(datum/component/com)
SIGNAL_HANDLER
data = null
/datum/netlink/Destroy()
passkey = null
data = null
return ..()
// If you don't want to use this fine, but this just shows how the system works
// I hate you all. I want to operator overload []
// So fuck you all, Do NOT access data directly you freaks
// or this breaks god knows what.
// FINE, you don't have to use get, is dirty or even clean
// proc overhead is WAY more important than fucking clarity or
// sealed classes. But for the LOVE OF GOD make sure _updated
// is set if your going to do this.
/datum/netlink/proc/get(idx)
return data ? data[idx] : null
/datum/netlink/proc/put(idx, V)
// is it posable to do this async without worry about racing conditions?
if(data && data[idx] != V)
data["_updated"] = TRUE
data[idx] = V
/datum/netlink/proc/is_dirty()
return data && data["_updated"]
/datum/netlink/proc/clean()
if(data)
data["_updated"] = FALSE
/datum/netlink/proc/is_connected()
return data != null
/datum/netdata
//this requires some thought later on but for now it's fine. (WarlockD) ARRRRG
// Packets are kind of shaped like IPX. IPX had a network, a node (aka id) and a port.
// Special case with receiver_id == null, that wil broadcast to the network_id
// Also, if the network id is not the same for both sender and receiver the packet is dropped.
var/sender_id
var/receiver_id
var/network_id
var/passkey = null // sends auth data used to check if we can connect or send data to a device
var/list/data = list()
// Used for packet queuing
var/datum/netdata/next = null
var/mob/user = null // used for sending error messages
/datum/netdata/New(list/data = null)
if(!data)
data = list()
src.data = data
/datum/netdata/Destroy()
data = null
passkey = null
next = null
user = null
return ..()
/datum/netdata/proc/clone(deep_copy=FALSE)
var/datum/netdata/C = new
C.sender_id = sender_id
C.receiver_id = receiver_id
C.network_id = network_id
C.passkey = passkey
C.user = user
C.next = null
if(deep_copy)
C.data = deepCopyList(data)
else
C.data = data
return C
/datum/netdata/proc/json_to_data(json)
data = json_decode(json)
/datum/netdata/proc/json_append_to_data(json)
data |= json_decode(json)
/datum/netdata/proc/data_to_json()
return json_encode(data)
/datum/netdata/proc/json_list_generation_admin() //for admin logs and such.
. = list()
. |= json_list_generation()
/datum/netdata/proc/json_list_generation()
. = list()
. |= json_list_generation_netlog()
/datum/netdata/proc/json_list_generation_netlog()
. = list()
.["network_id"] = network_id
.["sender_id"] = sender_id
.["receiver_id"] = receiver_id
.["data_list"] = data
/datum/netdata/proc/generate_netlog()
return "[json_encode(json_list_generation_netlog())]"