From cb066f409a162511851d3d49b3bebcc61d79b2b7 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 17 Feb 2024 19:21:18 +0100 Subject: [PATCH] Added rich log messages --- client/network/Chat.gd | 2 +- client/network/Client.gd | 3 +++ client/network/Login.gd | 4 ++-- client/network/PlayerAdd.gd | 2 +- client/network/PlayerRemove.gd | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/client/network/Chat.gd b/client/network/Chat.gd index 4d7111a..0646416 100644 --- a/client/network/Chat.gd +++ b/client/network/Chat.gd @@ -16,6 +16,6 @@ func handle_packet(data: PackedByteArray): var player := Global.players.get_player(player_id) var message := buffer.get_utf8_string() - print("[%s] %s: %s" % [Global.account.name, player.name, message]) + %Client.log("%s: %s" % [player.name, message]) message_received.emit("[color=#808080]%s:[/color] %s" % [player.name, message]) \ No newline at end of file diff --git a/client/network/Client.gd b/client/network/Client.gd index 9c1a6c9..4097048 100644 --- a/client/network/Client.gd +++ b/client/network/Client.gd @@ -32,3 +32,6 @@ func update_statistics(): func send(data: PackedByteArray): socket.put_packet(data) upload += data.size() + +func log(message: String): + print_rich("[color=#808080][%s][/color] %s" % [Global.account.name, message]) diff --git a/client/network/Login.gd b/client/network/Login.gd index eac3065..eb8235c 100644 --- a/client/network/Login.gd +++ b/client/network/Login.gd @@ -9,7 +9,7 @@ func handle_packet(data: PackedByteArray): var error := buffer.get_8() if error != 0: - print("[%s] Login failed." % Global.account.name) + %Client.log("[%s] Login failed." % Global.account.name) failure.emit() return @@ -27,7 +27,7 @@ func send_login(): buffer.put_u8(Packet.LOGIN) buffer.put_data(JSON.stringify([Global.account.name, password]).to_utf8_buffer()) %Client.send(buffer.data_array) - print("[%s] Connecting..." % Global.account.name) + %Client.log("Connecting...") func is_logged_in() -> bool: return Global.account.auth_token != "" diff --git a/client/network/PlayerAdd.gd b/client/network/PlayerAdd.gd index ede0ea9..274a0d7 100644 --- a/client/network/PlayerAdd.gd +++ b/client/network/PlayerAdd.gd @@ -19,7 +19,7 @@ func handle_packet(data: PackedByteArray): server_position.y = buffer.get_float() server_position.z = buffer.get_float() - print("[%s] Add player: %s %s @ %v" % [Global.account.name, player_id, player_name, server_position]) + %Client.log("Add player: %s %s @ %v" % [player_id, player_name, server_position]) var player := spawn_player(player_id) player.position = server_position diff --git a/client/network/PlayerRemove.gd b/client/network/PlayerRemove.gd index 53d2301..04ddf3f 100644 --- a/client/network/PlayerRemove.gd +++ b/client/network/PlayerRemove.gd @@ -2,5 +2,5 @@ extends PacketHandler func handle_packet(data: PackedByteArray): var player_id := data.get_string_from_ascii() - print("[%s] Remove player: %s" % [Global.account.name, player_id]) + %Client.log("Remove player: %s" % player_id) Global.players.remove(player_id) \ No newline at end of file