26 lines
531 B
GDScript3
Raw Normal View History

2024-01-20 21:18:58 +00:00
class_name NetworkNode
extends Node
var handlers: Array[Node] = []
2024-01-26 18:00:59 +00:00
var download := 0
2024-01-20 21:18:58 +00:00
func _init():
handlers.resize(256)
func get_handler(index: int) -> PacketHandler:
return handlers[index]
func set_handler(index: int, node: PacketHandler):
handlers[index] = node
2024-01-29 22:16:06 +00:00
func handle_packet(packet: PackedByteArray):
2024-01-20 21:18:58 +00:00
var type := packet.decode_u8(0)
var handler := get_handler(type)
if handler == null:
push_warning("Unknown packet type %d" % type)
return
2024-01-29 22:16:06 +00:00
handler.handle_packet(packet.slice(1))
2024-01-26 18:00:59 +00:00
download += packet.size()