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>
This commit is contained in:
dingo
2026-03-19 10:49:46 -04:00
co-authored by Claude Happy
parent e104330da4
commit efcd693d60
4 changed files with 47 additions and 7 deletions
@@ -76,6 +76,7 @@ func clear_state() -> void:
func create(lobby_name: String, deck_id: String, password: String,
rules_override: Dictionary, on_success: Callable = Callable(),
on_error: Callable = Callable()) -> void:
clear_state()
my_deck_id = deck_id
var payload := {
"lobbyName": lobby_name,
@@ -101,6 +102,7 @@ func create(lobby_name: String, deck_id: String, password: String,
func join(lid: String, deck_id: String, password: String,
on_success: Callable = Callable(),
on_error: Callable = Callable()) -> void:
clear_state()
my_deck_id = deck_id
var payload := { "lobbyId": lid, "deckId": deck_id }
if password != "":
@@ -261,7 +261,7 @@ func _exit_tree() -> void:
func _setup_spectator_ui() -> void:
# "SPECTATING" overlay label.
# "SPECTATING" label at top-center.
var lbl := Label.new()
lbl.text = "SPECTATING"
lbl.modulate = Color(1.0, 0.76, 0.2)
@@ -271,9 +271,21 @@ func _setup_spectator_ui() -> void:
lbl.position = Vector2(0, 8)
_hud.add_child(lbl)
# Hide action buttons — spectators can only watch.
# "Leave" button for spectators (top-right corner).
var leave_btn := Button.new()
leave_btn.text = "Leave"
leave_btn.set_anchors_preset(Control.PRESET_TOP_RIGHT)
leave_btn.position = Vector2(-90, 8)
leave_btn.custom_minimum_size = Vector2(80, 32)
leave_btn.pressed.connect(func() -> void:
Game.stop_spectating()
get_tree().change_scene_to_file("res://scenes/free_play/FreePlayScreen.tscn"))
_hud.add_child(leave_btn)
# Hide action buttons and the settings panel — spectators cannot interact with the game.
_draw_btn.visible = false
_end_turn_btn.visible = false
_settings_btn.visible = false
# ── Environment ───────────────────────────────────────────────────────────────
@@ -127,14 +127,19 @@ func _check_active_session() -> void:
func _on_active_session(payload: Variant) -> void:
var p := payload as Dictionary
var sid : String = str(p.get("sessionId", ""))
# A null or zero UUID means no active session.
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 : String = str(p.get("phase", "unknown"))
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
@@ -73,6 +73,7 @@ else
<th>Rules (SP/Turn, Hand)</th>
<th>Created</th>
<th>Session</th>
<th></th>
</tr>
</thead>
<tbody>
@@ -111,11 +112,21 @@ else
<span class="text-muted">—</span>
}
</td>
<td>
@if (lobby.Status == CustomLobbyStatus.Open || lobby.Status == CustomLobbyStatus.Full)
{
<button class="btn btn-outline-danger btn-sm"
@onclick="() => CancelLobbyAsync(lobby.Id)"
title="Force-cancel this lobby">
Cancel
</button>
}
</td>
</tr>
}
@if (!FilteredLobbies.Any())
{
<tr><td colspan="7" class="text-center text-muted py-3">No lobbies found.</td></tr>
<tr><td colspan="8" class="text-center text-muted py-3">No lobbies found.</td></tr>
}
</tbody>
</table>
@@ -151,6 +162,16 @@ else
? _lobbies
: _lobbies.Where(l => l.Status.ToString() == _statusFilter);
private async Task CancelLobbyAsync(Guid lobbyId)
{
var lobby = await GameDb.CustomLobbies.FindAsync(lobbyId);
if (lobby is null) return;
if (lobby.Status != CustomLobbyStatus.Open && lobby.Status != CustomLobbyStatus.Full) return;
lobby.Status = CustomLobbyStatus.Cancelled;
await GameDb.SaveChangesAsync();
await LoadAsync();
}
private static string StatusBadge(CustomLobbyStatus status) => status switch
{
CustomLobbyStatus.Open => "bg-primary",