mIRC Homepage

[Solved] Help Recalling From Hash Table

Posted By: Joe_Astor

[Solved] Help Recalling From Hash Table - 09/12/05 09:35 PM

I'm writing up a Blacklist using Hash Tables;

The Table's name is blacklist, and when I add a nick/address I'm using;

/hadd -m blacklist address reason

In my events I have;

on @*:join:#: {
if ($hmatch(blacklist,$address($nick,5))) {
ban # $nick 2
kick # $nick Blacklisted: (reason goes here)

What I am having trouble with, is recalling the value (reason) for the item (address) returned by $hmatch. confused

If you could point out a solution to this problem for me, it would be much appreciated. smile
Posted By: qwerty

Re: Help Recalling From Hash Table - 09/12/05 10:24 PM

$hmatch() returns the item name (which you could find out by putting an /echo $hmatch() anywhere in the code, /echo is useful like that). So you just need to get the data: $hget(blacklist,$v1)
on @*:join:#: {
  if ($hfind(blacklist,$fulladdress)) {
    ban -k # $nick 2 Blacklisted: $hget(blacklist,$v1)

Notice 4 things:

1. $hfind() is used instead of $hmatch. The latter is the 'old' version (deprecated) so better use the new one.
2. $fulladdress replaces $address($nick,5). The former doesn't depend on the IAL, it just uses the address included in the JOIN message that triggers the on JOIN event. Yours would have worked here too (assuming your IAL is on, which it should be) but it's a bit 'cleaner' and slightly more efficient to use the remote identifier $fulladdress.
3. /ban and /kick is combined into /ban -k
4. $v1 -which returns the first parameter of the last /if statement- is used instead of repeating $hmatch(). Of course, since the entire item name is the address, you could have used $hget(blacklist,$fulladdress) but $v1 is shorter.

The 4th item gives us an idea though: instead of searching the hash table, you can just aim for the specific item (the address) and see if it's there:
on @*:join:#: {
  if ($hget(blacklist,$fulladdress) != $null) {
    ban -k # $nick 2 Blacklisted: $v1
This solution is faster. The only reason you might prefer the first is in case you have an empty reason for a particular address.
Posted By: NeUtRoN_StaR

Re: Help Recalling From Hash Table - 09/12/05 10:32 PM

a while back i wrote a greeting script that stored a persons greeting which they set with a text event in a hash table

i wanted to do it by address but the fact of the matter is from network to network and time to time addresses change

so due to the dynamic nature of masks on a lot of networks
i opted to just do it by name

so the best your going to manage is good use of wild cards to prevent changes in mask from allowing people to slip through, unfortunatly this will also include people you dont want

im assuming you make the table add the entry and then test it
as i didnt see hmake or

umm this is totally untested but i figured i'd cobble something together for you

on *:start: {    
  if ($isfile(blacklist.hsh)) {      
    hmake blacklist 100    
    hload -o blacklist blacklist.hsh  
  else { 
    hmake blacklist 100
on *:exit: { 
  hsave -o blacklist " $+ $scriptdirblacklist.hsh"  
  hfree blacklist 
on !@*:join:#: {
  if (($hfind(blacklist, $address($nick,5))) {
    ban $chan $nick 2
    kick $chan $nick blacklisted: $hget(blacklist, $address($nick,5)) 

may work may not
if u can find the tutroial by king tomato thats really good

and im assuming you can make your own add/remove popups yourself or do it manually if not say so

good luck
© 2019 mIRC Discussion Forums