Added Godot based server

This commit is contained in:
2024-01-20 22:18:58 +01:00
parent ce699ee6db
commit 1f73d22cd6
28 changed files with 338 additions and 135 deletions

23
network/NetworkNode.gd Normal file
View File

@ -0,0 +1,23 @@
class_name NetworkNode
extends Node
var handlers: Array[Node] = []
func _init():
handlers.resize(256)
func get_handler(index: int) -> PacketHandler:
return handlers[index]
func set_handler(index: int, node: PacketHandler):
handlers[index] = node
func handle_packet(packet: PackedByteArray, peer: PacketPeer):
var type := packet.decode_u8(0)
var handler := get_handler(type)
if handler == null:
push_warning("Unknown packet type %d" % type)
return
handler.handle_packet(packet.slice(1), peer)