server: sending connected client names instead of count on every (dis)connect

This commit is contained in:
2025-07-07 09:58:34 +02:00
parent 63869dc530
commit a2bab58d3f
5 changed files with 58 additions and 47 deletions
+3 -3
View File
@@ -23,7 +23,7 @@ func _on_create_lobby_button_pressed() -> void:
client.create_lobby(name_input.text.strip_edges())
func _on_connect_button_pressed() -> void:
client.connect_to_server($MarginContainer/VBoxContainer/URLInput.text)
client.connect_to_server($MarginContainer/VBoxContainer/ServerInputs/URLInput.text)
func _on_join_lobby_button_pressed() -> void:
client.join_lobby(lobby_code_input.text.strip_edges(), name_input.text.strip_edges())
@@ -54,7 +54,7 @@ func _on_web_client_tcp_connected_to_lobby(lobby_id: String) -> void:
func _on_web_client_tcp_disconnected_from_lobby() -> void:
_write_line("You disconnected from the lobby")
func _on_web_client_tcp_client_joined_lobby(client_name: String) -> void:
func _on_web_client_tcp_client_joined_lobby(client_name: String, currently_connected_client_names: Array) -> void:
_write_line("{client_name} joined the lobby{you}".format({
"client_name": client_name,
"you": " (that's you!)" if client_name == name_input.text.strip_edges() else ""
@@ -66,7 +66,7 @@ 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:
func _on_web_client_tcp_client_left_lobby(client_name: String, currently_connected_client_names: Array) -> 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:
+9 -9
View File
@@ -17,7 +17,7 @@ var cached_response: String
var _thread: Thread
var _stop_thread: bool = false
var _players_in_lobby: int = 0
var _currently_connected_client_names: Array[String] = []
signal connected_to_server()
signal connection_error_occurred()
@@ -26,8 +26,8 @@ signal disconnected_from_server()
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 client_joined_lobby(client_name: String, currently_connected_client_names: Array[String])
signal client_left_lobby(client_name: String, currently_connected_client_names: Array[String])
signal received_chat_message(client_name: String, message: String)
@@ -100,18 +100,18 @@ func _handle_response(response: String) -> void:
connected_to_lobby.emit.call_deferred(_lobby_id)
connection_status_changed.emit.call_deferred(ConnectionStatus.JOINED)
"client_joined_lobby":
client_joined_lobby.emit.call_deferred(data["new_client_name"])
_players_in_lobby = data["connected_client_count"]
print(_players_in_lobby)
_currently_connected_client_names.assign(data["connected_client_names"])
client_joined_lobby.emit.call_deferred(data["new_client_name"], _currently_connected_client_names)
print(_currently_connected_client_names)
"leave_lobby_request":
leave_lobby()
"leave_lobby":
if data["status"] == "ok":
client_left_lobby.emit.call_deferred(data["client_name"])
"client_left_lobby":
_players_in_lobby = data["connected_client_count"]
print(_players_in_lobby)
client_left_lobby.emit.call_deferred(data["client_name"])
_currently_connected_client_names.assign(data["connected_client_names"])
print(_currently_connected_client_names)
client_left_lobby.emit.call_deferred(data["client_name"], _currently_connected_client_names)
"receive_chat_message":
received_chat_message.emit.call_deferred(data["client_name"], data["message"])