Report Eagle cache load rejection reasons

This commit is contained in:
2026-06-09 16:47:52 -07:00
parent 29b0a460e7
commit e00ff5f1a5
2 changed files with 53 additions and 9 deletions
@@ -278,7 +278,9 @@ namespace eagle {
var cachedState = EagleGameStateDiskCache.Load(GameId, factionId);
if (cachedState == null) {
_connectionLogger.LogLine(
$"[STATE_CACHE] Cache miss game={GameId} player={factionId?.ToString() ?? "spectator"}");
$"[STATE_CACHE] Cache miss game={GameId} " +
$"player={factionId?.ToString() ?? "spectator"} " +
$"reason={EagleGameStateDiskCache.LastLoadDiagnostic}");
return;
}
@@ -43,25 +43,66 @@ namespace eagle {
}
private static string _cacheDirectory;
public static string LastLoadDiagnostic { get; private set; }
public static CachedGameState Load(long gameId, int? playerId) {
EnsureCacheDirectoryInitialized();
var path = CachePath(gameId, playerId);
if (!File.Exists(path)) { return null; }
LastLoadDiagnostic = $"path={path}";
if (!File.Exists(path)) {
LastLoadDiagnostic = $"file not found at {path}";
return null;
}
try {
var cache = JsonUtility.FromJson<CacheFile>(File.ReadAllText(path));
if (cache == null || cache.schemaVersion != CurrentSchemaVersion) { return null; }
if (cache.gameId != gameId) { return null; }
if (cache.hasPlayerId != playerId.HasValue) { return null; }
if (cache.hasPlayerId && cache.playerId != playerId.Value) { return null; }
if (cache.unfilteredResultCount <= 0) { return null; }
if (String.IsNullOrEmpty(cache.gameStateViewBase64)) { return null; }
if (cache == null) {
LastLoadDiagnostic = $"cache JSON parsed to null at {path}";
return null;
}
if (cache.schemaVersion != CurrentSchemaVersion) {
LastLoadDiagnostic =
$"schema mismatch at {path}: cache={cache.schemaVersion} current={CurrentSchemaVersion}";
return null;
}
if (cache.gameId != gameId) {
LastLoadDiagnostic =
$"game id mismatch at {path}: cache={cache.gameId} requested={gameId}";
return null;
}
if (cache.hasPlayerId != playerId.HasValue) {
LastLoadDiagnostic =
$"player presence mismatch at {path}: cacheHas={cache.hasPlayerId} requestedHas={playerId.HasValue}";
return null;
}
if (cache.hasPlayerId && cache.playerId != playerId.Value) {
LastLoadDiagnostic =
$"player id mismatch at {path}: cache={cache.playerId} requested={playerId.Value}";
return null;
}
if (cache.unfilteredResultCount <= 0) {
LastLoadDiagnostic =
$"invalid unfiltered count at {path}: {cache.unfilteredResultCount}";
return null;
}
if (String.IsNullOrEmpty(cache.gameStateViewBase64)) {
LastLoadDiagnostic = $"missing GameStateView payload at {path}";
return null;
}
var bytes = Convert.FromBase64String(cache.gameStateViewBase64);
var gameStateView = GameStateView.Parser.ParseFrom(bytes);
if (gameStateView.GameId != gameId) { return null; }
if (gameStateView.GameId == 0) {
gameStateView.GameId = gameId;
} else if (gameStateView.GameId != gameId) {
LastLoadDiagnostic =
$"GameStateView game id mismatch at {path}: view={gameStateView.GameId} requested={gameId}";
return null;
}
LastLoadDiagnostic =
$"loaded {path} count={cache.unfilteredResultCount} shardokGames={cache.shardokGames?.Count ?? 0}";
return new CachedGameState {
GameStateView = gameStateView,
@@ -69,6 +110,7 @@ namespace eagle {
ShardokGames = LoadShardokGames(cache.shardokGames)
};
} catch (Exception e) {
LastLoadDiagnostic = $"exception loading {path}: {e}";
Debug.LogWarning($"Failed to load Eagle game state cache for game {gameId}: {e}");
TryDelete(path);
return null;