# # Copyright (c) 2001 Nick Johnson # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # if ( LIMITLOADED ){ echo Limiter already loaded, doing an unload first. limitunload; } { @LIMITLOADED=1; } # Defaults: # when there are < HIGH spots left, increase the size @ HIGH = 2 # when increasing the size, do it in UP increments @ UP = 5 # when there are > LOW spots left, decrease the size @ LOW = 10 # when decreasing the size, do it in DOWN increments @ DOWN = 5 # wait DELAY minutes between checks/updates @ DELAY = 5 # don't drop the limit below MIN @ MIN = 35 # don't raise the max above MAX @ MAX = 200 # ^assign savefile /home/spatula/.epic/limit.save ^assign DICT[HIGH] High water mark ^assign DICT[LOW] Low water mark ^assign DICT[UP] Increase factor ^assign DICT[DOWN] Decrease factor ^assign DICT[DELAY] Update delay ^assign DICT[MIN] Minimum limit ^assign DICT[MAX] Maximum limit if ( LOW < UP + HIGH ) { limitecho LOW must not be < UP+HIGH or a loop could be triggered!; @ LOW = UP + HIGH + 1; } if ( HIGH > LOW - DOWN ) { limitecho HIGH must not be > LOW-DOWN or a loop could be triggered!; @ HIGH = LOW - DOWN + 1; } if ( UP < HIGH ) { limitecho UP must be > HIGH!; @ UP = HIGH + 1; } if ( DOWN > LOW ) { limitecho DOWN must be < LOW!; @ DOWN = LOW - 1; } alias limitreload { limitecho Reloading saved config... foreach MANAGING x { limitrm \#$x; } eval load $savefile; } alias limitunload { # only need to get rid of globals as the aliases clean up after themselves foreach MANAGING x { limitrm \#$x; } ^alias -limitecho; ^alias -limitshow; ^alias -limitdelay; ^alias -limitmin; ^alias -limitmax; ^alias -limitdown; ^alias -limitup; ^alias -limitlow; ^alias -limithigh; ^alias -six.limit; ^alias -six.manageadd; ^alias -six.manage; ^alias -six.managerm; ^alias -limitrm; ^alias -limitadd; ^alias -limitsave; ^alias -limithelp; foreach DICT x { ^assign -DICT[$x]; } foreach CONF x { foreach $CONF[$x] y { ^assign -CONF[$x][$y]; } } ^assign -UP; ^assign -DOWN; ^assign -HIGH; ^assign -LOW; ^assign -MIN; ^assign -MAX; ^assign -DELAY; ^assign -savefile; echo =6= Channel Limiter unloaded ^alias -limitunload; } alias limitecho { echo =6= $0- } alias limitshow { if ( !ischannel($0) ){ limitecho Usage: /limitshow #channel limitecho Currently managing: foreach CONF x { limitecho \#$x; } ^assign -x; return; } ^assign l.chan $mid(1 999 $0); limitecho Limits in place for \#$l.chan: foreach CONF[$l.chan] key { limitecho $key \($DICT[$key]\) = $CONF[$l.chan][$key]; } ^assign -l.chan; ^assign -x; } alias limitdelay { if ( !ischannel($0) ){ limitecho Usage: /limitmax #channel delay limitecho Sets the interval in minutes between checks/updates return; } ^assign l.limit $1; ^assign l.chan $mid(1 999 $0); if ( !(l.limit > 0) ) { limitecho Invalid delay ^assign -l.limit; ^assign -l.chan; return; } @CONF[$l.chan][DELAY] = l.limit; limitecho DELAY set. Be sure to use /limitsave to save your changes if desired ^assign -l.limit; ^assign -l.chan; } alias limitmin { if ( !ischannel($0) ){ limitecho Usage: /limitmax #channel minlimit limitecho Sets the minimum limit for the channel return; } ^assign l.chan $mid(1 999 $0); ^assign l.limit $1; if ( l.limit >= CONF[$l.chan][MAX] ) { limitecho MAX must be > MIN limitecho Use /limitshow to see your limits ^assign -l.limit; ^assign -l.chan; return; } @CONF[$l.chan][MIN]=l.limit; limitecho MIN set. Be sure to use /limitsave to save your changes if desired ^assign -l.chan; ^assign -l.limit; } alias limitmax { if ( !ischannel($0) ){ limitecho Usage: /limitmax #channel maxlimit limitecho Sets the maximum limit for the channel return; } ^assign l.chan $mid(1 999 $0); ^assign l.limit $1; if ( l.limit <= CONF[$l.chan][MIN] ) { limitecho MAX must be > MIN limitecho Use /limitshow to see your limits ^assign -l.limit; ^assign -l.chan; return; } @CONF[$l.chan][MAX]=l.limit; limitecho MAX set. Be sure to use /limitsave to save your changes if desired ^assign -l.chan; ^assign -l.limit; } alias limitdown { if ( !ischannel($0) ){ limitecho Usage: /limitdown #channel limit limitecho Sets the factor by which the limit is decreased return; } ^assign l.limit $1; if ( !(l.limit > 0) ) { limitecho Invalid limit ^assign -l.limit; return; } ^assign l.chan $mid(1 999 $0); if ( CONF[$l.chan][HIGH] > CONF[$l.chan][LOW] - l.limit ) { limitecho HIGH must not be > LOW - DOWN limitecho Use /limitshow to see your limits ^assign -l.limit; ^assign -l.chan; return; } if ( l.limit > CONF[$l.chan][LOW] ) { limitecho DOWN must be < LOW limitecho Use /limitshow to see your limits ^assign -l.limit; ^assign -l.chan; return; } @CONF[$l.chan][DOWN] = l.limit; limitecho DOWN set. Be sure to use /limitsave to save your changes if desired ^assign -l.chan; ^assign -l.limit; } alias limitup { if ( !ischannel($0) ){ limitecho Usage: /limitup #channel limit limitecho Sets the factor by which the limit is increased return; } ^assign l.limit $1; if ( !(l.limit > 0) ) { limitecho Invalid limit ^assign -l.limit; return; } ^assign l.chan $mid(1 999 $0); if ( CONF[$l.chan][LOW] < l.limit + CONF[$l.chan][HIGH] ) { limitecho LOW must not be < UP + HIGH limitecho Use /limitshow to see your limits ^assign -l.limit; ^assign -l.chan; return; } if ( l.limit < CONF[$l.chan][HIGH] ) { limitecho UP must be > HIGH limitecho Use /limitshow to see your limits ^assign -l.limit; ^assign -l.chan; return; } @CONF[$l.chan][UP] = l.limit; limitecho UP set. Be sure to use /limitsave to save your changes if desired ^assign -l.chan; ^assign -l.limit; } alias limitlow { if ( !ischannel($0) ){ limitecho Usage: /limitlow #channel limit limitecho Sets the maximum space left before decreasing return; } ^assign l.limit $1; if ( !(l.limit > 0) ) { limitecho Invalid limit ^assign -l.limit; return; } ^assign l.chan $mid(1 999 $0); if ( l.limit < CONF[$l.chan][UP] + CONF[$l.chan][HIGH] ) { limitecho LOW must not be < UP + HIGH limitecho Use /limitshow to see your limits ^assign -l.limit; ^assign -l.chan; return; } if ( CONF[$l.chan][HIGH] > l.limit - CONF[$l.chan][DOWN] ) { limitecho HIGH must not be > LOW - DOWN limitecho Use /limitshow to see your limits ^assign -l.limit; ^assign -l.chan; return; } if ( CONF[$l.chan][DOWN] > l.limit ) { limitecho DOWN must be < LOW limitecho Use /limitshow to see your limits ^assign -l.limit; ^assign -l.chan; return; } @CONF[$l.chan][LOW] = l.limit; limitecho LOW set. Be sure to use /limitsave to save your changes if desired ^assign -l.chan; ^assign -l.limit; } alias limithigh { if ( !ischannel($0) ){ limitecho Usage: /limithigh #channel limit limitecho Sets the minimum space left before increasing return; } ^assign l.limit $1; if ( !(l.limit > 0) ) { limitecho Invalid limit ^assign -l.limit; return; } ^assign l.chan $mid(1 999 $0); if ( CONF[$l.chan][LOW] < CONF[$l.chan][UP] + l.limit ) { limitecho LOW must not be < UP + HIGH limitecho Use /limitshow to see your limits ^assign -l.limit; ^assign -l.chan; return; } if ( $l.limit > CONF[$l.chan][LOW] - CONF[$l.chan][DOWN] ) { limitecho HIGH must not be > LOW - DOWN limitecho Use /limitshow to see your limits ^assign -l.limit; ^assign -l.chan; return; } if ( CONF[$l.chan][UP] < $l.limit ) { limitecho UP must be > HIGH limitecho Use /limitshow to see your limits ^assign -l.limit; ^assign -l.chan; return; } @CONF[$l.chan][HIGH] = l.limit; limitecho HIGH set. Be sure to use /limitsave to save your changes if desired ^assign -l.chan; ^assign -l.limit; } alias six.limit { ^assign chan $0; ^assign chname \#$0; ^assign cmode $index("l" $before(" " $chanmode($chname))) if ( cmode >= 0 ) { ^assign current $after(-1 " " $chanmode($chname)); } { ^assign current 0 } ^assign count $numonchannel($chname); ^assign newsize 0; if ( current < CONF[$chan][MIN] ) { @ newsize = count + CONF[$chan][UP]; }{ if ( current > CONF[$chan][MAX] ) { @ newsize = count + CONF[$chan][UP]; }{ if ( count > current - CONF[$chan][HIGH] ) { @ newsize = count + CONF[$chan][UP]; }{ if ( count < current - CONF[$chan][LOW] ) { @ newsize = current - CONF[$chan][DOWN]; } } } } if ( newsize > CONF[$chan][MAX] ) { if ( current < CONF[$chan][MAX] ) { @ newsize = CONF[$chan][MAX]; } { @ newsize = 0; } } if ( newsize > 0 && newsize < CONF[$chan][MIN] ) { if ( current != CONF[$chan][MIN] ) { @ newsize = CONF[$chan][MIN]; } { @ newsize = 0; } } if ( newsize != 0 ) { if ( newsize < count ) { @ newsize = count + CONF[$chan][UP]; } /mode $chname +l $newsize; } ^assign -count; ^assign -current; ^assign -chan; ^assign -chname; ^assign -newsize; ^assign -cmode; } alias six.manageadd { ^assign manageadd.chan $0; if ( !MANAGING[$manageadd.chan] ) { @MANAGING[$manageadd.chan] = 1; ^timer -refnum $manageadd.chan -repeat -1 ${CONF[$manageadd.chan][DELAY] * 60} six.manage $manageadd.chan; } ^assign -manageadd.chan; } alias six.manage { ^assign manage.chan $0; if ( MANAGING[$manage.chan] ) { six.limit $manage.chan; } ^assign -manage.chan; } alias six.managerm { ^assign -MANAGING[$0]; ^timer -delete $0; } alias limitrm { if ( !ischannel($0) ) { limitecho Usage: /limitrm #channel return; } ^assign chan $mid(1 999 $0); six.managerm $chan foreach CONF[$chan] x { ^assign -CONF[$chan][$x]; } limitecho Removed \#$chan from limit management. ^assign -chan; } alias limitadd { if ( !ischannel($0) ) { limitecho "Usage: limitadd #channel"; return; } ^assign limitchan $0; limitecho Adding channel $limitchan to limit management; limitecho Copying defaults...; ^assign chan $mid(1 999 $limitchan); @CONF[$chan][HIGH] = HIGH; @CONF[$chan][UP] = UP; @CONF[$chan][LOW] = LOW; @CONF[$chan][DOWN] = DOWN; @CONF[$chan][DELAY] = DELAY; @CONF[$chan][MIN] = MIN; @CONF[$chan][MAX] = MAX; limitecho You can change the limits for the channel using the; limitecho limithigh, limitup, limitlow, limitdown, limitdelay,; limitecho limitmin, and limitmax commands.; six.manageadd $chan; ^assign -limitchan; ^assign -chan; } alias limitsave { ^exec -name saver cat >$savefile @l.count=0; foreach CONF channel { foreach CONF[$channel] setting { ^msg %saver ^assign CONF[$channel][$setting] $CONF[$channel][$setting]; } ^msg %saver ^six.manageadd $channel; ^msg %saver limitecho Loaded \#$channel; @l.count++; } ^msg %saver limitecho Loaded settings for $l.count channels ^exec -close %saver; ^assign -channel; ^assign -setting; limitecho Settings saved } alias limithelp { limitecho Channel limiter 0.5 by Number-6 limitecho Commands: limitecho /limitunload - unload this script limitecho /limitreload - reset configuration to saved settings limitecho /limitadd <#channel> - Add a channel to limit management limitecho /limitrm <#channel> - Remove a channel from limit management limitecho /limitsave - save limit settings limitecho /limitshow [#channel] - show what channels are being managed, or if a limitecho channel name is provided, show the settings for that channel limitecho /limithigh, /limitlow, /limitup, /limitdown, /limitmax, /limitmin, limitecho /limitdelay - adjust how limits are applied to a limitecho channel. For help with these commands, type the command with no limitecho arguments } eval load $savefile if ( epic() && V>=20000101 ) { limitecho Channel limiter 0.5 by Number-6 Loaded limitecho Use /limithelp for a list of commands } { limitecho This script requires ircii-epic4 or later limitunload }