Files
SVSimServer/SVSim.BattleNode/Bridge/BattleNodeOptions.cs
gamer147 8f270a87f0 refactor(battle-node): gate WS diagnostic logging behind config flag
The temporary [sio-in] / [sio-out] / [ws-rx-text] / [ws-rx-bin] /
[ws-recv-exit] / [ws-loop-exit] logs added during the hand-ack
investigation are useful enough to keep around (PvP testing, future WS
debugging) but too chatty to leave on by default. Promote them from
"strip before merge" to a permanent opt-in.

New BattleNodeOptions.DiagnosticLogging (bool, default false). Wired
through BattleNodeWebSocketHandler to RealParticipant via a new optional
ctor parameter (default false — existing test sites pick up the silent
default with no changes). Every Information/Warning log added during the
investigation is now if-gated; non-diagnostic logs (the decode-failure
warnings, the dispatch-drop debug) stay as-is.

Toggle via appsettings*.json:
  "BattleNode": { "DiagnosticLogging": true }

Or live via the singleton:
  factory.Services.GetRequiredService<BattleNodeOptions>().DiagnosticLogging = true

175 battle-node tests still passing — existing tests use the constructor
default and emit nothing, so no test changes were required.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-02 16:49:17 -04:00

44 lines
2.3 KiB
C#

namespace SVSim.BattleNode.Bridge;
/// <summary>
/// DI-injected options for the battle node. NodeServerUrl matches the prod
/// do_matching wire format: <c>host:port/socket.io/</c>, no scheme prefix.
/// BestHTTP's SocketManager parses it as the Socket.IO v2 endpoint URL.
/// </summary>
public sealed class BattleNodeOptions
{
public string NodeServerUrl { get; set; } = "localhost:5148/socket.io/";
/// <summary>
/// How long the first arriver's WS waits for a partner before disconnecting.
/// Matches the architecture spec's 60s default; override (typically lower)
/// in tests via the factory.
/// </summary>
public TimeSpan WaitingRoomTimeout { get; set; } = TimeSpan.FromSeconds(60);
/// <summary>
/// Dev convenience: when true, matchmaking endpoints that would otherwise park
/// a solo poller (returning 3002 RETRY until a partner arrives) instead return
/// a Scripted match immediately — equivalent to passing <c>?scripted=1</c> on
/// every request. Turn off to test real PvP with two clients. Default false.
/// <para>Trade-off: while on, two viewers polling simultaneously each get
/// their own Scripted match instead of pairing with each other. Toggling off
/// is the only way to get PvP behavior.</para>
/// </summary>
public bool SoloDefaultsToScripted { get; set; } = false;
/// <summary>
/// When true, <see cref="Sessions.Participants.RealParticipant"/> emits per-frame
/// diagnostic logs at Information level: <c>[sio-in]</c> on every inbound msg/alive/hand
/// envelope (URI, pubSeq, ackId, dispatch decision, ack-sent flag, ack arg, inbound
/// watermark); <c>[sio-out]</c> on every outbound push (URI, pubSeq, playSeq, noStock);
/// <c>[ws-rx-text]</c> / <c>[ws-rx-bin]</c> on every WS frame received at the transport
/// layer; <c>[ws-recv-exit]</c> / <c>[ws-loop-exit]</c> on read-loop termination
/// (with WebSocket state + exception type when applicable). Default false — keeps
/// production logs clean. Flip on per session for live WS debugging, PvP investigation,
/// or to reproduce the kind of softlock chased in
/// <c>docs/audits/battle-node-sio-events-2026-06-02.md</c>.
/// </summary>
public bool DiagnosticLogging { get; set; } = false;
}