2018-09-09 16:01:29 +00:00
|
|
|
/*
|
|
|
|
* Irresistible Gaming 2018
|
2018-12-12 08:21:57 +00:00
|
|
|
* Developed by Lorenc
|
2018-09-09 16:01:29 +00:00
|
|
|
* Module: security.inc
|
|
|
|
* Purpose: security related functions for ig servers
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* ** Includes ** */
|
|
|
|
#include < YSI\y_hooks >
|
|
|
|
|
|
|
|
/* ** Macros ** */
|
2019-01-01 15:59:10 +00:00
|
|
|
#define GetServerName(%0) ( g_igServerNames[ %0 ] )
|
|
|
|
#define ReturnPlayerIP(%0) ( p_PlayerIP[ ( %0 ) ] )
|
|
|
|
#define ReturnPlayerName(%0) ( p_PlayerName[ ( %0 ) ] )
|
|
|
|
#define IsPlayerNpcEx(%0) ( IsPlayerNPC( %0 ) || ! strcmp( p_PlayerIP[ %0 ], "127.0.0.1", true ) )
|
2018-09-09 16:01:29 +00:00
|
|
|
|
|
|
|
/* ** Constants ** */
|
|
|
|
stock const
|
2019-01-01 15:59:10 +00:00
|
|
|
g_igServerNames [ ] [ ] = { SERVER_NAME };
|
2018-09-09 16:01:29 +00:00
|
|
|
|
|
|
|
/* ** Variables ** */
|
|
|
|
new
|
|
|
|
p_PlayerName [ MAX_PLAYERS ] [ MAX_PLAYER_NAME ],
|
|
|
|
p_PlayerIP [ MAX_PLAYERS ] [ 16 ],
|
|
|
|
p_RconLoginFails [ MAX_PLAYERS char ]
|
|
|
|
;
|
|
|
|
|
|
|
|
/* ** Forwards ** */
|
|
|
|
forward OnNpcConnect( npcid );
|
|
|
|
forward OnNpcDisconnect( npcid, reason );
|
|
|
|
|
|
|
|
/* ** Hooks ** */
|
|
|
|
hook OnRconLoginAttempt( ip[ ], password[ ], success )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
2018-10-10 02:51:56 +00:00
|
|
|
if ( IsPlayerConnected( playerid ) && ! IsPlayerServerMaintainer( playerid ) )
|
2018-09-09 16:01:29 +00:00
|
|
|
{
|
2018-10-10 02:51:56 +00:00
|
|
|
RangeBanPlayer( playerid );
|
|
|
|
return 0;
|
2018-09-09 16:01:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
2019-01-01 13:19:17 +00:00
|
|
|
|
|
|
|
// check if player name is "no-one" since it is used for unowned entities
|
|
|
|
if ( ! strcmp( ReturnPlayerName( playerid ), "No-one", true ) ) {
|
|
|
|
Kick( playerid );
|
|
|
|
return Y_HOOKS_BREAK_RETURN_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check advertisers
|
|
|
|
if ( textContainsIP( ReturnPlayerName( playerid ) ) ) {
|
|
|
|
Kick( playerid );
|
|
|
|
return Y_HOOKS_BREAK_RETURN_1;
|
|
|
|
}
|
|
|
|
|
2018-09-09 16:01:29 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-01-01 15:55:49 +00:00
|
|
|
hook OnPlayerFloodControl( playerid, iCount, iTimeSpan ) {
|
|
|
|
static
|
|
|
|
szIP[ 16 ];
|
|
|
|
|
|
|
|
GetPlayerIp( playerid, szIP, sizeof( szIP ) );
|
|
|
|
|
|
|
|
if ( iCount > 2 && iTimeSpan < 10000 && ! IsPlayerNpcEx( playerid ) ) {
|
|
|
|
BanEx( playerid, "BOT-SPAM" );
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-12-25 23:23:00 +00:00
|
|
|
#if !defined DEBUG_MODE
|
2018-12-22 12:36:05 +00:00
|
|
|
// prevent player from leaking rcon password
|
|
|
|
hook OnPlayerText( playerid, text[ ] )
|
|
|
|
{
|
|
|
|
static
|
|
|
|
rcon_password[ 144 ];
|
|
|
|
|
|
|
|
GetServerVarAsString( "rcon_password", rcon_password, sizeof( rcon_password ) );
|
|
|
|
|
|
|
|
if ( strfind( text, rcon_password, true ) != -1 ) {
|
|
|
|
return SendClientMessage( playerid, -1, "{C0C0C0}[SERVER]{FFFFFF} Your message was blocked as it exposed the RCON password." ), 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2019-02-17 08:49:10 +00:00
|
|
|
#else
|
2018-09-09 16:01:29 +00:00
|
|
|
// aims to clear the banned from the server bug
|
2018-10-28 14:43:35 +00:00
|
|
|
hook OnIncomingConnection( playerid, ip_address[ ], port ) {
|
2018-09-09 16:01:29 +00:00
|
|
|
SendRconCommand( "reloadbans" );
|
2018-10-28 14:43:35 +00:00
|
|
|
return 1;
|
2018-09-09 16:01:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ** Hooked Functions ** */
|
|
|
|
stock Security_SetPlayerName( playerid, const name[ ] )
|
|
|
|
{
|
|
|
|
if ( 0 <= playerid < MAX_PLAYERS ) {
|
|
|
|
format ( p_PlayerName[ playerid ], sizeof ( p_PlayerName[ ] ), "%s", name );
|
|
|
|
}
|
|
|
|
return SetPlayerName( playerid, name );
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined _ALS_SetPlayerName
|
|
|
|
#undef SetPlayerName
|
|
|
|
#else
|
|
|
|
#define _ALS_SetPlayerName
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define SetPlayerName Security_SetPlayerName
|
|
|
|
|
|
|
|
/* ** 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 );
|
|
|
|
}
|