summaryrefslogtreecommitdiff
path: root/network/server.gd
diff options
context:
space:
mode:
Diffstat (limited to 'network/server.gd')
-rw-r--r--network/server.gd17
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)