move rapidfire detection and invalid bullet detection into its own ac module

This commit is contained in:
Lorenc Pekaj 2018-09-19 10:09:14 +10:00
parent 3da90fda9a
commit 52b7d22ee7
4 changed files with 82 additions and 50 deletions

View File

@ -37,7 +37,8 @@ enum
CHEAT_TYPE_AIRBRAKE, CHEAT_TYPE_AIRBRAKE,
CHEAT_TYPE_PROAIM, CHEAT_TYPE_PROAIM,
CHEAT_TYPE_AUTOCBUG, CHEAT_TYPE_AUTOCBUG,
CHEAT_TYPE_FLYHACKS CHEAT_TYPE_FLYHACKS,
CHEAT_TYPE_RAPIDFIRE
}; };
static stock static stock
@ -163,3 +164,4 @@ stock AC_SetPlayerSpawned( playerid, bool: spawned ) {
#include "irresistible\anticheat\autocbug.pwn" #include "irresistible\anticheat\autocbug.pwn"
#include "irresistible\anticheat\flying.pwn" #include "irresistible\anticheat\flying.pwn"
#include "irresistible\anticheat\remotejack.pwn" #include "irresistible\anticheat\remotejack.pwn"
#include "irresistible\anticheat\rapidfire.pwn"

View File

@ -0,0 +1,69 @@
/*
* Irresistible Gaming (c) 2018
* Developed by Lorenc Pekaj
* Module: anticheat\rapidfire.pwn
* Purpose: rapid fire detection as well as invalid bullet filtering
*/
/* ** Includes ** */
#include < YSI\y_hooks >
/* ** Variables ** */
static stock
p_RapidFireTickCount [ MAX_PLAYERS ],
p_RapidFireShots [ MAX_PLAYERS char ]
;
/* ** Hooks ** */
hook OnPlayerDisconnect( playerid, reason ) {
if ( 0 <= playerid < MAX_PLAYERS ) {
p_RapidFireShots{ playerid } = 0;
}
return 1;
}
hook OnPlayerWeaponShot( playerid, weaponid, hittype, hitid, Float: fX, Float: fY, Float: fZ )
{
new
keys, ud, lr;
GetPlayerKeys( playerid, keys, ud, lr );
// Simple. But effective. Anti-Shooting Hacks.
if ( ! ( keys & KEY_FIRE ) ) {
return Y_HOOKS_BREAK_RETURN_0;
}
// Invalid weapon id
if ( ! ( 22 <= weaponid <= 34 ) && weaponid != 38 ) {
return Y_HOOKS_BREAK_RETURN_0;
}
// Invalid hit (very far offset from player)
if ( hittype == BULLET_HIT_TYPE_PLAYER && ( ( fX >= 10.0 || fX <= -10.0 ) || ( fY >= 10.0 || fY <= -10.0 ) || ( fZ >= 10.0 || fZ <= -10.0 ) ) ) {
return Y_HOOKS_BREAK_RETURN_0;
}
// Anti-Rapid Fire
if ( ! p_RapidFireTickCount[ playerid ] ) p_RapidFireTickCount[ playerid ] = GetTickCount( );
else
{
new
iInterval = GetTickCount( ) - p_RapidFireTickCount[ playerid ];
if ( ( iInterval <= 35 && ( weaponid != 38 && weaponid != 28 && weaponid != 32 ) ) || ( iInterval <= 370 && ( weaponid == 34 || weaponid == 33 ) ) )
{
if ( p_RapidFireShots{ playerid } ++ >= 5 ) {
CallLocalFunction( "OnPlayerCheatDetected", "ddd", playerid, CHEAT_TYPE_RAPIDFIRE, 0 );
return Y_HOOKS_BREAK_RETURN_0;
}
}
else
{
p_RapidFireShots{ playerid } = 0;
}
p_RapidFireTickCount[ playerid ] = GetTickCount( );
}
return 1;
}

View File

@ -201,8 +201,6 @@ new
p_SpectateWeapons [ MAX_PLAYERS ] [ 13 ] [ 2 ], p_SpectateWeapons [ MAX_PLAYERS ] [ 13 ] [ 2 ],
bool: p_LeftCuffed [ MAX_PLAYERS char ], bool: p_LeftCuffed [ MAX_PLAYERS char ],
p_LabelColor [ MAX_PLAYERS ] = { COLOR_GREY, ... }, p_LabelColor [ MAX_PLAYERS ] = { COLOR_GREY, ... },
p_RapidFireTickCount [ MAX_PLAYERS ],
p_RapidFireShots [ MAX_PLAYERS char ],
p_BulletInvulnerbility [ MAX_PLAYERS ], p_BulletInvulnerbility [ MAX_PLAYERS ],
p_ProgressUpdateTimer [ MAX_PLAYERS ] = { 0xFFFF, ... }, p_ProgressUpdateTimer [ MAX_PLAYERS ] = { 0xFFFF, ... },
p_DeathMessage [ MAX_PLAYERS ] [ 32 ], p_DeathMessage [ MAX_PLAYERS ] [ 32 ],

View File

@ -4101,7 +4101,6 @@ public OnPlayerDisconnect( playerid, reason )
p_ToggledViewPM { playerid } = false; p_ToggledViewPM { playerid } = false;
p_VIPExpiretime [ playerid ] = 0; p_VIPExpiretime [ playerid ] = 0;
p_BankMoney [ playerid ] = 0; p_BankMoney [ playerid ] = 0;
p_RapidFireShots{ playerid } = 0;
p_Kills [ playerid ] = 0; p_Kills [ playerid ] = 0;
p_Deaths [ playerid ] = 0; p_Deaths [ playerid ] = 0;
p_VIPLevel [ playerid ] = 0; p_VIPLevel [ playerid ] = 0;
@ -4522,59 +4521,16 @@ public OnPlayerSpawn( playerid )
public OnPlayerWeaponShot( playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ ) public OnPlayerWeaponShot( playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ )
{ {
new
keys, ud, lr
;
GetPlayerKeys( playerid, keys, ud, lr );
// Simple. But effective. Anti-Shooting Hacks.
if ( !( keys & KEY_FIRE ) ) {
return 0;
}
if ( !( 22 <= weaponid <= 34 ) && weaponid != 38 ) {
return 0;
}
if ( p_AdminLevel[ playerid ] < 1 && IsWeaponBanned( weaponid ) ) { if ( p_AdminLevel[ playerid ] < 1 && IsWeaponBanned( weaponid ) ) {
return 0; return 0;
} }
if ( hittype == BULLET_HIT_TYPE_PLAYER && ( ( fX >= 10.0 || fX <= -10.0 ) || ( fY >= 10.0 || fY <= -10.0 ) || ( fZ >= 10.0 || fZ <= -10.0 ) ) ) {
return 0;
}
if ( IsPlayerAFK( playerid ) ) { if ( IsPlayerAFK( playerid ) ) {
return 0; return 0;
} }
static Float: X, Float: Y, Float: Z; static
Float: X, Float: Y, Float: Z;
// Anti-Rapid Fire
if ( !p_RapidFireTickCount[ playerid ] ) p_RapidFireTickCount[ playerid ] = GetTickCount( );
else
{
new
iInterval = GetTickCount( ) - p_RapidFireTickCount[ playerid ];
if ( ( iInterval <= 35 && ( weaponid != 38 && weaponid != 28 && weaponid != 32 ) ) || ( iInterval <= 370 && ( weaponid == 34 || weaponid == 33 ) ) )
{
if ( p_RapidFireShots{ playerid }++ >= 5 )
{
if ( g_Debugging )
{
SendClientMessageToRCON( COLOR_YELLOW, "RAPID-FIRE: %s, weapon %s, rate %d, times fucked up: %d", ReturnPlayerName( playerid ), ReturnWeaponName( weaponid ), iInterval, p_RapidFireShots{ playerid } );
printf("[DEBUG] [RAPID-FIRE] %s | %s | rate %d | times fucked up: %d", ReturnPlayerName( playerid ), ReturnWeaponName( weaponid ), iInterval, p_RapidFireShots{ playerid } );
}
SendGlobalMessage( -1, ""COL_PINK"[ANTI-CHEAT]{FFFFFF} %s(%d) has been kicked for rapid-firing.", ReturnPlayerName( playerid ), playerid );
KickPlayer( playerid );
return 0;
}
}
else p_RapidFireShots{ playerid } = 0;
p_RapidFireTickCount[ playerid ] = GetTickCount( );
}
if ( hittype == BULLET_HIT_TYPE_PLAYER ) if ( hittype == BULLET_HIT_TYPE_PLAYER )
{ {
@ -12065,8 +12021,9 @@ public OnPlayerStateChange(playerid, newstate, oldstate)
} }
} }
if ( newstate == PLAYER_STATE_DRIVER ) if ( newstate == PLAYER_STATE_DRIVER ) {
CallLocalFunction( "OnPlayerDriveVehicle", "dd", playerid, vID ); CallLocalFunction( "OnPlayerDriveVehicle", "dd", playerid, vID );
}
//if ( newstate == PLAYER_STATE_ONFOOT && p_Detained{ playerid } == true && IsPlayerConnected( p_DetainedBy[ playerid ] ) ) //if ( newstate == PLAYER_STATE_ONFOOT && p_Detained{ playerid } == true && IsPlayerConnected( p_DetainedBy[ playerid ] ) )
// return PutPlayerInEmptyVehicleSeat( p_LastVehicle[ p_DetainedBy[ playerid ] ], playerid ); // return PutPlayerInEmptyVehicleSeat( p_LastVehicle[ p_DetainedBy[ playerid ] ], playerid );
@ -13760,6 +13717,12 @@ function unpause_Player( playerid )
SendClientMessageToAdmins( -1, ""COL_PINK"[ABNORMAL JACKING]"COL_GREY" %s(%d) is a suspect of jacking vehicles abnormally.", ReturnPlayerName( playerid ), playerid ); SendClientMessageToAdmins( -1, ""COL_PINK"[ABNORMAL JACKING]"COL_GREY" %s(%d) is a suspect of jacking vehicles abnormally.", ReturnPlayerName( playerid ), playerid );
return 1; return 1;
} }
else if ( detection == CHEAT_TYPE_RAPIDFIRE )
{
SendGlobalMessage( -1, ""COL_PINK"[ANTI-CHEAT]{FFFFFF} %s(%d) has been kicked for rapid-firing.", ReturnPlayerName( playerid ), playerid );
Kick( playerid );
return 1;
}
else if ( detection == CHEAT_TYPE_AIRBRAKE ) else if ( detection == CHEAT_TYPE_AIRBRAKE )
{ {
//SendGlobalMessage( -1, ""COL_PINK"[ANTI-CHEAT]{FFFFFF} %s(%d) has been banned for airbraking.", ReturnPlayerName( playerid ), playerid ); //SendGlobalMessage( -1, ""COL_PINK"[ANTI-CHEAT]{FFFFFF} %s(%d) has been banned for airbraking.", ReturnPlayerName( playerid ), playerid );