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.

adding join flood check

Help for those learning Tcl or writing their own scripts.
Post Reply
Z
Zircon
Op
Posts: 191
Joined: Mon Aug 21, 2006 4:22 am
Location: Montreal

adding join flood check

Post by Zircon »

Hi all

I think i ll have more chance here. I have this little script that send a notice to everyone joining the channel. I want to prevent the bot from being laggued or disconnected when there is a join flood. I want to modify this script so the bot stop sending notices for 1 min, when there is 3 joins (or more) in 1 second. How can i do it ?

Code: Select all

bind join -|- * join_culture
proc join_culture {nick host hand chan} {
  if {$chan == "#culture"} {
puthelp "NOTICE $nick :tapez !help dans #culture pour avoir la liste des commandes"

  }
}
Thanks in advance
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

Theoretically using puthelp is quite a good methode to prevent floodings. However too many putquick scritps often screw this.

I use a little helper for anti-flood protections I wrote myself.

Code: Select all

#	#	#	#	#	#	#	#	#
# decrease
# usage  : decrease <var>
# return : 0 or 1 (can be discarded)
#
# info   : usefull for save var decreasings, var cannot drop below 0 and no
#          TCL error can occure
#

proc decrease {var} {
	if {[info exists ::$var]} {
		if {[set ::$var] <= 1} {
			set ::$var 0
		} else {
			incr ::$var -1
		}
		return 0
	} else {
		putlog "decrease: Variable '$var' doesn't exist"
		return 1
	}
}
You should now create a global variable containing a counter check for this before you send the stuff. An abstract example would be:

Code: Select all

set example_c 0

proc example {nick host hand chan} {
  if {$::example_c < 3} {
    incr $::example_c
    utimer 1 {decrease example_c}

    #do stuff here
  }
  return 0
}
Some explanations:
- The helper function is used to avoid the variable to drop below 0 due to .rehash while there is a timer running
- The parameter to the helper function must be the variable name, not the variable content.
- the constants 3 and 1 in the above example reflect allowed executions x within the timespan y seconds. Note that 1 second can never be accurate, since utimer triggers on full seconds, therefore the actual timespan x is: 0s < x < 1s
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Z
Zircon
Op
Posts: 191
Joined: Mon Aug 21, 2006 4:22 am
Location: Montreal

Post by Zircon »

Hello De Kus

Thanks a lot for your help, and clear explanations. I appreciate, really. I ll do what you advised me. Thanks again :)
User avatar
droolin
Halfop
Posts: 64
Joined: Thu Jul 24, 2003 9:07 pm
Contact:

Thank you also

Post by droolin »

I can see that bit of code being used for a few things that I've been planing to do, just never had an idea how to go about it.

droolin
Post Reply