mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2003
Posts: 63
N
NiCk2 Offline OP
Babel fish
OP Offline
Babel fish
N
Joined: Mar 2003
Posts: 63
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 :
Code:
 
;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 &lt; $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 crazy

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
_ 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)

Although it's possible to have a millisecond timer using the -m switch (/help /timer), I'd avoid them and stick with -u in vars/hash tables. You definitely don't have to use them.


_is this the best way to detect flood after all ?

Although it's not bad, it's probably not the best way. Personally, I think the best way is aircdll.dll (you can find it at the DLL section of www.mircscripts.org), which does all the work of calculating/determining flood. It's faster and more accurate.


_why does /hinc stop the internal hash timer started by /hadd -mu1 ?

No idea, but I don't like it either. If it's not a bug, it's an unnecessary feature which I hope is removed.


_are there any mistakes in my little script (is it good to set the parameters into local variables for example ?)

Your script looks correct and the idea behind it is logical too. A couple of suggestions though:
  • I'd perhaps avoid $readini() and instead store/retrieve these two values from a hash table (the same one you use now or a second one).
  • I'd use $cid instead of $server (I assume $$1 is $server right?). $cid is unique, $server is not. For example, you might have clones connected to the same server and joined the same channel. In this case, the flood values would be doubled because each clone would /hinc the same value. Rather extreme case, but still possible.
  • I'd avoid "_" as the delimeter between $$2 and $$3, because it could create conflicts. For example:

    channel: #blah
    nick: _bleh
    %y: #blah_bleh

    channel: #blah_
    nick: bleh
    %y: #blah_bleh

    to avoid this, use a character that at least cannot be the first letter of a nickname (I use ":", the colon, for such purposes)


If you want to get more ideas, there's an interesting flood protection tutorial here, check it out.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Mar 2003
Posts: 63
N
NiCk2 Offline OP
Babel fish
OP Offline
Babel fish
N
Joined: Mar 2003
Posts: 63
Well I must say, you have indeed helped me very much and I am very greatful for it. I will check out the dll even if I don't no nothing about them (only what it means... lol) !
Thank you for your time, help, tips and advice, I will make great use of them, thank you thank you again :tongue:


Link Copied to Clipboard