server: fixed bug that caused host client to disconnect when leaving lobby if they were the only connected client in the lobby

This commit is contained in:
2025-07-04 14:24:28 +02:00
parent b468a391f5
commit af763c89b3
6 changed files with 26 additions and 37 deletions
+3 -27
View File
@@ -2,6 +2,7 @@ class_name ClientInterface
extends Control
@export var client: WebClientTCP
@export var game_client: GameClient
@export var connect_button: Button
@export var create_lobby_button: Button
@@ -21,24 +22,14 @@ func _write_line(text: String) -> void:
func _on_create_lobby_button_pressed() -> void:
client.create_lobby(name_input.text.strip_edges())
create_lobby_button.disabled = true
join_lobby_button.disabled = true
leave_lobby_button.disabled = false
name_input.editable = false
lobby_code_input.editable = false
game_client.is_host = true
func _on_connect_button_pressed() -> void:
connect_button.disabled = true
client.connect_to_server()
create_lobby_button.disabled = true
join_lobby_button.disabled = true
leave_lobby_button.disabled = false
func _on_join_lobby_button_pressed() -> void:
client.join_lobby(lobby_code_input.text.strip_edges(), name_input.text.strip_edges())
game_client.is_host = false
func _on_disconnect_lobby_button_pressed() -> void:
leave_lobby_button.disabled = true
@@ -51,26 +42,12 @@ func _on_send_message_button_pressed() -> void:
chat_message_input.text = ""
func _on_web_client_tcp_connected_to_server() -> void:
create_lobby_button.disabled = false
join_lobby_button.disabled = false
name_input.editable = true
lobby_code_input.editable = true
_write_line("You are connected to the server")
func _on_web_client_tcp_connection_error_occurred() -> void:
connect_button.disabled = false
func _on_web_client_tcp_disconnected_from_server() -> void:
create_lobby_button.disabled = true
join_lobby_button.disabled = true
leave_lobby_button.disabled = true
name_input.editable = true
lobby_code_input.editable = false
lobby_code_input.text = ""
_write_line("You were disconnected from the server")
func _on_web_client_tcp_connected_to_lobby(lobby_id: String) -> void:
@@ -95,7 +72,6 @@ func _on_web_client_tcp_received_chat_message(client_name: String, message: Stri
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:
WebClientTCP.ConnectionStatus.DISCONNECTED: