diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-12-12 02:12:52 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-12-12 02:12:52 +0100 |
commit | a22381eff3bf2286ee27f4d15ddf4c431ea063be (patch) | |
tree | 965bdcf12e5e0cf63c88cbba1bd5a52ba474f81f /network/server.gd | |
parent | e3c185e05823e30eccd7728ceda2ee57cc66fd4d (diff) |
next commit
Diffstat (limited to 'network/server.gd')
-rw-r--r-- | network/server.gd | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/network/server.gd b/network/server.gd index e46e797..8b41b4f 100644 --- a/network/server.gd +++ b/network/server.gd @@ -35,10 +35,27 @@ func listen() -> void: raw_packet += packet_length raw_packet += peer.get_data(packet_length.decode_u16(0) - 4)[1] + prints("Upcoming Length:", packet_length.decode_u16(0), "for =>") var packet = packet_type.from_bytes(raw_packet) received_packet.emit(packet) + + var display_header = raw_packet.slice(0, 2) + display_header.reverse() + print("Received known packet with header ", display_header.hex_encode(), " = ", packet_type.get_global_name()) else: raw_packet.reverse() print("Received unknown packet with header ", raw_packet.hex_encode()) + + +func send(packet: Packet) -> Error: + var display_header = packet.get_header() + display_header.reverse() + print("Sent packet with header ", display_header.hex_encode()) + + return send_raw(packet.to_bytes()) + + +func send_raw(bytes: PackedByteArray) -> Error: + return peer.put_data(bytes) |