You won't face problems with {, }, -, _, or \ using [string match] (as long as you properly use string and list commands). You only need to skip [ and ], applying the following string map on the match should do it:
set banmask "*[M]*!*@*"
set blacklist($banmask)
bind join -|- * BLK:J
proc BLK:J {N uhost H C} {
set U "$N![getchanhost $N]"
foreach E [array names blacklist] {
if {[string match -nocase $E $U]} {
and you are suggesting what?
I once was an intelligent young man, now i am old and i can not remember who i was.
set banmasks {
*[M]*!*@*
bla!*@*
lame!*[foo]*@bar.*
}
bind join -|- * BLK:J
proc BLK:J {nick uhost hand chan} {
global banmasks
set U $nick!$uhost
foreach banmask $banmasks {
# here's where my suggestion helps
set banmask [string map {[ \\[ ] \\]} $banmask]
if {[string match -nocase $banmask $U]} {
# You've found a match!
break
}
}
}
1) the original post refected an aspect of the orginal topic user started
2) the orginal post was directed to user
3) it is set in an array because it does have value, 5+ values
4) are you suggesting i should use:
set banmask [string map {[ \\[ ] \\]} $banmask]
set banmask [string map {[ \\{ } \\]} $banmask]
set banmask [string map {[ \\- _ \\]} $banmask]
Last edited by Dedan on Sat Apr 28, 2007 10:27 pm, edited 1 time in total.
I once was an intelligent young man, now i am old and i can not remember who i was.
So your issue was with the move? I simply moved it because user's topic is about ban masks and not [string match]. If you don't want anyone but user to answer you then don't do a public post in the forum. I didn't get your array argument though, I still believe using a list is a better choice.
I already said that only [ and ] have special meaning in [string match] so all you need is to apply that string map to the match as I've indicated in the sample code I wrote.
# List of masks which you want to be banned
set banmasks {
*[M]*!*@*
bla!*@*
lame!*[foo]*@bar.*
nickwith\{!*@*
nick-with_\}!*@*
nickwith\\!*@*
}
bind join -|- * BLK:J
proc BLK:J {nick uhost hand chan} {
global banmasks
# U is nick!user@host
set U $nick!$uhost
foreach banmask $banmasks {
# here you skip the brackets [ and ]
set banmask [string map {[ \\[ ] \\]} $banmask]
# this way *[M]* will match only *[M]* and not *M*
if {[string match -nocase $banmask $U]} {
# You've found a match!
break
}
}
}