diff --git a/src/GameLogic/PlugIns/PeriodicTasks/CastleSiegeEventPlugIn.cs b/src/GameLogic/PlugIns/PeriodicTasks/CastleSiegeEventPlugIn.cs index a9b72ef..0c7ea92 100644 --- a/src/GameLogic/PlugIns/PeriodicTasks/CastleSiegeEventPlugIn.cs +++ b/src/GameLogic/PlugIns/PeriodicTasks/CastleSiegeEventPlugIn.cs @@ -12,6 +12,7 @@ using MUnique.OpenMU.GameLogic.NPC; using MUnique.OpenMU.GameLogic.Views; using MUnique.OpenMU.Interfaces; using MUnique.OpenMU.Pathfinding; +using MUnique.OpenMU.Persistence; using MUnique.OpenMU.PlugIns; /// @@ -150,11 +151,18 @@ public sealed class CastleSiegeEventPlugIn : IPeriodicTaskPlugIn, ISupportCustom config.PersistedPhaseStartedUtc = context.PhaseStartedUtc; config.PersistedRegisteredGuilds = context.RegisteredGuilds.ToList(); - // Write the plugin's custom-configuration JSON row back to the database (durable across restarts). + // Find our plugin-configuration row via the in-memory config graph to get its id. var pluginTypeId = typeof(CastleSiegeEventPlugIn).GUID; - using var ctx = gameContext.PersistenceContextProvider.CreateNewContext(gameContext.Configuration); - var configurations = await ctx.GetAsync().ConfigureAwait(false); - var row = configurations.FirstOrDefault(c => c.TypeId == pluginTypeId); + var inMemory = gameContext.Configuration.PlugInConfigurations.FirstOrDefault(c => c.TypeId == pluginTypeId); + if (inMemory is null) + { + return; + } + + // Load a fresh, change-tracked copy of that row in its own (non-caching) context, rewrite its + // custom-configuration JSON, and save — this is what actually persists to PostgreSQL. + using var ctx = gameContext.PersistenceContextProvider.CreateNewTypedContext(typeof(PlugInConfiguration), false, gameContext.Configuration); + var row = await ctx.GetByIdAsync(inMemory.GetId()).ConfigureAwait(false); if (row is null) { return; @@ -162,6 +170,9 @@ public sealed class CastleSiegeEventPlugIn : IPeriodicTaskPlugIn, ISupportCustom row.SetConfiguration(config, gameContext.PlugInManager.CustomConfigReferenceHandler); await ctx.SaveChangesAsync().ConfigureAwait(false); + + gameContext.LoggerFactory.CreateLogger() + .LogInformation("Castle Siege: persisted state (owner={owner}, phase={phase}).", config.PersistedOwnerGuildName ?? "(none)", config.PersistedPhase); } catch (Exception ex) {