2018-02-12 20:17:51 +00:00
/*
* Irresistible Gaming 2018
* Developed by Lorenc Pekaj
* Module : security . inc
* Purpose : security related functions for ig servers
*/
2018-03-17 18:51:31 +00:00
/* ** Includes ** */
#include < YSI\y_hooks >
2018-02-12 20:17:51 +00:00
/* ** Macros ** */
2018-03-17 18:51:31 +00:00
#define GetServerName(%0) g_igServerNames[%0]
#define ReturnPlayerIP(%0) (p_PlayerIP[(%0)])
#define ReturnPlayerName(%0) (p_PlayerName[(%0)])
/* ** Constants ** */
stock const
g_igServerNames [ ] [ 28 ] = { " San Fierro Cops And Robbers " };
2018-02-12 20:17:51 +00:00
/* ** Variables ** */
new
2018-03-17 18:51:31 +00:00
p_PlayerName [ MAX_PLAYERS ] [ MAX_PLAYER_NAME ],
p_PlayerIP [ MAX_PLAYERS ] [ 16 ],
p_RconLoginFails [ MAX_PLAYERS char ]
2018-02-12 20:17:51 +00:00
;
2018-03-17 18:51:31 +00:00
/* ** Forwards ** */
forward OnNpcConnect ( npcid );
2018-03-18 14:32:24 +00:00
forward OnNpcDisconnect ( npcid , reason );
2018-03-17 18:51:31 +00:00
/* ** Hooks ** */
hook OnRconLoginAttempt ( ip [ ], password [ ], success )
2018-02-12 20:17:51 +00:00
{
new
playerid = INVALID_PLAYER_ID ,
szIP [ 16 ]
;
foreach ( new i : Player )
{
if ( GetPlayerIp ( i , szIP , sizeof ( szIP ) ) )
{
if ( ! strcmp ( szIP , ip , true ) )
{
playerid = i ;
break ;
}
}
}
if ( ! success )
{
if ( IsPlayerConnected ( playerid ) )
{
p_RconLoginFails { playerid } ++ ;
SendClientMessageFormatted ( playerid , - 1 , " { FF0000}[ERROR] { FFFFFF} You have entered an invalid rcon password. { C0C0C0}[%d/2] " , p_RconLoginFails { playerid } );
if ( p_RconLoginFails { playerid } >= 2 ) {
SendClientMessageFormatted ( playerid , - 1 , " { C0C0C0}[SERVER] { FFFFFF} If you are not the server operator or manager, don't bother trying! " );
Kick ( playerid );
}
}
}
else
{
if ( IsPlayerConnected ( playerid ) )
{
new
name [ 24 ];
GetPlayerName ( playerid , name , sizeof ( name ) );
if ( strcmp ( name , " Lorenc " , true ) && strcmp ( name , " Banging7Grams " , true ) )
{
RangeBanPlayer ( playerid );
return 0 ;
}
}
}
return 1 ;
}
2018-03-17 18:51:31 +00:00
hook OnPlayerConnect ( playerid )
{
static
szName [ MAX_PLAYER_NAME ], szIP [ 16 ];
GetPlayerIp ( playerid , szIP , sizeof ( szIP ) );
GetPlayerName ( playerid , szName , sizeof ( szName ) );
if ( IsPlayerNPC ( playerid ) ) {
CallLocalFunction ( " OnNpcConnect " , " d " , playerid );
return Y_HOOKS_BREAK_RETURN_1 ;
}
strcpy ( p_PlayerIP [ playerid ], szIP );
strcpy ( p_PlayerName [ playerid ], szName );
2018-03-18 14:32:24 +00:00
// get out the bots/invalid player ids
if ( ! ( 0 <= playerid < MAX_PLAYERS ) ) {
Kick ( playerid );
return Y_HOOKS_BREAK_RETURN_1 ;
}
// check for invalid name
if ( strlen ( ReturnPlayerName ( playerid ) ) <= 2 ) {
Kick ( playerid );
return Y_HOOKS_BREAK_RETURN_1 ;
}
return 1 ;
}
2018-03-17 18:51:31 +00:00
2018-03-18 14:32:24 +00:00
hook OnPlayerDisconnect ( playerid , reason )
{
if ( IsPlayerNPC ( playerid ) ) {
CallLocalFunction ( " OnNpcDisconnect " , " dd " , playerid , reason );
return Y_HOOKS_BREAK_RETURN_1 ;
}
// Filter out bots
if ( ! ( 0 <= playerid < MAX_PLAYERS ) ) {
return Y_HOOKS_BREAK_RETURN_1 ;
}
2018-03-17 18:51:31 +00:00
return 1 ;
}
2018-02-12 20:17:51 +00:00
#if defined DEBUG_MODE
// aims to clear the banned from the server bug
public OnIncomingConnection ( playerid , ip_address [ ], port ) {
SendRconCommand ( " reloadbans " );
}
#endif
2018-03-17 18:51:31 +00:00
/* ** Hooked Functions ** */
Security_SetPlayerName ( playerid , const name [ ] )
{
if ( 0 <= playerid < MAX_PLAYERS ) {
format ( p_PlayerName [ playerid ], sizeof ( p_PlayerName [ ] ), " %s " , name );
}
print ( " Hooked SetPlayerName " );
return SetPlayerName ( playerid , name );
}
#if defined _ALS_SetPlayerName
#undef SetPlayerName
#else
#define _ALS_SetPlayerName
#endif
#define SetPlayerName Security_SetPlayerName
2018-02-12 20:17:51 +00:00
/* ** Functions ** */
stock RangeBanPlayer ( playerid )
{
if ( ! IsPlayerConnected ( playerid ) )
return 0 ;
new
szBan [ 24 ],
szIP [ 16 ]
;
GetPlayerIp ( playerid , szIP , sizeof ( szIP ) );
GetRangeIP ( szIP , sizeof ( szIP ) );
format ( szBan , sizeof ( szBan ), " banip %s " , szIP );
SendRconCommand ( szBan );
KickPlayerTimed ( playerid );
return 1 ;
}
stock GetRangeIP ( szIP [ ], iSize = sizeof ( szIP ) )
{
new
iCount = 0
;
for ( new i ; szIP [ i ] != '\0' ; i ++ )
{
if ( szIP [ i ] == '.' && ( iCount ++ ) == 1 )
{
strdel ( szIP , i , strlen ( szIP ) );
break ;
}
}
format ( szIP , iSize , " %s.*.* " , szIP );
}