Help Please -
Tass007 - 09.09.2016
Hey guys, I got this script. It complies fine but there's a bug that I'm not quite sure how to fix.
When you spam the chat so say I repeat the message "Bob" 4 times I get the message "[Anti-Spam]: Warning you are one message away from being muted!" If you message Bob 1 more time in 4 seconds you get muted. That works fine. However if you send "Bob" 4 times after the 4 seconds is over you don't get muted and never can unless you reconnect. So the script isn't resetting itself properly. Not sure how to do it.
PHP Code:
stock AntiSpam(playerid)
{
new msg[145];
SpamCount[playerid]++;
switch(SpamCount[playerid])
{
case 1:
{
ChatSpamTime[playerid][0]=gettime();
}
case 2:
{
if((gettime()-ChatSpamTime[playerid][0])<4)
{
ChatSpamTime[playerid][1]=gettime();
}
else SpamCount[playerid]=0;
}
case 3:
{
if((gettime()-ChatSpamTime[playerid][1])<4)
{
SendClientMessage(playerid, 0xFFFFFF, "[Anti-Spam]: Warning you are one message away from being muted!");
format(msg,sizeof(msg),"[Flood Control] - %s has been warned for flooding",GetName(playerid));
ABroadCast(COLOR_ADMIN,msg,1);
ChatSpamTime[playerid][2]=gettime();
}
else SpamCount[playerid]=0;
}
case 4..50:
{
if((gettime()-ChatSpamTime[playerid][2])<4)
{
format(msg, sizeof(msg), "[Anti-Spam]: %s has been muted for 5 minutes! (Reason: Spam)", GetName(playerid));
SendClientMessageToAll(0xFFFFFF, msg);
SendClientMessage(playerid,COLOR_GREEN,"You have received your final warning! You are now muted");
PlayerInfo[playerid][muted] = 1;
print(msg);
SetTimerEx("AutoUnMute",AutoUnmuteTime*60000,false,"i",playerid);
}
}
}
return 1;
}
Re: Anti Spam help -
Tass007 - 10.09.2016
Bump. For added information I've added some photos.
On this image I could spam forever. Without getting warned.
Re: Anti Spam help -
jlalt - 10.09.2016
try this function, also use char var in it so you will save more memory usage.
also you don't need "stock" in this function.
PHP Code:
new SpamCount[MAX_PLAYERS char], ChatSpamTime[MAX_PLAYERS char];
AntiSpam(playerid)
{
new msg[145];
if((gettime()-ChatSpamTime{playerid}) > 5 || !ChatSpamTime{playerid})
{
SpamCount{playerid} = 1;
ChatSpamTime{playerid} = gettime();
}
else
{
SpamCount{playerid}++;
switch(SpamCount{playerid})
{
case 2:
{
ChatSpamTime{playerid} = gettime(); // <- update the time!
}
case 3:
{
SendClientMessage(playerid, 0xFFFFFF, "[Anti-Spam]: Warning you are one message away from being muted!");
format(msg,sizeof(msg),"[Flood Control] - %s has been warned for flooding",GetName(playerid));
ABroadCast(COLOR_ADMIN,msg,1);
ChatSpamTime{playerid} = gettime();
}
case 4..99:
{
format(msg, sizeof(msg), "[Anti-Spam]: %s has been muted for 5 minutes! (Reason: Spam)", GetName(playerid));
SendClientMessageToAll(0xFFFFFF, msg);
SendClientMessage(playerid,COLOR_GREEN,"You have received your final warning! You are now muted");
PlayerInfo[playerid][muted] = 1;
print(msg);
SetTimerEx("AutoUnMute",AutoUnmuteTime*60000,false,"i",playerid);
ChatSpamTime{playerid} = 0;
SpamCount{playerid} = 0;
}
}
}
return 1;
}
Char:
https://sampwiki.blast.hk/wiki/Keywords:Operators#char
Stock:
https://sampforum.blast.hk/showthread.php?tid=570635
also be sure to do
PHP Code:
ChatSpamTime{playerid} = 0;
SpamCount{playerid} = 0;
at onplayerconnect callback.
Re: Anti Spam help -
Tass007 - 10.09.2016
Doing this, when ingame and I spam I don't get no message or anything no mute or anything of the sorts.
Also thanks for the information about Stock's I didn't know that. Just removed stock from my script :P
Also why are you using { } instead of []?
SpamCount{playerid}++;
SpamCount[playerid]++;
EDIT: I managed to fix it. It was the fact that you were using { } brackets instead of [ ].
Thank you.
Re: Anti Spam help -
jlalt - 10.09.2016
ops, my mistake I used char in ChatSpamTime and bugged it lol try this
.
PHP Code:
new SpamCount[MAX_PLAYERS char], ChatSpamTime[MAX_PLAYERS];
AntiSpam(playerid)
{
new msg[145];
if((gettime()-ChatSpamTime[playerid]) > 5 || !ChatSpamTime[playerid])
{
SpamCount{playerid} = 1;
ChatSpamTime[playerid] = gettime();
}
else
{
SpamCount{playerid}++;
switch(SpamCount{playerid})
{
case 2:
{
ChatSpamTime[playerid] = gettime(); // <- update the time!
}
case 3:
{
SendClientMessage(playerid, 0xFFFFFF, "[Anti-Spam]: Warning you are one message away from being muted!");
format(msg,sizeof(msg),"[Flood Control] - %s has been warned for flooding",GetName(playerid));
ABroadCast(COLOR_ADMIN,msg,1);
ChatSpamTime[playerid] = gettime();
}
case 4..99:
{
format(msg, sizeof(msg), "[Anti-Spam]: %s has been muted for 5 minutes! (Reason: Spam)", GetName(playerid));
SendClientMessageToAll(0xFFFFFF, msg);
SendClientMessage(playerid,COLOR_GREEN,"You have received your final warning! You are now muted");
PlayerInfo[playerid][muted] = 1;
print(msg);
SetTimerEx("AutoUnMute",AutoUnmuteTime*60000,false,"i",playerid);
ChatSpamTime[playerid] = 0;
SpamCount{playerid} = 0;
}
}
}
return 1;
}
also I used { } because I used SpamCount[MAX_PLAYERS char] not SpamCount[MAX_PLAYERS]
Re: Anti Spam help -
Threshold - 10.09.2016
chars are only really used when you know the value is going to be between 0 and 255. So yeah, shouldn't be used for functions like gettime.
Small improvements:
PHP Code:
new SpamCount[MAX_PLAYERS char], ChatSpamTime[MAX_PLAYERS];
AntiSpam(playerid)
{
new time = gettime();
if((time - ChatSpamTime[playerid]) < 5 || !ChatSpamTime[playerid])
{
ChatSpamTime[playerid] = time;
switch(++SpamCount{playerid})
{
case 3:
{
new msg[75];
SendClientMessage(playerid, 0xFFFFFFFF, "[Anti-Spam]: Warning you are one message away from being muted!");
format(msg, sizeof(msg), "[Flood Control] - %s has been warned for flooding", GetName(playerid));
ABroadCast(COLOR_ADMIN, msg, 1);
}
case 4:
{
new msg[75];
format(msg, sizeof(msg), "[Anti-Spam]: %s has been muted for 5 minutes! (Reason: Spam)", GetName(playerid));
SendClientMessageToAll(0xFFFFFFFF, msg);
SendClientMessage(playerid, COLOR_GREEN, "You have received your final warning! You are now muted");
PlayerInfo[playerid][muted] = 1;
print(msg);
SetTimerEx("AutoUnMute", AutoUnmuteTime * 60000, false, "i", playerid);
SpamCount{playerid} = 0;
return 0;
}
}
}
else
{
SpamCount{playerid} = 0;
ChatSpamTime[playerid] = time;
}
return 1;
}
public OnPlayerText(playerid, text[])
{
if(!AntiSpam(playerid)) return 0;
// Rest of OnPlayerText...
}