client & server: added error handling for lobby connection issues
This commit is contained in:
@@ -123,3 +123,7 @@ func _on_web_client_tcp_connection_status_changed(new_status: WebClientTCP.Conne
|
||||
lobby_code_input.editable = false
|
||||
chat_message_input.editable = true
|
||||
send_chat_message_button.disabled = false
|
||||
|
||||
|
||||
func _on_web_client_tcp_received_connection_message(message: String) -> void:
|
||||
_write_line(message)
|
||||
|
||||
@@ -29,6 +29,7 @@ signal disconnected_from_lobby()
|
||||
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_connection_message(message: String)
|
||||
signal received_chat_message(client_name: String, message: String)
|
||||
|
||||
signal connection_status_changed(new_status: ConnectionStatus)
|
||||
@@ -94,11 +95,8 @@ func _handle_response(response: String) -> void:
|
||||
_client_id = data["client_id"]
|
||||
connected_to_lobby.emit.call_deferred(_lobby_id)
|
||||
connection_status_changed.emit.call_deferred(ConnectionStatus.JOINED)
|
||||
"join_lobby":
|
||||
if data["status"] == "ok":
|
||||
_client_id = data["client_id"]
|
||||
connected_to_lobby.emit.call_deferred(_lobby_id)
|
||||
connection_status_changed.emit.call_deferred(ConnectionStatus.JOINED)
|
||||
"join_lobby_response":
|
||||
_handle_join(data)
|
||||
"client_joined_lobby":
|
||||
_currently_connected_client_names.assign(data["connected_client_names"])
|
||||
client_joined_lobby.emit.call_deferred(data["new_client_name"], _currently_connected_client_names)
|
||||
@@ -115,6 +113,19 @@ func _handle_response(response: String) -> void:
|
||||
"receive_chat_message":
|
||||
received_chat_message.emit.call_deferred(data["client_name"], data["message"])
|
||||
|
||||
func _handle_join(data) -> void:
|
||||
match data["status"]:
|
||||
"lobby_not_found":
|
||||
received_connection_message.emit.call_deferred("Could not join; lobby does not exist")
|
||||
connection_status_changed.emit.call_deferred(ConnectionStatus.LOBBYLESS)
|
||||
"lobby_full":
|
||||
received_connection_message.emit.call_deferred("Could not join; lobby is full")
|
||||
connection_status_changed.emit.call_deferred(ConnectionStatus.LOBBYLESS)
|
||||
"ok":
|
||||
_client_id = data["client_id"]
|
||||
connected_to_lobby.emit.call_deferred(_lobby_id)
|
||||
connection_status_changed.emit.call_deferred(ConnectionStatus.JOINED)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
disconnect_from_server()
|
||||
|
||||
@@ -138,6 +149,7 @@ func join_lobby(lobby_id: String, client_name: String) -> void:
|
||||
_client_name = client_name
|
||||
|
||||
_send_message(TCPMessages.join_lobby(_lobby_id, client_name))
|
||||
connection_status_changed.emit.call_deferred(ConnectionStatus.ATTEMPTING_JOIN)
|
||||
|
||||
func leave_lobby() -> void:
|
||||
_send_message(TCPMessages.leave_lobby(_lobby_id, _client_id))
|
||||
|
||||
Reference in New Issue
Block a user