Class RpcRateLimiter
- Namespace
- Unity.Multiplayer.Core
The server's per-sender rate limiter for ToServerAttribute calls: one TokenBucket per (sender, RPC), so a client flooding one RPC is throttled without touching other clients or its other RPCs.
public sealed class RpcRateLimiter
- Inheritance
-
RpcRateLimiter
- Inherited Members
Remarks
The RPC key is any stable string; the adapter uses the declaring type and method name, so the limit is per sender across every entity of that type (spawning more entities buys no extra rate).
Not thread-safe; the adapter calls it from Unity's main thread. Call Forget(ulong) when a client leaves.
Properties
BucketCount
The number of live buckets (one per sender and limited RPC it has called).
public int BucketCount { get; }
Property Value
Methods
Clear()
Drops everything (the session ended).
public void Clear()
Forget(ulong)
Drops every bucket and count for sender (it disconnected).
public void Forget(ulong sender)
Parameters
senderulong
RejectedCount(ulong)
How many calls from sender this limiter has refused since it last forgot the sender.
public long RejectedCount(ulong sender)
Parameters
senderulong
Returns
TryAcquire(ulong, string, double, int, double)
Lets one rpc call from sender through at now, or not.
public bool TryAcquire(ulong sender, string rpc, double ratePerSecond, int burst, double now)
Parameters
senderulongThe calling client id.
rpcstringA stable key for the RPC.
ratePerSeconddoubleThe limit; 0 or less means unlimited (always true, no bucket kept).
burstintThe bucket size; 0 or less means
ratePerSecond(at least 1).nowdoubleThe current time in seconds.
Returns
- bool
True when the call is within the limit.
Exceptions
- ArgumentNullException
rpcis null.