move bot attack code into its own module
This commit is contained in:
parent
e74c80e5c5
commit
d03591a9a2
@ -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"
|
||||
|
57
gamemodes/irresistible/anticheat/bot_attack.pwn
Normal file
57
gamemodes/irresistible/anticheat/bot_attack.pwn
Normal file
@ -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;
|
||||
}
|
@ -1275,52 +1275,6 @@ public OnNpcConnect( npcid )
|
||||
return Kick( npcid ), 1;
|
||||
}
|
||||
|
||||
new g_LastConnection = 0;
|
||||
new g_ConnectionSpamCount = 0;
|
||||
|
||||
public OnIncomingConnection( playerid, ip_address[ ], port ) {
|
||||
|
||||
new player_name[ 24 ];
|
||||
new player_version[ 24 ];
|
||||
new player_ip[ 16 ];
|
||||
new player_ping = GetPlayerPing( playerid );
|
||||
new netstats[ 500 ];
|
||||
new playerserial[ 45 ];
|
||||
|
||||
GetPlayerName( playerid, player_name, sizeof( player_name ) );
|
||||
GetPlayerVersion( playerid, player_version, sizeof( player_version ) );
|
||||
GetPlayerIp( playerid, player_ip, sizeof( player_ip ) );
|
||||
GetPlayerNetworkStats( playerid, netstats, sizeof( netstats ) );
|
||||
gpci( playerid, playerserial, sizeof( playerserial ) );
|
||||
|
||||
if ( ! ( 0 <= playerid < MAX_PLAYERS ) ) {
|
||||
BlockIpAddress( ip_address, 60000 ); // block id if invalid ip
|
||||
}
|
||||
|
||||
// script will only work if the server is online for more than 10 minutes
|
||||
if ( g_iTime - g_ServerUptime > 300 )
|
||||
{
|
||||
new
|
||||
time = GetTickCount( );
|
||||
|
||||
switch( time - g_LastConnection )
|
||||
{
|
||||
case 0 .. 500:
|
||||
{
|
||||
if ( ++ g_ConnectionSpamCount >= 5 )
|
||||
{
|
||||
BlockIpAddress( ip_address, 60 * 1000 );
|
||||
printf( "Name:%s(%d)\nVersion:%s\nIP:%s / %s:%d\nNetwork Stats:{%s}\nPing:%d\nNPC:%d\nGPCI:%s", player_name, playerid, player_version, player_ip, ip_address, port, netstats, player_ping, IsPlayerNPC( playerid ), playerserial );
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
default: g_ConnectionSpamCount = 0;
|
||||
}
|
||||
g_LastConnection = time;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
public OnPlayerConnect( playerid )
|
||||
{
|
||||
static
|
||||
@ -1332,26 +1286,6 @@ public OnPlayerConnect( playerid )
|
||||
if ( textContainsIP( ReturnPlayerName( playerid ) ) )
|
||||
return Kick( playerid ), 1;
|
||||
|
||||
if ( g_iTime - g_ServerUptime > 300 )
|
||||
{
|
||||
new player_name[ 24 ];
|
||||
new player_version[ 24 ];
|
||||
new player_ip[ 16 ];
|
||||
new player_ping = GetPlayerPing( playerid );
|
||||
new netstats[ 500 ];
|
||||
new playerserial[ 45 ];
|
||||
|
||||
GetPlayerName( playerid, player_name, sizeof( player_name ) );
|
||||
GetPlayerVersion( playerid, player_version, sizeof( player_version ) );
|
||||
GetPlayerIp( playerid, player_ip, sizeof( player_ip ) );
|
||||
GetPlayerNetworkStats( playerid, netstats, sizeof( netstats ) );
|
||||
gpci( playerid, playerserial, sizeof( playerserial ) );
|
||||
|
||||
if ( strlen( player_name ) >= 16 ) {
|
||||
printf( "Name:%s(%d)\nVersion:%s\nIP:%s\nNetwork Stats:{%s}\nPing:%d\nNPC:%d\nGPCI:%s", player_name, playerid, player_version, player_ip, netstats, player_ping, IsPlayerNPC( playerid ), playerserial );
|
||||
}
|
||||
}
|
||||
|
||||
// Ultra fast queries...
|
||||
format( Query, sizeof( Query ), "SELECT * FROM `BANS` WHERE (`NAME`='%s' OR `IP`='%s') AND `SERVER`=0 LIMIT 0,1", mysql_escape( ReturnPlayerName( playerid ) ), mysql_escape( ReturnPlayerIP( playerid ) ) );
|
||||
mysql_function_query( dbHandle, Query, true, "OnPlayerBanCheck", "i", playerid );
|
||||
|
Loading…
Reference in New Issue
Block a user