Files
sor/Client/origin-client/scenes/init/init_screen.gd
T
efcd693d60 Fix null-session prompt, stale ready state, spectator UI, and admin cancel
- init_screen.gd: handle null sessionId from game.get_active_session.ack
  properly — str(null)="<null>" which passed the is_empty() check causing
  every player to see "active game in progress (null phase)" on login
- CustomLobby.gd: call clear_state() at the start of create() and join() so
  that i_am_ready/partner_ready are reset between lobbies — fixes players
  appearing instantly ready when entering a new lobby after a previous game
- game_screen.gd: in _setup_spectator_ui(), hide _settings_btn (prevents
  accessing the Concede button) and add a programmatic "Leave" button that
  calls Game.stop_spectating() and navigates back to FreePlayScreen
- CustomLobbiesPage.razor: add Cancel button (admin) for Open/Full lobbies;
  directly sets Status=Cancelled and refreshes the list

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-03-19 10:49:46 -04:00

178 lines
6.0 KiB
GDScript

extends Control
## Post-auth initialization screen.
##
## Runs on every launch after a successful authentication:
## 1. version.check — block on UpdateRequired; soft banner on UpdateAvailable
## 2. content.sync — incremental definition sync via ContentCache
## 3. Transition — change scene to MainScreen
##
## If the network is not yet up when this screen opens, we wait for the
## Network.connected signal before starting.
const CLIENT_VERSION := "0.1.0"
const PLATFORM := "web" # TODO: detect at runtime for native builds.
@onready var status_label : Label = %StatusLabel
@onready var update_panel : Control = %UpdatePanel
@onready var update_msg : Label = %UpdateMsg
@onready var retry_btn : Button = %RetryBtn
# ── Lifecycle ─────────────────────────────────────────────────────────────────
func _ready() -> void:
update_panel.visible = false
retry_btn.visible = false
ContentCache.sync_progress.connect(_on_sync_progress)
ContentCache.sync_complete.connect(_on_sync_complete)
ContentCache.sync_failed.connect(_on_sync_failed)
retry_btn.pressed.connect(_start)
if Network.is_online():
_start()
else:
_set_status("Connecting to server…")
Network.connected.connect(_start, CONNECT_ONE_SHOT)
func _exit_tree() -> void:
if ContentCache.sync_progress.is_connected(_on_sync_progress):
ContentCache.sync_progress.disconnect(_on_sync_progress)
if ContentCache.sync_complete.is_connected(_on_sync_complete):
ContentCache.sync_complete.disconnect(_on_sync_complete)
if ContentCache.sync_failed.is_connected(_on_sync_failed):
ContentCache.sync_failed.disconnect(_on_sync_failed)
# ── Initialization sequence ───────────────────────────────────────────────────
func _start() -> void:
update_panel.visible = false
retry_btn.visible = false
_set_status("Checking for updates…")
Network.request(
"version.check",
{ "clientVersion": CLIENT_VERSION, "platform": PLATFORM },
func(_type: String, p: Variant): _on_version_ok(p),
func(code: String, _msg: String): _on_version_error(code)
)
func _on_version_ok(payload: Variant) -> void:
var p := payload as Dictionary
var status := p.get("status", "Ok") as String
match status:
"UpdateRequired":
var url : String = p.get("downloadUrl", "") as String
var notes: String = p.get("releaseNotes", "") as String
update_panel.visible = true
if url.is_empty():
update_msg.text = (
"A required update is available.\n"
+ "Please refresh your browser to continue."
)
else:
update_msg.text = (
"A required update is available.\n%s\n\nRefresh your browser or visit:\n%s"
% [notes, url]
)
# Block here — do not proceed to sync.
"UpdateAvailable":
# Non-blocking soft notice, then continue.
_set_status("Update available (not required) — starting…")
_do_sync()
_: # "Ok" or anything unrecognised
_do_sync()
func _on_version_error(code: String) -> void:
if code == "DISCONNECTED":
# Lost connection before we got a reply — wait for reconnect and retry.
_set_status("Connection lost. Waiting to reconnect…")
Network.connected.connect(_start, CONNECT_ONE_SHOT)
return
# Any other error (server-side, unknown type, etc.): don't block the player.
push_warning("InitScreen: version check failed (%s) — proceeding anyway" % code)
_do_sync()
func _do_sync() -> void:
var cached := ContentCache.definition_count()
if cached > 0:
_set_status("Syncing card database… (%d cached)" % cached)
else:
_set_status("Downloading card database…")
ContentCache.start_sync()
# ── ContentCache signal handlers ──────────────────────────────────────────────
func _on_sync_progress(fetched_total: int) -> void:
_set_status("Syncing card database… (%d cards)" % fetched_total)
func _on_sync_complete(_total: int) -> void:
_check_active_session()
func _check_active_session() -> void:
_set_status("Checking for active games…")
Network.request(
"game.get_active_session",
{},
func(_type: String, p: Variant): _on_active_session(p),
func(_code: String, _msg: String): _go_to_main()
)
func _on_active_session(payload: Variant) -> void:
var p := payload as Dictionary
var sid_raw = p.get("sessionId") # may be null when server has no active session
# Treat null or zero UUID as "no active session".
if sid_raw == null:
_go_to_main()
return
var sid : String = str(sid_raw)
if sid.is_empty() or sid == "00000000-0000-0000-0000-000000000000":
_go_to_main()
return
var phase_raw = p.get("phase")
var phase : String = str(phase_raw) if phase_raw != null else "unknown"
var dialog := ConfirmationDialog.new()
dialog.title = "Active Game Found"
dialog.dialog_text = "You have an active game in progress (%s phase).\nWould you like to rejoin?" % phase
dialog.ok_button_text = "Rejoin"
dialog.cancel_button_text = "Concede"
add_child(dialog)
dialog.confirmed.connect(func() -> void:
Game.session_id = sid
get_tree().change_scene_to_file("res://scenes/game/GameScreen.tscn")
)
dialog.canceled.connect(func() -> void:
_set_status("Conceding game…")
Network.request(
"game.concede",
{ "sessionId": sid },
func(_t: String, _rp: Variant): _go_to_main(),
func(_c: String, _m: String): _go_to_main()
)
)
dialog.popup_centered()
func _go_to_main() -> void:
get_tree().change_scene_to_file("res://scenes/main/MainScreen.tscn")
func _on_sync_failed(error: String) -> void:
_set_status("Sync failed: %s" % error)
retry_btn.visible = true
# ── Helpers ───────────────────────────────────────────────────────────────────
func _set_status(text: String) -> void:
status_label.text = text