# On initialise le namespace et on règle les paramètres
namespace eval EXEMPLE {
#### PARAMETRES DE L'ANTI-FLOOD
#
# Anti-flood (0 = désactivé, 1 = activé)
variable antiflood 1
# Combien de commandes sont autorisées en combien de temps ?
# exemple : "6:30" = 6 commandes maximum en 30 secondes;
# les suivantes seront ignorées.
#
# Contrôle anti-flood individuel
# Paramètres antiflood pour la commande1 :
variable cmdflood_commande1 "2:120"
# Paramètres antiflood pour la commande2 :
variable cmdflood_commande2 "4:80"
# Paramètres antiflood pour la commande3 :
variable cmdflood_commande1 "1:60"
#
# Contrôle anti-flood global (toutes commandes confondues)
# remarque : pour le nombre de commandes, spécifiez une valeur supérieure à
# la plus grande valeur définie pour le contrôle de flood
# individuel.
variable cmdflood_global "6:120"
# Intervalle de temps minimum entre l'affichage de 2 messages
# avertissant que l'anti-flood a été déclenché (ne réglez pas
# cette valeur trop bas afin de ne pas être floodé par les messages
# d'avertissement de l'anti-flood...)
variable antiflood_msg_interval 20
# Déclaration des binds et initialisation des variables
bind pub -|- !commande1 EXEMPLE::pub_commande1
bind pub -|- !commande2 EXEMPLE::pub_commande2
bind pub -|- !commande3 EXEMPLE::pub_commande3
# la variable floodsettingsstring doit être modifiée en fonction des commandes
# sur lesquelles vous souhaitez mettre un antiflood :
variable floodsettingsstring [split "global $cmdflood_global commande1 $cmdflood_commande1 commande2 $cmdflood_commande2 commande3 $cmdflood_commande3"]
variable floodsettings ; array set floodsettings $floodsettingsstring
variable instance ; array set instance {}
variable antiflood_msg ; array set antiflood_msg {}
}
# Procédures appelées par les binds :
proc EXEMPLE::pub_commande1 {nick host handle chan arg} {
if {($EXEMPLE::antiflood == 1) && (([EXEMPLE::antiflood $chan "global"] == "flood") || ([EXEMPLE::antiflood $chan "commande1"] == "flood"))} { return }
...
}
proc EXEMPLE::pub_commande2 {nick host handle chan arg} {
if {($EXEMPLE::antiflood == 1) && (([EXEMPLE::antiflood $chan "global"] == "flood") || ([EXEMPLE::antiflood $chan "commande2"] == "flood"))} { return }
...
}
proc EXEMPLE::pub_commande3 {nick host handle chan arg} {
if {($EXEMPLE::antiflood == 1) && (([EXEMPLE::antiflood $chan "global"] == "flood") || ([EXEMPLE::antiflood $chan "commande3"] == "flood"))} { return }
...
}
# Procédures de l'antiflood :
proc EXEMPLE::antiflood {chan type} {
variable antiflood_msg
if {![info exists antiflood_msg($chan$type)]} { set antiflood_msg($chan$type) 0 }
variable instance
if {![info exists instance($chan$type)]} { set instance($chan$type) 0 }
set max_instances [lindex [split $EXEMPLE::floodsettings($type) ":"] 0]
set instance_length [lindex [split $EXEMPLE::floodsettings($type) ":"] 1]
if { $instance($chan$type) >= $max_instances } {
if { $antiflood_msg($chan$type) == 0 } {
set antiflood_msg($chan$type) 1
if {$type != "global"} {
putquick "privmsg $chan :::: Contrôle de flood activé pour la commande \002!$type\002 : pas plus de $max_instances requête(s) toutes les $instance_length secondes."
} else {
putquick "privmsg $chan :::: Contrôle de flood activé sur toutes les commandes de \002NOM_DU_SCRIPT\002 : pas plus de $max_instances commandes toutes les $instance_length secondes."
}
utimer $EXEMPLE::antiflood_msg_interval "EXEMPLE::antiflood_msg_reset $chan $type"
}
return "flood"
} else {
incr instance($chan$type)
utimer $instance_length "EXEMPLE::antiflood_close_instance $chan $type"
return "no flood"
}
}
# Une instance se termine
proc EXEMPLE::antiflood_close_instance {chan type} {
variable instance
if { $instance($chan$type) > 0 } { incr instance($chan$type) -1 }
}
# Réinitialisation du message d'avertissement de l'antiflood
proc EXEMPLE::antiflood_msg_reset {chan type} {
variable antiflood_msg
set antiflood_msg($chan$type) 0
}