[Include] FloodControl.inc ─ Easily block flood bots
#1

Introduction

I saw JernejL's topic about blocking flood bots and read this comment:
Quote:
Originally Posted by JernejL
Посмотреть сообщение
Anyways, i post snippets.. i'm hoping someone of you will turn this into a filterscript that reads a flood limit number off a cfg file and enables people to easily set up flood control.
So I decided to quickly create a simple include which makes it very easy to manage everything.

Functions

We have only one callback:
pawn Код:
forward OnPlayerFloodControl(playerid, iCount, iTimeSpan);
And two defines:
pawn Код:
#if !defined MAX_JOIN_LOGS
    #define MAX_JOIN_LOGS (50)
#endif
pawn Код:
#if !defined MAX_THRESHOLD
    #define MAX_THRESHOLD (8000) // The amount of time in which all joins are valid and counted
#endif
Your custom values will be applied once you set these values before including it.

Example

The following example will IP-Ban the player/bot that joined more than 2 times in a time span of less then 8 seconds:
pawn Код:
#include <a_samp>
#include <FloodControl>

public OnPlayerFloodControl(playerid, iCount, iTimeSpan) {
    if(iCount > 2 && iTimeSpan < 8000) {
        Ban(playerid);
    }
}

public OnPlayerConnect(playerid) {
    return 1;
}
You can customize it like however you want it.

Download

FloodControl.inc

Changelog
  • 24/02/2012:
    • Initial release
  • 28/06/2012:
    • Fixed an important bug where the timespan gets messed up if you first join, wait a bit, and then spam.
    • Fixed the hooking method.
    • Added:
      pawn Код:
      #if !defined MAX_THRESHOLD
          #define MAX_THRESHOLD (8000) // The amount of time in which all joins are valid and counted
      #endif
      This was important to fix the first bug.
Reply
#2

Exelent ryder, this is great, great work.
Reply
#3

LoL another flood control i just seen Jernejl's Flood control one :O
And press back button and seen urs lol
Nice
Reply
#4

GJ and thank you
Reply
#5

Nice release And do you mind if i use it in my cPanel ?
Reply
#6

Thanks!

Quote:
Originally Posted by Niko_boy
Посмотреть сообщение
LoL another flood control i just seen Jernejl's Flood control one :O
And press back button and seen urs lol
Nice
Hmm, let me think... What about reading the first post?


Quote:
Originally Posted by Michael@Belgium
Посмотреть сообщение
Nice release And do you mind if i use it in my cPanel ?
Sure, you can use it like however you want it.
Reply
#7

Just tested and it works brilliant, thanks.
Reply
#8

Wow thats so nice i will update my server because i was so annoyed with those bunch of bots!
Reply
#9

"rcon 0"

That would work as well.
Reply
#10

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
"rcon 0"

That would work as well.
What do you mean?
Reply
#11

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
"rcon 0"

That would work as well.
That secures from Rcon flooders, not bot connects.

Anyway, RyDeR`, do you think 3 connects per 10 seconds is surely a bot? I mean, people could have a few pc's in their houses, and connect with them at ~the same time.
Reply
#12

Quote:
Originally Posted by Lorenc_
Посмотреть сообщение
"rcon 0"

That would work as well.
No, you're confusing RCON flood with bots connecting to a server like normal players.

Quote:
Originally Posted by wups
Посмотреть сообщение
Anyway, RyDeR`, do you think 3 connects per 10 seconds is surely a bot? I mean, people could have a few pc's in their houses, and connect with them at ~the same time.
Sure, that's possible, but that's just an example. You could add a few more if blocks containing different criteria under the callback.
Reply
#13

Okay, I checked out your hooking method, and it needs some adjustments.
For example, if I don't have OnPlayerConnect callback(which is a rare case), then funcidx will keep repeating every time(and we know, that the callback won't magically appear).
That's just a minor thing you should look up in future developments.

I'm using this include for sure. Thanks.
Reply
#14

Can you post the download of the .inc file not pastebin thanks.
Reply
#15

Quote:
Originally Posted by Translator
Посмотреть сообщение
Can you post the download of the .inc file not pastebin thanks.
There is a download link.
http://pastebin.com/download.php?i=FxS1CyX5
Reply
#16

Quote:
Originally Posted by wups
Посмотреть сообщение
Okay, I checked out your hooking method, and it needs some adjustments.
For example, if I don't have OnPlayerConnect callback(which is a rare case), then funcidx will keep repeating every time(and we know, that the callback won't magically appear).
That's just a minor thing you should look up in future developments.

I'm using this include for sure. Thanks.
Will check it out.
Reply
#17

Important update! Please re-download and recompile your gamemode as soon as possible if you're using this and care about security. Check changelog for more information.

Quote:
Originally Posted by ******
Посмотреть сообщение
pawn Код:
if(iHasOPC == -1) {
        iHasOPC = funcidx("FC_OnPlayerConnect");
    }
    if(iHasOPC != -1) {
        return CallLocalFunction("FC_OnPlayerConnect", "i", playerid);
    }
That code will call "funcidx" every time "OnPlayerConnect" is called if there is no other callback, entirely negating the point of using that hook method.
I remember wups making me aware of this a while ago in the previous page, but for some reason I forgot to check it out.

Quote:
Originally Posted by ******
Посмотреть сообщение
There is also a bug in your period check code - you don't take the "g_eaJoinLog" overflow in to account when looking for the first connection from an IP. The first connection could actually be later in the array than the current one, but you always start checking from the start of the array; possibly giving a much higher time span than is actually involved.
Should be fixed now.

Quote:
Originally Posted by ******
Посмотреть сообщение
And your code is very hard to read given your re-use of poorly named variables. Why is "iTimeSpan" "szIP[2]" in the "OnPlayerConnect" code? How does that relate in any way?
Well, instead of recreating variables, I'm just re-using them, that's why it's a bit harder to read. Also szIP[2] contains the total time of the amount of joins, what's wrong with that?
Reply
#18

Quote:
Originally Posted by ******
Посмотреть сообщение
I'm also not sure why you're using float maths in the first place...
Because I need the absolute value between the two timestamps and we have no native "abs" function for integers.
Reply
#19

Quote:
Originally Posted by ******
Посмотреть сообщение
pawn Код:
abs(a)
{
    return (a < 0) ? (-a) : (a);
}
Well I know, I just didn't want to implement it. What's wrong floatabs and floatround anyway?
Reply
#20

Agreed with the slowness, but in this case, it's not inaccurate at all!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)