Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #if defined _lib_flood
- #error Flood Control is already defined.
- #else
- #define _lib_flood
- #endif
- #pragma library flood_control
- /* by Stewie` -2012-
- ALS Hooking by Y_Less
- */
- new
- flood_gPlayerRowStamp[MAX_PLAYERS],
- flood_gPlayerRowCount[MAX_PLAYERS],
- flood_death_gPlayerLastStamp[MAX_PLAYERS],
- flood_death_gPlayerCount[MAX_PLAYERS];
- #define flood_HandleMessage flood_MessageHandler
- forward flood_MessageHandler(playerid, source);
- enum
- {
- FLOOD_SOURCE_CHAT,
- FLOOD_SOURCE_COMMAND,
- FLOOD_SOURCE_DEATH
- }
- forward OnPlayerFlood(playerid, source, row);
- #define FLOOD_NEW_ROW_INTERVAL 1000
- #define MAX_MESSAGES_PER_INTERVAL 5
- #define DEATHS_NEW_ROW_INTERVAL 2000
- #define MAX_DEATHS_PER_INTERVAL 3
- public flood_MessageHandler(playerid, source)
- {
- // source MUST NOT be deaths source (FLOOD_SOURCE_DEATH)
- // since its data vars are different.
- // you can still use this function to prevent asses from
- // other floods such as OnPlayerDialogResponse, and other client
- // info
- // source NÃO PODE ser a fonte de mortes (FLOOD_SOURCE_DEATH)
- // porque as variaveis são diferentes para mortes
- // você ainda pode usar esta função para previnir babacas de
- // outros floods, tais como OnPlayerDialogResponse, e outros
- // dados do cliente.
- if(flood_gPlayerRowCount[playerid] > MAX_MESSAGES_PER_INTERVAL)
- {
- if(tickcount() > (flood_gPlayerRowStamp[playerid] + FLOOD_NEW_ROW_INTERVAL))
- {
- flood_gPlayerRowStamp[playerid] = tickcount();
- flood_gPlayerRowCount[playerid] = 0;
- }
- else
- {
- if(funcidx("OnPlayerFlood"))
- {
- CallLocalFunction("OnPlayerFlood", "iii", playerid, source, flood_gPlayerRowCount[playerid]);
- }
- return 1;
- }
- }
- flood_gPlayerRowCount[playerid]++;
- return 1;
- }
- // -- OnPlayerDeath -- Checking death floods.
- public OnPlayerDeath(playerid, killerid, reason)
- {
- if(flood_death_gPlayerCount[playerid] > MAX_DEATHS_PER_INTERVAL)
- {
- if(tickcount() > (flood_death_gPlayerLastStamp[playerid] + DEATHS_NEW_ROW_INTERVAL))
- {
- flood_death_gPlayerLastStamp[playerid] = tickcount();
- flood_death_gPlayerCount[playerid] = 0;
- }
- else
- {
- if(funcidx("OnPlayerFlood"))
- {
- CallLocalFunction("OnPlayerFlood", "iii", playerid, FLOOD_SOURCE_DEATH, flood_death_gPlayerCount[playerid]);
- }
- return 1;
- }
- }
- flood_death_gPlayerCount[playerid]++;
- if(funcidx("flood_OnPlayerDeath") != -1)
- {
- return CallLocalFunction("flood_OnPlayerDeath", "iii", playerid, killerid, reason);
- }
- return 1;
- }
- #if defined _ALS_OnPlayerDeath
- #undef OnPlayerDeath
- #else
- #define _ALS_OnPlayerDeath
- #endif
- #define OnPlayerDeath flood_OnPlayerDeath
- forward flood_OnPlayerDeath(playerid, killerid, reason);
- // -- OnPlayerConnect -- Resetting variables
- public OnPlayerConnect(playerid)
- {
- flood_gPlayerRowStamp[playerid] = 0;
- flood_gPlayerRowCount[playerid] = 0;
- flood_death_gPlayerLastStamp[playerid] = 0;
- flood_death_gPlayerCount[playerid] = 0;
- if(funcidx("flood_OnPlayerConnect") != -1)
- {
- return CallLocalFunction("flood_OnPlayerConnect", "i", playerid);
- }
- return 1;
- }
- #if defined _ALS_OnPlayerConnect
- #undef OnPlayerConnect
- #else
- #define _ALS_OnPlayerConnect
- #endif
- #define OnPlayerConnect flood_OnPlayerConnect
- forward flood_OnPlayerConnect(playerid);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement