08-18-2017, 14:40 +0200
AuthorPost
CyBex  07-02-2004, 14:04   | [EGG] Anti Flood Trigger Jabber  ICQ  AOL IM  Yahoo IM  MSN  Homepage
nie da
(Administrator)

Avatar

Member since 01/2004
260 Posts
Location: Berlin
                                                                                                                              
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
bind pub - !example PROCNAME
proc PROCNAME {nick host hand chan text} {

    # setup flood time
    set floodtime 120

    # create a globalvar to save lasttime usage
    if ![info exist ::mylastPROCNAME] {set ::mylastPROCNAME [unixtime]}

    # select type .. notice to nick when last usage is lesser then 30 secs
    if {[expr [unixtime]-$::mylastPROCNAME]>$floodtime} {set type privmsg; set dest $chan} \
        else {set type notice; set dest $nick}

    # save last usage of trigger
    set ::mylastPROCNAME [unixtime];

    #output
    puthelp "$type $dest :$text"

}


This example switch from public-message to private-notice if someone use the trigger to fast...

mfG CyBex @ QuakeNet, UnderNet, EFNet, Freenode, euIRC, GameSurge & ShadowWorld - Files
This post was edited 6 times, last on 08-12-2009, 21:22 by thommey
Deflex  07-02-2004, 14:22   Homepage
(Moderator)

Avatar

Member since 03/2004
6 Posts
Location: Germany, NRW
(u)timer method:                                                                                                                               
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
bind pub - !example PROCNAME

proc PROCNAME { nick uhost handle chan arg } {

    # create a sub-proc to delay
    proc delay {} { return }

    # timer already running?
    if {[utimerexists delay] == ""} {

        # timer is not active, perform something
        puthelp "PRIVMSG $chan :your text here"
        # your code goes here, like call an other proc

        # starting timer to prevent flooding next time
        utimer 120 delay

    } else {

        # timer is already active
        puthelp "NOTICE $nick :Your Errormsg here"

    }
}

This post was edited 3 times, last on 08-12-2009, 21:22 by thommey
CyBex  07-02-2004, 15:18   Jabber  ICQ  AOL IM  Yahoo IM  MSN  Homepage
nie da
(Administrator)

Avatar

Member since 01/2004
260 Posts
Location: Berlin
                                                                                                                              
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
bind pub - !example PROCNAME

proc PROCNAME {nick host hand chan text} {

    # flood-setup  maxusage:persecond , like other flood settings, this means 3 time in 3 minutes
    set flood 3:180

    # create a counter
    if ![info exists ::mylastPROCNAME] {set ::mylastPROCNAME 0}

    # easier use of the flood-settings
    set max [lindex [split $flood ":"] 0]; set time [lindex [split $flood ":"] 1]

    # select type
    if {$::mylastPROCNAME>=$max} {set type notice; set dest $nick} \
        else {set type privmsg; set dest $chan}

    # increase the counter now and after time decrease to zero
    incr ::mylastPROCNAME; utimer $time [list incr ::mylastPROCNAME -1]

    #output
    puthelp "$type $dest :$text"

}


This example switch from public-message to private-notice if someone use the trigger to fast...

mfG CyBex @ QuakeNet, UnderNet, EFNet, Freenode, euIRC, GameSurge & ShadowWorld - Files
This post was edited 2 times, last on 08-12-2009, 21:23 by thommey
CyBex  09-10-2005, 21:47   Jabber  ICQ  AOL IM  Yahoo IM  MSN  Homepage
nie da
(Administrator)

Avatar

Member since 01/2004
260 Posts
Location: Berlin
It is often desired to limit certain public triggers to only once each n seconds; this is how you do it:

You need a global variable to hold a timestamp - that is an unique representation of the time your command was last triggered. That variable is checked/set in the associated proc, as following:                                                                                                                               
01
02
03
04
05
06
07
08
09
10
11
12
13
proc mylimitedproc {param1 param2} {
    global limit_mylimitedproc
    if {[info exists limit_mylimitedproc] && [unixtime] - ${limit_mylimitedproc} < 20} {
        return ;# This procedure may not be called right now

    } else {
        set limit_mylimitedproc [unixtime]

    }



}


Moved from other alone topic, Author Elven

mfG CyBex @ QuakeNet, UnderNet, EFNet, Freenode, euIRC, GameSurge & ShadowWorld - Files
This post was edited 2 times, last on 08-12-2009, 21:24 by thommey
sKy\  10-12-2005, 01:46  
(Moderator)

Avatar

Member since 05/2005
8 Posts
Location: Germany, Zeitz
                                                                                                                              
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
####################################################################################################################################
# preprocname
####################################################################################################################################

proc preprocname { } {
    return [lindex [split [info level [expr [info level] - 2]]] 0]
}

####################################################################################################################################
# variable:minus:one
####################################################################################################################################

proc variable:minus:one { varname } {
    if { [info exists $varname] } {
        set $varname [expr [set $varname] - 1]
        if { [set $varname] <= 0 } {
            unset $varname
        }
        return 1
    } else {
        return 0
    }
}

####################################################################################################################################
# utimer_floodprotection_action_intime (utimer method)
####################################################################################################################################
# advantage: no memory lag
# disadvantage: many utimers, high cpu usage
# usage: utimer_floodprotection_action_intime $allowed_actions $intime_seconds
# usage: if { [utimer_floodprotection_action_intime 3 10] } { return }
# usage: if { [utimer_floodprotection_action_intime 3 10 "$channel,$hostname"] } { return }

proc utimer_floodprotection_action_intime { allowed_actions intime_seconds {arglist ""} } {
    set preprocname "::utimer_floodprotection_action_intime_array("
    append preprocname [preprocname]
    if { $arglist != "" } {
        append preprocname ",$arglist)"
    } else {
        append preprocname ")"
    }
    if { ! [info exists $preprocname] } {
        set $preprocname 0
    }
    if { [set $preprocname] >= $allowed_actions } {
        return 1
    } else {
        incr $preprocname
        utimer $intime_seconds [list variable:minus:one $preprocname]
        return 0
    }
}

# testproc utimer method
proc teee { } {
    if { [utimer_floodprotection_action_intime 3 10] } {
        return "tee: floodprotected"
    } else {
        return "tee: okay"
    }
}

####################################################################################################################################
# flood_protection (unixtime method)
####################################################################################################################################
# advantage: no utimers, lower cpu usage
# disadvantage: memory lag, unixtime necessary
# usage: unixtime_flood_protection_action_intime $allowed_actions $intime_seconds
# usage: if { [unixtime_flood_protection_action_intime 3 10] } { return }
# usage: if { [unixtime_flood_protection_action_intime 3 10 "$channel,$hostname"] } { return }

proc unixtime_flood_protection_action_intime { allowed_actions intime_seconds {arglist ""} } {
    set preprocname "::unixtime_flood_protection__action_intime_array("
    set counter "::unixtime_flood_protection_counter_array("
    append preprocname [preprocname]
    append counter [preprocname]
    if { $arglist != "" } {
        append preprocname ",$arglist)"
        append counter ",$arglist)"
    } else {
        append preprocname ")"
        append counter ")"
    }
    if { ! [info exists $preprocname] } {
        set $preprocname [unixtime]
    }
    if { ! [info exists $counter] } {
        set $counter 1
    }
    set result [expr { [unixtime] - [set $preprocname] } ]
    if { $result < $intime_seconds } {
        if { $allowed_actions == 1 } {
            return 1
        }
        if { [set $counter] >= $allowed_actions } {
            return 1
        } else {
            incr $counter
            set $preprocname [unixtime]
            return 0
        }
    } else {
        unset -nocomplain $counter
        set $preprocname [unixtime]
        return 0
    }
}

# testproc unixtime method
proc feee { } {
    if { [unixtime_flood_protection_action_intime 3 10] } {
        return "feee: floodprotected"
    } else {
        return "feee: okay"
    }
}


[Not loaded: http://sky.tclhelp.net/sky.gif]
This post was edited 1 times, last on 08-12-2009, 21:26 by thommey
Advanced options for this topic:

Ignore this topic (Do not list this topic in the "unread topics" search. You are currently not ignoring this topic.)
Hide this topic (Hidden topics are not displayed in the topics list. This topic is currently not hidden.)
Go to forum

Unclassified NewsBoard 1.5.3-d | © 2003-4 by Yves Goergen