Slice 2: telemetry, vitals, chat, spawn/portal, rare, kills and combat stats
The frames the backend reads most, each pinned by a golden test written from the original's source (field order, JSON types, string-formatted numbers, mem_mb in bytes, the PascalCase aggregates Newtonsoft emits for combat_stats). Coordinates repeat the original's float arithmetic from the landblock-local float, so ew/ns carry the same float-widened values as before. Telemetry goes out on connect and every 5 s, vitals every 5 s, combat stats every 10 s when dirty. The rare meta-state switch is not carried over (owner decision); the allegiance rare announcement and the !report reply are. Kill patterns and combat patterns are the original's, unchanged. Also fixes the tick scheduler re-arming repeating jobs from now instead of from their due time, which made every cadence drift a frame late per period. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5dbb294a96
commit
1ff0a40aeb
19 changed files with 1824 additions and 5 deletions
84
src/OpenAC.MosswartMassacre/Streams/TelemetryStream.cs
Normal file
84
src/OpenAC.MosswartMassacre/Streams/TelemetryStream.cs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
using System.Globalization;
|
||||
using OpenAC.MosswartMassacre.Backend;
|
||||
using OpenAC.MosswartMassacre.Infrastructure;
|
||||
|
||||
namespace OpenAC.MosswartMassacre.Streams;
|
||||
|
||||
/// <summary>
|
||||
/// The <c>telemetry</c> frame: sent right after the socket registers and then
|
||||
/// every five seconds, as the original's socket loop did.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Several fields are strings on the wire (kill rate, deaths, taper count) and
|
||||
/// <c>mem_mb</c> carries bytes; the backend reads them that way.
|
||||
/// </remarks>
|
||||
internal sealed class TelemetryStream : IMmFeature, IBackendConnectionListener
|
||||
{
|
||||
public static readonly TimeSpan Interval = TimeSpan.FromSeconds(5);
|
||||
|
||||
private readonly MmContext _context;
|
||||
private readonly SessionStats _stats;
|
||||
private readonly ProcessTelemetry _process = new();
|
||||
private IDisposable? _timer;
|
||||
|
||||
public TelemetryStream(MmContext context, SessionStats stats)
|
||||
{
|
||||
_context = context;
|
||||
_stats = stats;
|
||||
}
|
||||
|
||||
public void OnBackendConnected()
|
||||
{
|
||||
if (!_context.IsLoggedIn)
|
||||
return;
|
||||
SendNow();
|
||||
_timer?.Dispose();
|
||||
_timer = _context.Scheduler.Every(Interval, SendNow);
|
||||
}
|
||||
|
||||
public void OnLogin()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnLogoff()
|
||||
{
|
||||
_timer?.Dispose();
|
||||
_timer = null;
|
||||
}
|
||||
|
||||
public void Dispose() => OnLogoff();
|
||||
|
||||
internal void SendNow()
|
||||
{
|
||||
if (!_context.IsLoggedIn)
|
||||
return;
|
||||
_context.Send(Build());
|
||||
}
|
||||
|
||||
internal object Build()
|
||||
{
|
||||
MmCoordinates coords = MmCoordinates.From(_context.Automation.Navigation.Snapshot.Position);
|
||||
var kills = _stats.Kills;
|
||||
return new
|
||||
{
|
||||
type = "telemetry",
|
||||
character_name = _context.CharacterName,
|
||||
char_tag = _context.Settings.Current.CharTag ?? "",
|
||||
session_id = MmContext.ProcessSessionId,
|
||||
timestamp = Wire.Timestamp(_context.Clock),
|
||||
ew = coords.EW,
|
||||
ns = coords.NS,
|
||||
z = coords.Z,
|
||||
kills = kills.TotalKills,
|
||||
kills_per_hour = kills.KillsPerHour.ToString("F0", CultureInfo.CurrentCulture),
|
||||
onlinetime = (_context.Clock.Now - kills.StatsStartTime).ToString(@"dd\.hh\:mm\:ss", CultureInfo.InvariantCulture),
|
||||
deaths = kills.SessionDeaths.ToString(CultureInfo.CurrentCulture),
|
||||
total_deaths = kills.TotalDeaths.ToString(CultureInfo.CurrentCulture),
|
||||
prismatic_taper_count = _context.PrismaticTaperCount().ToString(CultureInfo.CurrentCulture),
|
||||
vt_state = _context.MetaState() ?? string.Empty,
|
||||
mem_mb = _process.MemoryBytes,
|
||||
cpu_pct = _process.SampleCpuUsage(),
|
||||
mem_handles = _process.HandleCount,
|
||||
};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue