[Include] OnFloodDetected
#1

OnFloodDetected

Introduction
Since I like releasing includes that introduce new and useful callbacks, I came up with this small but useful include which detects all types of flooding (connection flooding, chat and command flooding too).

This include has been updated. Now it won't crash the server when a player with an invalid name joins (con, lpt1, com1, etc).

How it works
The connection flooding detection works by detecting the amount of connections from the same IP during a short interval of time. If the number of connections exceed MAX_IP_CONNECTIONS, the OnFloodDetected callback is called.

This does not include NPC connections. I've tested it on my VPS with a bot tool and it works.

Callback
There is one callback only:

pawn Код:
public OnFloodDetected(playerid, ip[], type)
{
    return 1;
}
playerid is the ID of the last player who connected.
ip[] is the IP address of the player.
type is the type of flooding method used.

To kick all of the players that have the same IP address as ip[] then do this:

pawn Код:
public OnFloodDetected(playerid, ip[], type)
{
    if (type == FLOOD_TYPE_CONNECT)
    {
        KickIP(ip);
    }
    return 1;
}
Or use BanIP(ip); to ban the players instead.

Here are a list of types associated with this callback:

FeatureDescription
FLOOD_TYPE_CONNECTThis type is used when a specified number of IP's connect under the time interval.
FLOOD_TYPE_CHATThis type is used when a specified number of chats are sent under the time interval.
FLOOD_TYPE_COMMANDThis type is used when a specified number of commands are executed under the time interval
Instructions
To install it on your server, simply add:

pawn Код:
#include <OFD>
At the top of the script (preferably under a_samp).

To adjust the TIME_INTERVAL then do this:

pawn Код:
#define TIME_INTERVAL (2000) // 2000 milliseconds = 2 seconds!
#include <OFD>
Or the maximum number of connections per IP address:

pawn Код:
#define MAX_IP_CONNECTIONS (5)
#include <OFD>
There is also FLOOD_CHAT_LIMIT and FLOOD_CMD_LIMIT - for limiting the amount of chats sent or commands executed under the time interval by a single player.

Downloads
Pastebin
Solidfiles
Reply
#2

Really explicit, very good, though his missions might get improved, but it is excellent.

It will serve many.
Reply
#3

Quote:
Originally Posted by EnzoMetlc
Посмотреть сообщение
Really explicit, very good, though his missions might get improved, but it is excellent.

It will serve many.
Emmet might have boring single player missions, but he has some good things to release nowadays. And thanks :D.
Reply
#4

Nice one... I like your filter-scripts... There all very nice.
Reply
#5

there's y_flood for this o_O
Reply
#6

Was really good.
Reply
#7

I would like to ask you to make a OnPlayerShoot(); include wait.... I have one.... Ok Emmetize this.

pawn Код:
#include <YSI\y_hooks>

forward OnPlayerShoot(playerid,weaponid,ammo);

static OldAmmo[MAX_PLAYERS], OldWeap[MAX_PLAYERS], CurrAmmo[MAX_PLAYERS], CurrWeap[MAX_PLAYERS];

hook OnPlayerUpdate(playerid)
{
    // Get the current weapon and ammo
    CurrWeap[playerid] = GetPlayerWeapon(playerid);
    CurrAmmo[playerid] = GetPlayerAmmo(playerid);
   
    // Player still has old weapon does this weapon now have less ammo?
    if(CurrWeap[playerid] == OldWeap[playerid] && CurrAmmo[playerid] < OldAmmo[playerid])
    {
        CallLocalFunction( "OnPlayerShoot", "iii", playerid, CurrWeap[playerid], CurrAmmo[playerid]);
    }
    OldWeap[playerid] = CurrWeap[playerid];
    OldAmmo[playerid] = CurrAmmo[playerid];
    return 1;
}
Reply
#8

More great work from Emmet, nice work!
Reply
#9

vary good 8/10
Reply
#10

Quote:
Originally Posted by Sublime
Посмотреть сообщение
there's y_flood for this o_O
I was actually planning to add support for y_flooding functions (e.g. instead of MAX_IP_CONNECTIONS you can use SetMaxConnections) although this is a callback so you can take action against the IP (and I might need permission from ****** first so I can add y_flooding integration).

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
I would like to ask you to make a OnPlayerShoot(); include wait.... I have one.... Ok Emmetize this.

pawn Код:
code
I was actually thinking about the exact same callback last night!

*Emmet gets to work*
Reply
#11

Alright, version 2 has been released:

The server won't crash anymore when a player with an invalid name joins (con, lpt1, com1, etc).
Reply
#12

pawn Код:
if (length == 3 || length == 4) // ???????
"CLOCK$" 6 characters!
Reply
#13

Quote:
Originally Posted by smeti
Посмотреть сообщение
pawn Код:
if (length == 3 || length == 4) // ???????
"CLOCK$" 6 characters!
Fixed, thanks
Reply
#14

OnFloodDetected what? Text, joining/disconnecting from the server, specific keys/features? This include either deserves the name OnConnectingFloodDetected or you should improve the code to make it fit it's name even more.
Reply
#15

Quote:
Originally Posted by Biesmen
Посмотреть сообщение
OnFloodDetected what? Text, joining/disconnecting from the server, specific keys/features? This include either deserves the name OnConnectingFloodDetected or you should improve the code to make it fit it's name even more.
It only detects mass connection from the same IP (which is the most popular way amongst flooding), however I plan on adding more features such as text flooding and stuff.

Might consider doing this:

pawn Код:
public OnFloodDetected(playerid, ip[], type)
{
    if (type == FLOOD_TYPE_CONNECT)
    {
        ...
    }
    else if (type == FLOOD_TYPE_CHAT)
    {
        ...
    }
    else if (type == FLOOD_TYPE_BLABLA)
    {
        ...
    }
    return 1;
}
Reply
#16

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
It only detects mass connection from the same IP (which is the most popular way amongst flooding), however I plan on adding more features such as text flooding and stuff.

Might consider doing this:

pawn Код:
public OnFloodDetected(playerid, ip[], type)
{
    if (type == FLOOD_TYPE_CONNECT)
    {
        ...
    }
    else if (type == FLOOD_TYPE_CHAT)
    {
        ...
    }
    else if (type == FLOOD_TYPE_BLABLA)
    {
        ...
    }
    return 1;
}
That will make this include's name fulfill it's name! Awesome =)
Reply
#17

Quote:
Originally Posted by Biesmen
Посмотреть сообщение
That will make this include's name fulfill it's name! Awesome =)
Or you could simply use switch statement, I believe it's faster than if( ... )

pawn Код:
public OnFloodDetected(playerid, ip[], type)   
{    
    switch( type )
    {
        case FLOOD_TYPE_CONNECT:           
        {        
            ...    
        }
        case FLOOD_TYPE_CHAT:
        {      
            ...    
        }    
        case FLOOD_TYPE_BLABLA:
        {
            ...
        }
    }
    return true;
}
Reply
#18

Include updated with several new types, please read the first post for more info. Thanks to Biesmen for the suggestions!

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
Or you could simply use switch statement, I believe it's faster than if( ... )

pawn Код:
public OnFloodDetected(playerid, ip[], type)   
{    
    switch( type )
    {
        case FLOOD_TYPE_CONNECT:           
        {        
            ...    
        }
        case FLOOD_TYPE_CHAT:
        {      
            ...    
        }    
        case FLOOD_TYPE_BLABLA:
        {
            ...
        }
    }
    return true;
}
With if and switch, speed isn't really an issue, it's all about good structuring and organization.
Reply
#19

An outstanding work, unfortunately it won't work for sscanf command engine.
Reply
#20

Quote:
Originally Posted by CriticalRP
Посмотреть сообщение
An outstanding work, unfortunately it won't work for sscanf command engine.
You mean zcmd/y_commands? Yeah, this include should support it, it worked for one of my zcmd scripts .
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)