diff --git a/MosswartMassacre/LiveInventoryTracker.cs b/MosswartMassacre/LiveInventoryTracker.cs index 8712463..1fc3c7a 100644 --- a/MosswartMassacre/LiveInventoryTracker.cs +++ b/MosswartMassacre/LiveInventoryTracker.cs @@ -24,13 +24,27 @@ namespace MosswartMassacre // so the backend sees ~1 update per item per flush instead of many per // second. Adds and removes stay immediate (they're rare and meaningful). private readonly HashSet _dirtyItemIds = new HashSet(); - private const int FlushIntervalMs = 60000; // 60s — tune here if needed + // Flush on a RANDOMIZED interval — 2 minutes plus up to 3 more (so + // 2–5 min) — re-rolled after every tick. This de-synchronizes the + // fleet: even when many clients hot-reload at once (an auto-update + // wave) and start their timers at the same instant, each picks a + // different interval, so their flushes spread out instead of arriving + // at the backend as one synchronized burst (which starved telemetry + // and made the player count flap). + private const int FlushBaseMs = 120000; // 2 minutes + private const int FlushJitterMs = 180000; // + up to 3 minutes → 2–5 min + private readonly Random _rng = new Random(); private readonly System.Windows.Forms.Timer _flushTimer; + private int NextFlushIntervalMs() + { + return FlushBaseMs + _rng.Next(0, FlushJitterMs + 1); // 120000–300000 ms + } + internal LiveInventoryTracker(IPluginLogger logger) { _logger = logger; - _flushTimer = new System.Windows.Forms.Timer { Interval = FlushIntervalMs }; + _flushTimer = new System.Windows.Forms.Timer { Interval = NextFlushIntervalMs() }; _flushTimer.Tick += FlushDirtyItems; } @@ -53,6 +67,7 @@ namespace MosswartMassacre { _logger?.Log($"[LiveInv] Error initializing: {ex.Message}"); } + _flushTimer.Interval = NextFlushIntervalMs(); // fresh random phase per login _flushTimer.Start(); } @@ -148,6 +163,11 @@ namespace MosswartMassacre /// private void FlushDirtyItems(object sender, EventArgs e) { + // Re-roll the interval every tick so the fleet's timers keep + // drifting apart and never re-synchronize. (Setting Interval on a + // WinForms timer restarts its countdown — desired here.) + _flushTimer.Interval = NextFlushIntervalMs(); + if (_dirtyItemIds.Count == 0) return; // Snapshot then clear, so changes arriving during the flush are diff --git a/MosswartMassacre/bin/Release/MosswartMassacre.dll b/MosswartMassacre/bin/Release/MosswartMassacre.dll index 0bbea51..c01e9a9 100644 Binary files a/MosswartMassacre/bin/Release/MosswartMassacre.dll and b/MosswartMassacre/bin/Release/MosswartMassacre.dll differ