final fix
This commit is contained in:
parent
57b2f0400e
commit
1142a012ef
2 changed files with 31 additions and 16 deletions
|
|
@ -36,6 +36,11 @@ namespace MosswartMassacre
|
||||||
private const int IntervalSec = 5;
|
private const int IntervalSec = 5;
|
||||||
private static string SessionId = "";
|
private static string SessionId = "";
|
||||||
|
|
||||||
|
// ─── cached prismatic taper count ───────────
|
||||||
|
private static int _cachedPrismaticTaperCount = 0;
|
||||||
|
private static DateTime _lastPrismaticTaperUpdate = DateTime.MinValue;
|
||||||
|
private static readonly TimeSpan PrismaticTaperCacheInterval = TimeSpan.FromMinutes(10);
|
||||||
|
|
||||||
// ─── runtime state ──────────────────────────
|
// ─── runtime state ──────────────────────────
|
||||||
private static ClientWebSocket _ws;
|
private static ClientWebSocket _ws;
|
||||||
private static CancellationTokenSource _cts;
|
private static CancellationTokenSource _cts;
|
||||||
|
|
@ -164,16 +169,12 @@ namespace MosswartMassacre
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PluginCore.WriteToChat("[WebSocket] Building telemetry payload...");
|
|
||||||
var json = BuildPayloadJson();
|
var json = BuildPayloadJson();
|
||||||
PluginCore.WriteToChat($"[WebSocket] Payload built ({json.Length} chars), sending...");
|
|
||||||
await SendEncodedAsync(json, _cts.Token);
|
await SendEncodedAsync(json, _cts.Token);
|
||||||
PluginCore.WriteToChat("[WebSocket] Telemetry sent successfully");
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
PluginCore.WriteToChat($"[WebSocket] Telemetry failed: {ex.Message}");
|
PluginCore.WriteToChat($"[WebSocket] Telemetry failed: {ex.Message}");
|
||||||
PluginCore.WriteToChat($"[WebSocket] Stack trace: {ex.StackTrace}");
|
|
||||||
break; // Exit telemetry loop on failure
|
break; // Exit telemetry loop on failure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -293,16 +294,8 @@ namespace MosswartMassacre
|
||||||
await _sendLock.WaitAsync(token);
|
await _sendLock.WaitAsync(token);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (_ws == null)
|
if (_ws == null || _ws.State != WebSocketState.Open)
|
||||||
{
|
|
||||||
PluginCore.WriteToChat("[WebSocket] Send failed - WebSocket is null");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (_ws.State != WebSocketState.Open)
|
|
||||||
{
|
|
||||||
PluginCore.WriteToChat($"[WebSocket] Send failed - State: {_ws.State}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var bytes = Encoding.UTF8.GetBytes(text);
|
var bytes = Encoding.UTF8.GetBytes(text);
|
||||||
await _ws.SendAsync(new ArraySegment<byte>(bytes),
|
await _ws.SendAsync(new ArraySegment<byte>(bytes),
|
||||||
|
|
@ -312,7 +305,7 @@ namespace MosswartMassacre
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
PluginCore.WriteToChat($"[WebSocket] Send error: {ex.Message} (State: {_ws?.State})");
|
PluginCore.WriteToChat($"[WebSocket] Send error: {ex.Message}");
|
||||||
_ws?.Abort();
|
_ws?.Abort();
|
||||||
_ws?.Dispose();
|
_ws?.Dispose();
|
||||||
_ws = null;
|
_ws = null;
|
||||||
|
|
@ -325,7 +318,29 @@ namespace MosswartMassacre
|
||||||
|
|
||||||
// ─── payload builder ──────────────────────────────
|
// ─── payload builder ──────────────────────────────
|
||||||
|
|
||||||
|
private static void UpdatePrismaticTaperCache()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_cachedPrismaticTaperCount = Utils.GetItemStackSize("Prismatic Taper");
|
||||||
|
_lastPrismaticTaperUpdate = DateTime.Now;
|
||||||
|
PluginCore.WriteToChat($"[WebSocket] Updated prismatic taper cache: {_cachedPrismaticTaperCount}");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
PluginCore.WriteToChat($"[WebSocket] Failed to update prismatic taper cache: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int GetCachedPrismaticTaperCount()
|
||||||
|
{
|
||||||
|
// Update cache if it's stale (older than 2 minutes)
|
||||||
|
if (DateTime.Now - _lastPrismaticTaperUpdate > PrismaticTaperCacheInterval)
|
||||||
|
{
|
||||||
|
UpdatePrismaticTaperCache();
|
||||||
|
}
|
||||||
|
return _cachedPrismaticTaperCount;
|
||||||
|
}
|
||||||
|
|
||||||
private static string BuildPayloadJson()
|
private static string BuildPayloadJson()
|
||||||
{
|
{
|
||||||
|
|
@ -346,7 +361,7 @@ namespace MosswartMassacre
|
||||||
onlinetime = (DateTime.Now - PluginCore.statsStartTime).ToString(@"dd\.hh\:mm\:ss"),
|
onlinetime = (DateTime.Now - PluginCore.statsStartTime).ToString(@"dd\.hh\:mm\:ss"),
|
||||||
deaths = PluginCore.sessionDeaths.ToString(),
|
deaths = PluginCore.sessionDeaths.ToString(),
|
||||||
total_deaths = PluginCore.totalDeaths.ToString(),
|
total_deaths = PluginCore.totalDeaths.ToString(),
|
||||||
prismatic_taper_count = Utils.GetItemStackSize("Prismatic Taper").ToString(),
|
prismatic_taper_count = GetCachedPrismaticTaperCount().ToString(),
|
||||||
vt_state = VtankControl.VtGetMetaState(),
|
vt_state = VtankControl.VtGetMetaState(),
|
||||||
mem_mb = tele.MemoryBytes,
|
mem_mb = tele.MemoryBytes,
|
||||||
cpu_pct = tele.GetCpuUsage(),
|
cpu_pct = tele.GetCpuUsage(),
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue