Table of Contents

Class ExpiringKeyTracker<TKey>

Namespace
FishMMO.Auth.Core.Collections
Assembly
FishMMO-ServerAuth.dll

Queue/index tracker for expiring keyed entries. Uses head-first sweeps to avoid full dictionary enumeration under heavy load.

public sealed class ExpiringKeyTracker<TKey>

Type Parameters

TKey

Tracker key type.

Inheritance
ExpiringKeyTracker<TKey>
Inherited Members

Remarks

Time is monotonic seconds — a MonotonicClock.NowSeconds reading from the authenticator's clock, never DateTime.UtcNow. A debounce is a duration, and on the host's wall clock a step backwards held every recently seen key inside its window for the size of the step (an account refused for two seconds was refused for an hour), while a step forward opened every window at once. The tracker only compares the readings it is given with one another, so the clock's origin does not matter.

There is deliberately no DateTime overload. The game server's copy of this class still carries one for callers outside authentication, and one tracker driven through both compared unrelated numbers; this copy's callers are all in the authenticator and all on the one clock, so the choice cannot be made wrongly here.

Constructors

ExpiringKeyTracker(IEqualityComparer<TKey>?)

Initializes a new tracker with an optional key comparer.

public ExpiringKeyTracker(IEqualityComparer<TKey>? comparer = null)

Parameters

comparer IEqualityComparer<TKey>

Properties

Count

Current number of tracked keys.

public int Count { get; }

Property Value

int

Methods

Clear()

Clears all tracked entries.

public void Clear()

SweepExpired(double, int, int)

Sweeps expired keys with bounded scan and removal limits.

public int SweepExpired(double nowSeconds, int maxScan, int maxRemove)

Parameters

nowSeconds double

Current monotonic time in seconds.

maxScan int

Maximum queue nodes to inspect this sweep.

maxRemove int

Maximum keys to remove this sweep.

Returns

int

Number of entries removed.

TryBegin(TKey, double, TimeSpan)

Attempts to begin a debounce/rate-limit window for a key.

public bool TryBegin(TKey key, double nowSeconds, TimeSpan duration)

Parameters

key TKey

Tracker key.

nowSeconds double

Current monotonic time in seconds.

duration TimeSpan

Window duration.

Returns

bool

true if allowed now; otherwise false.