Advertisement
luisgustavomiki

fcontrol - Stewie

Apr 27th, 2012
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.62 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. #if defined _lib_flood
  4.     #error Flood Control is already defined.
  5. #else
  6.     #define _lib_flood
  7. #endif
  8.  
  9. #pragma library flood_control
  10.  
  11. /*  by Stewie` -2012-
  12.         ALS Hooking by Y_Less
  13. */
  14.  
  15. new
  16.     flood_gPlayerRowStamp[MAX_PLAYERS],
  17.     flood_gPlayerRowCount[MAX_PLAYERS],
  18.  
  19.     flood_death_gPlayerLastStamp[MAX_PLAYERS],
  20.     flood_death_gPlayerCount[MAX_PLAYERS];
  21.  
  22. #define flood_HandleMessage flood_MessageHandler
  23. forward flood_MessageHandler(playerid, source);
  24.  
  25. enum
  26. {
  27.     FLOOD_SOURCE_CHAT,
  28.     FLOOD_SOURCE_COMMAND,
  29.     FLOOD_SOURCE_DEATH
  30. }
  31. forward OnPlayerFlood(playerid, source, row);
  32.  
  33.  
  34. #define FLOOD_NEW_ROW_INTERVAL 1000
  35. #define MAX_MESSAGES_PER_INTERVAL 5
  36.  
  37. #define DEATHS_NEW_ROW_INTERVAL 2000
  38. #define MAX_DEATHS_PER_INTERVAL 3
  39.  
  40. public flood_MessageHandler(playerid, source)
  41. {
  42.     // source MUST NOT be deaths source (FLOOD_SOURCE_DEATH)
  43.     // since its data vars are different.
  44.     // you can still use this function to prevent asses from
  45.     // other floods such as OnPlayerDialogResponse, and other client
  46.     // info
  47.  
  48.     // source NÃO PODE ser a fonte de mortes (FLOOD_SOURCE_DEATH)
  49.     // porque as variaveis são diferentes para mortes
  50.     // você ainda pode usar esta função para previnir babacas de
  51.     // outros floods, tais como OnPlayerDialogResponse, e outros
  52.     // dados do cliente.
  53.  
  54.     if(flood_gPlayerRowCount[playerid] > MAX_MESSAGES_PER_INTERVAL)
  55.     {
  56.         if(tickcount() > (flood_gPlayerRowStamp[playerid] + FLOOD_NEW_ROW_INTERVAL))
  57.         {
  58.             flood_gPlayerRowStamp[playerid] = tickcount();
  59.             flood_gPlayerRowCount[playerid] = 0;
  60.         }
  61.         else
  62.         {
  63.             if(funcidx("OnPlayerFlood"))
  64.             {
  65.                 CallLocalFunction("OnPlayerFlood", "iii", playerid, source, flood_gPlayerRowCount[playerid]);
  66.             }
  67.             return 1;
  68.         }
  69.     }
  70.     flood_gPlayerRowCount[playerid]++;
  71.     return 1;
  72. }
  73.  
  74.  
  75. // -- OnPlayerDeath -- Checking death floods.
  76. public OnPlayerDeath(playerid, killerid, reason)
  77. {
  78.     if(flood_death_gPlayerCount[playerid] > MAX_DEATHS_PER_INTERVAL)
  79.     {
  80.         if(tickcount() > (flood_death_gPlayerLastStamp[playerid] + DEATHS_NEW_ROW_INTERVAL))
  81.         {
  82.             flood_death_gPlayerLastStamp[playerid] = tickcount();
  83.             flood_death_gPlayerCount[playerid] = 0;
  84.         }
  85.         else
  86.         {
  87.             if(funcidx("OnPlayerFlood"))
  88.             {
  89.                 CallLocalFunction("OnPlayerFlood", "iii", playerid, FLOOD_SOURCE_DEATH, flood_death_gPlayerCount[playerid]);
  90.             }
  91.             return 1;
  92.         }
  93.     }
  94.     flood_death_gPlayerCount[playerid]++;
  95.  
  96.     if(funcidx("flood_OnPlayerDeath") != -1)
  97.     {
  98.         return CallLocalFunction("flood_OnPlayerDeath", "iii", playerid, killerid, reason);
  99.     }
  100.     return 1;
  101. }
  102.  
  103. #if defined _ALS_OnPlayerDeath
  104.     #undef OnPlayerDeath
  105. #else
  106.     #define _ALS_OnPlayerDeath
  107. #endif
  108. #define OnPlayerDeath flood_OnPlayerDeath
  109.  
  110. forward flood_OnPlayerDeath(playerid, killerid, reason);
  111.  
  112. // -- OnPlayerConnect -- Resetting variables
  113. public OnPlayerConnect(playerid)
  114. {
  115.     flood_gPlayerRowStamp[playerid] = 0;
  116.     flood_gPlayerRowCount[playerid] = 0;
  117.     flood_death_gPlayerLastStamp[playerid] = 0;
  118.     flood_death_gPlayerCount[playerid] = 0;
  119.  
  120.     if(funcidx("flood_OnPlayerConnect") != -1)
  121.     {
  122.         return CallLocalFunction("flood_OnPlayerConnect", "i", playerid);
  123.     }
  124.     return 1;
  125. }
  126. #if defined _ALS_OnPlayerConnect
  127.     #undef OnPlayerConnect
  128. #else
  129.     #define _ALS_OnPlayerConnect
  130. #endif
  131. #define OnPlayerConnect flood_OnPlayerConnect
  132.  
  133. forward flood_OnPlayerConnect(playerid);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement