mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
fix: handle matchmaking session expiry
This commit is contained in:
@@ -6,12 +6,14 @@ extends Node
|
||||
|
||||
signal request_succeeded(operation: String, payload: Dictionary)
|
||||
signal request_failed(operation: String, http_code: int, detail: String)
|
||||
signal session_expired()
|
||||
|
||||
const DEFAULT_BASE_URL := "http://127.0.0.1:8080"
|
||||
const PERSIST_PATH := "user://matchmaking_state.cfg"
|
||||
|
||||
var base_url := DEFAULT_BASE_URL
|
||||
var access_token := ""
|
||||
var auth_expired := false
|
||||
var state: MatchmakingState
|
||||
var ranked_profile: RankedProfileState
|
||||
|
||||
@@ -38,6 +40,7 @@ func configure(url: String, token: String) -> bool:
|
||||
return false
|
||||
base_url = normalized
|
||||
access_token = normalized_token
|
||||
auth_expired = false
|
||||
return true
|
||||
|
||||
|
||||
@@ -161,8 +164,11 @@ func _on_request_completed(result: HTTPRequest.Result, response_code: int, _head
|
||||
if response_code < 200 or response_code >= 300:
|
||||
var detail := String(parsed.get("error", "request rejected"))
|
||||
if response_code == HTTPClient.RESPONSE_UNAUTHORIZED:
|
||||
access_token = ""
|
||||
auth_expired = true
|
||||
state.fail("Session expired; sign in again")
|
||||
ranked_profile.set_error("Session expired; sign in again")
|
||||
session_expired.emit()
|
||||
elif response_code == HTTPClient.RESPONSE_GONE and operation == "queue_recover":
|
||||
state.expire("Queue ticket expired")
|
||||
elif response_code == HTTPClient.RESPONSE_SERVICE_UNAVAILABLE:
|
||||
|
||||
@@ -29,6 +29,7 @@ func _ready() -> void:
|
||||
ControlPlaneClient.state.changed.connect(_on_state_changed)
|
||||
ControlPlaneClient.request_failed.connect(_on_request_failed)
|
||||
ControlPlaneClient.request_succeeded.connect(_on_request_succeeded)
|
||||
ControlPlaneClient.session_expired.connect(_on_session_expired)
|
||||
_refresh_ranked_profile()
|
||||
_render(ControlPlaneClient.state.snapshot())
|
||||
|
||||
@@ -125,6 +126,12 @@ func _on_request_failed(_operation: String, _http_code: int, detail: String) ->
|
||||
_render(ControlPlaneClient.state.snapshot())
|
||||
|
||||
|
||||
func _on_session_expired() -> void:
|
||||
status_label.text = "Session expired"
|
||||
detail_label.text = "Sign in again before searching for a match"
|
||||
queue_button.disabled = true
|
||||
|
||||
|
||||
func _on_local_error(detail: String) -> void:
|
||||
detail_label.text = detail
|
||||
|
||||
@@ -171,7 +178,7 @@ func _render(snapshot: Dictionary) -> void:
|
||||
cancel_button.visible = ControlPlaneClient.state.can_cancel()
|
||||
accept_button.visible = phase == MatchmakingState.PROPOSED
|
||||
decline_button.visible = phase == MatchmakingState.PROPOSED
|
||||
queue_button.disabled = not (_can_start_new_search(phase) or ControlPlaneClient.can_retry_queue_create())
|
||||
queue_button.disabled = ControlPlaneClient.auth_expired or not (_can_start_new_search(phase) or ControlPlaneClient.can_retry_queue_create())
|
||||
queue_button.text = "Retry Search" if ControlPlaneClient.can_retry_queue_create() else "Search"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user