Table of Contents

Class ChatRateGate

Namespace
FishMMO.Server.Implementation.World.SceneServer
Assembly
FishMMO.Server.dll

The per-sender chat rate rule: a token bucket, then a minimum gap between messages.

public static class ChatRateGate
Inheritance
ChatRateGate
Inherited Members

Remarks

A pure function over the sender's four rate fields, so the rule can be pinned by a test without a character, a connection or a server. ChatSystem copies the fields off the character, charges, and copies them back.

On the monotonic clock. The ticks are MonotonicClock.NowTicks, not the message's legal receipt stamp: a bucket and a gap are local durations, and on the wall clock a host stepped back refused every sender for the size of the step. A character's fields start at zero, which reads as "never", whatever the clock.

Charged when a message is queued, not when it is processed. The incoming queue used to take everything a client sent and charge the bucket only as the queue drained, so the queue's size bounded nothing any one sender did. Its global cap then kicked whichever connection happened to push it over — after a one-second main-thread hitch with a hundred busy players, the next honest player to type (hot-path audit L2). Charged at the door, a sender can occupy the queue only at the rate the bucket allows, so the cap is reached by many honest senders at once or not at all, and nobody is kicked for it.

Methods

TryCharge(ref State, long, int, double, double)

Charges one message against state.

public static bool TryCharge(ref ChatRateGate.State state, long nowTicks, int capacity, double refillPerSecond, double minimumGapMilliseconds)

Parameters

state ChatRateGate.State

The sender's rate state; updated in place.

nowTicks long

Monotonic ticks as the message was received.

capacity int

Bucket capacity: the burst a sender may send. Zero or less disables the bucket.

refillPerSecond double

Tokens returned per second. Zero or less disables the bucket.

minimumGapMilliseconds double

Minimum gap between messages. Zero or less disables it.

Returns

bool

True if the message may be sent.

Remarks

The token is spent before the gap is tested, as it always was: a message refused by the gap still cost its token. A bucket marked full is filled on the first message whatever the elapsed time; it used to be filled only when some time had passed since the last refill, which in the same tick left a new character's first message refused against an empty bucket it had been told was full.