Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #define _CHANGE_NAME_BEFORE_KICK true
- stock
- bool: bIllegalPlayer [ MAX_PLAYERS ] = false,
- szTmpKickName [ MAX_PLAYER_NAME ];
- public OnFilterScriptInit( )
- {
- print( "* Bad name protection has been enabled." );
- print( "* The following names are forbidden to join your server:" );
- print( "\tcom[1-9], lpt[1-9], clock$, nul, aux, prn, con" );
- #if _CHANGE_NAME_BEFORE_KICK == true
- for ( new i = 0; i < MAX_PLAYER_NAME; i++ )
- szTmpKickName[ i ] = '_';
- szTmpKickName[ MAX_PLAYER_NAME - 1 ] = '\0';
- print( "* The temporary name used to disconnect crashers will be:" );
- printf( "\t%s", szTmpKickName );
- #endif
- return 1;
- }
- public OnPlayerConnect( playerid )
- {
- new
- szPlayerName[ MAX_PLAYER_NAME ];
- bIllegalPlayer[ playerid ] = false;
- GetPlayerName( playerid, szPlayerName, MAX_PLAYER_NAME );
- if ( !strcmp( szPlayerName, "com", true, 3 ) || !strcmp( szPlayerName, "lpt", true, 3 ) )
- {
- if ( szPlayerName[ 3 ] >= '0' && szPlayerName[ 3 ] <= '9' && szPlayerName[ 4 ] == '\0' )
- return aKick( playerid, szPlayerName );
- }
- else if ( !strcmp( szPlayerName, "clock$", true, 6 ) )
- return aKick( playerid, szPlayerName );
- else
- {
- static const
- szForbiddenName[ ][ ] =
- {
- "nul", "aux",
- "prn", "con"
- };
- for ( new i = 0; i < sizeof( szForbiddenName ); i++ )
- {
- if ( !strcmp( szPlayerName, szForbiddenName[ i ], true, 3 ) )
- return aKick( playerid, szPlayerName );
- }
- #if _CHANGE_NAME_BEFORE_KICK == true
- // Players cannot join with our temporary kicking name either...
- // this name is "________________" by default which you probably don't want anyways.
- if ( !strcmp( szPlayerName, szTmpKickName, true, MAX_PLAYER_NAME ) )
- return aKick( playerid, szPlayerName );
- #endif
- }
- return 1;
- }
- public OnPlayerDisconnect( playerid, reason )
- {
- if ( bIllegalPlayer[ playerid ] )
- {
- bIllegalPlayer[ playerid ] = false;
- return 0;
- }
- return 1;
- }
- stock aKick( playerid, pname[ ] )
- {
- new
- szIP[ 16 ];
- bIllegalPlayer[ playerid ] = true;
- #if _CHANGE_NAME_BEFORE_KICK
- SetPlayerName( playerid, szTmpKickName );
- #endif
- GetPlayerIp( playerid, szIP, 16 );
- SendClientMessage( playerid, 0xFFFFFFFF, "SERVER: You have been because you have an illegal nickname." );
- Kick( playerid );
- printf( "[protect] %s (%d:%s) was kicked for an illegal nickname.", pname, playerid, szIP );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment