Add [RULES] diagnostic logging + remove [DELTA] console noise
- MatchmakerService: log whether ranked ruleset was found and its StartingRandomTilePct after DB query - GameReadyHandler: log RuleSnapshotJson snippet and deserialized StartingRandomTilePct/BoardWidth/BoardHeight when both players ready - GameHandlerBase: remove [DELTA] Console.WriteLines added for delta diffing debug (issue resolved) 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:
@@ -128,28 +128,9 @@ internal abstract class GameHandlerBase
|
||||
{
|
||||
var prevState = GameEngine.Deserialize(prevStateJson);
|
||||
|
||||
// ── DIAGNOSTIC: log prev/next state to identify why deltas are consistently null ──
|
||||
Console.WriteLine(
|
||||
$"[DELTA] prev: phase={prevState.Phase}({(int)prevState.Phase}) turn={prevState.TurnNumber} " +
|
||||
$"active={prevState.ActivePlayerAccountId} seq={prevState.NextActionSequence}");
|
||||
Console.WriteLine(
|
||||
$"[DELTA] next: phase={state.Phase}({(int)state.Phase}) turn={state.TurnNumber} " +
|
||||
$"active={state.ActivePlayerAccountId} seq={state.NextActionSequence}");
|
||||
Console.WriteLine(
|
||||
$"[DELTA] prevStateJson length={prevStateJson.Length} " +
|
||||
$"sameAsCurrentSession={(prevStateJson == session.StateJson)} " +
|
||||
$"referenceEqual={ReferenceEquals(prevStateJson, session.StateJson)}");
|
||||
// ─────────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
var d1 = GameStateDiffer.ComputeDelta(prevState, state, p1Id);
|
||||
var d2 = GameStateDiffer.ComputeDelta(prevState, state, p2Id);
|
||||
|
||||
Console.WriteLine(
|
||||
$"[DELTA] d1: meta={d1.MetaDelta != null} tiles={d1.ChangedTiles != null} " +
|
||||
$"units+={d1.AddedUnits != null} units-={d1.RemovedUnitIds != null} " +
|
||||
$"hand+={d1.HandAdded != null} ownStats={d1.OwnStatsDelta != null} " +
|
||||
$"oppStats={d1.OpponentStatsDelta != null} ver={d1.StateVersion}");
|
||||
|
||||
// Safety fallback: if the differ produces an empty delta (all content fields null),
|
||||
// the client would advance its stateVersion but see no visual changes. Fall back to
|
||||
// a full state_update so clients always reflect the correct post-action state.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace SOR.Game.Handlers;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Database.Entities.Catalog;
|
||||
using SOR.Database.Entities.Collection;
|
||||
@@ -23,19 +24,22 @@ internal sealed class GameReadyHandler : GameHandlerBase, IMessageHandler
|
||||
private readonly CollectionDbContext _collectionDb;
|
||||
private readonly CatalogDbContext _catalogDb;
|
||||
private readonly IClientPush _clientPush;
|
||||
private readonly ILogger<GameReadyHandler> _logger;
|
||||
|
||||
public GameReadyHandler(
|
||||
IMessageSerializer serializer,
|
||||
GameDbContext gameDb,
|
||||
CollectionDbContext collectionDb,
|
||||
CatalogDbContext catalogDb,
|
||||
IClientPush clientPush)
|
||||
IClientPush clientPush,
|
||||
ILogger<GameReadyHandler> logger)
|
||||
{
|
||||
_serializer = serializer;
|
||||
_gameDb = gameDb;
|
||||
_collectionDb = collectionDb;
|
||||
_catalogDb = catalogDb;
|
||||
_clientPush = clientPush;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public string MessageType => "game.ready";
|
||||
@@ -98,10 +102,21 @@ internal sealed class GameReadyHandler : GameHandlerBase, IMessageHandler
|
||||
var p2ArchSpirit = await LoadDeckArchSpiritAsync(session.PlayerTwoDeckId, ct);
|
||||
|
||||
// Deserialize rule snapshot (falls back to default if none stored).
|
||||
_logger.LogInformation(
|
||||
"[RULES] Session {SessionId} RuleSnapshotJson: {Snippet}",
|
||||
session.Id,
|
||||
session.RuleSnapshotJson is null ? "<null>" : session.RuleSnapshotJson[..Math.Min(300, session.RuleSnapshotJson.Length)]);
|
||||
|
||||
var rules = session.RuleSnapshotJson is not null
|
||||
? GameEngine.DeserializeRules(session.RuleSnapshotJson)
|
||||
: null;
|
||||
|
||||
_logger.LogInformation(
|
||||
"[RULES] Deserialized StartingRandomTilePct={Pct} BoardWidth={W} BoardHeight={H}",
|
||||
rules?.StartingRandomTilePct ?? GameRules.Default.StartingRandomTilePct,
|
||||
rules?.BoardWidth ?? GameRules.Default.BoardWidth,
|
||||
rules?.BoardHeight ?? GameRules.Default.BoardHeight);
|
||||
|
||||
var state = GameEngine.Initialize(
|
||||
session.Id,
|
||||
session.PlayerOneAccountId, p1DeckCards, p1ArchSpirit,
|
||||
|
||||
@@ -110,6 +110,11 @@ internal sealed class MatchmakerService : BackgroundService
|
||||
.Where(r => r.IsRankedDefault)
|
||||
.FirstOrDefaultAsync(ct);
|
||||
|
||||
_logger.LogInformation(
|
||||
"[RULES] Ranked rules loaded: found={Found} StartingRandomTilePct={Pct}",
|
||||
rankedRules is not null,
|
||||
rankedRules?.StartingRandomTilePct);
|
||||
|
||||
// Create a game session.
|
||||
var session = new GameSession
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user