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.

script help and optimization help please

Help for those learning Tcl or writing their own scripts.
Post Reply
B
BillTech
Voice
Posts: 7
Joined: Sat Oct 15, 2011 5:27 pm

script help and optimization help please

Post by BillTech »

need a little help and optimization help please

i couldnt find a script to do this so i gave it a shot and tried to make one myself

what i want the script to do is count the number of excess floods a user does and temp ban after 3 in less then a minute
my script does this but i cant seem to make it include the channel and evaluate the channel on the count tried a few things but they havent worked out

my script works but if the users on multiple channels they get combined in the count

heres my hacked up code that works except for parsing channel in checks

Code: Select all

#xs_flood.tcl

bind sign - * xs_flood
set xs_bantime 3

bind pub - .xs xs_flood

proc xs_flood {nick uhost hand chan arg} {
global xs_bantime xs_flooder
    if {![botisop $chan]} { return 0 }
    if {[string equal "Excess Flood" $arg]} {
    if {![info exists xs_flooder]} {
    set xs_flooder 0
    } else {
    incr xs_flooder
    putlog "xs_flooder = $nick $chan Flood count $xs_flooder"
    timer 1 "set xs_flooder 0"
    }
    if {$xs_flooder >= 3} {
    puthelp "PRIVMSG $chan :Temp Ban $nick $xs_bantime Min XS-Flood"
    putserv "MODE $chan +b *!$uhost"
    timer $xs_bantime "pushmode $chan -b *!$uhost"
    puthelp "PRIVMSG $nick :Temp Ban $xs_bantime Min on $chan XS-Flood"
    putlog "Temp Ban $xs_bantime Min $nick *!$uhost on $chan XS-Flood"
    timer 1 "set xs_flooder 0"
  return 0
  }
 }
}

putlog "XS-Flood Loaded Bantime $xs_bantime Min RaT"
tia for your help
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

I see your problem. You would have to somehow employ an array variable to keep track of the flood on a per channel basis xs_flooder($chan).

This script does such a thing to restrict channel access when a PART flood occurs WITH part messages. You may be able to adapt it.

Code: Select all

# part.tcl
# profers channel protection for mass parts with part message

### ....................................................................... ###
### .......... configuration (edit as required) ........................... ###

# set here the bot channels you want part flood protection in
set vPartChannels "#channel1 #channel2"

# set here the number of parts in how many seconds for the script to react
set vPartLimit 4:8

# set here the channel throttle (joins per seconds) when channel is restricted
set vPartJoins 3:3

# set here the time in minutes for the channel to remain restricted
set vPartTime 5

# set here the modes to set to restrict channel (excluding throttle mode j)
set vPartModes mMR

### ....................................................................... ###
### .......... code (do not edit) ......................................... ###

set vPartChannels [split [string tolower $vPartChannels]]
scan $vPartLimit {%d:%d} vPartNumber vPartSeconds

bind PART - * pPartBind

proc pPartBind {nick uhost hand chan msg} {
    global vPartActive vPartChannels vPartData vPartJoins vPartModes vPartNumber vPartSeconds vPartTime
    if {[lsearch -exact $vPartChannels [string tolower $chan]] != -1} {
        if {![info exists vPartActive($chan)]} {set vPartActive($chan) 0}
        if {!$vPartActive($chan)} {
            if {[string length $msg] != 0} {
                lappend vPartData($chan) [clock seconds]
                set vPartData($chan) [lrange $vPartData($chan) end-[expr {$vPartNumber - 1}] end]
                if {[llength $vPartData($chan)] == $vPartNumber} {
                    set period [expr {[lindex $vPartData($chan) end] - [lindex $vPartData($chan) 0]}]
                    if {$period <= $vPartSeconds} {
                        set vPartActive($chan) 1
                        putquick "MODE $chan +${vPartModes}j $vPartJoins"
                        timer $vPartTime [list pPartCancel $chan]
                    }
                }
            }
        }
    }
    return 0
}

proc pPartCancel {chan} {
    global vPartActive vPartModes
    set vPartActive($chan) 0
    putquick "MODE $chan -${vPartModes}j"
    return 0
}

# eof
I must have had nothing to do
B
BillTech
Voice
Posts: 7
Joined: Sat Oct 15, 2011 5:27 pm

Post by BillTech »

thanks for the responce still a lil bit over my head
i have tried xs_flooder($chan) i think i get an array error i couldnt track
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

Sorry, I didn't mean to imply that simply changing xs_flooder to xs_flooder($chan) would suffice.

I was generalising when pointing the way to using an array variable rather than a normal scalar variable to store information in a per channel way. There would be one array element per channel you wished the code to function in.

What I perhaps failed to explain is that this would inevitably require other changes in the code.

As far as I can see, there is also nothing in your code to indicate which nick has previously done the flooding. The variable xs_flooder is simply incremented, resulting in the last nick to contribute getting banned.

To correct this, you would have to emulate a two dimensional array. Say something like xs_flooder($uhost,$chan). My code doesn't require this because I don't ban a user, rather I regulate a channel.

In any event I would advise that what you are trying to do is somewhat more difficult than your original code.
I must have had nothing to do
B
BillTech
Voice
Posts: 7
Joined: Sat Oct 15, 2011 5:27 pm

Post by BillTech »

think i got it
also seems i was having a issue with the _ in some of the variables
B
BillTech
Voice
Posts: 7
Joined: Sat Oct 15, 2011 5:27 pm

Post by BillTech »

heres what i have so far seems to work as needed

bind sign - * xs:flood
set xsbantime 3

bind pub - .xs xs:flood

proc xs:flood {nick uhost hand chan arg} {
global xsbantime xsflooder
if {![botisop $chan]} { return 0 }
if {![string equal "Excess Flood" $arg]} { return 0 }
if {![info exists xsflooder($chan:$uhost)]} {
set xsflooder($chan:$uhost) 1
putlog "No Info - $nick $chan Flood Count $xsflooder($chan:$uhost)"
utimer 30 "set xsflooder($chan:$uhost) 0"
} else {
incr xsflooder($chan:$uhost)
putlog "Add Flood Count - $nick $chan Flood Count $xsflooder($chan:$uhost)"
utimer 30 "set xsflooder($chan:$uhost) 0"
}
if {$xsflooder($chan:$uhost) >= 3} {
puthelp "PRIVMSG $chan :Temp Ban $nick $xsbantime Min XS-Flood"
putserv "MODE $chan +b *!$uhost"
timer $xsbantime "pushmode $chan -b *!$uhost"
puthelp "PRIVMSG $nick :Temp Ban $xsbantime Min on $chan XS-Flood"
putlog "Temp Ban $xsbantime Min $nick *!$uhost on $chan XS-Flood"
set xsflooder($chan:$uhost) 0"
putlog "Reset - $nick $chan Flood Count $xsflooder($chan:$uhost)"
}
}
Post Reply