diff --git a/Game/World/WorldBroadcastService.cs b/Game/World/WorldBroadcastService.cs
index c7c9888..103d0c5 100644
--- a/Game/World/WorldBroadcastService.cs
+++ b/Game/World/WorldBroadcastService.cs
@@ -124,4 +124,27 @@ public sealed class WorldBroadcastService
.Select(p => SendAsync(p.Connection, opCode, payload, CancellationToken.None));
await Task.WhenAll(tasks);
}
+
+ ///
+ /// Send a chunk delta to all players who currently have the given chunk key in their visible set.
+ ///
+ public async Task BroadcastChunkDeltaAsync(
+ string chunkKey,
+ object deltaPayload,
+ long newVersion,
+ ConcurrentDictionary players)
+ {
+ var tasks = new List();
+ foreach (var s in players.Values)
+ {
+ if (!s.ChunkVersions.ContainsKey(chunkKey))
+ continue;
+
+ // Update the player's tracked version so the next tick doesn't re-send a full chunk_load
+ s.ChunkVersions[chunkKey] = newVersion;
+ tasks.Add(SendAsync(s.Connection, OpCodes.WORLD_CHUNK_DELTA, deltaPayload, CancellationToken.None));
+ }
+ if (tasks.Count > 0)
+ await Task.WhenAll(tasks);
+ }
}
diff --git a/Game/World/WorldHandler.cs b/Game/World/WorldHandler.cs
index cc1a824..6d0645f 100644
--- a/Game/World/WorldHandler.cs
+++ b/Game/World/WorldHandler.cs
@@ -1,6 +1,8 @@
using System.Collections.Concurrent;
+using System.Text.Json;
using DataServer.Data;
using DataServer.Data.Entities;
+using GameServices;
using GameServices.Auth;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
@@ -23,6 +25,7 @@ public sealed class WorldHandler : IClientMessageHandler
private readonly WorldChunkCache _cache;
private readonly WorldMovementService _movement;
private readonly WorldBroadcastService _broadcast;
+ private readonly WorldEditDeltaHub _deltaHub;
private readonly ConcurrentDictionary _players = new();
private readonly ConcurrentDictionary _portalCooldownByCharacter = new();
@@ -39,7 +42,8 @@ public sealed class WorldHandler : IClientMessageHandler
IServiceScopeFactory scopeFactory,
WorldChunkCache cache,
WorldMovementService movement,
- WorldBroadcastService broadcast)
+ WorldBroadcastService broadcast,
+ WorldEditDeltaHub deltaHub)
{
_log = log;
_sessions = sessions;
@@ -47,6 +51,7 @@ public sealed class WorldHandler : IClientMessageHandler
_cache = cache;
_movement = movement;
_broadcast = broadcast;
+ _deltaHub = deltaHub;
var debugInputEnv = Environment.GetEnvironmentVariable("WORLD_INPUT_DEBUG");
_debugInput = !string.IsNullOrWhiteSpace(debugInputEnv) &&
@@ -65,8 +70,9 @@ public sealed class WorldHandler : IClientMessageHandler
if (_initialized) return Task.CompletedTask;
_tickCts = new CancellationTokenSource();
_tickTask = Task.Run(() => TickLoopAsync(_tickCts.Token), _tickCts.Token);
+ _deltaHub.OnDeltaPublished += OnWorldEditDelta;
_initialized = true;
- _log.LogInformation("WorldHandler initialized (cached movement pipeline)");
+ _log.LogInformation("WorldHandler initialized (cached movement pipeline + live delta forwarding)");
return Task.CompletedTask;
}
@@ -354,6 +360,51 @@ public sealed class WorldHandler : IClientMessageHandler
Math.Abs(p.X - self.X) <= (TileSize * 48) &&
Math.Abs(p.Y - self.Y) <= (TileSize * 48));
+ // ---- Live delta forwarding (admin world edits -> game clients) ----
+
+ private void OnWorldEditDelta(string chunkKey, string deltaJson)
+ {
+ // Fire-and-forget: forward delta to clients and invalidate cache
+ _ = ProcessDeltaAsync(chunkKey, deltaJson);
+ }
+
+ private async Task ProcessDeltaAsync(string chunkKey, string deltaJson)
+ {
+ try
+ {
+ // Parse the delta to extract version and operation details
+ using var doc = JsonDocument.Parse(deltaJson);
+ var root = doc.RootElement;
+ var toVersion = root.TryGetProperty("toVersion", out var tv) && tv.ValueKind == JsonValueKind.Number
+ ? tv.GetInt64() : 0L;
+
+ // Parse chunk coordinates from the key for cache invalidation
+ var parts = chunkKey.Split(':');
+ if (parts.Length == 5 &&
+ int.TryParse(parts[0], out var regionId) &&
+ int.TryParse(parts[1], out var zoneX) &&
+ int.TryParse(parts[2], out var zoneY) &&
+ int.TryParse(parts[3], out var chunkX) &&
+ int.TryParse(parts[4], out var chunkY))
+ {
+ // Invalidate cache so next access reloads fresh data from DB
+ _cache.InvalidateChunk(regionId, zoneX, zoneY, chunkX, chunkY);
+
+ // Deserialize the delta to a dynamic object for forwarding to clients.
+ // The raw JSON from the hub already has all the fields the client needs.
+ var deltaPayload = JsonSerializer.Deserialize