Snapshot for release 2026.10.13.1 (internal 90a2f4a)
This commit is contained in:
parent
b0f9d74b21
commit
1d86acdf27
218 changed files with 24019 additions and 1517 deletions
|
|
@ -348,8 +348,14 @@ internal sealed unsafe class FlightCapture
|
|||
NoteTarget(arg1, now);
|
||||
}
|
||||
|
||||
f |= MatchEngineCall(action, arg0, arg1, now) ? FlightFlags.Engine : FlightFlags.Client;
|
||||
Keep(_out, now, FlightDir.Out, f, msg, len, fullLen, seq, 0);
|
||||
// An IdentifyObject is the engine's when an engine send for that object was
|
||||
// registered just before (EngineSend, with who asked); otherwise AC or Decal sent it.
|
||||
byte idWho = action == FlightOp.AcIdentifyObject ? MatchEngineSend(arg0, now) : (byte)0;
|
||||
bool engine = idWho != 0 || MatchEngineCall(action, arg0, arg1, now);
|
||||
if (action == FlightOp.AcIdentifyObject && !engine)
|
||||
Interlocked.Increment(ref _identifyForeign);
|
||||
f |= engine ? FlightFlags.Engine : FlightFlags.Client;
|
||||
Keep(_out, now, FlightDir.Out, f, msg, len, fullLen, seq, 0, idWho);
|
||||
|
||||
if (action == FlightOp.AcUse || action == FlightOp.AcUseWithTarget)
|
||||
DetectUseSent(action == FlightOp.AcUse ? arg0 : arg1, counted: action == FlightOp.AcUse, now);
|
||||
|
|
@ -431,10 +437,10 @@ internal sealed unsafe class FlightCapture
|
|||
}
|
||||
}
|
||||
|
||||
private void Keep(Side side, long now, FlightDir dir, FlightFlags f, byte* msg, int len, int fullLen, uint seq, uint suppressed)
|
||||
private void Keep(Side side, long now, FlightDir dir, FlightFlags f, byte* msg, int len, int fullLen, uint seq, uint suppressed, uint requester = 0)
|
||||
{
|
||||
side.Kept++;
|
||||
Ring.WriteMessage(now, dir, f, msg, len, fullLen, seq, suppressed);
|
||||
Ring.WriteMessage(now, dir, f, msg, len, fullLen, seq, suppressed, requester);
|
||||
}
|
||||
|
||||
// ── positions ──────────────────────────────────────────────────────────
|
||||
|
|
@ -589,6 +595,72 @@ internal sealed unsafe class FlightCapture
|
|||
}
|
||||
}
|
||||
|
||||
// -- engine IdentifyObject (0xC8) sends --
|
||||
// Kept apart from _pending: AutoId alone can send 30 a second, which would push every
|
||||
// other engine call out of that 16-entry table. No marker line per send: the tag on the
|
||||
// 0xC8 itself ([eng:<who>]) says who asked. 256 entries = AcMainThreadQueue's
|
||||
// MaxRequestIdQueue: one drain can send a whole full queue before any of it reaches sendto.
|
||||
private struct IdPending { public uint Id; public byte Who; public long Stamp; public bool Used; }
|
||||
private readonly IdPending[] _idPending = new IdPending[256];
|
||||
private int _idPendingNext;
|
||||
private long _identifyForeign;
|
||||
|
||||
/// <summary>IdentifyObject (0xC8) messages sent with no engine send to match: AC itself or Decal.</summary>
|
||||
public long IdentifyForeignTotal => Interlocked.Read(ref _identifyForeign);
|
||||
|
||||
/// <summary>
|
||||
/// The engine is about to send an IdentifyObject for <paramref name="id"/> on behalf of
|
||||
/// <paramref name="who"/> (an IdRequester, non-zero). The next 0xC8 for that id within
|
||||
/// EngineMatchMs is tagged [eng:<who>]. Called BEFORE the send, so a 0xC8 that AC puts
|
||||
/// on the wire inside the call is still matched. Returns a token for EngineSendFailed, or -1.
|
||||
/// </summary>
|
||||
public int EngineSend(byte who, uint id)
|
||||
{
|
||||
if (who == 0) return -1;
|
||||
long now = _clock();
|
||||
lock (_engineLock)
|
||||
{
|
||||
int slot = _idPendingNext;
|
||||
ref IdPending p = ref _idPending[slot];
|
||||
_idPendingNext = (_idPendingNext + 1) & (_idPending.Length - 1);
|
||||
p.Id = id; p.Who = who; p.Stamp = now; p.Used = false;
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The send registered as <paramref name="token"/> did not happen (the call returned false or
|
||||
/// threw): retire its entry so it cannot tag a later 0xC8 for the same id. A no-op when the
|
||||
/// entry was already matched or the slot has since been reused for another id.
|
||||
/// </summary>
|
||||
public void EngineSendFailed(int token, uint id)
|
||||
{
|
||||
if (token < 0 || token >= _idPending.Length) return;
|
||||
lock (_engineLock)
|
||||
{
|
||||
ref IdPending p = ref _idPending[token];
|
||||
if (p.Id == id && !p.Used) p.Used = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The requester of the oldest unmatched engine send for <paramref name="id"/>, or 0.</summary>
|
||||
private byte MatchEngineSend(uint id, long now)
|
||||
{
|
||||
lock (_engineLock)
|
||||
{
|
||||
int best = -1;
|
||||
for (int i = 0; i < _idPending.Length; i++)
|
||||
{
|
||||
ref IdPending p = ref _idPending[i];
|
||||
if (p.Who == 0 || p.Used || p.Id != id || now < p.Stamp || Ms(now - p.Stamp) > EngineMatchMs) continue;
|
||||
if (best < 0 || p.Stamp < _idPending[best].Stamp) best = i;
|
||||
}
|
||||
if (best < 0) return 0;
|
||||
_idPending[best].Used = true;
|
||||
return _idPending[best].Who;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Engine calls that send something to the server.</summary>
|
||||
private static bool Expects(string name) => name switch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -344,7 +344,9 @@ internal static class FlightFormat
|
|||
|
||||
uint seq = rd.U32();
|
||||
uint action = rd.U32();
|
||||
string tag = (e.Flags & FlightFlags.Engine) != 0 ? "[eng] " : (e.Flags & FlightFlags.Client) != 0 ? "[cli] " : "";
|
||||
string who = IdRequesters.Label(e.C);
|
||||
string tag = (e.Flags & FlightFlags.Engine) != 0 ? (who.Length > 0 ? $"[eng:{who}] " : "[eng] ")
|
||||
: (e.Flags & FlightFlags.Client) != 0 ? "[cli] " : "";
|
||||
string body = action switch
|
||||
{
|
||||
FlightOp.AcUse => $"{Id(rd.U32())}",
|
||||
|
|
@ -539,12 +541,12 @@ internal static class FlightFormat
|
|||
case FlightOp.EvAttackerNotification:
|
||||
{
|
||||
string who = rd.Str(40); rd.U32(); double pct = rd.F64(); uint dmg = rd.U32(); uint crit = rd.U32();
|
||||
return $"hit '{who}' for {dmg}{(crit != 0 ? " (crit)" : "")}, {pct * 100:0}% left";
|
||||
return $"hit '{who}' for {dmg}{(crit != 0 ? " (crit)" : "")} ({pct * 100:0}% of its max health)"; // the share is damage / max, not what is left
|
||||
}
|
||||
case FlightOp.EvDefenderNotification:
|
||||
{
|
||||
string who = rd.Str(40); rd.U32(); double pct = rd.F64(); uint dmg = rd.U32();
|
||||
return $"'{who}' hit you for {dmg}, {pct * 100:0}% left";
|
||||
return $"'{who}' hit you for {dmg} ({pct * 100:0}% of your max health)";
|
||||
}
|
||||
case FlightOp.EvEvasionAttacker: return $"'{rd.Str(40)}' evaded";
|
||||
case FlightOp.EvEvasionDefender: return $"evaded '{rd.Str(40)}'";
|
||||
|
|
@ -794,6 +796,8 @@ internal static class FlightFormat
|
|||
" -> client to server (what this client sent). [eng] = matches an engine direct-action call just before",
|
||||
" (the 'engine ...' marker above it); [cli] = no engine call to match: the client's own path",
|
||||
" (keyboard/mouse, or a plugin calling AC some other way). Movement matches are by time only.",
|
||||
" IdentifyObject: [eng:autoid-target|autoid-container|autoid-inventory|autoid-world|plugin|self|ui]",
|
||||
" = an engine appraisal and who asked for it; [cli] = AC itself or Decal.",
|
||||
" <- server to client: game events (UseDone, ViewContents, errors, magic, combat), the player's own",
|
||||
" motion/position/teleport, system text, and messages about objects the character just used.",
|
||||
" ** engine markers: engine calls, m_cBusy changes and resets, action-gate clears, a per-second link",
|
||||
|
|
|
|||
|
|
@ -125,6 +125,35 @@ internal static unsafe class FlightRecorder
|
|||
try { c.EngineCall(name, a, b); } catch { }
|
||||
}
|
||||
|
||||
/// <summary>An engine IdentifyObject send for <paramref name="id"/>, asked for by <paramref name="who"/>
|
||||
/// (IdRequester): the 0xC8 it produces is tagged [eng:<who>]. Call it before the send; the
|
||||
/// token goes to EngineSendFailed when the send does not happen. -1 while the recorder is off.</summary>
|
||||
public static int EngineSend(byte who, uint id)
|
||||
{
|
||||
FlightCapture? c = _cap;
|
||||
if (c == null || _paused) return -1;
|
||||
try { return c.EngineSend(who, id); } catch { return -1; }
|
||||
}
|
||||
|
||||
/// <summary>The send registered as <paramref name="token"/> did not happen: retire its entry.</summary>
|
||||
public static void EngineSendFailed(int token, uint id)
|
||||
{
|
||||
if (token < 0) return;
|
||||
FlightCapture? c = _cap;
|
||||
if (c == null) return;
|
||||
try { c.EngineSendFailed(token, id); } catch { }
|
||||
}
|
||||
|
||||
/// <summary>IdentifyObject messages sent with no engine send to match (AC or Decal); -1 while the recorder is off.</summary>
|
||||
public static long ForeignIdentifyTotal
|
||||
{
|
||||
get
|
||||
{
|
||||
FlightCapture? c = _cap;
|
||||
return c == null ? -1 : c.IdentifyForeignTotal;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Mark(FlightMark kind, uint a = 0, uint b = 0, uint c = 0, string? text = null)
|
||||
{
|
||||
FlightCapture? cap = _cap;
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ internal unsafe struct FlightEntry
|
|||
public uint A;
|
||||
/// <summary>Messages: rate-limited copies dropped before this one. Markers: second number.</summary>
|
||||
public uint B;
|
||||
/// <summary>Messages: unused. Markers: third number.</summary>
|
||||
/// <summary>Messages: an engine 0xC8's requester (IdRequester), else 0. Markers: third number.</summary>
|
||||
public uint C;
|
||||
public fixed byte Data[DataCap];
|
||||
}
|
||||
|
|
@ -153,7 +153,8 @@ internal sealed unsafe class FlightRing
|
|||
}
|
||||
|
||||
/// <summary>A message: its first DataCap bytes.</summary>
|
||||
public void WriteMessage(long stamp, FlightDir dir, FlightFlags flags, byte* msg, int len, int fullLen, uint fragSeq, uint suppressed)
|
||||
/// <param name="requester">Messages' C: for an engine 0xC8, who asked (IdRequester); else 0.</param>
|
||||
public void WriteMessage(long stamp, FlightDir dir, FlightFlags flags, byte* msg, int len, int fullLen, uint fragSeq, uint suppressed, uint requester = 0)
|
||||
{
|
||||
if (!Own(out int i, out int serial)) return;
|
||||
ref FlightEntry e = ref _slots[i];
|
||||
|
|
@ -167,7 +168,7 @@ internal sealed unsafe class FlightRing
|
|||
e.FullLen = (ushort)Math.Clamp(fullLen, 0, ushort.MaxValue);
|
||||
e.A = fragSeq;
|
||||
e.B = suppressed;
|
||||
e.C = 0;
|
||||
e.C = requester;
|
||||
fixed (byte* d = e.Data)
|
||||
{
|
||||
if (keep > 0) Buffer.MemoryCopy(msg, d, FlightEntry.DataCap, keep);
|
||||
|
|
|
|||
116
src/RynthCore.Engine/Net/IdRequester.cs
Normal file
116
src/RynthCore.Engine/Net/IdRequester.cs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
// ============================================================================
|
||||
// RynthCore.Engine - Net/IdRequester.cs
|
||||
//
|
||||
// Who asked for an IdentifyObject (0xC8) the engine sends, so the flight recorder and
|
||||
// the per-minute counters can tell the engine's appraisals apart from AC's and Decal's.
|
||||
//
|
||||
// Before: the recorder tagged every 0xC8 [cli] (FlightCapture had no case for it), so
|
||||
// 3211 identifies in one session's dump could not be split between AutoId, the plugins
|
||||
// and the client itself.
|
||||
//
|
||||
// The marker is call-scoped and thread-local: whoever calls CombatActionHooks.RequestId
|
||||
// wraps the call in EngineSendMarker.Enter(who). When the call is queued for AC's main
|
||||
// thread, the requester rides with the queued entry (PendingIdQueue) and the drain
|
||||
// re-enters the marker around the real send. Only a send made under a marker is
|
||||
// registered with the recorder (FlightCapture.EngineSend), so a 0xC8 nobody marked stays
|
||||
// [cli]: AC itself or Decal.
|
||||
//
|
||||
// Pure: no engine state. Compiled into tools\EngineRobustnessTests and
|
||||
// tools\FlightRecorderTests.
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace RynthCore.Engine.Net;
|
||||
|
||||
/// <summary>Who asked for an engine 0xC8. The byte value is what the flight ring stores.</summary>
|
||||
internal enum IdRequester : byte
|
||||
{
|
||||
/// <summary>No marker: not an engine send (AC itself, Decal), or an unmarked engine path.</summary>
|
||||
None = 0,
|
||||
AutoIdTarget = 1,
|
||||
AutoIdContainer = 2,
|
||||
AutoIdInventory = 3,
|
||||
/// <summary>AutoIdMode All only: an object that is not the target, in an open container or in the pack.</summary>
|
||||
AutoIdWorld = 4,
|
||||
/// <summary>A plugin through the host RequestId (plugin API).</summary>
|
||||
Plugin = 5,
|
||||
/// <summary>The engine's delayed login self-identify (max vitals).</summary>
|
||||
Self = 6,
|
||||
/// <summary>The engine's Inventory panel identifying the item under the cursor.</summary>
|
||||
Ui = 7,
|
||||
}
|
||||
|
||||
internal static class IdRequesters
|
||||
{
|
||||
public const int Count = 8;
|
||||
|
||||
/// <summary>The flight-recorder label after "eng:" ("" for None or an unknown code).</summary>
|
||||
public static string Label(uint code) => code switch
|
||||
{
|
||||
1 => "autoid-target",
|
||||
2 => "autoid-container",
|
||||
3 => "autoid-inventory",
|
||||
4 => "autoid-world",
|
||||
5 => "plugin",
|
||||
6 => "self",
|
||||
7 => "ui",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
/// <summary>Short heartbeat field names (none contains fps=, plug=, login= or qd=).</summary>
|
||||
public static string Short(IdRequester who) => who switch
|
||||
{
|
||||
IdRequester.AutoIdTarget => "tgt",
|
||||
IdRequester.AutoIdContainer => "ctr",
|
||||
IdRequester.AutoIdInventory => "inv",
|
||||
IdRequester.AutoIdWorld => "wld",
|
||||
IdRequester.Plugin => "plg",
|
||||
IdRequester.Self => "slf",
|
||||
IdRequester.Ui => "ui",
|
||||
_ => "unm",
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>The thread-local "this 0xC8 is the engine's" marker around a RequestId call.</summary>
|
||||
internal static class EngineSendMarker
|
||||
{
|
||||
[ThreadStatic] private static IdRequester t_current;
|
||||
|
||||
/// <summary>The requester marked on this thread (None outside any scope).</summary>
|
||||
public static IdRequester Current => t_current;
|
||||
|
||||
/// <summary>Marks this thread until the returned scope is disposed (scopes nest).</summary>
|
||||
public static Scope Enter(IdRequester who)
|
||||
{
|
||||
IdRequester previous = t_current;
|
||||
t_current = who;
|
||||
return new Scope(previous);
|
||||
}
|
||||
|
||||
public readonly struct Scope : IDisposable
|
||||
{
|
||||
private readonly IdRequester _previous;
|
||||
internal Scope(IdRequester previous) { _previous = previous; }
|
||||
public void Dispose() => t_current = _previous;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Engine 0xC8 sends that really went out, per requester (running totals; any thread).</summary>
|
||||
internal static class IdSendStats
|
||||
{
|
||||
private static readonly long[] _sent = new long[IdRequesters.Count];
|
||||
|
||||
public static void CountSent(IdRequester who)
|
||||
{
|
||||
int i = (int)who;
|
||||
if ((uint)i < (uint)_sent.Length) Interlocked.Increment(ref _sent[i]);
|
||||
}
|
||||
|
||||
public static long Sent(IdRequester who)
|
||||
{
|
||||
int i = (int)who;
|
||||
return (uint)i < (uint)_sent.Length ? Interlocked.Read(ref _sent[i]) : 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -218,6 +218,14 @@ internal static unsafe class ServerMessageStream
|
|||
{
|
||||
try { InventoryOrder.Observe(new ReadOnlySpan<byte>(message, length)); }
|
||||
catch (Exception ex) { RynthLog.Compat($"ServerMessageStream: inventory order failed - {ex.GetType().Name}: {ex.Message}"); }
|
||||
// The SERVER deleted an object (0xF747 ObjectDelete, its id after the opcode). AutoId
|
||||
// tells this apart from the client's own releases: only this one makes a re-create
|
||||
// under the same id due an appraisal again (AutoIdEligibility).
|
||||
if (opcode == InventoryOrder.DeleteObjectOpcode && length >= 8)
|
||||
{
|
||||
try { Compatibility.AutoIdService.OnServerDelete(AcPacketWire.ReadU32(message + 4)); }
|
||||
catch (Exception ex) { RynthLog.Compat($"ServerMessageStream: server delete failed - {ex.GetType().Name}: {ex.Message}"); }
|
||||
}
|
||||
}
|
||||
if (_pluginsWant)
|
||||
_dispatchedToPlugins += PluginManager.DispatchServerMessage(opcode, eventType, message + 4, length - 4);
|
||||
|
|
|
|||
Loading…
Reference in a new issue