I am making several classes for an IRC bot with PHP. The bot will ideally be a channel protective bot to kick and ban offenders.
Now, I have a good idea on how to do most things (swear words match, all caps, etc). But the most important things are the flood controls.
I want to see if a user types, let’s say, 5 lines of text in 3 seconds, or if the user inputted over 220 bytes of text in under 3 seconds, the bot will take action. This all of course is received in sockets, which I’m not very sharp at.
Examples:
Lines flood
[11:17:00] <user1> Hey!
[11:17:00] <user1> Hey!
[11:17:00] <user1> Hey!
[11:17:11] <user1> Hey!
[11:17:11] <user1> SPAAAAAACE!
*Line flood detected!*
Byte flood
[11:17:00] <user1> Hey! this is a very long long text.
[11:17:00] <user1> and I pasted it from a file or something so that these lines all occur one after another with 0 time
[11:17:00] <user1> This should be considered a byte flood since it's so very looooooooooooooong.
*byte flood detected overall counted bytes in the last 3 seconds from user1 is too much*
So the question: How can count if a certain input had occurred X time in Y seconds, and also how can I count if another certain input was X bytes (accumulative) was sent under Y seconds?
My code is similar socket-wise to the one Here
If you want to calculate sums over size and time, you need first of all to store the related data you want to make the calculations with.
For example, each time a user types something:
To keep the example simple, I’m using an array. If you want to also track repetition, you need to store the data entered as well / and or compare against the data last entered by a user and see if it is the same.
You can then use this array to calculate the values and check what you’re looking for.
You can also after you made that remove all entries from that array that are older than a minute or so to keep that list small.