pmsgs You have no new messages
Fri Jul 3rd 2009 Welcome, Anonymous! › Log in Or Register
› Viewing Code Snippet → Channel Flood Protection.

Projects's information

Project Name : Channel Flood Protection
File Size : 15.921 kb
Author : tye
Project Description : Advanced Channel Text flood protection for channel operators.
Line Numbers : Show Lines Number

; Channel Text Flood Protection
; Copyright 2004,2005 Tye Shavik <tye@mirc.net>
; Tye on DALnet in #mirc
; Tye (or Tye__) on Undernet in #mirc.net and #hawkee.com
;
; You are free to use this code in your script provided you keep the copyright notice and the following documentation intact.
; If you wish to contribute any changes to the code or report a bug/suggestion contact me at the email above.
;
; Installation:
; Load the script file into your remotes using the command:
;        /load -rs "C:\path\to\file.mrc"
; You can also cut/paste the script and paste it into a new remote file.
; Create a new remote file by opening the Script Editor and using the File -> New menu in the Remote section.
;
; Description:
; This is advanced Channel Text flood protection. This is geared towards power users. I've tried to make it very configurable. It is
; only for channel text (including actions and notices) and is meant for channel operators to easily punish flooders. It provides
; no personal protection.
;
; Configuration:
; The script will set default values when it is loaded. The entire script is disabled by default.
; Use the channel or menubar popups to configure the script.
;
; Menus:
; 'Use Flood Protection'
;   This is the global setting to turn on/off the addon. It is OFF by default.
;
; 'Use only when opped/hopped'
;   This option will turn off the addon for channels that you are not opped/halfopped in.
;
; 'Do not use for other ops/hops'
;   This will protect other ops/hops from triggering the flood protection
;
; 'Change Kick Message'
;   This allows you to change the kick message you use to kick flooders. You can use the %nick %lines and %secs variables to enter their
;   respective values in the kick message. Leave the editbox blank when editing this option to set the default value.
;
; 'Set Ban Time'
;   If this option is set, bans set by the addon will be automatically removed after the specified number of sections. Set it to 0 to disable it.
;
; 'Alert' menu
; 'Alert me when protection is triggered'
;   This is the global option to enable/disable all of the options in the Alert menu.
;
; 'Highlight the window button'
;   If enabled the window button of a channel where the flood protection has been triggered will be highlighted with the highlight colour
;   in mIRC Options (Alt+o) -> Display
;
; 'Flash the mIRC taskbar button'
;   If enabled this option will cause the mIRC taskbar button (or system tray icon) to flash. When you are enabling the option you will
;   be prompted to enter a message to flash. Use the $nick $chan and $network identifiers to print their respective values. Leave the editbox
;   blank to set the default option. To change the message without toggling the option hold Shift when you click the menu item.
;
; 'Dispay message in active window'
;   This will display a message in the active mIRC window with the channel/network the flood protection has been triggered in.
;
; 'Reaction' menu
;   This menu contains the action to perform when a user has triggered the flood protection.
; 'Ban host'
;   Ban the user's *!*@host when they trigger the flood protection
;
; 'Kick/Ban user and clones'
;   Bans the user's *!*@host and kick them and all of their clones
;
; 'Let me choose'
;   This option will give you the choice of punishment by pressing an FKEY (See the fkeys section below) or typing a command.
;
; 'Triggers' menu
; The triggers menu allows you to set when the flood protection will be triggered. Click the 'Add Trigger' menu to add a trigger.
; Enter the number of lines and seconds the trigger should execute at. The number of seconds can contain decimals. Click on one
; of the listed triggers and you will be prompted to change or delete it. The order of the triggers does not matter.
;
; When a user triggers the flood protection your Alert settings will be applied. A message will be displayed in the channel
; the protection was triggered in.
;
; 'Fkeys' menu
; To bind a punishment to an fkey for quicker action. Select a punishment and its fkey to bind that punishment to that fkey.
; Only Fkeys not being used by other scripts are shown. Click the selected fkey to deselect it. If you want to use the punishments
; with a different fkey management addon or if you don't want to use fkeys enter these commands:
;   Kick/ban punishment: /flood.kick
;   Ban only: /flood.ban
;   Moderate channel: /flood.mod
; All of those commands work for the active window.

alias flood.kick { flood_punish kick $active }
alias flood.ban { flood_punish ban $active }
; Change the +m in the command below to the modes to set when moderating a channel
; For example, you could use +M on DALnet, or add i to set it invite only
alias flood.mod { flood_punish +m $active }

on *:TEXT:*:#: flood_
on *:ACTION:*:#: flood_
on *:NOTICE:*:#: flood_

/*
; A good way to protect users is to use these events instead of the above and add users to your userlist (/guser 2 nick 3)
on +1:TEXT:*:#: flood_
on +1:ACTION:*:#: flood_
on +1:NOTICE:*:#: flood_
*/


alias -l flood_punish {
  ; Check if we're using the 'Moderate channel' punishment
  if (!$istok(ban kick,$1,32)) {
    if (($me isop $2) || ($me ishop $2)) {
      mode $chan $1-
    }
  }
  else {
    var %q = $($+(%,flood_punish.,$cid,.,$2),2)
    if (%q) {
      ; Check if you're opped/hopped on the channel
      if (($me isop $2) || ($me ishop $2)) {
        var %wildsite = $gettok(%q,2,32)
        ; Ban the *!*@host
        mode $2 +b $gettok(%q,2,32)
        ; Set timer to unban if enabled
        if (%flood_ban) { .timer 1 %flood_ban if (($me isop $2 $+ ) || ($me ishop $2 $+ )) && ($me ison $2 $+ ) mode $2 -b %wildsite }
        ; If this is the ban punishment, stop here
        if ($1 == ban) { return }

        ; Set variables and kick the nickname who triggered the protection
        var %nick = $gettok(%q,1,32), %lines = $gettok(%q,3,32), %secs = $gettok(%q,4,32)
        if ((%nick isreg $2) || (%nick isvoice $2)) && (%nick ison $2) {
          kick $2 %nick $(%flood_kick,2)
        }

        ; Loop through $ialchan and kick clones of user who triggered
        var %x = $ialchan(%wildsite,$2,0)
        while (%x) {
          var %nick = $ialchan(%wildsite,$2,%x).nick
          if (%nick isreg $2) || (%nick isvoice $2) {
            kick $2 %nick $(%flood_kick,2)
          }
          dec %x
        }
      }
    }
  }
}

alias -l flood_ {
  ; Check if protection is enabled
  if (%flood_protection) && (!$($+(%,flood_triggered.,$cid,.,$site),2)) {
    ; Check if we need to be opped/hopped to use it
    if (%flood_opt & 1) && (($me isop $chan) || ($me ishop $chan)) || (%flood_opt !& 1) {
      ; Check if target user is opped/hopped
      if (%flood_opt & 2) && (($nick isreg $chan) || ($nick isvoice $chan)) || (%flood_opt !& 2) {

        var %q = $+($chan,.,$cid,.,$site)
        var %f = $hget(flood_,%q)

        ; Reset records according to options
        if ($calc($ticks - $gettok(%f,1,32)) > $calc($gettok(%flood_reset,2,32) * 1000)) { unset %f }
        if ($gettok(%f,2,32) >= $gettok(%flood_reset,1,32)) { unset %f }

        ; Increment line count
        if (!$len(%f)) { var %f = $ticks 0 }
        hadd -m flood_ %q $gettok(%f,1,32) $calc($gettok(%f,2,32) + 1)
        var %f = $hget(flood_,%q)

        ; Loop through triggers and see if any have been exceeded
        var %secs = $calc(($ticks - $gettok(%f,1,32)) / 1000)
        var %lines = $gettok(%f,2,32)
        var %x = $numtok(%flood_trigger,32)
        while (%x) && (%lines) && (%secs) {
          var %f = $gettok(%flood_trigger,%x,32)
          var %l = $gettok(%f,1,58)
          var %s = $gettok(%f,2,58)
          if (%lines >= %l) && (%secs <= %s) {
            ; If a trigger has been exceeded, display this message
            echo $color(highlight) -t $chan * Channel Flood from $nick ( $+ $site $+ ): %lines lines in %secs seconds.
            if (%flood_reaction == 3) {
              var %kick_key = $replace($upper($gettok(%flood_fkeys,1,32)),s,Shift+,c,Ctrl+)
              var %ban_key = $replace($upper($gettok(%flood_fkeys,2,32)),s,Shift+,c,Ctrl+)
              echo $color(highlight) -t $chan * $iif(%kick_key != _,Press $+(,%kick_key,),Type /flood.kick) to kick/ban or $iif(%ban_key != _,$+(,%ban_key,),/flood.ban) to ban
            }
            elseif (%flood_reaction == 2) {
              echo $color(highlight) -t $chan * Punishing by kick/ban
              flood_punish kick $chan
            }
            elseif (%flood_reaction == 1) {
              echo $color(highlight) -t $chan * Punishing by ban
              flood_punish ban $chan
            }
            if (%flood_opt & 4) {
              if (%flood_opt & 8) {
                ; Highlight the switchbar button
                window -g2 $chan
              }
              if (%flood_opt & 16) && (%flood_switchbar) {
                ; Flash taskbar button
                flash $(%flood_switchbar,2)
              }
              if (%flood_opt & 32) && (($active != $chan) || ($activecid != $cid)) {
                ; Display message in active window
                echo $colour(highlight) -ta * Flood protection triggered in $chan on $network 
              }
            }
            ; Record user who triggered protection
            set $+(%,flood_punish.,$cid,.,$chan) $nick $wildsite %lines %secs
            set -u60 $+(%,flood_triggered.,$cid,.,$site) 1
            break
          }
          dec %x
        }
      }
    }
  }
}
on *:EXIT: {
  ; Cleanup temp variables
  unset %flood_triggered.*
  unset %flood_punish.*
}
on *:LOAD: {
  ; Set defaults
  unset %flood_triggered.* %flood_punish.* %flood_trigger %flood_protection %flood_opt %flood_reset $&
    %flood_switchbar %flood_kick %flood_ban %flood_reaction
  set %flood_opt 29
  set %flood_kick Text Flood: $+(%,lines) lines in $+(%,secs) seconds.
  set %flood_switchbar Flood in $!chan on $!network
  set %flood_trigger 5:5.5 7:9 8:10 12:15 17:27
  set %flood_reset 18 28
  set %flood_reaction 3
  set %flood_fkeys _ _ _
}
on *:START: {
  ; Cleanup temp variables
  unset %flood_triggered.*
  unset %flood_punish.*
}
on *:UNLOAD: {
  ; Unset all variables
  unset %flood_triggered.* %flood_punish.* %flood_trigger %flood_protection %flood_opt %flood_reset $&
    %flood_switchbar %flood_kick %flood_ban %flood_reaction %flood_fkeys
}

menu channel,menubar {
  Channel Text Flood Protection
  .$iif(%flood_protection,$style(1)) Use Flood Protection:set %flood_protection $iif(%flood_protection,0,1)
  .$iif(%flood_opt & 1,$style(1)) Use only when opped/hopped:set %flood_opt $iif(%flood_opt & 1,$calc(%flood_opt - 1),$calc(%flood_opt + 1))
  .$iif(%flood_opt & 2,$style(1)) Do not use for other ops/hops:set %flood_opt $iif(%flood_opt & 2,$calc(%flood_opt - 2),$calc(%flood_opt + 2))
  .Change Kick Message: {
    var %k = $input(Enter kick message. Use $+(%,nick) $+ $chr(44) $+(%,lines) and $+(%,secs) variables.,e,Input Request,%flood_kick)
    if (%k) {
      set %flood_kick %k
    }
    else {
      set %flood_kick Text Flood: $+(%,lines) lines in $+(%,secs) seconds.
    }
  }
  .Set Ban Time [[ $+ $iif(%flood_ban,$+($v1,s),Disabled) $+ ]:set %flood_ban $input(Enter ban time in seconds (0 to disable):,e)
  .-

  .Alert
  ..$iif(%flood_opt & 4,$style(1)) Alert me when protection is triggered:set %flood_opt $iif(%flood_opt & 4,$calc(%flood_opt - 4),$calc(%flood_opt + 4))
  ..-
  ..$iif(%flood_opt & 8,$style(1)) Highlight the window button:set %flood_opt $iif(%flood_opt & 8,$calc(%flood_opt - 8),$calc(%flood_opt + 8))
  ..$iif(%flood_opt & 16,$style(1)) Flash the mIRC taskbar button: {
    if ($mouse.key !& 4) { set %flood_opt $iif(%flood_opt & 16,$calc(%flood_opt - 16),$calc(%flood_opt + 16)) }
    if (%flood_opt & 16) || ($mouse.key & 4) {
      set %flood_switchbar $iif($input(Enter message to flash. Use $!nick $+ $chr(44) $!network and $!chan identifiers.,e,Input Request,%flood_switchbar),$v1,Flood in $!chan on $!network)
    }
  }
  ..$iif(%flood_opt & 32,$style(1)) Dispay message in active window:set %flood_opt $iif(%flood_opt & 32,$calc(%flood_opt - 32),$calc(%flood_opt + 32))

  .Reaction
  ..$iif(%flood_reaction == 1,$style(1)) Ban host: { set %flood_reaction 1 }
  ..$iif(%flood_reaction == 2,$style(1)) Kick/Ban user and clones: { set %flood_reaction 2 }
  ..$iif(%flood_reaction == 3,$style(1)) Let me choose: { set %flood_reaction 3 }

  .Triggers
  ..Add Trigger:flood_add_trigger
  ..-
  ..$submenu($flood_trigger($1))
  .Fkeys
  ..Punish with kick/ban
  ...$submenu($fkeys(kick,$1))
  ..Punish with ban
  ...$submenu($fkeys(ban,$1))
  ..Moderate channel
  ...$submenu($fkeys(mod,$1))
  .-
  .Set Defaults:{
    if ($input(Reset all flood protection options to defaults?,yv) == $yes) {
      unset %flood_*
      set %flood_opt 29
      set %flood_kick Text Flood: $+(%,lines) lines in $+(%,secs) seconds.
      set %flood_switchbar Flood in $!chan on $!network
      set %flood_trigger 5:5.5 7:9 8:10 12:15 17:27
      set %flood_reset 18 28
      set %flood_reaction 3
      set %flood_fkeys _ _ _
    }
  }
}
; Display fkeys in a submenu
alias -l fkeys {
  if ($2 == begin) { set %flood_fkeys_temp 0 }
  if ($2 == end) { unset %flood_fkeys_temp }
  if ($2 isnum) {
    tokenize 32 $1 %flood_fkeys_temp
    var %div = $int($calc($2 / 12))
    var %mod = $calc(($2 % 12) + 1)
    if (%div >= 3) { return }
    var %alias = $+($replace(%div,0,$null,1,s,2,c),f,%mod)
    var %cmd = $isalias(%alias).alias
    if ($gettok(%cmd,1,32) != $+(flood.,$1)) && ($len(%cmd)) { var %return = $style(2) }
    if ($gettok(%cmd,1,32) == $+(flood.,$1)) { var %return = $style(1) }
    inc %flood_fkeys_temp
    return %return $+($replace(%div,0,$null,1,Shift+,2,Ctrl+),F,%mod) $+ :flood_fkeys_set %alias $1
  }
}
alias -l flood_fkeys_set {
  var %x = $replace($2,kick,1,ban,2,mod,3)
  var %old_alias = $gettok(%flood_fkeys,%x,32)
  ; Remove old alias
  if ($isalias(%old_alias).alias == $+(flood.,$2)) {
    .alias %old_alias
  }
  if (%old_alias != $1) {
    ; Add new alias
    .alias $1 $+(flood.,$2)
    set %flood_fkeys $puttok(%flood_fkeys,$1,%x,32)
  }
  else {
    set %flood_fkeys $puttok(%flood_fkeys,_,%x,32)
  }
}
alias -l flood_trigger {
  ; Display triggers in submenu
  if ($1 <= $numtok(%flood_trigger,32)) {
    var %q = $gettok(%flood_trigger,$1,32)
    return $gettok(%q,1,58) lines in $gettok(%q,2,58) seconds:flood_set_trigger $1
  }
  if (!$numtok(%flood_trigger,32)) && ($1 = 1) {
    return $style(2) No triggers defined:/
  }
}
alias -l flood_add_trigger {
  ; Add a trigger
  var %lines = $input(Enter number of lines:,e)
  var %seconds = $input(Enter number of seconds:,e)
  if (%lines isnum) && (%seconds isnum) {
    %flood_trigger = %flood_trigger $+(%lines,:,%seconds)
  }
  flood_update_reset
}
alias -l flood_set_trigger {
  ; Change or delete a trigger
  var %q = $gettok(%flood_trigger,$1,32)
  var %d = $input(Do you want to delete this entry or update it? $crlf $+ Click YES to DELETE it. $crlf $+ Click NO to UPDATE it.,nv)
  if (%d == $cancel) { return }
  elseif (%d == $yes) {
    %flood_trigger = $iif($deltok(%flood_trigger,$1,32),$v1,"")
  }
  elseif (%d == $no) {
    var %lines = $input(Enter number of lines:,e,Input Request,$gettok(%q,1,58))
    var %seconds = $input(Enter number of seconds:,e,Input Request,$gettok(%q,2,58))
    if (%lines isnum) && (%seconds isnum) {
      %flood_trigger = $puttok(%flood_trigger,$+(%lines,:,%seconds),$1,32)
    }
  }
  flood_update_reset
}
alias -l flood_update_reset {
  ; This dynamically updates the flood reset parameters
  var %x = $numtok(%flood_trigger,32)
  while (%x) {
    var %f = $gettok(%flood_trigger,%x,32)
    var %lines = $gettok(%f,1,58) %lines
    var %secs =  $gettok(%f,2,58) %secs
    dec %x
  }
  var %highlines = $gettok($sorttok(%lines,32,nr),1,32)
  var %highsecs = $gettok($sorttok(%secs,32,nr),1,32)
  set %flood_reset $calc(%highlines + 1) $calc(%highsecs + 1)
}
 

Changes log | Contributers | DALnet Services | mIRC Scripts | Technical | Useful Links | Chat Now | Guidelines | DALnet