diff --git a/gamemodes/irresistible/anticheat/_anticheat.pwn b/gamemodes/irresistible/anticheat/_anticheat.pwn index 8014a0c..0825fd7 100644 --- a/gamemodes/irresistible/anticheat/_anticheat.pwn +++ b/gamemodes/irresistible/anticheat/_anticheat.pwn @@ -158,6 +158,7 @@ stock AC_SetPlayerSpawned( playerid, bool: spawned ) { /* ** Modules (remove to disable) ** */ #include "irresistible\anticheat\money.pwn" +#include "irresistible\anticheat\bot_attack.pwn" #include "irresistible\anticheat\hitpoints.pwn" #include "irresistible\anticheat\weapon.pwn" #include "irresistible\anticheat\carmod_checker.pwn" diff --git a/gamemodes/irresistible/anticheat/bot_attack.pwn b/gamemodes/irresistible/anticheat/bot_attack.pwn new file mode 100644 index 0000000..197342a --- /dev/null +++ b/gamemodes/irresistible/anticheat/bot_attack.pwn @@ -0,0 +1,57 @@ +/* + * Irresistible Gaming (c) 2018 + * Developed by Lorenc Pekaj + * Module: anticheat\bot_attack.pwn + * Purpose: mitigates bot attacks with random IP addresses + */ + +/* ** Includes ** */ +#include < YSI\y_hooks > + +/* ** Constants ** */ +static const BOT_ATTACK_BLOCK_TIME = 120000; // 2 minutes + +/* ** Variables ** */ +static stock botattack_ServerInitTS = 0; +static stock botattack_LastConnection = 0; +static stock botattack_ConnectionSpamCount = 0; + +/* ** Hooks ** */ +hook OnScriptInit( ) +{ + botattack_ServerInitTS = gettime( ); + return 1; +} + +hook OnIncomingConnection( playerid, ip_address[ ], port ) +{ + // block id if invalid player ID ... otherwise our bots go + if ( ! ( 0 <= playerid < MAX_PLAYERS ) ) { + BlockIpAddress( ip_address, BOT_ATTACK_BLOCK_TIME ); + } + + new + current_time = gettime( ); + + // script will only work if the server is online for more than 5 minutes + if ( current_time - botattack_ServerInitTS >= 300 ) + { + // if the last connection was within 2 seconds + if ( current_time - botattack_LastConnection <= 2 ) + { + // and we had more than 5 connections in this interval + if ( ++ botattack_ConnectionSpamCount >= 5 ) + { + BlockIpAddress( ip_address, BOT_ATTACK_BLOCK_TIME ); + return 1; + } + } + else + { + botattack_ConnectionSpamCount = 0; + } + + botattack_LastConnection = current_time; + } + return 1; +} diff --git a/gamemodes/irresistible/security.pwn b/gamemodes/irresistible/security.pwn index 694a7f7..3005998 100644 --- a/gamemodes/irresistible/security.pwn +++ b/gamemodes/irresistible/security.pwn @@ -119,8 +119,9 @@ hook OnPlayerDisconnect( playerid, reason ) #if defined DEBUG_MODE // aims to clear the banned from the server bug - public OnIncomingConnection( playerid, ip_address[ ], port ) { + hook OnIncomingConnection( playerid, ip_address[ ], port ) { SendRconCommand( "reloadbans" ); + return 1; } #endif