client: now displays when clients leave the lobby

This commit is contained in:
2025-07-04 11:41:57 +02:00
parent 4b4285ca99
commit 2aa6d710cf
4 changed files with 17 additions and 6 deletions
+3
View File
@@ -88,6 +88,9 @@ func _on_web_client_tcp_received_chat_message(client_name: String, message: Stri
"message": message,
}))
func _on_web_client_tcp_client_left_lobby(client_name: String) -> void:
_write_line("{client_name} left the lobby".format({"client_name": client_name}))
func _on_web_client_tcp_connection_status_changed(new_status: WebClientTCP.ConnectionStatus) -> void:
match new_status:
+5 -3
View File
@@ -23,6 +23,7 @@ signal connected_to_lobby(lobby_id: String)
signal disconnected_from_lobby()
signal client_joined_lobby(client_name: String)
signal client_left_lobby(client_name: String)
signal received_chat_message(client_name: String, message: String)
@@ -36,7 +37,7 @@ enum ConnectionStatus {
JOINED,
}
func _process(delta: float) -> void:
func _process(_delta: float) -> void:
_tcp.poll()
_new_status = _tcp.get_status()
# Ensure status change is only processed once
@@ -60,7 +61,6 @@ func _process(delta: float) -> void:
func _listen_for_data() -> void:
while not _stop_thread and not _tcp.get_status() == StreamPeerTCP.Status.STATUS_ERROR:
#received_data += String.chr(_tcp.get_data(1)[0])
received_data += _tcp.get_utf8_string(1)
print(received_data)
if received_data.ends_with("}"):
@@ -87,7 +87,9 @@ func _handle_response(response: String) -> void:
leave_lobby()
"leave_lobby":
if data["status"] == "ok":
print(data["client_id"] + " left")
client_left_lobby.emit.call_deferred(data["client_name"])
"client_left_lobby":
client_left_lobby.emit.call_deferred(data["client_name"])
"receive_chat_message":
received_chat_message.emit.call_deferred(data["client_name"], data["message"])