Table of Contents

Class IngressGuard

Namespace
FishMMO.Server.Core
Assembly
FishMMO.Server.dll

Reusable per-connection, per-operation debounce and in-flight guard. Eliminates duplicated ingress-guard boilerplate across server systems. Thread-safe: backed by ConcurrentDictionary for cross-thread access.

public sealed class IngressGuard
Inheritance
IngressGuard
Inherited Members

Constructors

IngressGuard()

Initializes a new instance of the IngressGuard class.

public IngressGuard()

Methods

Clear()

Clears all tracked entries. Safe to call during shutdown.

public void Clear()

End(long)

Releases the in-flight lock for the given guard key. Call in a finally block.

public void End(long guardKey)

Parameters

guardKey long

Sweep(float, float, int)

Bounded sweep of stale ingress entries. Call once per frame or at a configured interval.

public void Sweep(float sweepIntervalSeconds, float entryTtlSeconds, int maxRemovals)

Parameters

sweepIntervalSeconds float

Minimum seconds between sweep passes.

entryTtlSeconds float

Entries older than this are considered stale.

maxRemovals int

Maximum entries to remove per sweep pass.

TryBegin(int, byte, int, out long, int)

Attempts to acquire the ingress guard for the given connection and operation. Returns false if debounce is active, the tracker is saturated, or an operation is already in-flight. Debounce timestamp is only updated AFTER a successful in-flight acquisition, preventing unintended sliding-window extension on rejected requests.

public bool TryBegin(int connectionId, byte operation, int debounceMilliseconds, out long guardKey, int globalRateMilliseconds = 0)

Parameters

connectionId int

Network connection identifier.

operation byte

Operation code (cast your enum to byte).

debounceMilliseconds int

Minimum milliseconds between requests for this key.

guardKey long

Output guard key to pass to End() in a finally block.

globalRateMilliseconds int

Optional global per-connection rate (0 = disabled). Uses operation 0 key.

Returns

bool

True if the guard was acquired; false if the request should be rejected.