From 014d2645403fa4920e41ec72bff937389369c38b Mon Sep 17 00:00:00 2001 From: dingo Date: Mon, 9 Mar 2026 18:51:18 -0400 Subject: [PATCH] Fix: remove spurious 'no state key' warning from game.ready ack; handle session_abandoned push MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For WaitingForOpponent/Started, state always arrives via game.state_update push not via the ack payload — calling _apply_state_from_payload on the ack was producing a confusing warning with no real effect. Replace with a match that only fetches state for AlreadyStarted. Also add game.session_abandoned push handler: emits Game.session_abandoned signal (new) and game_screen connects to it to navigate back to MainScreen, so clients stuck on the loading screen after a server restart recover cleanly. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- Client/origin-client/autoloads/Game.gd | 19 +++++++++++++++---- .../origin-client/scenes/game/game_screen.gd | 9 ++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Client/origin-client/autoloads/Game.gd b/Client/origin-client/autoloads/Game.gd index f879db8..f58fe60 100644 --- a/Client/origin-client/autoloads/Game.gd +++ b/Client/origin-client/autoloads/Game.gd @@ -22,6 +22,9 @@ signal state_updated(state: Dictionary) signal game_over(winner_account_id: String, win_condition: String, winner_rank_delta: int, loser_rank_delta: int) +## Emitted when the server abandons an Initializing session (e.g. server restart). +signal session_abandoned(reason: String) + # ── State ───────────────────────────────────────────────────────────────────── var session_id : String = "" @@ -129,10 +132,11 @@ func send_ready() -> void: func(_t: String, p: Variant) -> void: print("[Game] <<< game.ready.ack ", JSON.stringify(p)) var d := p as Dictionary - if d.get("status", "") == "AlreadyStarted": - _fetch_state() - else: - _apply_state_from_payload(p), + match d.get("status", ""): + "AlreadyStarted": + _fetch_state() + _: + pass # "WaitingForOpponent" / "Started": state arrives via game.state_update push, func(code: String, msg: String) -> void: print("[Game] ERR game.ready code=", code, " msg=", msg)) @@ -275,3 +279,10 @@ func _on_server_push(type: String, payload: Variant) -> void: var wd : int = int(d.get("winnerRankDelta", 0)) var ld : int = int(d.get("loserRankDelta", 0)) game_over.emit(winner, wc, wd, ld) + + "game.session_abandoned": + var d := payload as Dictionary + var reason : String = str(d.get("reason", "unknown")) + print("[Game] session abandoned: ", reason) + _clear_state() + session_abandoned.emit(reason) diff --git a/Client/origin-client/scenes/game/game_screen.gd b/Client/origin-client/scenes/game/game_screen.gd index c2fb936..154894e 100644 --- a/Client/origin-client/scenes/game/game_screen.gd +++ b/Client/origin-client/scenes/game/game_screen.gd @@ -169,6 +169,7 @@ func _ready() -> void: Game.state_updated.connect(_on_state_updated) Game.game_over.connect(_on_game_over) + Game.session_abandoned.connect(_on_session_abandoned) if not Game.state.is_empty(): _on_state_updated(Game.state) @@ -181,6 +182,8 @@ func _exit_tree() -> void: Game.state_updated.disconnect(_on_state_updated) if Game.game_over.is_connected(_on_game_over): Game.game_over.disconnect(_on_game_over) + if Game.session_abandoned.is_connected(_on_session_abandoned): + Game.session_abandoned.disconnect(_on_session_abandoned) # Remove chat overlay added to the viewport root. var root := get_tree().get_root() for child in root.get_children(): @@ -461,7 +464,7 @@ func _fit_model_to_tile(model: Node3D, tile_size: float) -> void: var aabb := _model_local_aabb(model) if aabb.size == Vector3.ZERO: return - var footprint := max(aabb.size.x, aabb.size.z) + var footprint :float = max(aabb.size.x, aabb.size.z) if footprint <= 0.0: return var s := tile_size / footprint @@ -1491,6 +1494,10 @@ func _on_game_over(winner_id: String, win_condition: String, win_condition, "+" if my_delta >= 0 else "", my_delta] _go_overlay.visible = true + +func _on_session_abandoned(_reason: String) -> void: + get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn") + # ── State → scene ───────────────────────────────────────────────────────────── func _on_state_updated(state: Dictionary) -> void: