anti spam bug
#1

hi,

my attempt to make an anti spam:

pawn Код:
new SpamCount[MAX_PLAYERS];
new ChatSpamTime[MAX_PLAYERS][2];


public OnPlayerText(playerid, text[])
{

    if(muted[playerid] == 1)
    {
        SendClientMessage(playerid, 0xFF0000FF, "You have been muted!");
        return 0;
    }
    else
    {
        new string[192], name[24];
        GetPlayerName(playerid,name,24);
        SpamCount[playerid]++;
        ChatSpamTime[playerid][0]=gettime();
        AntiSpam(playerid);
    }
    return 1;
}

stock AntiSpam(playerid)
{
        new SpamProof[MAX_PLAYERS];
        ChatSpamTime[playerid][1]=gettime();
        SpamProof[playerid] = ChatSpamTime[playerid][1]-ChatSpamTime[playerid][0];
        if(SpamCount[playerid]==2)
        {
                if(SpamProof[playerid]<4)
                {
                    SendClientMessage(playerid,0xFF0000FF,"You got a warning for spamming");
                }
                else SpamCount[playerid]=0;
        }
        if(SpamCount[playerid]==3)
        {
                if(SpamProof[playerid]<4)
                {
                    SendClientMessage(playerid,0xFF0000FF,"You got a warning for spamming");
                }
                else SpamCount[playerid]=0;
        }
        if(SpamCount[playerid]>=4)
        {
                new strings[128],names[24];
                GetPlayerName(playerid,names,24);
                if(SpamProof[playerid]<4)
                {
                    format(strings,sizeof(strings),"%s has been muted for spamming",names);
                    SendClientMessageToAll(0xFF0000FF,strings);
                    muted[playerid] = 1;
                }
        }
        return 1;
}
But it is buggy, the first time i write smth. its ok but then it gives me the 2 warnings and then it mutes me. (no matter how long i w8 untill i write smth. in the chat again.)
As soon as someone chats more than 1 line in 4 secs he shall be muted.

Would be happy about some help
Reply
#2

for the last 2 spamcount do
pawn Код:
else if(SpamCount[playerid]==3)
        {
                if(SpamProof[playerid]<4)
                {
                    SendClientMessage(playerid,0xFF0000FF,"You got a warning for spamming");
                }
                else SpamCount[playerid]=0;
        }
        else if(SpamCount[playerid]>=4)
        {
                new strings[128],names[24];
                GetPlayerName(playerid,names,24);
                if(SpamProof[playerid]<4)
                {
                    format(strings,sizeof(strings),"%s has been muted for spamming",names);
                    SendClientMessageToAll(0xFF0000FF,strings);
                    muted[playerid] = 1;
                }
        }
Reply
#3

you only changed the if to else if i guess...
That wouldnt change anything

Any other ideas?
Reply
#4

did you even try, that does change something.
Reply
#5

yes, i tried it ofc but no effect.
Can someone find the bug? Would be much appreciated and +rep ofc
Reply
#6

Well; I used to use this:

pawn Код:
new bool:Muted[MAX_PLAYERS], MessageCount[MAX_PLAYERS];
forward Spam_Timer();

public OnGameModeInit()
{
    SetTimer("SpamTimer", 10000, true);
    //Rest of OnGameModeInit
}

public OnPlayerText(playerid, text[])
{
    if(Muted[playerid]) return SendClientMessage(playerid, COLOUR_RED, "You are muted."), 0;

    MessageCount[playerid]++;
    //Rest of OnPlayerText
}

public SpamTimer()
{
    for(new playerid; playerid < GetMaxPlayers(); playerid++)
    {
        if(Muted[playerid])
        {
            MessageCount[playerid]++;
            if(MessageCount[playerid] == 6)
            {
                Muted[playerid] = false;
                MessageCount[playerid] = 0;
                SendClientMessage(playerid, COLOUR_RED, "You have been unmuted.");
            }
        }
        if(MessageCount[playerid] > 10)
        {
            SendClientMessage(playerid, COLOUR_RED, "You have been muted for spamming the chat.");
            Muted[playerid] = true;
        }
        MessageCount[playerid] = 0;
    }
    return 1;
}
When a player sends a message, it increments a variable called "MessageCount". If their "MessageCount" variable is greater than ten, it mutes them. It then waits 60 seconds (6 timer 'ticks') and un-mutes them.

Like I told you in PM, I'm not in a position to re-create that efficiently, therefore they may be a few issues.
Reply
#7

thx a lot for your code
But i want to get rid of any timer i can get rid of.

Maybe someone can help me to get this done with the gettime function?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)