I discovered Hash tables not long ago and I must say : they have made my script faster and given me new ideas... Such as doing a flood detector over several lines (in this example 3 lines in less than a second), that is to say :
<nick> d
<nick> gff
<nick> dfgf
---> Warning by an /echo something
With .ini files, I use to have a timer that would unset a value in an .ini file after one second, for example, in NameServer.ini, I would have :
[#NameChan]
Nickname=Number of lines said on #NameChan
During this second, the value would increment if needed and if bigger than 2, I would be warned of the flood.
I have then tried to do the same with Hash tables and ended up with :
;Takes a server, a chan and a nickname as parameters and
;returns $true if the nickname is flooding, $false otherwise
alias Mod.Detecteur.Flood2 {
var %x = Flood2_ $+ $$1
var %y = $$2 $+ _ $+ $$3
var %u = system\moderation\init.ini
var %a = $hget(%x,%y)
if (!%a) {
;$readini(%u,scroll,510) is worth 1 in the example
hadd -mu $+ $readini(%u,scroll,510) %x %y 1
return $false
}
;$readini(%u,scroll,507) is worth 3 in the example
else if (%a < $calc($readini(%u,scroll,507) - 1)) {
hinc -u $+ $hget(%x,%y).unset %x %y
return $false
}
else {
hdel %x %y
return $true
}
}
The problem with this is that when it does /hinc there is a hic lol. I have to specify (again) how long is the value going to be existing for. I would have prefered my /hadd -mu1 to work even after the /hinc. Here, I have to reevaluate the unsetting of the hash value by /hinc -u $+ $hget(%x,%y).unset which is not as good.
Sorry I was long but here are my questions :
_ do I have to use a timer instead of the /hadd -mu1 ? (I didn't find any option that would enable me to have a time set in milliseconds)
_is this the best way to detect flood after all ? lol
_why does /hinc stop the internal hash timer started by /hadd -mu1 ?
_are there any mistakes in my little script (is it good to set the parameters into local variables for example ?)
Thank you in advance for any help you may give me