diff --git a/Game/Dungeon/DungeonHandler.Dungeons.cs b/Game/Dungeon/DungeonHandler.Dungeons.cs index f8ffae3..c811cb3 100644 --- a/Game/Dungeon/DungeonHandler.Dungeons.cs +++ b/Game/Dungeon/DungeonHandler.Dungeons.cs @@ -423,8 +423,7 @@ public sealed partial class DungeonHandler health = m.Health, maxHealth = m.MaxHealth, state = m.State.ToString().ToLower(), - spriteConfig = string.IsNullOrEmpty(m.SpriteConfigJson) ? null : - System.Text.Json.JsonSerializer.Deserialize(m.SpriteConfigJson), + spriteConfig = DeserializeSpriteConfigSafe(m.SpriteConfigJson), tintColor = m.TintColor, scale = m.Scale }), diff --git a/Game/Dungeon/DungeonHandler.cs b/Game/Dungeon/DungeonHandler.cs index c3a95a8..9c22b3b 100644 --- a/Game/Dungeon/DungeonHandler.cs +++ b/Game/Dungeon/DungeonHandler.cs @@ -104,6 +104,22 @@ public sealed partial class DungeonHandler : IClientMessageHandler } } + private static object? DeserializeSpriteConfigSafe(string? spriteConfigJson) + { + if (string.IsNullOrWhiteSpace(spriteConfigJson)) + return null; + + try + { + // Keep JSON structure intact for client-side consumers. + return JsonSerializer.Deserialize(spriteConfigJson); + } + catch + { + return null; + } + } + public IReadOnlyCollection SupportedOpCodes => new[] { DungeonOpCodes.HUB_STATE, @@ -829,8 +845,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler y = m.Y, health = m.Health, maxHealth = m.MaxHealth, - spriteConfig = string.IsNullOrEmpty(m.SpriteConfigJson) ? null : - System.Text.Json.JsonSerializer.Deserialize(m.SpriteConfigJson), + spriteConfig = DeserializeSpriteConfigSafe(m.SpriteConfigJson), tintColor = m.TintColor, scale = m.Scale }), @@ -2851,8 +2866,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler health = m.Health, maxHealth = m.MaxHealth, state = m.State.ToString().ToLower(), - spriteConfig = string.IsNullOrEmpty(m.SpriteConfigJson) ? null : - System.Text.Json.JsonSerializer.Deserialize(m.SpriteConfigJson), + spriteConfig = DeserializeSpriteConfigSafe(m.SpriteConfigJson), tintColor = m.TintColor, scale = m.Scale }), @@ -2861,8 +2875,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler id = m.Id, definitionId = m.DefinitionId, name = m.Name, - spriteConfig = string.IsNullOrEmpty(m.SpriteConfigJson) ? null : - System.Text.Json.JsonSerializer.Deserialize(m.SpriteConfigJson), + spriteConfig = DeserializeSpriteConfigSafe(m.SpriteConfigJson), tintColor = m.TintColor, scale = m.Scale }) : null, @@ -2886,9 +2899,8 @@ public sealed partial class DungeonHandler : IClientMessageHandler y = i.Y }), - portals = (sendSpatialThisTick - ? sim.Portals.Values.Where(p => p.IsActive && (!spatialFiltering || IsNearby(p.X, p.Y))) - : sim.Portals.Values.Where(p => p.IsActive && p.Type == PortalType.Exit)) + portals = sim.Portals.Values + .Where(p => p.IsActive) .Select(p => new { id = p.Id, diff --git a/pending-clientChanges.md b/pending-clientChanges.md new file mode 100644 index 0000000..c751108 --- /dev/null +++ b/pending-clientChanges.md @@ -0,0 +1,38 @@ +# Pending Client Changes + +## Context +Server-side dungeon state payloads now support spatial filtering and one-time mob metadata delivery per dungeon session. + +## Required Client Updates +1. Support `mobCatalog` on `DUNGEON_STATE` packets. +- `mobCatalog` is sent once per dungeon join and contains static mob render metadata: + - `id` + - `definitionId` + - `name` + - `spriteConfig` + - `tintColor` + - `scale` +- Client should cache this per-runtime mob `id` and use it to preload/resolve art. + +2. Do not assume all mobs are present every tick. +- With spatial filtering enabled, `mobs` in `DUNGEON_STATE` only includes nearby/relevant mobs. +- Client entity lifecycle should be "visibility-scoped", not "full authoritative list each tick". +- Recommended behavior: + - Keep existing mob entities when omitted for a tick (out of range), do not hard-delete immediately. + - Remove only when confirmed dead/despawned via explicit state/event signal or timeout policy. + +3. Use `definitionId` when available. +- `definitionId` is now included in enter/state mob payloads. +- Client can use this for fallback art resolution or future dictionary-based rendering. + +4. Portal rendering should treat payload as authoritative for active portals. +- Server now sends active portals each state packet regardless of spatial throttling. +- If client currently clears portals aggressively between packets, keep the most recent active set. + +## Optional Hardening +1. Handle missing/invalid `spriteConfig` gracefully. +- Server now nulls bad JSON instead of throwing. +- Client should apply safe defaults (placeholder sprite, default tint/scale) when `spriteConfig` is null. + +2. Add debug overlay for spatial tuning validation. +- Show current nearby mob count vs total known on minimap for live tuning checks.