A flight capture from one 26-minute session showed the client sending 3211 IdentifyObject
(0xC8) messages, most of everything it sent, because AutoId appraised every object the
client created. Bots already appraise at the point of use, so the background appraisals
are now limited.
AutoIdMode (engine.json "AutoIdMode", default Limited; /rc autoid all|limited|off, live
and saved; /rc autoid alone reports it):
All the old behaviour.
Limited only the selected target (fresh-cache skip), items in the container the
player has open now, and items in the player's own inventory with nothing
cached. The last two wait until the object is 2 s old and until 30 s after a
world transition's settle window ends (death, portal, teleport, landblock jump;
walking into the next landblock never defers). A container opened after the
settle ended is not deferred. Creatures, ground items, other players: never.
Off nothing, the selected target included.
Plugins' own RequestId calls are not limited; they still merge in the RequestId slot.
The decision is AutoIdPolicy (pure). AutoIdService now keeps a pending list on its drain
timer (waits for age/defer stay, skips leave), classifies each candidate from the PWD
snapshot (container / wielder / side pack owner, and the ground container from
ViewObjectContents), takes InventoryPutObjInContainer (0x0022) moves from the server
message stream, and rescans an opened container 2.5 s after the open.
Requester tagging: a thread-local EngineSendMarker around every engine RequestId call
(AutoId by class, plugin host API, the login self-identify, the Inventory panel hover).
A queued request carries its requester in PendingIdQueue and the main-thread drain
re-enters the marker around the real send. Only a marked send registers with the
flight recorder (FlightCapture.EngineSend, its own 64-entry table so bursts never evict
other engine calls), so its 0xC8 shows as [eng:autoid-target|autoid-container|
autoid-inventory|autoid-world|plugin|self|ui]; an unmarked 0xC8 stays [cli] and counts
as AC's or Decal's.
Per-minute log line "autoid 60s: ..." (its own line, not part of "hb #"): sends by
requester, cli, total, AutoId skips by reason (mode, age, defer, fresh), pending.
EngineSettings keeps upstream's MaxHotReloads, IltServerNames/IltHosts, ReportEndpoint
and CloseOnServerDisconnect next to AutoIdMode (owned keys, load and save).
Tests: EngineRobustnessTests (decision table against an independent expected function,
spot cases, defer window from WorldTransitionState inputs, classification, marker scopes
and thread-locality, requester through PendingIdQueue, heartbeat field names against the
launcher regex), FlightRecorderTests (identify tagging, foreign count, match window, burst),
EngineSettingsTests (AutoIdMode round trip, default left out). check_offthread_mutators.py:
DrainPending allow-listed like DrainTick (it only enqueues).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
176 lines
8.5 KiB
C#
176 lines
8.5 KiB
C#
// ============================================================================
|
|
// RynthCore.Engine - Compatibility/AutoIdPolicy.cs
|
|
//
|
|
// Which background appraisals AutoIdService sends (the decision only; AutoIdService
|
|
// does the queueing, the lookups and the sends).
|
|
//
|
|
// Why: in one 26-minute session (1585 s) the client sent 3211 IdentifyObject (0xC8),
|
|
// about three quarters of everything it sent, for 2479 objects against 28
|
|
// kills. AutoId appraised every object the client created. The bot (RynthAi) already
|
|
// appraises what it needs at the point of use (corpse items its loot rules need, the
|
|
// selected creature, equipment, meta conditions), so most of that was traffic for
|
|
// nothing; it is now limited (engine.json "AutoIdMode", /rc autoid).
|
|
//
|
|
// Modes:
|
|
// All the old behaviour: every created object except the player, the selected
|
|
// target with its fresh-cache skip.
|
|
// Limited (default) only
|
|
// Target the selected target (fresh-cache skip, no age, no defer);
|
|
// Container items in the container the player has open now (a corpse,
|
|
// a chest, a pack opened through ViewContents);
|
|
// Inventory items in the player's own inventory (worn, in the main pack
|
|
// or in a side pack) that have no cached appraisal.
|
|
// Container and Inventory wait until the object is MinAgeMs old, and until
|
|
// DeferMs after a world transition's settle window ends (death, portal,
|
|
// teleport, landblock jump; walking into the next landblock is not one).
|
|
// A container the player opened after that settle window ended is not
|
|
// deferred. Creatures, ground items, other players: never.
|
|
// Off nothing, the selected target included.
|
|
// Plugins calling the host RequestId are not limited by any of this.
|
|
//
|
|
// Pure: no engine state, no locking. Compiled into tools\EngineRobustnessTests and
|
|
// tools\EngineSettingsTests.
|
|
// ============================================================================
|
|
|
|
using System;
|
|
|
|
namespace RynthCore.Engine.Compatibility;
|
|
|
|
/// <summary>engine.json "AutoIdMode" (see <see cref="AutoIdPolicy"/>).</summary>
|
|
internal enum AutoIdMode { All = 0, Limited = 1, Off = 2 }
|
|
|
|
internal static class AutoIdPolicy
|
|
{
|
|
public const AutoIdMode DefaultMode = AutoIdMode.Limited;
|
|
|
|
/// <summary>Container and Inventory appraisals wait until the object is this old.</summary>
|
|
public const long MinAgeMs = 2_000;
|
|
|
|
/// <summary>Container and Inventory appraisals wait this long after a transition's settle window ends.</summary>
|
|
public const long DeferMs = 30_000;
|
|
|
|
public enum Class
|
|
{
|
|
/// <summary>The selected target (the priority path).</summary>
|
|
Target,
|
|
/// <summary>In the container the player has open now.</summary>
|
|
Container,
|
|
/// <summary>In the player's own inventory (worn, main pack, side pack).</summary>
|
|
Inventory,
|
|
/// <summary>Anything else the client knows where it is: a creature, a ground item, another player.</summary>
|
|
World,
|
|
/// <summary>Not in the engine's object snapshot yet (created moments ago), so its place is unknown.</summary>
|
|
Unknown,
|
|
}
|
|
|
|
public enum Verdict
|
|
{
|
|
/// <summary>Appraise it now.</summary>
|
|
Send,
|
|
/// <summary>The mode does not appraise this: drop it.</summary>
|
|
SkipMode,
|
|
/// <summary>Too young: keep it and ask again later.</summary>
|
|
WaitAge,
|
|
/// <summary>Inside the post-transition defer: keep it and ask again later.</summary>
|
|
WaitDefer,
|
|
/// <summary>Its appraisal is cached (fresh): drop it.</summary>
|
|
SkipFresh,
|
|
}
|
|
|
|
/// <summary>
|
|
/// The decision for one candidate.
|
|
/// <paramref name="ageMs"/>: how long the object has existed (or since it moved, for a move).
|
|
/// <paramref name="inDefer"/>: inside the post-transition defer window (<see cref="InDefer"/>).
|
|
/// <paramref name="openedAfterSettle"/>: Container only, the player opened it after the last
|
|
/// settle window ended (<see cref="OpenedAfterSettle"/>), which exempts it from the defer.
|
|
/// <paramref name="fresh"/>: its appraisal is cached and recent (Target, Container).
|
|
/// <paramref name="cached"/>: its appraisal is cached at all (Inventory).
|
|
/// </summary>
|
|
public static Verdict Decide(AutoIdMode mode, Class cls, long ageMs, bool inDefer, bool openedAfterSettle,
|
|
bool fresh, bool cached)
|
|
{
|
|
switch (mode)
|
|
{
|
|
case AutoIdMode.Off:
|
|
return Verdict.SkipMode;
|
|
|
|
case AutoIdMode.All:
|
|
// The old behaviour: the create-time eligibility already decided; only the
|
|
// selected target has the fresh-cache skip.
|
|
if (cls == Class.Target && fresh) return Verdict.SkipFresh;
|
|
return Verdict.Send;
|
|
|
|
default: // Limited
|
|
switch (cls)
|
|
{
|
|
case Class.Target:
|
|
return fresh ? Verdict.SkipFresh : Verdict.Send;
|
|
case Class.Container:
|
|
if (fresh) return Verdict.SkipFresh;
|
|
if (ageMs < MinAgeMs) return Verdict.WaitAge;
|
|
if (inDefer && !openedAfterSettle) return Verdict.WaitDefer;
|
|
return Verdict.Send;
|
|
case Class.Inventory:
|
|
if (cached) return Verdict.SkipFresh;
|
|
if (ageMs < MinAgeMs) return Verdict.WaitAge;
|
|
if (inDefer) return Verdict.WaitDefer;
|
|
return Verdict.Send;
|
|
case Class.Unknown:
|
|
// Its place shows up in the snapshot within a tick or two; until it is
|
|
// MinAgeMs old it may still turn out to be in the open container or the pack.
|
|
return ageMs < MinAgeMs ? Verdict.WaitAge : Verdict.SkipMode;
|
|
default: // World
|
|
return Verdict.SkipMode;
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inside the post-transition defer: in a transition now, or less than <see cref="DeferMs"/>
|
|
/// after the last settle window ended. <paramref name="settleUntilMs"/> is
|
|
/// WorldTransitionState.SettleUntilMs (0 = no transition yet); it only moves on a death,
|
|
/// a portal, a teleport or a landblock jump, never on a walk into the next landblock.
|
|
/// </summary>
|
|
public static bool InDefer(long nowMs, long settleUntilMs, bool inTransition) =>
|
|
inTransition || (settleUntilMs > 0 && nowMs < settleUntilMs + DeferMs);
|
|
|
|
/// <summary>The player opened the container (at <paramref name="openedAtMs"/>) after the last settle window ended.</summary>
|
|
public static bool OpenedAfterSettle(long openedAtMs, long settleUntilMs) =>
|
|
openedAtMs > 0 && openedAtMs >= settleUntilMs;
|
|
|
|
/// <summary>
|
|
/// Where an object is, from its PublicWeenieDesc ownership fields (<paramref name="known"/> =
|
|
/// the snapshot had it). <paramref name="containerParent"/> is the container's own container
|
|
/// (a side pack's owner), 0 when unknown or none. <paramref name="openContainer"/> is the
|
|
/// container the player has open now (0 = none).
|
|
/// </summary>
|
|
public static Class Classify(bool known, uint playerId, uint openContainer,
|
|
uint container, uint wielder, uint containerParent)
|
|
{
|
|
if (!known) return Class.Unknown;
|
|
if (playerId != 0 && (container == playerId || wielder == playerId || (container != 0 && containerParent == playerId)))
|
|
return Class.Inventory;
|
|
// openContainer != 0 also keeps a ground item (container 0) out of here.
|
|
if (openContainer != 0 && (container == openContainer || containerParent == openContainer))
|
|
return Class.Container;
|
|
return Class.World;
|
|
}
|
|
|
|
public static bool TryParseMode(string? text, out AutoIdMode mode)
|
|
{
|
|
switch ((text ?? "").Trim().ToLowerInvariant())
|
|
{
|
|
case "all": mode = AutoIdMode.All; return true;
|
|
case "limited": case "limit": mode = AutoIdMode.Limited; return true;
|
|
case "off": case "none": mode = AutoIdMode.Off; return true;
|
|
default: mode = DefaultMode; return false;
|
|
}
|
|
}
|
|
|
|
public static string Name(AutoIdMode mode) => mode switch
|
|
{
|
|
AutoIdMode.All => "all",
|
|
AutoIdMode.Off => "off",
|
|
_ => "limited",
|
|
};
|
|
}
|