fix(combat): remove plugin-side lifetime — backend accumulates now

The plugin's _lifetimeState was always identical to _sessionState
because both started fresh on every load/login and accumulated the
same events. Lifetime needs persistence across sessions.

Fix: plugin now only maintains _sessionState and sends lifetime=null.
The backend computes deltas between consecutive session snapshots and
accumulates them into a persisted lifetime in the combat_stats DB table.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-14 10:58:21 +02:00
parent b48af81a13
commit 0b1abf69f9
2 changed files with 7 additions and 9 deletions

View file

@ -13,7 +13,7 @@ namespace MosswartMassacre
///
/// Maintains two CombatSessionState objects:
/// - _sessionState: cleared on login / manual reset
/// - _lifetimeState: accumulated across sessions, never cleared
/// - Lifetime: accumulated on the backend by merging session deltas
///
/// Every 10 seconds, sends a combat_stats snapshot to MosswartOverlord
/// via WebSocket so the browser dashboard can display the same grid
@ -25,7 +25,6 @@ namespace MosswartMassacre
private readonly IPluginLogger _logger;
private CombatSessionState _sessionState = new CombatSessionState();
private CombatSessionState _lifetimeState = new CombatSessionState();
private System.Windows.Forms.Timer _sendTimer;
private bool _dirty;
private bool _disposed;
@ -34,7 +33,6 @@ namespace MosswartMassacre
{
_logger = logger;
_sessionState.SessionStart = DateTime.UtcNow.ToString("o");
_lifetimeState.SessionStart = DateTime.UtcNow.ToString("o");
}
public void Start()
@ -198,7 +196,7 @@ namespace MosswartMassacre
};
apply(_sessionState);
apply(_lifetimeState);
_dirty = true;
}
@ -219,7 +217,7 @@ namespace MosswartMassacre
};
apply(_sessionState);
apply(_lifetimeState);
_dirty = true;
}
@ -235,7 +233,7 @@ namespace MosswartMassacre
};
apply(_sessionState);
apply(_lifetimeState);
_dirty = true;
}
@ -251,7 +249,7 @@ namespace MosswartMassacre
};
apply(_sessionState);
apply(_lifetimeState);
_dirty = true;
}
@ -267,7 +265,7 @@ namespace MosswartMassacre
};
apply(_sessionState);
apply(_lifetimeState);
_dirty = true;
}
@ -541,7 +539,7 @@ namespace MosswartMassacre
character_name = SafeCharacterName(),
session_id = WebSocket.SessionId ?? "",
session = _sessionState,
lifetime = _lifetimeState,
lifetime = (object)null, // lifetime is accumulated on the backend
};
_ = WebSocket.SendCombatStatsAsync(payload);
}