chat messages are now sent and relayed. server: handling host client leaving correctly

This commit is contained in:
2025-07-04 11:29:25 +02:00
parent f4a7fb722e
commit 4b4285ca99
5 changed files with 116 additions and 25 deletions
+9 -4
View File
@@ -24,6 +24,8 @@ signal disconnected_from_lobby()
signal client_joined_lobby(client_name: String)
signal received_chat_message(client_name: String, message: String)
signal connection_status_changed(new_status: ConnectionStatus)
enum ConnectionStatus {
@@ -86,8 +88,8 @@ func _handle_response(response: String) -> void:
"leave_lobby":
if data["status"] == "ok":
print(data["client_id"] + " left")
#if data["client_id"] == _client_id:
#connection_status_changed.emit.call_deferred(ConnectionStatus.LOBBYLESS)
"receive_chat_message":
received_chat_message.emit.call_deferred(data["client_name"], data["message"])
func _exit_tree() -> void:
disconnect_from_server()
@@ -123,8 +125,11 @@ func leave_lobby() -> void:
_client_id = ""
_client_name = ""
disconnected_from_lobby.emit()
connection_status_changed.emit(ConnectionStatus.LOBBYLESS)
disconnected_from_lobby.emit.call_deferred()
connection_status_changed.emit.call_deferred(ConnectionStatus.LOBBYLESS)
func send_chat_message(message: String) -> void:
_send_message(TCPMessages.send_chat_message(_lobby_id, _client_id, message))
func _send_message(message: String) -> void:
_tcp.put_data(message.to_utf8_buffer())