Class ChatFloodMute
- Namespace
- FishMMO.Server.Implementation.World.SceneServer
- Assembly
- FishMMO.Server.dll
The escalation from refused chat lines to a temporary mute: a sender whose lines the rate gate refuses too often within a short window is muted for a few minutes.
public static class ChatFloodMute
- Inheritance
-
ChatFloodMute
- Inherited Members
Remarks
ChatRateGate already bounds what any sender can put through, so a flood costs nobody else anything. It was silent, though: a flooding client kept hammering the gate for as long as it liked and was never told, and the lines it did get through — one a second at the default refill — kept arriving in everybody's chat. Past a threshold the sender is muted and told why, with a system line.
Counted from refusals, not from lines. An honest player is refused now and then: two short lines typed inside the minimum gap, or several delivered at once after a network stall — a few, once. The threshold sits well above that: at the defaults, ten refusals within ten seconds takes a client sending twice the sustained rate for ten seconds once its burst is spent, or anything much faster for about a second.
The window opens at the first refusal and closes a fixed time later; a refusal after it has closed opens a new one. Reaching the threshold mutes the sender and empties the window, so a sender who goes on flooding while muted reaches it again and the mute is pushed out from then: the mute ends a full term after the flooding stops.
Monotonic seconds. A duration measured on the wall clock ends early or late when the
host clock is stepped (see FishMMO.Server.Core.MonotonicClock). This is never
compared with anything outside the process, so the process clock is the right one.
Pure, so the rule can be pinned by a test without a character, a connection or a server. ChatSystem holds one ChatFloodMute.State per character that has been refused.
Methods
DescribeForPlayer(double, double)
The system line a flood-muted sender is shown: when the mute starts, and for each line refused while it lasts.
public static string DescribeForPlayer(double mutedUntilSeconds, double nowSeconds)
Parameters
mutedUntilSecondsdoubleMonotonic seconds the mute ends at.
nowSecondsdoubleMonotonic seconds now.
Returns
- string
The line; well inside
ChatBroadcast.MaxTextLength.
Remarks
Says why and for how long, and that commands still work: a player refused with no reason types the line again, and one who is not told they can still file a ticket has no way to ask. The remaining time is rounded up, so the first line of a three-minute mute says three minutes and not two.
IsMuted(State, double)
Whether a sender is flood-muted now.
public static bool IsMuted(ChatFloodMute.State state, double nowSeconds)
Parameters
stateChatFloodMute.StateThe sender's flood state.
nowSecondsdoubleMonotonic seconds now.
Returns
- bool
True while the mute has time left.
IsSpent(State, double, double)
Whether a sender's flood state has nothing left to remember, so it can be dropped.
public static bool IsSpent(ChatFloodMute.State state, double nowSeconds, double windowSeconds)
Parameters
stateChatFloodMute.StateThe sender's flood state.
nowSecondsdoubleMonotonic seconds now.
windowSecondsdoubleThe window's length.
Returns
- bool
True when the sender is not muted and no window is open.
RecordRefusal(ref State, double, int, double, double)
Records one line refused by the rate gate.
public static ChatFloodMute.Outcome RecordRefusal(ref ChatFloodMute.State state, double nowSeconds, int threshold, double windowSeconds, double muteSeconds)
Parameters
stateChatFloodMute.StateThe sender's flood state; updated in place.
nowSecondsdoubleMonotonic seconds now.
thresholdintRefusals within the window that mute. Zero or less disables the flood mute.
windowSecondsdoubleThe window's length. Zero or less disables the flood mute.
muteSecondsdoubleHow long a mute lasts. Zero or less disables the flood mute.
Returns
- ChatFloodMute.Outcome
What the refusal did.