Guest User

Simon

a guest
Mar 19th, 2008
1,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.44 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #define _CHANGE_NAME_BEFORE_KICK    true
  4.  
  5. stock
  6.     bool:   bIllegalPlayer  [ MAX_PLAYERS ] = false,
  7.             szTmpKickName   [ MAX_PLAYER_NAME ];
  8.    
  9. public OnFilterScriptInit( )
  10. {
  11.     print( "* Bad name protection has been enabled." );
  12.     print( "* The following names are forbidden to join your server:" );
  13.     print( "\tcom[1-9], lpt[1-9], clock$, nul, aux, prn, con" );
  14.    
  15.     #if _CHANGE_NAME_BEFORE_KICK == true
  16.     for ( new i = 0; i < MAX_PLAYER_NAME; i++ )
  17.         szTmpKickName[ i ] = '_';
  18.  
  19.     szTmpKickName[ MAX_PLAYER_NAME - 1 ] = '\0';
  20.    
  21.     print( "* The temporary name used to disconnect crashers will be:" );
  22.     printf( "\t%s", szTmpKickName );
  23.     #endif
  24.    
  25.     return 1;
  26. }
  27.  
  28. public OnPlayerConnect( playerid )
  29. {
  30.     new
  31.         szPlayerName[ MAX_PLAYER_NAME ];
  32.  
  33.     bIllegalPlayer[ playerid ] = false;
  34.  
  35.     GetPlayerName( playerid, szPlayerName, MAX_PLAYER_NAME );
  36.    
  37.     if ( !strcmp( szPlayerName, "com", true, 3 ) || !strcmp( szPlayerName, "lpt", true, 3 ) )
  38.     {
  39.         if ( szPlayerName[ 3 ] >= '0' && szPlayerName[ 3 ] <= '9' && szPlayerName[ 4 ] == '\0' )
  40.             return aKick( playerid, szPlayerName );
  41.     }
  42.  
  43.     else if ( !strcmp( szPlayerName, "clock$", true, 6 ) )
  44.         return aKick( playerid, szPlayerName );
  45.  
  46.     else
  47.     {
  48.         static const
  49.             szForbiddenName[ ][ ] =
  50.             {
  51.                 "nul", "aux",
  52.                 "prn", "con"
  53.             };
  54.  
  55.         for ( new i = 0; i < sizeof( szForbiddenName ); i++ )
  56.         {
  57.             if ( !strcmp( szPlayerName, szForbiddenName[ i ], true, 3 ) )
  58.                 return aKick( playerid, szPlayerName );
  59.         }
  60.        
  61.         #if _CHANGE_NAME_BEFORE_KICK == true
  62.         // Players cannot join with our temporary kicking name either...
  63.         // this name is "________________" by default which you probably don't want anyways.
  64.         if ( !strcmp( szPlayerName, szTmpKickName, true, MAX_PLAYER_NAME ) )
  65.             return aKick( playerid, szPlayerName );
  66.         #endif
  67.        
  68.     }
  69.  
  70.     return 1;
  71. }
  72.  
  73. public OnPlayerDisconnect( playerid, reason )
  74. {
  75.     if ( bIllegalPlayer[ playerid ] )
  76.     {
  77.         bIllegalPlayer[ playerid ] = false;
  78.  
  79.         return 0;
  80.     }
  81.  
  82.     return 1;
  83. }
  84.  
  85. stock aKick( playerid, pname[ ] )
  86. {
  87.     new
  88.         szIP[ 16 ];
  89.  
  90.     bIllegalPlayer[ playerid ] = true;
  91.    
  92.     #if _CHANGE_NAME_BEFORE_KICK
  93.     SetPlayerName( playerid, szTmpKickName );
  94.     #endif
  95.    
  96.     GetPlayerIp( playerid, szIP, 16 );
  97.     SendClientMessage( playerid, 0xFFFFFFFF, "SERVER: You have been because you have an illegal nickname." );
  98.     Kick( playerid );
  99.     printf( "[protect] %s (%d:%s) was kicked for an illegal nickname.", pname, playerid, szIP );
  100.  
  101.     return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment