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
+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));
}