SA-MP Forums Archive
[Tutorial] Flood control for sa-mp servers. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+--- Thread: [Tutorial] Flood control for sa-mp servers. (/showthread.php?tid=320614)



Flood control for sa-mp servers. - JernejL - 23.02.2012

pawn Код:
#define foreach(%1,%2) for (new %2 = 0; %2 < sizeof(%1); %2++ )
   
    // Store last X ips, 37 seems to be a perfectly decent and efficiently well rounded number for this purpose.
    #define max_joins_log 37
   
    // Current index @ ipjoinlog in sequence
    new autoinc_join_sequence = 0;
   
    enum core_ipjoin { // struct
        ip_add,
        timestamp
    }
   
    new ipjoinlog[max_joins_log][core_ipjoin]; // last X times and ips of people joining.

stock intabs(innumber) {
   
    if (innumber < 0)
        return -innumber;
   
    return innumber;
}

stock Distance1Dint(fPos1, fPos2) {
   
    if (fPos1 > fPos2)
        return intabs(fPos1 - fPos2);
    else
        return intabs(fPos2 - fPos1);
   
}

// This function manages to properly calculate time even if the timers wrap around and underflow.
stock GetTimeDistance(a, b) {
   
    // a pawn cell is signed 32-bit integer.
    // -2147483648 to 2147483647
   
    if ((a < 0) && (b > 0)) {
       
        new dist;
        dist = Distance1Dint(a, b);
        if (dist > 2147483647)
            return Distance1Dint(a - 2147483647, b - 2147483647);
        else
            return dist;
       
    } else {
       
        return Distance1Dint(a, b);
       
    }
   
}

// please note that this is NOT a perfect inet_aton function, but you will not be able to output the number as a unsigned integer as pawn uses signed int32 only.
// (by specification the returned type of inet_aton should be UNSIGNED int 32)
// example conversion failures:
// 127.0.0.1 -> 2130706433
// 128.68.103.132 -> -2143000700

stock inet_aton(ip[]) {
   
    new ipv = strval(ip) << 24, pos = 0;
   
    while (pos < 15 && ip[pos++] != '.') {}
    ipv += strval(ip[pos]) << 16;
    while (pos < 15 && ip[pos++] != '.') {}
    ipv += strval(ip[pos]) << 8;
    while (pos < 15 && ip[pos++] != '.') {}
    ipv += strval(ip[pos]);
   
    return ipv;
}

stock log_new_join(PlayerID) {
   
    new ip[18];
    GetPlayerIp(PlayerID, ip, sizeof(ip));
    new ipv = inet_aton(ip);
   
    ipjoinlog[autoinc_join_sequence][ip_add]    = ipv;
    ipjoinlog[autoinc_join_sequence][timestamp] = TickCount();
   
    autoinc_join_sequence++;
   
    if (autoinc_join_sequence >= max_joins_log)
        autoinc_join_sequence = 0;
   
}

stock number_joins_time_range(PlayerID, max_time) {
   
    new ip[18];
    GetPlayerIp(PlayerID, ip, sizeof(ip));
   
    new ipv = inet_aton(ip);
    new counted = 0;
   
    foreach(ipjoinlog, I) {
       
        if (ipjoinlog[I][ip_add] != ipv) // different IP.
            continue;
       
        if (GetTimeDistance(TickCount(), ipjoinlog[I][timestamp]) <= max_time)
            counted++;
       
    }
   
    return counted;
}

public OnPlayerConnect(playerid) {
    log_new_join(playerid);
    new intjoins = number_joins_time_range(playerid, 5000);
   
    printf("received player %d with nickname %s and number of joins from same ip in last 5 seconds is %d", playerid, pNickname[playerid], intjoins);
   
    // Now you know how many times the IP has joined in past 5 seconds, now you can do as you please.
    // I suggest a RCON ban as it will block all the join spam and all further attempts to mess with your server further
   
}
I think this should finally show you all how to make flood control and be able to protect against flood bots in a efficient manner.


Re: Flood control for sa-mp servers. - FireCat - 23.02.2012

This looks helpfull, even tho I'll have to re-read it xD


Re: Flood control for sa-mp servers. - Amit_B - 23.02.2012

Nice one! Thanks.


Re: Flood control for sa-mp servers. - Shadow_ - 23.02.2012

I dont want to be the prick that points out a developer and forum admin posted in the wrong section; but... :P

correction; he is neither a developer nor an administrator he is simply a...






Re: Flood control for sa-mp servers. - JernejL - 23.02.2012

I'm not a developer or an admin. i'm a turtle.

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.


Re: Flood control for sa-mp servers. - FireCat - 23.02.2012

Quote:
Originally Posted by Shadow_
Посмотреть сообщение
I dont want to be the prick that points out a developer and forum admin posted in the wrong section; but... :P
Lol I guess your right xD!
PRICK :bbbbbbb


Re: Flood control for sa-mp servers. - Shadow_ - 23.02.2012

Quote:
Originally Posted by FireCat
Посмотреть сообщение
Lol I guess your right xD!
PRICK :bbbbbbb
:P haha


Re: Flood control for sa-mp servers. - tyler12 - 23.02.2012

Nice

Turtle for you


Respuesta: Flood control for sa-mp servers. - Kurama - 23.02.2012

I saw a bot attack with bots that has not the same IP, as if the attacker sends false packets.


Re: Flood control for sa-mp servers. - Lee_Percox - 23.02.2012

haha, I love it how you make this tutorial after our talk on IRC.
Love to a brother! Will definately come in handy


Re: Flood control for sa-mp servers. - Niko_boy - 24.02.2012

:O
Awesome man!!
Really helpful for those pissed off ppl from Bot attacks and fake players |


Re: Flood control for sa-mp servers. - Shadow_ - 24.02.2012

https://sampforum.blast.hk/showthread.php?tid=320649


Re: Flood control for sa-mp servers. - Michael@Belgium - 24.02.2012

Turtle, good job !


Re: Flood control for sa-mp servers. - Marduk_Malverde - 21.03.2012

thanks


Re : Flood control for sa-mp servers. - [M.A]Angel[M.A] - 19.08.2012

Can someone tell me how its works and if it can protect the server from the attacks and bad rcon attempt?