crowdcontrol.tcl

crowdcontrol.tcl

TCL script that protects the channel and limit it when its neccesary, without human intervention. crowdcontrol.tcl v1.0 for Eggdrop 1.3.x

Postat de Copyright Categorie Review user Vizualizari Data
btc Dagmar d`Surreal protections Cod netestat 500 2023-12-25 00:09:06

#
# crowdcontrol.tcl v1.0 for Eggdrop 1.3.x series bots
#                     Dagmar d'Surreal -- [email protected]
#
# $Source: /home/devel/eggdrop/scripts/RCS/crowdcontrol-1.0.tcl,v $
# $Date: 1998/11/04 21:43:14 $
# $Revision: 1.2 $
#
# This is the second revision of the script, and should work without much
# intervention on the part of the bot operator.  Provided you all use the
# same settings, this should also be able to be run on more then one bot at
# a time, but this will basically make the limits a little TOO flexible so
# until the botnet code is written, *don't* do it.
#
# I should probably explain the parameters of operation here, so pay
# attention.  The ccontrol_period variable controls how many minutes will
# pass before the bot will consider changing the channel limit.  This can
# only be set to one interval for all channels at the moment.  The
# ccontrol_channels variable is a two-dimensional array which is explained a
# little more below.  The clearance value it refers to is the number of
# people more than the current number in the channel that the limit will
# be set to if it needs tweaking.  (69 people in the channel with a clearance
# of 7 will mean +l 73)  The grace value is a number which should be set
# relatively low to try and cut down further on the mode changes without
# screwing things up too much.  If the current limit is within +/- the grace
# value from the exact limit wanted, the bot will just leave the limit alone.
# This is both to be nice to the servers, as well as to cut down on silly
# mode scrolling just because one or two people left.  I would NEVER set
# this to more than 1/3 the clearance value, because it weakens the limit's
# effectiveness.
#
# Final note: This won't entirely eliminate mutli-clone flooding, but it
# will at least cut down on it's effectiveness without bogging the bot
# down too much.
#
# Problems:  (to be eliminated later, maybe)
#  - Long netsplits could cause ugly problems, but if your split wait isn't
#  set to 20 to 30 minutes, you probably already have them.  ;)
#  - Still working on an elegant way of dealing with tcl's crappy hashing
#  system for working out the botnet protocols.  *sigh*
#
# Fixed:
#  - The bot can now run this on multiple channels, but DON'T break the
#  ccontrol_channels array shown below.  Ugly things will happen.
#  - The bot will now check the current channel settings to see if it should
#  attempt to change the limit. 
#  - Contains no polyunsaturated cholesterols and no sodium.
#  - Configuration variable is now a lot easier to deal with.



### BEGIN USER CUSTOMIZABLE AREA

# Okay.  This is the number of minutes between triggers.  This is something
# you probably shouldn't set any lower than it is already.
set ccontrol_period 1

# Here's an example of how to set the parameters for a channel.  Don't
# complain that this is too complex.  It's as elegant as it can get.
# It's a list of lists.  In each sublist, the first argument is the name of
# the channel, the second is the ceiling value for the channel, and the
# third is the grace value for that channel.
set ccontrol_channel {
    { "#BigChannel" 9 3 }
    { "#SmallChannel" 4 1 }
  }

# This is so if you've ever wondered what the bot is doing about things,
# change it to 1 and it will write debugging-type messages to the logs.
# Warning!  This is about five lines of stuff every time it triggers, which
# adds up quick.  I'd suggest you only set this sucker on and off manually
# when you're testing things.
set ccontrol_debug 0

### END USER CUSTOMIZABLE AREA


# Don't go editing below here.  Bad things could happen.

# A little voodoo to set the revision numbers from RCS...
set Revision ""
set Revision [lindex [split "$Revision: 1.2 $" " "] 1]
set Revision [expr int($Revision * 10)]

set scriptver(CrowdControl) "CrowdControl v1.0 r$Revision by Dagmar d'Surreal"

# In case you weren't listening, this script is NOT for pre-1.3.x versions.
if {![info exists numversion] || ($numversion < 1030000)} {
  # Problems with bot stability are YOUR problems.  If this check causes
  # the bot to bail out and die, don't ask me about them.  Recompile using
  # tcl 7.6p2 as static or shared, or 8.0p2 as shared libraries only.
  if {![info exists numversion]} {
    putlog "*** EEEK!  Something is wrong with your tcl!  Please consider"
    putlog "    fixing it before attempting to run $scriptver(CrowdControl)."
    return 0
  }
  putlog "*** Can't load $scriptver(CrowdControl) -- Eggdrop v1.3.x required!"
  return 0
}

# This line is purely so that the value won't start unintialized.
set ccontrol_last 0

proc crowd_control {} {
  global ccontrol_period ccontrol_channel ccontrol_debug
  set already_active 0

  # Screw that flag variable nonsense.  We're hardcore! This slightly
  # obfuscated routine is to ENSURE that no matter how many times you
  # rehash or reload, that the timer can't ever double-up on you.
  foreach item [timers] {
    if {([string compare [lindex $item 1] "crowd_control"] == 0)} {
      # Apparently there's a matching timer already running.  Good!
      set already_active 1
    }
  }

  # If we're not pending to be run again in the future...
  if {!($already_active)} {
    # ...then we need to be.
    timer $ccontrol_period crowd_control
  }
     
  # This is where we start setting up values for channels.
  foreach item $ccontrol_channel {
    set chan [lindex $item 0]

    # Can't do anything if we're not an op.  This also eliminates a bug
    # that shows up when the bot is first started.  :)
    if {![botisop $chan]} {
      if {($ccontrol_debug == 1)} {
        putlog "DEBUG(${chan}): Skipping channel since I'm not an op here." 
      }
      continue
    }

    set total [llength [chanlist $chan]]
    set ceiling [lindex $item 1]
    set grace [lindex $item 2]
    set newlimit [expr $total + $ceiling]
    
    set chan_max [expr $total + $ceiling + $grace]
    set chan_min [expr $total + $ceiling - $grace]

    # What are the modes on that channel at the moment?
    set modes [getchanmode ${chan}]
    # Is there a limit set in the channel already?
    if {([string first "l" [lindex $modes 0]] == -1)} {
      # Nope...
      set limit 0
    } else {
      # Yup.  Set the variable...
      set limit [lindex $modes 1]
    }

    if {($ccontrol_debug == 1)} {
      putlog "DEBUG(${chan}): Channel limit is currently $limit."
      putlog "DEBUG(${chan}): There are $total people in the channel."
      putlog "DEBUG(${chan}): Acceptable range is $chan_min - $chan_max."
    }
    if {(($limit > $chan_max) || ($limit < $chan_min))} {
      if {($ccontrol_debug == 1)} {
        putlog "DEBUG(${chan}): Setting channel limit to $newlimit."
      }
      pushmode ${chan} +l $newlimit
    } else {
      if {($ccontrol_debug == 1)} {
        putlog "DEBUG(${chan}): Channel limit is with acceptable range."
      }
    }
  }
}


putlog "$scriptver(CrowdControl) now loaded."

crowd_control