Advertisement
Guest User

Anti FLOOD SA:MP

a guest
Apr 12th, 2015
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.89 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. // * Settings for the anti-flood
  4. // I recommend using these settings if you want to protect the server from flood attacks.
  5. // If you want to deal with annoying spammers, lower the thresold a bit and set the mode to 2 (kick).
  6. // FS Anti-Flood BY Hooliganu====================================*
  7. #define RATE_INC (500) // The sensitivity per message, no need to modify.
  8. #define RATE_MAX (2500) // When the flood rate reaches this value the action below will be taken
  9.  
  10. // * Action to take when the flood rate reached the thresold
  11. // 1 - Ban
  12. // 2 - Kick
  13. // 3 - Give a warning (not recommended)
  14.  
  15. #define THRESOLD_ACTION 1
  16.  
  17. enum LIST_ANTIFLOOD
  18. {
  19.     lastCheck,
  20.     floodRate
  21. }
  22.  
  23. new AntiFlood_Data[MAX_PLAYERS][LIST_ANTIFLOOD];
  24.  
  25. public OnFilterScriptInit()
  26. {
  27.     for ( new playerid; playerid < MAX_PLAYERS; playerid++ )
  28.     {
  29.         if ( IsPlayerConnected( playerid ) )
  30.             AntiFlood_InitPlayer( playerid );
  31.     }
  32.  
  33.     return 1;
  34. }
  35.  
  36. public OnFilterScriptExit()
  37. {
  38.     return 1;
  39. }
  40.  
  41. public OnPlayerConnect( playerid )
  42. {
  43.     AntiFlood_InitPlayer( playerid );
  44.  
  45.     return 1;
  46. }
  47.  
  48. public OnPlayerDisconnect( playerid )
  49. {
  50.     return 1;
  51. }
  52.  
  53. public OnPlayerText( playerid, text[] )
  54. {
  55.     assert( AntiFlood_Check( playerid ) );
  56.  
  57.     return 1;
  58. }
  59.  
  60. public OnPlayerCommandText( playerid, cmdtext[] )
  61. {
  62.     assert( AntiFlood_Check( playerid ) );
  63.     return 0;
  64. }
  65.  
  66. forward OnPlayerTeamPrivmsg( playerid, text[] );
  67. public OnPlayerTeamPrivmsg( playerid, text[] )
  68. {
  69.     assert( AntiFlood_Check( playerid ) );
  70.  
  71.     return 1;
  72. }
  73.  
  74. public OnPlayerDeath( playerid, killerid, reason )
  75. {
  76.     assert( AntiFlood_Check( playerid ) );
  77.  
  78.     return 1;
  79. }
  80.  
  81. AntiFlood_Check( playerid, bool:inc=true )
  82. {
  83.     AntiFlood_Data[playerid][floodRate] += inc ? RATE_INC : 0;
  84.     AntiFlood_Data[playerid][floodRate] = AntiFlood_Data[playerid][floodRate] - ( GetTickCount() - AntiFlood_Data[playerid][lastCheck] );
  85.     AntiFlood_Data[playerid][lastCheck] = GetTickCount();
  86.     AntiFlood_Data[playerid][floodRate] = AntiFlood_Data[playerid][floodRate] < 0 ? 0 : AntiFlood_Data[playerid][floodRate];
  87.  
  88.     if ( AntiFlood_Data[playerid][floodRate] >= RATE_MAX )
  89.     {
  90.         #if THRESOLD_ACTION == 1
  91.             new msg[64], name[MAX_PLAYER_NAME];
  92.  
  93.             GetPlayerName( playerid, name, sizeof( name ) );
  94.  
  95.             format( msg, sizeof( msg ), ">> %s has been banned for flooding.", name );
  96.  
  97.             SendClientMessageToAll( 0xEE9911FF, msg );
  98.  
  99.             Ban( playerid );
  100.         #elseif THRESOLD_ACTION == 2
  101.             new msg[64], name[MAX_PLAYER_NAME];
  102.  
  103.             GetPlayerName( playerid, name, sizeof( name ) );
  104.  
  105.             format( msg, sizeof( msg ), ">> %s has been kicked for flooding.", name );
  106.  
  107.             SendClientMessageToAll( 0xEE9911FF, msg );
  108.  
  109.             Kick( playerid );
  110.         #else
  111.             SendClientMessage( playerid, 0xC00000FF, "Stop flooding." );
  112.         #endif
  113.  
  114.         return false;
  115.     }
  116.  
  117.     return true;
  118. }
  119.  
  120. AntiFlood_InitPlayer( playerid )
  121. {
  122.     AntiFlood_Data[playerid][lastCheck] = GetTickCount();
  123.     AntiFlood_Data[playerid][floodRate] = 0;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement