24.06.2015, 16:14
Stop chat spam attack from bot?
who know how to stop it ?
#sorryformybadenglish
who know how to stop it ?
#sorryformybadenglish
// TOP OF SCRIPT
new chatcount[MAX_PLAYERS];
// Inside OnPlayerConnect
public OnPlayerConnect(playerid)
{
SetTimerEx("antispam", 2000, 1, "i", playerid);
// The rest of your code
return 1;
}
// Somewhere
forward antispam(playerid);
public antispam(playerid)
{
if(chatcount[playerid] > 3) // If player sent more than 3 messages in 2 seconds... probably a bot/keybind
{
return Kick(playerid); // Kick player if spamming, now you can do anything to him.
}
else
{
chatcount[playerid] = 0; // If he didn't spam, reset count.
}
return 1;
}
// In your chat, e.g. OnPlayerText
public OnPlayerText(playerid, text[])
{
chatcount[playerid]++;
// THE REST OF YOUR CODE
return 1;
}
public OnPlayerText(playerid, text[])//This Callback is called as soon as a player types smth. into the chat. { SpamCount[playerid]++; if(SpamCount[playerid] == 1) { spamtime[playerid][0] = gettime(); } if(SpamCount[playerid] == 2) { if(gettime()-spamtime[playerid][0] < 2)//We will check if the player send the next message within two seconds. And if yes give him a warning or something. { Give a warning. spamtime[playerid][1] = gettime(); } else { SpamCount[playerid] = 0; } } if(SpamCount[playerid] == 3) { if(gettime()-spamtime[playerid][1] < 3)//We will check if the player send the next message within 3 seconds. And if yes give him a warning or something. { Kick him. SpamCount[playerid] = 0; } else { SpamCount[playerid] = 0; } } }
public OnPlayerText(playerid, text[])
{
//==============================================================================
// Flood/Spam Protection
//==============================================================================
if(ServerInfo[AntiSpam] == 1 && (pInfo[playerid][Admin] == 0 && !IsPlayerAdmin(playerid)))
{
if(pInfo[playerid][SpamCount] == 0) pInfo[playerid][SpamTime] = TimeStamp();
pInfo[playerid][SpamCount]++;
if(TimeStamp() - pInfo[playerid][SpamTime] > SPAM_TIMELIMIT) { // Its OK your messages were far enough apart
pInfo[playerid][SpamCount] = 0;
pInfo[playerid][SpamTime] = TimeStamp();
}
else if(pInfo[playerid][SpamCount] == SPAM_MAX_MSGS) {
new string[250];
format(string,sizeof(string),"{FF0000}|- Player %s (Id:%d) telah otomatis di Kick. | Alasan: Flood/Spam Protection -|", GetName(playerid),playerid);
if(GetPVarInt(playerid,"Kick") != 1)
{
SendClientMessageToAll(grey,string);
SetPVarInt(playerid,"Kick",1);
}
SaveIn("KickLog",string);
pKick(playerid);
}
else if(pInfo[playerid][SpamCount] == SPAM_MAX_MSGS-1)
{
SendClientMessage(playerid,Red,"ATTENTION: Anti Spam! Selanjutnya = Kick!");
SMT(playerid,"~r~~h~WARNING: ~w~Stop spam 1x lagi anda chat = kick dari server!");
return 0;
}
}
return 0;
}