Fix custom lobby staying in Started state after game ends
Add CustomLobbyStatus.Completed; in FinalizeGameAsync, query the lobby linked via GameSessionId and set Status=Completed when the game ends. This removes finished games from the active-games browser (list_active only returns Started lobbies) and from the admin "active" count. Admin page: add Completed filter option, dark badge, include Started lobbies in the always-loaded set so stale in-progress games are visible. 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:
@@ -44,8 +44,8 @@ else
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-3">
|
||||||
<div class="card text-center p-3">
|
<div class="card text-center p-3">
|
||||||
<div class="fs-2 fw-bold text-secondary">@_lobbies.Count(l => l.Status == CustomLobbyStatus.Cancelled)</div>
|
<div class="fs-2 fw-bold text-secondary">@_lobbies.Count(l => l.Status == CustomLobbyStatus.Cancelled || l.Status == CustomLobbyStatus.Completed)</div>
|
||||||
<div class="text-muted small">Cancelled Today</div>
|
<div class="text-muted small">Ended Today</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -59,6 +59,7 @@ else
|
|||||||
<option value="Full">Full</option>
|
<option value="Full">Full</option>
|
||||||
<option value="Started">Started</option>
|
<option value="Started">Started</option>
|
||||||
<option value="Cancelled">Cancelled</option>
|
<option value="Cancelled">Cancelled</option>
|
||||||
|
<option value="Completed">Completed</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -149,6 +150,7 @@ else
|
|||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.Where(l => l.Status == CustomLobbyStatus.Open
|
.Where(l => l.Status == CustomLobbyStatus.Open
|
||||||
|| l.Status == CustomLobbyStatus.Full
|
|| l.Status == CustomLobbyStatus.Full
|
||||||
|
|| l.Status == CustomLobbyStatus.Started
|
||||||
|| l.CreatedAt >= cutoff)
|
|| l.CreatedAt >= cutoff)
|
||||||
.OrderByDescending(l => l.CreatedAt)
|
.OrderByDescending(l => l.CreatedAt)
|
||||||
.Take(200)
|
.Take(200)
|
||||||
@@ -178,6 +180,7 @@ else
|
|||||||
CustomLobbyStatus.Full => "bg-warning text-dark",
|
CustomLobbyStatus.Full => "bg-warning text-dark",
|
||||||
CustomLobbyStatus.Started => "bg-success",
|
CustomLobbyStatus.Started => "bg-success",
|
||||||
CustomLobbyStatus.Cancelled => "bg-secondary",
|
CustomLobbyStatus.Cancelled => "bg-secondary",
|
||||||
|
CustomLobbyStatus.Completed => "bg-dark",
|
||||||
_ => "bg-secondary",
|
_ => "bg-secondary",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,4 +60,6 @@ public enum CustomLobbyStatus
|
|||||||
Started,
|
Started,
|
||||||
/// <summary>Lobby was cancelled by the host before a game started.</summary>
|
/// <summary>Lobby was cancelled by the host before a game started.</summary>
|
||||||
Cancelled,
|
Cancelled,
|
||||||
|
/// <summary>The game session created from this lobby has ended.</summary>
|
||||||
|
Completed,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,6 +161,13 @@ internal abstract class GameHandlerBase
|
|||||||
session.WinCondition = winCondition;
|
session.WinCondition = winCondition;
|
||||||
session.EndedAt = DateTimeOffset.UtcNow;
|
session.EndedAt = DateTimeOffset.UtcNow;
|
||||||
|
|
||||||
|
// Mark the linked custom lobby as Completed so it disappears from the active-games
|
||||||
|
// browser. Ranked sessions have no linked lobby; the query safely returns null.
|
||||||
|
var linkedLobby = await gameDb.CustomLobbies
|
||||||
|
.FirstOrDefaultAsync(l => l.GameSessionId == session.Id, ct);
|
||||||
|
if (linkedLobby != null && linkedLobby.Status == CustomLobbyStatus.Started)
|
||||||
|
linkedLobby.Status = CustomLobbyStatus.Completed;
|
||||||
|
|
||||||
// Save game session status FIRST — this must succeed before we touch ELO.
|
// Save game session status FIRST — this must succeed before we touch ELO.
|
||||||
// If identity DB fails below, the session is still correctly marked Completed
|
// If identity DB fails below, the session is still correctly marked Completed
|
||||||
// so players won't be stuck in a ghost match on next login.
|
// so players won't be stuck in a ghost match on next login.
|
||||||
|
|||||||
Reference in New Issue
Block a user