Guest User

FloodControl.inc - SEM FLOOD!

a guest
Jun 23rd, 2012
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.17 KB | None | 0 0
  1. /*
  2.     SA-MP FloodControl Include
  3.     Copyright © 2012 RoacH`
  4. */
  5.  
  6. #if defined _FloodControl_Included
  7.     #error Flood Control is already defined.
  8.         #endinput
  9.             #endif
  10.                 #define _FloodControl_Included
  11.             #if !defined _samp_included
  12.         #error Please include a_samp before Flood Control.
  13.     #endif
  14. #pragma library "FloodControl"
  15.  
  16. enum {
  17.     FLOOD_CONTROL_DEATH,
  18.     FLOOD_CONTROL_BOOT,
  19.     FLOOD_CONTROL_VEHICLES,
  20.     FLOOD_CONTROL_COMMAND,
  21.     FLOOD_CONTROL_CHAT
  22. };
  23. forward OnPlayerFloodControl(playerid, config);
  24.  
  25. static
  26.     flood_stamp[MAX_PLAYERS]
  27. ;
  28.  
  29. public OnPlayerDeath(playerid, killerid, reason) {
  30.     if(killerid != INVALID_PLAYER_ID) {
  31.         if(playerid == killerid) {
  32.             if(funcidx("OnPlayerFloodControl")) {
  33.                 CallLocalFunction("OnPlayerFloodControl", "ii", playerid, FLOOD_CONTROL_DEATH);
  34.             }
  35.         }
  36.         if(gettime() - GetPVarInt(playerid, "#lastdeath") < 1) {
  37.             if(funcidx("OnPlayerFloodControl")) {
  38.                 CallLocalFunction("OnPlayerFloodControl", "ii", playerid, FLOOD_CONTROL_DEATH);
  39.             }
  40.             return 0;
  41.         }
  42.         SetPVarInt(playerid, "#lastdeath", gettime());
  43.     }
  44.     if(funcidx("flood_controlOnPlayerDeath") != -1) {
  45.         return CallLocalFunction("flood_controlOnPlayerDeath", "iii", playerid, killerid, reason);
  46.     }
  47.     return true;
  48. }
  49. #if defined _ALS_OnPlayerDeath
  50.     #undef OnPlayerDeath
  51. #else
  52.     #define _ALS_OnPlayerDeath
  53. #endif
  54. #define OnPlayerDeath flood_controlOnPlayerDeath
  55. forward flood_controlOnPlayerDeath(playerid, killerid, reason);
  56.  
  57. public OnPlayerUpdate(playerid) {
  58.     new
  59.         iVehicle = GetPlayerVehicleID(playerid)
  60.     ;
  61.     if(GetPlayerVehicleSeat(playerid) != 0) {
  62.         if(GetPVarInt(playerid, "#ultimoveiculo") != iVehicle) {
  63.             SetPVarInt(playerid, "#ultimoveiculo", iVehicle);
  64.             if(GetVehicleModel(iVehicle)) {
  65.                 @ChangeVehicles(playerid, PLAYER_STATE_DRIVER, iVehicle);
  66.             }
  67.         }
  68.     }
  69.     if(funcidx("flood_controlOnPlayerUpdate") != -1) {
  70.         return CallLocalFunction("flood_controlOnPlayerUpdate", "i", playerid);
  71.     }
  72.     return true;
  73. }
  74. #if defined _ALS_OnPlayerUpdate
  75.     #undef OnPlayerUpdate
  76. #else
  77.     #define _ALS_OnPlayerUpdate
  78. #endif
  79. #define OnPlayerUpdate flood_controlOnPlayerUpdate
  80. forward flood_controlOnPlayerUpdate(playerid);
  81.  
  82. forward @ChangeVehicles(playerid, newstate, vehicleid);
  83. public @ChangeVehicles(playerid, newstate, vehicleid) {
  84.     if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER && GetPlayerState(playerid) != PLAYER_STATE_ONFOOT) {
  85.         if((gettime() - GetPVarInt(playerid, "#getarTime")) < 2) {
  86.             if(funcidx("OnPlayerFloodControl")) {
  87.                 CallLocalFunction("OnPlayerFloodControl", "ii", playerid, FLOOD_CONTROL_VEHICLES);
  88.             }
  89.         }
  90.         SetPVarInt(playerid, "#getarTime", gettime());
  91.     }
  92.     return true;
  93. }
  94.  
  95. forward OnPlayerFloodChat@Command(playerid, config, iCount, iTime);
  96. public OnPlayerFloodChat@Command(playerid, config, iCount, iTime) {
  97.     if((gettime() - GetPVarInt(playerid, "#lasttext")) < iTime && flood_stamp[playerid] > iCount) {
  98.         if(funcidx("OnPlayerFloodControl")) {
  99.             CallLocalFunction("OnPlayerFloodControl", "ii", playerid, config);
  100.         }
  101.     }
  102.     SetPVarInt(playerid, "#lasttext", gettime());
  103.     flood_stamp[playerid] ++;
  104.     return true;
  105. }
  106.  
  107. public OnPlayerConnect(playerid) {
  108.     static
  109.         PlayerIp[16],
  110.         LastIPConnected[16],
  111.         flood_boot
  112.     ;
  113.     GetPlayerIp(playerid, PlayerIp, sizeof(PlayerIp));
  114.     GetPlayerIp(playerid, LastIPConnected, sizeof(LastIPConnected));
  115.     if(strcmp(PlayerIp, LastIPConnected, true) == 0 && gettime() - GetPVarInt(playerid, "#lastip") <= 2) {
  116.         flood_boot ++;
  117.         if(flood_boot >= 5) {
  118.             if(funcidx("OnPlayerFloodControl")) {
  119.                 CallLocalFunction("OnPlayerFloodControl", "ii", playerid, FLOOD_CONTROL_BOOT);
  120.             }
  121.         }
  122.     }
  123.     else flood_boot = 0;
  124.     flood_stamp[playerid] = 0;
  125.     SetPVarInt(playerid, "#lastip", gettime());
  126.     if(funcidx("flood_controlOnPlayerConnect") != -1) {
  127.         return CallLocalFunction("flood_controlOnPlayerConnect", "i", playerid);
  128.     }
  129.     return true;
  130. }
  131. #if defined _ALS_OnPlayerConnect
  132.     #undef OnPlayerConnect
  133. #else
  134.     #define _ALS_OnPlayerConnect
  135. #endif
  136. #define OnPlayerConnect flood_controlOnPlayerConnect
  137. forward flood_controlOnPlayerConnect(playerid);
Advertisement
Add Comment
Please, Sign In to add comment