Leaky bucket rate limiter

I am trying to implement a way to keep exploiters from firing their guns faster than the base fire rate that is in place for them.

I’ve been searching for a solution for a while now that accounts for latency.

I came across the leaky bucket method but my small mind fails to wrap my head around how exactly it works.

I have looked at several posts by now but I have failed to put 2 and 2 together.

if someone would give a brief and simple explanation on how it works and how I could go about writing it, much would be greatly appreciated.

Could you send what you found here?

A good way to think of it is as follows:

When the server receives a request, it increments a counter. If this counter goes above a max specified value, the request is ignored.
Then, every X seconds (where you specify this time), you decrease the counter by 1.

This is analogous to a leaky bucket, where the counter is the height of water in the bucket, and a hole in the bottom of the bucket slowly drains the water. When the bucket gets too much water, the overflow is just ignored and doesn’t change the height of water in the bucket.

This might require some tuning to adjust to your gun’s firerate, but should work in general.

9 Likes

Thanks for the reply, should I keep the counter from decreasing too low? For example the counter can’t decrease to anything lower then 0.

If all the weapons are automatic, you can simply have the client say “I want to start shooting” and “I want to stop shooting”…

1 Like

Yes, just like how the minimum height of water in a bucket is 0 ( i.e. an empty bucket)