PtokaX forum

Development Section => Your Developing Problems => Topic started by: xjr13sp on 29 January, 2004, 16:07:06

Title: Reinitializing a Timer...
Post by: xjr13sp on 29 January, 2004, 16:07:06
Hi,

I have troubles to finish a little script. This script is to manage Flood in the CC. It works ok, but I'd like to add a Timer (because if I say 3x the same word in a range time of 1 or 2 min it's ok, but if I do that in a range time of 10 hours it is not good) but I don't know how to do :-/

If you could help me... thx :-)

max = 4 -- nb maxi de r?p?tition avant action
table = {}
sec = 1000
min = 60 * sec


warnmsg = "Merci de ne pas flooder..."
kickmsg = "Flood..."

function Main()
SetTimer(10000)
--SetTimer(5 * min)
StartTimer()
end

function DataArrival(user, data)
if strsub(data, 1, 1) == "<" and not user.bOperator then
local s, e, str = strfind(data, "^%b<> (.*)|$")
return check(user, str)
end
end


function check(user, str)
local tmp, ret = table[user.sName] or {}
if tmp[1] ~= str then
tmp = { str, 1 }
else
tmp[2] = tmp[2] + 1
if tmp[2] == max - 1 then
user:SendData("Hub-Security", warnmsg)
elseif tmp[2] == max then
user:Kick(kickmsg)
SendPmToOps("Hub-Security", user.sName.." a ?t? kick? pour flood. Il a dit : ["..str.."] "..max.." fois")
tmp, ret = nil, 1
end
end table[user.sName] = tmp
return ret
end

function OnTimer()
table = nil
end
Title:
Post by: NightLitch on 29 January, 2004, 16:31:25
just a hint for clearing the table:

function OnTimer()
    table = nil
    table = {}
end
Title:
Post by: NightLitch on 29 January, 2004, 16:32:09
otherwise I find no problems in your script for maybe the calculation you wanna do with the time.
Title:
Post by: NightLitch on 29 January, 2004, 16:33:49
here is for your calculation:


Sec    = 1000
Min    = 60 * sec

function Main()
   SetTimer(5 * Min)
   StartTimer()
end
Title:
Post by: xjr13sp on 29 January, 2004, 17:00:54
Thank you NightLitch :)
Title:
Post by: xjr13sp on 29 January, 2004, 17:25:58
After testing, here is my problem:

1- I say 3 times "test"
2- I get the message in field warnmsg
3- I wait for the re-init of the Timer and the Table
4- After re-init, I say 3 times again "test"
5- I get the message in field warnmsg and I'm disconnected... I don't understand why because I haven't a user:disconnected in the script  ?(

At step 4 if I say something different of at step 1, I'm not disconnected...
Title:
Post by: NightLitch on 29 January, 2004, 17:45:13
Well one other guess can maybe be that you have a low number
in hubsoft than is detecting spamming.
either turn it off 0 in both boxes or set it a little bit higher than you have now.

just a guess...
Title:
Post by: VidFamne on 29 January, 2004, 19:10:35
Was thinking of this line; local tmp, ret = table[user.sName] or {} Shouldnt it be like this or somethinglocal tmp, ret = table[user.sName] or {}, 0