Fix leave handler, partner-left push, and GDScript compile error

- GameLeaveCustomLobbyHandler: return success silently for Started/Cancelled
  status (allows the Leave button to work regardless of lobby state); inject
  IClientPush and send LobbyPartnerLeftPush to remaining participant when
  someone leaves a Full lobby; reset ready flags when guest leaves
- GameMessages: add LobbyPartnerLeftPush(LobbyId, Reason)
- CustomLobby.gd: add partner_left signal; handle game.custom.lobby.partner_left
  push by calling clear_state() then emitting partner_left
- lobby_room_screen.gd: connect/disconnect partner_left; show toast + navigate
  back to FreePlayScreen when partner leaves
- free_play_screen.gd: extract auto-select into _auto_select_deck() helper to
  fix GDScript parse error (comma inside multi-line if-body within lambda)

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 09:45:24 -04:00
co-authored by Claude Happy
parent 116d3c10f2
commit 2ec29ce2dc
8 changed files with 78 additions and 14 deletions
@@ -40,6 +40,10 @@ signal preset_vote_rejected(lobby_id: String, preset_id: String)
## Emitted locally when the player has left or cancelled the lobby.
signal lobby_left
## Pushed by the server when the other participant leaves a Full lobby.
## reason is "host_cancelled" or "guest_left".
signal partner_left(reason: String)
# ── State ─────────────────────────────────────────────────────────────────────
var lobby_id : String = ""
@@ -253,3 +257,9 @@ func _on_server_push(type: String, payload: Variant) -> void:
var lid := str(d.get("lobbyId", ""))
var pid := str(d.get("presetId", ""))
preset_vote_rejected.emit(lid, pid)
"game.custom.lobby.partner_left":
var d := payload as Dictionary
var reason : String = str(d.get("reason", ""))
clear_state()
partner_left.emit(reason)
@@ -0,0 +1 @@
uid://jy5lpxwyc6f7
@@ -73,12 +73,16 @@ func _load_decks() -> void:
var d := p as Dictionary
_all_decks = d.get("decks", [])
_populate_create_deck_buttons()
# Auto-select first deck so _selected_deck is never empty.
if not _all_decks.is_empty() and _selected_deck.is_empty():
_selected_deck = str(_all_decks[0].get("id", "")),
_auto_select_deck(),
func(_c: String, _m: String) -> void: pass)
func _auto_select_deck() -> void:
# Auto-select the first deck so _selected_deck is never empty when joining/creating.
if not _all_decks.is_empty() and _selected_deck.is_empty():
_selected_deck = str(_all_decks[0].get("id", ""))
func _refresh_lobbies() -> void:
if _current_tab == "open":
_load_open_lobbies()
@@ -0,0 +1 @@
uid://dw508xf153tvr
@@ -57,6 +57,7 @@ func _exit_tree() -> void:
CustomLobby.preset_vote_requested.disconnect(_on_preset_vote_requested)
CustomLobby.preset_vote_rejected.disconnect(_on_preset_vote_rejected)
CustomLobby.lobby_left.disconnect(_on_lobby_left)
CustomLobby.partner_left.disconnect(_on_partner_left)
# ── Setup ─────────────────────────────────────────────────────────────────────
@@ -113,6 +114,7 @@ func _connect_signals() -> void:
CustomLobby.preset_vote_requested.connect(_on_preset_vote_requested)
CustomLobby.preset_vote_rejected.connect(_on_preset_vote_rejected)
CustomLobby.lobby_left.connect(_on_lobby_left)
CustomLobby.partner_left.connect(_on_partner_left)
# ── Refresh ───────────────────────────────────────────────────────────────────
@@ -237,6 +239,13 @@ func _on_preset_vote_rejected(_lid: String, _pid: String) -> void:
func _on_lobby_left() -> void:
get_tree().change_scene_to_file("res://scenes/free_play/FreePlayScreen.tscn")
func _on_partner_left(reason: String) -> void:
var msg := "Your partner left the lobby." if reason == "guest_left" else "The host cancelled the lobby."
_show_toast(msg)
await get_tree().create_timer(1.5).timeout
get_tree().change_scene_to_file("res://scenes/free_play/FreePlayScreen.tscn")
# ── Actions ───────────────────────────────────────────────────────────────────
func _on_leave_pressed() -> void:
@@ -0,0 +1 @@
uid://ba1ux64fml50t
+6
View File
@@ -348,6 +348,12 @@ public sealed record LobbyReadyStatusPush(Guid LobbyId, bool HostReady, bool Gue
/// <summary>Pushed to both participants when a lobby participant changes their selected deck.</summary>
public sealed record LobbyDeckChangedPush(Guid LobbyId, Guid AccountId, Guid DeckId);
/// <summary>
/// Pushed to the remaining participant when the other player leaves a Full lobby.
/// Reason is "host_cancelled" (host left) or "guest_left" (guest left).
/// </summary>
public sealed record LobbyPartnerLeftPush(Guid LobbyId, string Reason);
// ── DTOs ─────────────────────────────────────────────────────────────────────
/// <summary>
@@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore;
using SOR.Database.Contexts;
using SOR.Database.Enums;
using SOR.Networking.Abstractions.Messaging;
using SOR.Networking.Abstractions.Push;
using SOR.Networking.Abstractions.Transport;
using SOR.Shared.Networking;
@@ -12,16 +13,26 @@ using SOR.Shared.Networking;
///
/// Host cancelling: marks the lobby Cancelled (removes it for guests).
/// Guest leaving: clears their slot, resets lobby to Open.
///
/// If the lobby is already Started (game in progress) or Cancelled, returns success silently —
/// the caller should concede the game via game.concede instead of trying to leave the lobby.
///
/// When a Full lobby loses a participant, pushes LobbyPartnerLeftPush to the remaining player.
/// </summary>
internal sealed class GameLeaveCustomLobbyHandler : GameHandlerBase, IMessageHandler
{
private readonly IMessageSerializer _serializer;
private readonly GameDbContext _gameDb;
private readonly IClientPush _clientPush;
public GameLeaveCustomLobbyHandler(IMessageSerializer serializer, GameDbContext gameDb)
public GameLeaveCustomLobbyHandler(
IMessageSerializer serializer,
GameDbContext gameDb,
IClientPush clientPush)
{
_serializer = serializer;
_gameDb = gameDb;
_serializer = serializer;
_gameDb = gameDb;
_clientPush = clientPush;
}
public string MessageType => "game.custom.leave";
@@ -37,28 +48,49 @@ internal sealed class GameLeaveCustomLobbyHandler : GameHandlerBase, IMessageHan
var lobby = await _gameDb.CustomLobbies.FindAsync([req.LobbyId], ct)
?? throw new GameException("LOBBY_NOT_FOUND");
// If already resolved (game started or lobby cancelled), return success silently.
// Player should use game.concede for an in-progress game.
if (lobby.Status == CustomLobbyStatus.Started || lobby.Status == CustomLobbyStatus.Cancelled)
throw new GameException("LOBBY_ALREADY_RESOLVED");
return ServerMessage.Reply("game.custom.leave.ack", message.Seq,
new LeaveCustomLobbyResponse(LobbyId: lobby.Id));
if (lobby.HostAccountId == accountId)
{
// Host cancels — closes the lobby entirely.
// Host cancels — close the lobby entirely.
// If a guest is present, notify them.
var guestId = lobby.GuestAccountId;
lobby.Status = CustomLobbyStatus.Cancelled;
await _gameDb.SaveChangesAsync(ct);
if (guestId.HasValue)
{
await _clientPush.PushAsync(guestId.Value.ToString(),
ServerMessage.Push("game.custom.lobby.partner_left",
new LobbyPartnerLeftPush(lobby.Id, "host_cancelled")), ct);
}
}
else if (lobby.GuestAccountId == accountId)
{
// Guest leaves — free up the slot.
lobby.GuestAccountId = null;
lobby.GuestDeckId = null;
lobby.Status = CustomLobbyStatus.Open;
// Guest leaves — free up the slot and reset ready flags.
var hostId = lobby.HostAccountId;
lobby.GuestAccountId = null;
lobby.GuestDeckId = null;
lobby.HostReady = false;
lobby.GuestReady = false;
lobby.HostFirstTurnPref = null;
lobby.GuestFirstTurnPref = null;
lobby.Status = CustomLobbyStatus.Open;
await _gameDb.SaveChangesAsync(ct);
await _clientPush.PushAsync(hostId.ToString(),
ServerMessage.Push("game.custom.lobby.partner_left",
new LobbyPartnerLeftPush(lobby.Id, "guest_left")), ct);
}
else
{
throw new GameException("NOT_IN_LOBBY");
}
await _gameDb.SaveChangesAsync(ct);
return ServerMessage.Reply("game.custom.leave.ack", message.Seq,
new LeaveCustomLobbyResponse(LobbyId: lobby.Id));
}