forward OnAntiCheatMessageFlood(playerid);

static MessageInfractions[MAX_PLAYERS];

#define         MAX_MESSAGE_INFRACTIONS         4
#define         MAX_MESSAGE_RATE                100

#if defined FILTERSCRIPT
    public OnFilterScriptInit()
    {
        SetTimer("CheckMessages", 1000, true);
        if (funcidx("ACMSGF_OnFilterScriptInit") != -1)
        {
            return CallLocalFunction("ACMSGF_OnFilterScriptInit", "");
        }
        return 1;
    }

    #if defined _ALS_OnFilterScriptInit
        #undef OnFilterScriptInit
    #else
        #define _ALS_OnFilterScriptInit
    #endif
    #define OnFilterScriptInit ACMSGF_OnFilterScriptInit

    forward ACMSGF_OnFilterScriptInit();
#else
    public OnGameModeInit()
    {
        SetTimer("CheckMessages", 1000, true);
        if (funcidx("ACMSGF_OnGameModeInit") != -1)
        {
            return CallLocalFunction("ACMSGF_OnGameModeInit", "");
        }
        return 1;
    }

    #if defined _ALS_OnGameModeInit
        #undef OnGameModeInit
    #else
        #define _ALS_OnGameModeInit
    #endif
    #define OnGameModeInit ACMSGF_OnGameModeInit

    forward ACMSGF_OnGameModeInit();
#endif


public OnPlayerDisconnect(playerid, reason)
{
    MessageInfractions[playerid] = 0;
    if (funcidx("ACMSGF_OnPlayerDisconnect") != -1)
    {
        return CallLocalFunction("ACMSGF_OnPlayerDisconnect", "ii", playerid, reason);
    }
    return 1;
}

#if defined _ALS_OnPlayerDisconnect
    #undef OnPlayerDisconnect
#else
    #define _ALS_OnPlayerDisconnect
#endif
#define OnPlayerDisconnect ACMSGF_OnPlayerDisconnect

forward ACMSGF_OnPlayerDisconnect(playerid, reason);

forward CheckMessages();
public CheckMessages()
{
#if !defined foreach
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) continue;
#else
    foreach(new i : Player)
    {
#endif
        if(NetStats_MessagesRecvPerSecond(i) > MAX_MESSAGE_RATE)  MessageInfractions[i]++;
        else MessageInfractions[i] = 0;
        if(MessageInfractions[i] == MAX_MESSAGE_INFRACTIONS) CallLocalFunction("OnAntiCheatMessageFlood", "i", i);
    }
    return 1;
}