This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

ASCII ban

Old posts that have not been replied to for several years.
Locked
User avatar
ReaLz
Op
Posts: 121
Joined: Sat Oct 19, 2002 5:33 am
Location: Athens, Greece

ASCII ban

Post by ReaLz »

I'm trying to make a script that firstly warns the users who use ASCII chars in the channel and if they do it again they get banned... but when someone uses ASCII chars it gets banned and the bot also sends him notices at the same time.

Code: Select all

bind pubm - "* *\002*" ascii:pubm
bind pubm - "* *\003*" ascii:pubm
bind pubm - "* *\006*" ascii:pubm
bind pubm - "* *\007*" ascii:pubm
bind pubm - "* *\017*" ascii:pubm
bind pubm - "* *\026*" ascii:pubm
bind pubm - "* *\037*" ascii:pubm

proc ascii:pubm {nick uhost hand chan text} {
  if {[matchattr $hand of|fo $chan] || [isop $nick $chan]} {
    return
  }
if {![validuser $nick]} {
adduser $nick
putserv "NOTICE $nick :Please don't use ASCII chars in $chan"
return
}
if {[validuser $nick]} {
deluser $nick
set mask "*!*@[lindex [split $uhost @] 1]"
newban $mask ASCII "\00210 minutes\002 ban for using \002ASCII characters\002 within \002$chan\002 " 10
return 1
}
}
«A fantastic spaghetti is a spaghetti that does not exist»
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

You realize that ASCII characters include a-z, A-Z, 0-9, and all that right? heh

Aside from that, the reason you're probably having this problem is that the pubm bind is "stackable". Which means, it gets executed multiple times for the same input. So if a user types a line with more than one of your forbidden characters, the procedure will get called more than once, thus warning him and banning him.

Instead, you should have a single bind with *, and check for illegal chars within it.
User avatar
ReaLz
Op
Posts: 121
Joined: Sat Oct 19, 2002 5:33 am
Location: Athens, Greece

Post by ReaLz »

yeah... good idea thanx
but it will still be a problem if a user uses

Code: Select all

\002
and

Code: Select all

\003
in the same line
«A fantastic spaghetti is a spaghetti that does not exist»
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

No it won't.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

stdragon was correct in regards to the script being called multiple times, however, there is a second reason for the notice and ban in one go, that requires only a single control character to be used in the text.

In your second "if" test, you see if the user ISNT there. If not, then add them and warn them.

Your third i"if" checks to see if they ARE added. If so, then ban them.

The way you use this is very correct, however, but your ordering isn't.

The first "validuser" returns 0, so add them. The second "validuser" returns 1, because you have just added them.

A qucik fix for this, is to switch the order in which these "if" statments are called.
User avatar
ReaLz
Op
Posts: 121
Joined: Sat Oct 19, 2002 5:33 am
Location: Athens, Greece

Post by ReaLz »

you mean to write first the

Code: Select all

[validuser
and then the

Code: Select all

![validuser
?
«A fantastic spaghetti is a spaghetti that does not exist»
User avatar
caesar
Mint Rubber
Posts: 3777
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Exactly. Anyway, you should use an array to do what you do with the userlist.
Once the game is over, the king and the pawn go back in the same box.
User avatar
ReaLz
Op
Posts: 121
Joined: Sat Oct 19, 2002 5:33 am
Location: Athens, Greece

Post by ReaLz »

could u give me an example?
«A fantastic spaghetti is a spaghetti that does not exist»
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

For the issue I posted, take this

"usera" is not added to the bot. He triggers the bind.

Code: Select all

if {![validuser usera]} {
  #User isn't added, as noted
  #So do this code
  adduser usera
}
if {[validuser usera]} {
  #User is added, we just added him above, so this gets called now
  #SO we call ban code
}
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

ppslim, actually he had it correct the first time. The reason is that he has a 'return' statement after adding the user. So basically he's using the user record as a flag to see if the person has been warned already.

1. sheep sends a msg with control chars
2. bot checks if user exists
3: no - so bot adds user and sends notice, returns
4. sheep sends another msg with control chars
5. bot checks if user exists
6. yes - so bot bans and deletes user (resetting flag), returns

It's actually a very smart way of doing it, because using the user record automatically adds permanance (e.g. bot saves user records automatically, so on .restart the user still exists).
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

I'll goto bed now.

You wanna see how red my cheeks are, flame grilled steak any1.
T
TsT
Voice
Posts: 16
Joined: Tue Mar 04, 2003 11:03 am
Location: Strasbourg, France
Contact:

Post by TsT »

Why not use global variable?

like:

Code: Select all

# add a user
proc my_adduser {mask} {
    global my_users
    set my_users([string tolower $mask]) ""
}

# return "" = not found
# else return the 1st mask which matched
proc my_searchuser {uhost} {
    global my_users
    set uhost [string tolower $uhost]
    foreach mask $my_users {
        if {[string match $mask $uhost]} {
            return $mask
        }
    }
    return
}

# remove a user
proc my_deluser {mask} {
    global my_users
    catch {unset my_users($mask)}
}

Code: Select all

set validuser [my_searchuser $nick!$uhost]
if {$validuser == ""} {
  #User isn't added, as noted
  #So do this code
  my_adduser [maskhost $uhost]
}
if {$validuser != ""} {
  #User is added, we just added him above, so this gets called now
  #SO we call ban code
}

# remove the user:
my_deluser $validuser
User avatar
caesar
Mint Rubber
Posts: 3777
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

This thing with the userlist is not a good ideea because in case someone uses a colour or something today, it's added to the list and after 24 hours when it uses it again it's directly banned so he used only one time the colours per that day. :)

Also, instead of adding a user, removing it and so on, just add it's host to a certain user and see if it's mask is there either by checking the masks or by matching his handle with a certain flag of that user.
Once the game is over, the king and the pawn go back in the same box.
Locked