Prevent instability and crash due to message flood #3510
This patch adds a rate limiting to selected patches. The underlying rate limiter
For now its set to a burst of 30 allowed messages and a subsequent limit of 4 messages per second, which seems to do the trick without inconveniencing normal users.
It should to some extend prevent the recent issues with bots decribed in #3505.
What was tested with the patch:
I'm thanking the Zom.bi community for testing and @Natenom for some insight into the problem.
I'm open to any suggestions.
Qt 4 builds failing because:
In file included from /usr/include/c++/4.8/chrono:35:0, from ./ServerUser.h:17, from ../ACL.cpp:14: /usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. #error This file requires compiler and library support for the \ ^
MinGW builds failing because:
ServerUser.h:106:36: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] bool limit = this->currentTokens > (MAX_TOKENS - tokens); ^
Alright, I can work with that. The first problem should be fixable by relying on pre-C++11 means to measure time if the software is not build using at least a C++11 compiler, unless we can have this as a requirement for building.
The second problem I didn't have, but it is easily fixable.
This patch adds a rate limiting to selected patches. The underlying rate limiter used is the Leaky-Bucket algorithm. It allows for a burst of messages, but limits them after a specified amount of messages within a time frame.
I separated the now and millisecondsBetween methods from the LeakyBucket class, as they were neither operating directly on the object nor public. And I added static inline to each to encourage the compile to inline them.
Also I moved a comment.
Please look at it again to see if you're okay with that.