;==========================================================
; Project    : Complete Protection System (CPS)
; Script     : CPS remotes File. (Documented)
;==========================================================
; Author     : amit (uber @ dalnet #mumbai)
; Email      : amit9815@yahoo.com
; Version    : 7.0
; FileName   : cpsr1.mrc
; Section(s) : 3
; Copyright (C) 2006 Amit (amit9815@yahoo.com)
;==========================================================

;=================
; Remotes & Events
;=================

;----------------------------------------
; Section A
;----------------------------------------
; Desc: The events that will signal to 
;       the signal events in section B.
;----------------------------------------

; This group disables itself when a flood triggers so as to avoid multiple processing
#cpsfloodd on

;join part flood
ON @!*:JOIN:#: {
  IF (($nick != $me) && ($nick != %done.nick)) {
    IF (($istok(%controlchan,$chan,44) == $true) && ($cps.rval($chan,n5,2) == 1)) {
      var %joins = $dll($airc, Flood, $+(joinf,$chr(44),$chan,$chr(44),*!*@*) 1 $cps.rvi($chan,JPFLOOD) $cps.rvi($chan,JPFLOOD.TIME))
      var %total.nicks = $cps.rvi($chan,JPFLOOD)
      set $+(-u,$cps.rvi($chan,JPFLOOD.TIME)) %nick.joinned [ $+ [ $chan ] ] $addtok(%nick.joinned [ $+ [ $chan ] ],$nick,44) 
      if ($numtok(%nick.joinned [ $+ [ $chan ] ],44) > $cps.rvi($chan,JPFLOOD)) { 
        set $+(-u,$cps.rvi($chan,JPFLOOD.TIME)) %nick.joinned [ $+ [ $chan ] ] $deltok(%nick.joinned [ $+ [ $chan ] ],1,44) 
      }
      IF (+Flood* iswm %joins) {
        if (%channel.flooded [ $+ [ $chan ] ] != YES) {
          .raw -q MODE $chan +miRMck Locked
          .timerraw $+ $chan 1 60 .mode $chan -miRMck UnLocked
          set -u30 %channel.flooded [ $+ [ $chan ] ] YES
        }
        if ($cps.rvi($chan,JPFLOOD) > 6) {
          var %vareds1 = 1
          while (%vareds1 < 7) {
            if (%vareds1 == 1) { set %varbanned1 [ $+ [ $chan ] ] $address($gettok(%nick.joinned [ $+ [ $chan ] ],%vareds1,44),$left($cps.rvi($chan,jpflood.ktype),1)) }
            set %varbanned1 [ $+ [ $chan ] ] $addtok(%varbanned1 [ $+ [ $chan ] ],$address($gettok(%nick.joinned [ $+ [ $chan ] ],%vareds1,44),$left($cps.rvi($chan,jpflood.ktype),1)),32)
            inc %vareds1
          }
          while (%vareds1 < 13) {
            if (%vareds1 == 7) { set %varbanned2 [ $+ [ $chan ] ] $address($gettok(%nick.joinned [ $+ [ $chan ] ],%vareds1,44),$left($cps.rvi($chan,jpflood.ktype),1)) }
            set %varbanned2 [ $+ [ $chan ] ] $addtok(%varbanned2 [ $+ [ $chan ] ],$address($gettok(%nick.joinned [ $+ [ $chan ] ],%vareds1,44),$left($cps.rvi($chan,jpflood.ktype),1)),32)
            inc %vareds1
          }
          while (%vareds1 < 19) {
            if (%vareds1 == 13) { set %varbanned3 [ $+ [ $chan ] ] $address($gettok(%nick.joinned [ $+ [ $chan ] ],%vareds1,44),$left($cps.rvi($chan,jpflood.ktype),1)) }
            set %varbanned3 [ $+ [ $chan ] ] $addtok(%varbanned3 [ $+ [ $chan ] ],$address($gettok(%nick.joinned [ $+ [ $chan ] ],%vareds1,44),$left($cps.rvi($chan,jpflood.ktype),1)),32)
            inc %vareds1
          }
          if ($cps.rvi($chan,JPFLOOD) <= 12) {
            .mode $chan $+(+,$str(b,$iif($cps.rvi($chan,JPFLOOD) > 6,6,$cps.rvi($chan,JPFLOOD)))) %varbanned1 [ $+ [ $chan ] ]
            .timer $+ $chan $+ 1 1 $cps.rvi($chan,jpflood.ktime) .mode $chan $+(-,$str(b,$iif($cps.rvi($chan,JPFLOOD) > 6,6,$cps.rvi($chan,JPFLOOD)))) %varbanned1 [ $+ [ $chan ] ]
            .mode $chan $+(+,$str(b,$calc($iif($cps.rvi($chan,JPFLOOD) > 6,$cps.rvi($chan,JPFLOOD),6)-6))) %varbanned2 [ $+ [ $chan ] ]
            .timer $+ $chan $+ 2 1 $cps.rvi($chan,jpflood.ktime) .mode $chan $+(-,$str(b,$calc($iif($cps.rvi($chan,JPFLOOD) > 6,$cps.rvi($chan,JPFLOOD),6)-6))) %varbanned2 [ $+ [ $chan ] ]
            var %kick.time.jp1 = $numtok(%varbanned1 [ $+ [ $chan ] ],32)
            while (%kick.time.jp1 > 0) {
              fk $chan $gettok(%varbanned1 [ $+ [ $chan ] ],%kick.time.jp1,32) %joins
              dec %kick.time.jp1 1
            }
            var %kick.time.jp2 = $numtok(%varbanned2 [ $+ [ $chan ] ],32)
            while (%kick.time.jp2 > 0) {
              fk $chan $gettok(%varbanned2 [ $+ [ $chan ] ],%kick.time.jp2,32) %joins
              dec %kick.time.jp2 1 
            }
            unset %var*
            unset %nick.joinned [ $+ [ $chan ] ]
            ;.disable #cpsfloodd 
            ;.timergrp $+ $chan 1 10 .enable #cpsfloodd 
          }
          else {
            .mode $chan $+(+,$str(b,$iif($cps.rvi($chan,JPFLOOD) > 6,6,$cps.rvi($chan,JPFLOOD)))) %varbanned1 [ $+ [ $chan ] ]
            .timer $+ $chan $+ 3 1 $cps.rvi($chan,jpflood.ktime) .mode $chan $+(-,$str(b,$iif($cps.rvi($chan,JPFLOOD) > 6,6,$cps.rvi($chan,JPFLOOD)))) %varbanned1 [ $+ [ $chan ] ]
            .mode $chan $+(+,$str(b,$calc($iif($cps.rvi($chan,JPFLOOD) > 6,6,$cps.rvi($chan,JPFLOOD)))) %varbanned2 [ $+ [ $chan ] ]
            .timer $+ $chan $+ 4 1 $cps.rvi($chan,jpflood.ktime) .mode $chan $+(-,$str(b,$calc($iif($cps.rvi($chan,JPFLOOD) > 6,6,$cps.rvi($chan,JPFLOOD)))) %varbanned2 [ $+ [ $chan ] ]
            .mode $chan $+(+,$str(b,$calc($iif($cps.rvi($chan,JPFLOOD) > 6,6,$cps.rvi($chan,JPFLOOD))-12))) %varbanned3 [ $+ [ $chan ] ]
            .timer $+ $chan $+ 5 1 $cps.rvi($chan,jpflood.ktime) .mode $chan $+(-,$str(b,$calc($iif($cps.rvi($chan,JPFLOOD) > 6,6,$cps.rvi($chan,JPFLOOD))-12))) %varbanned3 [ $+ [ $chan ] ]
            var %kick.time.jp1 = $numtok(%varbanned1 [ $+ [ $chan ] ],32)
            while (%kick.time.jp1 > 0) {
              fk $chan $gettok(%varbanned1 [ $+ [ $chan ] ],%kick.time.jp1,32) %joins
              dec %kick.time.jp1 1 
            }
            var %kick.time.jp2 = $numtok(%varbanned2 [ $+ [ $chan ] ],32)
            while (%kick.time.jp2 > 0) {
              fk $chan $gettok(%varbanned2 [ $+ [ $chan ] ],%kick.time.jp2,32) %joins
              dec %kick.time.jp2 1 
            }
            var %kick.time.jp3 = $numtok(%varbanned3 [ $+ [ $chan ] ],32)
            while (%kick.time.jp3 > 0) {
              fk $chan $gettok(%varbanned3 [ $+ [ $chan ] ],%kick.time.jp3,32) %joins
              dec %kick.time.jp3 1 
            }
            unset %var*
            unset %nick.joinned [ $+ [ $chan ] ]
            ;.disable #cpsfloodd 
            ;.timergrp $+ $chan 1 10 .enable #cpsfloodd 
          }
        }
        else {
          var %vared = $cps.rvi($chan,JPFLOOD)
          while (%vared >= 0) {
            set %varbanned6 [ $+ [ $chan ] ] $addtok(%varbanned6 [ $+ [ $chan ] ],$address($gettok(%nick.joinned [ $+ [ $chan ] ],%vared,44),$left($cps.rvi($chan,jpflood.ktype),1)),32)
            dec %vared
          }
          var %uti = $rand(1,99999)
          .mode $chan $+(+,$str(b,$cps.rvi($chan,JPFLOOD))) %varbanned6 [ $+ [ $chan ] ]
          .timer $+ $chan $+ 7 $+ %uti 1 $cps.rvi($chan,jpflood.ktime) .mode $chan $+(-,$str(b,$cps.rvi($chan,JPFLOOD))) %varbanned6 [ $+ [ $chan ] ]
          var %kick.time.jp = $numtok(%varbanned6 [ $+ [ $chan ] ],32)
          while (%kick.time.jp > 0) {
            fk $chan $gettok(%varbanned6 [ $+ [ $chan ] ],%kick.time.jp,32) %joins
            dec %kick.time.jp 1 
          }
          unset %var*
          unset %nick.joinned [ $+ [ $chan ] ]
          ;.disable #cpsfloodd 
          ;.timergrp $+ $chan 1 10 .enable #cpsfloodd 
        }
      }
    }
  }
}
#cpsfloodd end

; Drone bot notice event
ON ^*:NOTICE:*:?:{
  IF ($1 == !unbanme) {
    .signal drone.notice $nick $1-
    haltdef
  }
}

; Bot commands given in channel are tackled in this event
ON *:TEXT:*:#: {
  IF ($owner($nick) == $true) {
    ; Sends help
    IF ($1 == ~help) { .signal cps.send.help $nick $1- }
    ; Sends other commands than help
    IF ($1 != ~help) { .signal cps.do $nick $1- }
    ; Join channel
    IF (($1 == ~join) && ($2 != $null)) { join $+($chr(35),$remove($2,$chr(35))) }
    ; Part channel
    IF (($1 == ~part) && ($2 != $null)) { part $+($chr(35),$remove($2,$chr(35))) }
    ; Op nick
    IF (($1 == ~op) && ($2 != $null)) { 
      IF ($me isop $chan) { mode $chan +ooooooooo $2- }
      ELSE { .msg $nick Master: I am not oped in $2 }
    }
    ; Deop nick
    IF (($1 == ~deop) && ($2 != $null)) { 
      IF ($me isop $chan) { mode $chan -ooooooooo $2- }
      ELSE { .msg $nick Master: I am not oped in $2 }
    }
    ; Kick nick
    IF (($1 == ~kick) && ($2 != $null)) { 
      IF ($me isop $chan) {
        IF ($2 ison $chan) { kick $chan $2- }
        ELSE { .msg $nick Master: $2 is not on $chan }
      }
      ELSE { .msg $nick Master: I am not oped in $2 }
    }
    ; Ban nick
    IF (($1 == ~ban) && ($2 != $null)) { 
      IF ($me isop $chan) { mode $chan +b $2- }
      ELSE { .msg $nick Master: I am not oped in $2 }
    }
    ; Voice nick
    IF (($1 == ~voice) && ($2 != $null)) { 
      IF ($me isop $chan) { mode $chan +vvvvvvvvv $2- }
      ELSE { .msg $nick Master: I am not oped in $2 }
    }
    ; Devoice nick
    IF (($1 == ~devoice) && ($2 != $null)) { 
      IF ($me isop $chan) { mode $chan -vvvvvvvvvv $2- }
      ELSE { .msg $nick Master: I am not oped in $2 }
    }
    ; Half nick
    IF (($1 == ~half) && ($2 != $null)) { 
      IF ($me isop $chan) { mode $chan +hhhhhhhhhhh $2- }
      ELSE { .msg $nick Master: I am not oped in $2 }
    }
    ; Dehalf nick
    IF (($1 == ~dehalf) && ($2 != $null)) { 
      IF ($me isop $chan) { mode $chan -hhhhhhhhhhh $2- }
      ELSE { .msg $nick Master: I am not oped in $2 }
    }
  }
}
; Event to login into the bot
ON *:TEXT:*:?: {
  IF ($1 == ~Login) {
    IF (($cps.rvi(default,lognc) == $2) && ($cps.rvi(default,logps) == $3)) {
      set %loggednick $nick
      .msg $nick Master: You have successfully logged in.
    }
  }
  IF ($owner($nick) == $true) {
    IF ($1 == ~unban) {
      IF ($0 > 2) {
        IF ($me isop $2) { mode $2 -b $3- }
        ELSE { .msg $nick Master: I am not oped in $2 }
      }
    }
  }
}
;----------------------------------------
; Section B
;----------------------------------------
; Desc: The Signal events of section A
;----------------------------------------

; Event handling the notice of unban from a person who got kicked for being a dronebot
ON *:SIGNAL:DRONE.NOTICE: {
  ;varify if the notice is complete
  IF (($left($3,1) == $chr(35)) && ($me ison $3) && ($left($4,$len($1)) == $1) && ($remove($4,$1) isnum)) {
    ; Verify if the nick was kicked
    IF ($istok(%droned,$1,44) == $true) {
      ; Verify if you are still op in that channel
      IF ($me isop $3) {
        ; verify if nick is not already un banned
        IF ($istok(%drone.exp,$1,44) != $true) {
          .notice $1 Sorry for kicking you but your nick is similar to a possible drone/spam bot; I am UN banning you in $3  join back and you won't be kicked again!
          ; add nick to exception list
          set %drone.exp $addtok(%drone.exp,$1,44)
          ; UN ban the mask which was stored in hash table after the kick
          .raw -q mode $3 -b $cps.rvi(DRONE,$4)
        }
        ELSE {
          .notice $1 You have already been unbanned - are you Flooding me by notice?
          .ignore -nu20 $1
        }
      }
      ELSE {
        .notice $1 $1 I am no longer an operator (@) in $3 so I can't unban you!
        set %drone.exp $addtok(%drone.exp,$1,44)
      }
    }
    ELSE {
      .notice $1 IF I didn't kicked you how can I un ban you? - Don't exploit this feature of my script - Added to ignore!
      .ignore -nu20 $nick
      echo $color(info2) $_place $_time *** 4(CPS) Added $nick to ignore list for drone check abuse!
    }
  }
  ELSE {
    .notice $1 $1 I am either no longer in that Channel ( $+ $3 $+ ) or you have typed the wrong command try again! or 4/WHOIS $me to verify IF I am in that channel!
  }
}

; This group is disabled when a quit flood is detected
#CPSQUIT ON

; Quit flood
ON *:QUIT: {
  IF (($istok(%controlchan,$comchan($nick,1),44) == $true) && ($cps.rval($comchan($nick,1),N5,3) == 1) && ($nick ison $comchan($nick,1)) && ($me isop $comchan($nick,1))) {
    var %quiters = $dll($airc,Flood,$+(qflood,$chr(44),$address($2,2)) 1 $cps.rvi($nick,QFLOOD) $cps.rvi($nick,QFLOOD.TIME))
    IF (+Flood* iswm %quiters) {
      .disable #CPSQUIT
      .raw -q MODE $comchan($nick,1) +bbcim *!~*@* $address($nick,2)
      set %qflooder. [ $+ [ $nick ] ] $nick
      .timerCPSQUIT 1 10 .enable #cpsquit
      .timerUNBANALL 1 30 .raw -q mode $comchan($nick,1) -bb *!~*@* $address($nick,2)
    }
  }
}

#CPSQUIT END

; Sends help of the related topic to the nick
ON *:SIGNAL:CPS.SEND.HELP: {
  IF ($3 == $null) { _help $1 all }
  ELSE { _help $1 $3- } 
}

ON *:SIGNAL:CPS.DO: {
  IF ($2 == ~set) { 
    IF ($5 != $null) { 
      IF ($istok(%controlchan,$3,44) == $true) { 
        IF ($istok($cps.rvi(cpsk,bot4),$ktype($4),44) == $true) {
          IF ($5 == ON) {
            cps.set $3 $cps.rvi(cpsk,$+(k,$ktype($4))) 1
            .msg $1 Master: $upper($4) Kick is now ON for $3
          }
          IF ($5 == OFF) {
            cps.set $3 $cps.rvi(cpsk,$+(k,$ktype($4))) 0
            .msg $1 Master: $upper($4) Kick is now OFF for $3
          }
          IF (($5 != ON) && ($5 != OFF)) { .msg $1 Master: You have used invalid syntax please use -> ~Set $3 $4 ON|OFF <- Note: Use one of the parameters either ON or OFF }
        } 
        ELSE { .signal CPS.SET $1- }
      }
      ELSE { .msg $1 Master: The Channel $3 is not in Protected Channels List. Check !Help to see how to add a channel in protected list. }
    }
    ELSE { .msg $1 Master: You did not used enough parameters check ~Help ~Set }
  }
  ; $nick !addchan #channel URL
  IF ($2 == ~addchan) {
    IF ($left($3,1) == $chr(35)) {
      IF ($istok(%controlchan,$3,44) != $true) { 
        IF ($dialog(CPS) == CPS) { dialog -x cps }
        SET %_cps $3 
        .signal cps.did.2 cps 2 BOT $1 $4- 
      }
      else { .msg $1 Master: I already have $3 in my Protected List. }
    }
    else { .msg $1 Master: A Channel Name should Start with $chr(35)  } 
  }
  ; $nick !delchan #channel
  IF ($2 == ~delchan) {
    IF ($left($3,1) == $chr(35)) {
      IF ($istok(%controlchan,$3,44) == $true) { 
        IF ($dialog(CPS) == CPS) { dialog -x cps }
        SET %_cps $3 
        .signal cps.did.3 $1 $3
      }
      else { .msg $1 Master: I Don't have $3 in my Protected List. }
    }
    else { .msg $1 Master: A Channel Name should Start with $chr(35)  } 
  }
  ; $nick !listchan
  IF ($2 == ~listchan) {
    IF ($cps.rvi(default,controlchan) != $null) { .msg $1 Master: I have following Channel(s) in protected list -> $upper($replace($cps.rvi(default,controlchan),$chr(44),$chr(32))) }
    else { .msg $1 Master: I don't have any channel(s) in Protected list. }
  }
}

; Adding channel into protected list via command in channel
ON *:SIGNAL:CPS.DID.2: {
  If ((/ isin %_cps) || (\ isin %_cps) || ($chr(42) isin %_cps) || (: isin %_cps) || (" isin %_cps) || ($chr(32) isin %_cps) || (| isin %_cps) || (< isin %_cps) || (> isin %_cps)) {
    msg $4 Master: Sorry CPS doesn't yet support this type of channel names which you entered [Special Charchters or Space is Not Allowed]
    return
  }
  ; Make the channel named hash table
  cps.make %_cps
  ; Save the hash table in a file
  cps.save %_cps
  ; Set the channel url
  var %cps.vared = $5-
  IF (%cps.vared != $null) { cps.rvs %_cps channelurl %cps.vared }
  ; Below we copy all the settings
  cps.rvs %_cps n1 $cps.rvi(default,n1)
  cps.rvs %_cps n2 $cps.rvi(default,n2)
  cps.rvs %_cps n3 $cps.rvi(default,n3)
  cps.rvs %_cps n4 $cps.rvi(default,n4)
  cps.rvs %_cps n5 $cps.rvi(default,n5)
  cps.rvs %_cps n6 $cps.rvi(default,n6)
  cps.rvs %_cps n7 $cps.rvi(default,n7)
  cps.rvs %_cps n8 $cps.rvi(default,n8)
  cps.rvs %_cps swear $cps.rvi(default,swear)
  cps.rvs %_cps swear.ktrig $cps.rvi(default,swear.ktrig)
  cps.rvs %_cps swear.kact $cps.rvi(default,swear.kact)
  cps.rvs %_cps swear.ktime $cps.rvi(default,swear.ktime)
  cps.rvs %_cps swear.ktype $cps.rvi(default,swear.ktype)
  cps.rvs %_cps swear.kmsg $cps.rvi(default,swear.kmsg)
  cps.rvs %_cps urlads $cps.rvi(default,urlads)
  cps.rvs %_cps urlads.ktrig $cps.rvi(default,urlads.ktrig)
  cps.rvs %_cps urlads.kact $cps.rvi(default,urlads.kact)
  cps.rvs %_cps urlads.ktime $cps.rvi(default,urlads.ktime)
  cps.rvs %_cps urlads.ktype $cps.rvi(default,urlads.ktype)
  cps.rvs %_cps urlads.kmsg $cps.rvi(default,urlads.kmsg)
  cps.rvs %_cps chanads $cps.rvi(default,chanads)
  cps.rvs %_cps chanads.ktrig $cps.rvi(default,chanads.ktrig)
  cps.rvs %_cps chanads.kact $cps.rvi(default,chanads.kact)
  cps.rvs %_cps chanads.ktime $cps.rvi(default,chanads.ktime)
  cps.rvs %_cps chanads.ktype $cps.rvi(default,chanads.ktype)
  cps.rvs %_cps chanads.kmsg $cps.rvi(default,chanads.kmsg)
  cps.rvs %_cps nick $cps.rvi(default,nick)
  cps.rvs %_cps nick.ktrig $cps.rvi(default,nick.ktrig)
  cps.rvs %_cps nick.kact $cps.rvi(default,nick.kact)
  cps.rvs %_cps nick.ktime $cps.rvi(default,nick.ktime)
  cps.rvs %_cps nick.ktype $cps.rvi(default,nick.ktype)
  cps.rvs %_cps nick.kmsg $cps.rvi(default,nick.kmsg)
  cps.rvs %_cps ident $cps.rvi(default,ident)
  cps.rvs %_cps ident.ktrig $cps.rvi(default,ident.ktrig)
  cps.rvs %_cps ident.kact $cps.rvi(default,ident.kact)
  cps.rvs %_cps ident.ktime $cps.rvi(default,ident.ktime)
  cps.rvs %_cps ident.ktype $cps.rvi(default,ident.ktype)
  cps.rvs %_cps ident.kmsg $cps.rvi(default,ident.kmsg)
  cps.rvs %_cps script $cps.rvi(default,script)
  cps.rvs %_cps script.ktrig $cps.rvi(default,script.ktrig)
  cps.rvs %_cps script.kact $cps.rvi(default,script.kact)
  cps.rvs %_cps script.ktime $cps.rvi(default,script.ktime)
  cps.rvs %_cps script.ktype $cps.rvi(default,script.ktype)
  cps.rvs %_cps script.kmsg $cps.rvi(default,script.kmsg)
  cps.rvs %_cps channel $cps.rvi(default,channel)
  cps.rvs %_cps channel.ktrig $cps.rvi(default,channel.ktrig)
  cps.rvs %_cps channel.kact $cps.rvi(default,channel.kact)
  cps.rvs %_cps channel.ktime $cps.rvi(default,channel.ktime)
  cps.rvs %_cps channel.ktype $cps.rvi(default,channel.ktype)
  cps.rvs %_cps channel.kmsg $cps.rvi(default,channel.kmsg)
  cps.rvs %_cps blnic $cps.rvi(default,blnic)
  cps.rvs %_cps blnic.ktrig $cps.rvi(default,blnic.ktrig)
  cps.rvs %_cps blnic.kact $cps.rvi(default,blnic.kact)
  cps.rvs %_cps blnic.ktime $cps.rvi(default,blnic.ktime)
  cps.rvs %_cps blnic.ktype $cps.rvi(default,blnic.ktype)
  cps.rvs %_cps blnic.kmsg $cps.rvi(default,blnic.kmsg)
  cps.rvs %_cps repeat $cps.rvi(default,repeat)
  cps.rvs %_cps repeat.time $cps.rvi(default,repeat.time)
  cps.rvs %_cps repeat.ktrig $cps.rvi(default,repeat.ktrig)
  cps.rvs %_cps repeat.kact $cps.rvi(default,repeat.kact)
  cps.rvs %_cps repeat.ktime $cps.rvi(default,repeat.ktime)
  cps.rvs %_cps repeat.ktype $cps.rvi(default,repeat.ktype)
  cps.rvs %_cps repeat.kmsg $cps.rvi(default,repeat.kmsg)
  cps.rvs %_cps txtflood $cps.rvi(default,txtflood)
  cps.rvs %_cps txtflood.time $cps.rvi(default,txtflood.time)
  cps.rvs %_cps txtflood.ktrig $cps.rvi(default,txtflood.ktrig)
  cps.rvs %_cps txtflood.kact $cps.rvi(default,txtflood.kact)
  cps.rvs %_cps txtflood.ktime $cps.rvi(default,txtflood.ktime)
  cps.rvs %_cps txtflood.ktype $cps.rvi(default,txtflood.ktype)
  cps.rvs %_cps txtflood.kmsg $cps.rvi(default,txtflood.kmsg)
  cps.rvs %_cps jpflood $cps.rvi(default,jpflood)
  cps.rvs %_cps jpflood.time $cps.rvi(default,jpflood.time)
  cps.rvs %_cps jpflood.ktrig $cps.rvi(default,jpflood.ktrig)
  cps.rvs %_cps jpflood.kact $cps.rvi(default,jpflood.kact)
  cps.rvs %_cps jpflood.ktime $cps.rvi(default,jpflood.ktime)
  cps.rvs %_cps jpflood.ktype $cps.rvi(default,jpflood.ktype)
  cps.rvs %_cps jpflood.kmsg $cps.rvi(default,jpflood.kmsg)
  cps.rvs %_cps slap $cps.rvi(default,slap)
  cps.rvs %_cps slap.time $cps.rvi(default,slap.time)
  cps.rvs %_cps slap.ktrig $cps.rvi(default,slap.ktrig)
  cps.rvs %_cps slap.kact $cps.rvi(default,slap.kact)
  cps.rvs %_cps slap.ktime $cps.rvi(default,slap.ktime)
  cps.rvs %_cps slap.ktype $cps.rvi(default,slap.ktype)
  cps.rvs %_cps slap.kmsg $cps.rvi(default,slap.kmsg)
  cps.rvs %_cps sound $cps.rvi(default,sound)
  cps.rvs %_cps sound.time $cps.rvi(default,sound.time)
  cps.rvs %_cps sound.ktrig $cps.rvi(default,sound.ktrig)
  cps.rvs %_cps sound.kact $cps.rvi(default,sound.kact)
  cps.rvs %_cps sound.ktime $cps.rvi(default,sound.ktime)
  cps.rvs %_cps sound.ktype $cps.rvi(default,sound.ktype)
  cps.rvs %_cps sound.kmsg $cps.rvi(default,sound.kmsg)
  cps.rvs %_cps cnote $cps.rvi(default,cnote)
  cps.rvs %_cps cnote.time $cps.rvi(default,cnote.time)
  cps.rvs %_cps cnote.ktrig $cps.rvi(default,cnote.ktrig)
  cps.rvs %_cps cnote.kact $cps.rvi(default,cnote.kact)
  cps.rvs %_cps cnote.ktime $cps.rvi(default,cnote.ktime)
  cps.rvs %_cps cnote.ktype $cps.rvi(default,cnote.ktype)
  cps.rvs %_cps cnote.kmsg $cps.rvi(default,cnote.kmsg)
  cps.rvs %_cps qflood $cps.rvi(default,qflood)
  cps.rvs %_cps qflood.time $cps.rvi(default,qflood.time)
  cps.rvs %_cps qflood.ktrig $cps.rvi(default,qflood.ktrig)
  cps.rvs %_cps qflood.kact $cps.rvi(default,qflood.kact)
  cps.rvs %_cps qflood.ktime $cps.rvi(default,qflood.ktime)
  cps.rvs %_cps qflood.ktype $cps.rvi(default,qflood.ktype)
  cps.rvs %_cps qflood.kmsg $cps.rvi(default,qflood.kmsg)
  cps.rvs %_cps away $cps.rvi(default,away)
  cps.rvs %_cps away.time $cps.rvi(default,away.time)
  cps.rvs %_cps away.ktrig $cps.rvi(default,away.ktrig)
  cps.rvs %_cps away.kact $cps.rvi(default,away.kact)
  cps.rvs %_cps away.ktime $cps.rvi(default,away.ktime)
  cps.rvs %_cps away.ktype $cps.rvi(default,away.ktype)
  cps.rvs %_cps away.kmsg $cps.rvi(default,away.kmsg)
  cps.rvs %_cps longtxt $cps.rvi(default,longtxt)
  cps.rvs %_cps longtxt.ktrig $cps.rvi(default,longtxt.ktrig)
  cps.rvs %_cps longtxt.kact $cps.rvi(default,longtxt.kact)
  cps.rvs %_cps longtxt.ktime $cps.rvi(default,longtxt.ktime)
  cps.rvs %_cps longtxt.ktype $cps.rvi(default,longtxt.ktype)
  cps.rvs %_cps longtxt.kmsg $cps.rvi(default,longtxt.kmsg)
  cps.rvs %_cps punctuation $cps.rvi(default,punctuation)
  cps.rvs %_cps punctuation.ktrig $cps.rvi(default,punctuation.ktrig)
  cps.rvs %_cps punctuation.kact $cps.rvi(default,punctuation.kact)
  cps.rvs %_cps punctuation.ktime $cps.rvi(default,punctuation.ktime)
  cps.rvs %_cps punctuation.ktype $cps.rvi(default,punctuation.ktype)
  cps.rvs %_cps punctuation.kmsg $cps.rvi(default,punctuation.kmsg)
  cps.rvs %_cps caps $cps.rvi(default,caps)
  cps.rvs %_cps caps.ktrig $cps.rvi(default,caps.ktrig)
  cps.rvs %_cps caps.kact $cps.rvi(default,caps.kact)
  cps.rvs %_cps caps.ktime $cps.rvi(default,caps.ktime)
  cps.rvs %_cps caps.ktype $cps.rvi(default,caps.ktype)
  cps.rvs %_cps caps.kmsg $cps.rvi(default,caps.kmsg)
  cps.rvs %_cps idle $cps.rvi(default,idle)
  cps.rvs %_cps idle.ktrig $cps.rvi(default,idle.ktrig)
  cps.rvs %_cps idle.kact $cps.rvi(default,idle.kact)
  cps.rvs %_cps idle.ktime $cps.rvi(default,idle.ktime)
  cps.rvs %_cps idle.ktype $cps.rvi(default,idle.ktype)
  cps.rvs %_cps idle.kmsg $cps.rvi(default,idle.kmsg)
  cps.rvs %_cps colors $cps.rvi(default,colors)
  cps.rvs %_cps colors.ktrig $cps.rvi(default,colors.ktrig)
  cps.rvs %_cps colors.kact $cps.rvi(default,colors.kact)
  cps.rvs %_cps colors.ktime $cps.rvi(default,colors.ktime)
  cps.rvs %_cps colors.ktype $cps.rvi(default,colors.ktype)
  cps.rvs %_cps colors.kmsg $cps.rvi(default,colors.kmsg)
  cps.rvs %_cps clones $cps.rvi(default,clones)
  cps.rvs %_cps clones.ktrig $cps.rvi(default,clones.ktrig)
  cps.rvs %_cps clones.kact $cps.rvi(default,clones.kact)
  cps.rvs %_cps clones.ktime $cps.rvi(default,clones.ktime)
  cps.rvs %_cps clones.ktype $cps.rvi(default,clones.ktype)
  cps.rvs %_cps clones.kmsg $cps.rvi(default,clones.kmsg)
  cps.rvs %_cps nonletters $cps.rvi(default,nonletters)
  cps.rvs %_cps nonletters.ktrig $cps.rvi(default,nonletters.ktrig)
  cps.rvs %_cps nonletters.kact $cps.rvi(default,nonletters.kact)
  cps.rvs %_cps nonletters.ktime $cps.rvi(default,nonletters.ktime)
  cps.rvs %_cps nonletters.ktype $cps.rvi(default,nonletters.ktype)
  cps.rvs %_cps nonletters.kmsg $cps.rvi(default,nonletters.kmsg)
  cps.rvs %_cps atext.ktrig $cps.rvi(default,atext.ktrig)
  cps.rvs %_cps atext.kact $cps.rvi(default,atext.kact)
  cps.rvs %_cps atext.ktime $cps.rvi(default,atext.ktime)
  cps.rvs %_cps atext.ktype $cps.rvi(default,atext.ktype)
  cps.rvs %_cps atext.kmsg $cps.rvi(default,atext.kmsg)
  cps.rvs %_cps euser.ktrig $cps.rvi(default,euser.ktrig)
  cps.rvs %_cps euser.kact $cps.rvi(default,euser.kact)
  cps.rvs %_cps euser.ktime $cps.rvi(default,euser.ktime)
  cps.rvs %_cps euser.ktype $cps.rvi(default,euser.ktype)
  cps.rvs %_cps euser.kmsg $cps.rvi(default,euser.kmsg)
  cps.rvs %_cps drone.ktrig $cps.rvi(default,drone.ktrig)
  cps.rvs %_cps drone.kact $cps.rvi(default,drone.kact)
  cps.rvs %_cps drone.ktime $cps.rvi(default,drone.ktime)
  cps.rvs %_cps drone.ktype $cps.rvi(default,drone.ktype)
  cps.rvs %_cps drone.kmsg $cps.rvi(default,drone.kmsg)
  cps.rvs %_cps guest.ktrig $cps.rvi(default,guest.ktrig)
  cps.rvs %_cps guest.kact $cps.rvi(default,guest.kact)
  cps.rvs %_cps guest.ktime $cps.rvi(default,guest.ktime)
  cps.rvs %_cps guest.ktype $cps.rvi(default,guest.ktype)
  cps.rvs %_cps guest.kmsg $cps.rvi(default,guest.kmsg)
  cps.rvs %_cps rejoin.ktrig $cps.rvi(default,rejoin.ktrig)
  cps.rvs %_cps rejoin.kact $cps.rvi(default,rejoin.kact)
  cps.rvs %_cps rejoin.ktime $cps.rvi(default,rejoin.ktime)
  cps.rvs %_cps rejoin.ktype $cps.rvi(default,rejoin.ktype)
  cps.rvs %_cps rejoin.kmsg $cps.rvi(default,rejoin.kmsg)
  cps.rvs %_cps ojctcp.ktrig $cps.rvi(default,ojctcp.ktrig)
  cps.rvs %_cps ojctcp.kact $cps.rvi(default,ojctcp.kact)
  cps.rvs %_cps ojctcp.ktime $cps.rvi(default,ojctcp.ktime)
  cps.rvs %_cps ojctcp.ktype $cps.rvi(default,ojctcp.ktype)
  cps.rvs %_cps ojctcp.kmsg $cps.rvi(default,ojctcp.kmsg)
  cps.rvs %_cps ojnote.ktrig $cps.rvi(default,ojnote.ktrig)
  cps.rvs %_cps ojnote.kact $cps.rvi(default,ojnote.kact)
  cps.rvs %_cps ojnote.ktime $cps.rvi(default,ojnote.ktime)
  cps.rvs %_cps ojnote.ktype $cps.rvi(default,ojnote.ktype)
  cps.rvs %_cps ojnote.kmsg $cps.rvi(default,ojnote.kmsg)
  cps.rvs %_cps ojmsg.ktrig $cps.rvi(default,ojmsg.ktrig)
  cps.rvs %_cps ojmsg.kact $cps.rvi(default,ojmsg.kact)
  cps.rvs %_cps ojmsg.ktime $cps.rvi(default,ojmsg.ktime)
  cps.rvs %_cps ojmsg.ktype $cps.rvi(default,ojmsg.ktype)
  cps.rvs %_cps ojmsg.kmsg $cps.rvi(default,ojmsg.kmsg)
  cps.rvs %_cps ctcpf $cps.rvi(default,ctcpf)
  cps.rvs %_cps ctcpf.time $cps.rvi(default,ctcpf.time)
  cps.rvs %_cps ctcpf.ktrig $cps.rvi(default,ctcpf.ktrig)
  cps.rvs %_cps ctcpf.kact $cps.rvi(default,ctcpf.kact)
  cps.rvs %_cps ctcpf.ktime $cps.rvi(default,ctcpf.ktime)
  cps.rvs %_cps ctcpf.ktype $cps.rvi(default,ctcpf.ktype)
  cps.rvs %_cps ctcpf.kmsg $cps.rvi(default,ctcpf.kmsg)
  cps.rvs %_cps kline.ktrig $cps.rvi(default,kline.ktrig)
  cps.rvs %_cps kline.ktime $cps.rvi(default,kline.ktime)
  cps.rvs %_cps kline.ktype $cps.rvi(default,kline.ktype)
  cps.rvs %_cps door $cps.rvi(default,door)
  cps.rvs %_cps door.time $cps.rvi(default,door.time)
  cps.rvs %_cps door.ktrig $cps.rvi(default,door.ktrig)
  cps.rvs %_cps door.kact $cps.rvi(default,door.kact)
  cps.rvs %_cps door.ktime $cps.rvi(default,door.ktime)
  cps.rvs %_cps door.ktype $cps.rvi(default,door.ktype)
  cps.rvs %_cps door.kmsg $cps.rvi(default,door.kmsg)
  cps.rvs %_cps excess.ktrig $cps.rvi(default,excess.ktrig)
  cps.rvs %_cps excess.ktime $cps.rvi(default,excess.ktime)
  cps.rvs %_cps excess.ktype $cps.rvi(default,excess.ktype)
  cps.rvs %_cps squit.ktrig $cps.rvi(default,squit.ktrig)
  cps.rvs %_cps limiter $cps.rvi(default,limiter)
  cps.rvs %_cps userlimit $cps.rvi(default,userlimit)
  cps.rvs %_cps userlimit.time $cps.rvi(default,userlimit.time)
  cps.rvs %_cps squit.ktime $cps.rvi(default,squit.ktime)
  cps.rvs %_cps squit.ktype $cps.rvi(default,squit.ktype)
  cps.rvs %_cps agreet $cps.rvi(default,agreet)
  cps.rvs %_cps kickops $cps.rvi(default,kickops)
  cps.rvs %_cps kickvos $cps.rvi(default,kickvos)
  cps.rvs %_cps sbhop 5
  ; Save the hash table again
  cps.save %_cps
  ; Add the new channelin protected channels list
  set %cps.protchan $addtok(%cps.protchan,%_cps,44)
  IF (%cps.protchan != $null) { cps.rvs default controlchan %cps.protchan }
  set %controlchan %cps.protchan
  ; Save the deafult hash tabel
  cps.save default
  ; Msg the nick that job was done
  IF (%cps.vared != $null) { .msg $4 Master: I have added %_CPS In the list of my Protected Channels with the URL -> $5- }
  ELSE { .msg $4 Master: I have added %_CPS In the list of my Protected Channels. }
  ; Tell the nick the total protected channels 
  IF ($cps.rvi(default,controlchan) != $null) { .msg $4 Master: I have following Channel(s) in protected list -> $upper($replace($cps.rvi(default,controlchan),$chr(44),$chr(32))) }
}

; Deleting the channel
ON *:SIGNAL:CPS.DID.3: {
  ; Free the channel hash table
  cps.free %_cps
  ; Delete the hash table file
  cps.rem %_cps
  ; Remove the channel name from protected channels list
  var %i = $cps.rvi(default,controlchan)
  %controlchan = $remtok(%i,%_CPS,44)
  ; Set this in the default hash table
  cps.rvs default controlchan %controlchan 
  ; Save the default hash table
  cps.save default
  ; Modify the variable the saves the protected channels list
  set %cps.protchan $cps.rvi(default,controlchan)
  ; Msg the nick that channel has been deleted
  .msg $1 Master: I have deleted %_cps From Protected Channels.
  ; Message the nick the total protected channels in the list
  IF ($cps.rvi(default,controlchan) != $null) { .msg $1 Master: I have following Channel(s) left in protected list -> $upper($replace($cps.rvi(default,controlchan),$chr(44),$chr(32))) }
}

; Some more settings handler.
ON *:SIGNAL:CPS.SET: {
  IF ($4 == LIMITER) { 
    IF (($5 == ON) || ($5 == OFF)) { cps.rvs $3 LIMITER $5 }
    else { .msg $1 Master: You have used invalid syntax please use -> ~Set $3 $4 ON|OFF <- Note: Use one of the parameters either ON or OFF }
  }
  IF ($4 == AUTO-GREET) { 
    IF ($5 == ON) {
      cps.set $3 N8 2 1
      .Msg $1 Master: Auto Greet For $3 is now ON, auto greet message -> $cps.rvi($3,agreet)
    }
    IF ($5 == OFF) {
      cps.set $3 N8 2 0
      .Msg $1 Master: Auto Greet For $3 is now OFF
    }
    IF ($5 == SET) {
      IF ($6 != $null) { cps.rvs $3 Agreet $6- }
      ELSE { .msg $1 Master: You have used invalid syntax please use -> ~Set $3 $4 $5 Auto-Greet-Message }
      IF (($5 != ON) && ($5 != OFF) && ($5 != SET)) { .msg $1 Master: You have used invalid syntax please use -> ~Set $3 $4 ON|OFF <- Note: Use one of the parameters either ON or OFF }
    }
  }
}

ON *:SIGNAL:SBE_NICK: {
  IF ($_getnick($1) == $_me) { _me $_strip:($3) }
}

ON *:SIGNAL:SBE_PRIVMSG:{
  IF (:ACTION * iswm $4-) { .signal -n sbeaction $1 ACTION $3 $left($5-,-1) }
  ELSEIF (:* iswm $4-) { .signal -n sbectcp $1 CTCP $3 $mid($_strip:($4-),2,-1) }
  ELSE { .signal -n sbeTEXT $1 TEXT $3 $_strip:($4-) }
}

ON *:SIGNAL:SBE_NOTICE:{
  IF (:* iswm $4-) { .signal -n sbectctreply $1 CTCPREPLY $3 $mid($_strip:($4-),2,-1) }
  ELSEIF (. isin $_getnick($1)) { .signal -n sbesnotice $1 SNOTICE $3 $_strip:($4-) }
  ELSE { .signal -n sbenotice $1 NOTICE $3 $_strip:($4-) }
}

#sb_connecting off

ON *:SIGNAL:SBE_433: { sb_out NICK $sb_anick }

ON *:SIGNAL:SBE_422: { sb_connected $3 }

ON *:SIGNAL:SBE_376: { sb_connected $3 }

#sb_connecting end

;----------------------------------------
; Section C
;----------------------------------------
; Desc: This section has remotes that do
;       processing in their own body.
;----------------------------------------

; This is the event which handles the double clicking of manual kick echo.
ON *:HOTLINK:*:*:{
  IF (*shift* !iswm $strip($hotline)) { F9 }
  ELSE { SF9 }
}

; This is a personal unban event works only on networks that have chanserv on them
; The unban command can be modified according to the network
; Also includes event for dialog ccontroler
ON *:KICK:#: {
  IF (($knick == $me) && (nick != $me) && ($me isop $chan)) {
    IF ($notify(chanserv).ison == $true) { .ChanServ UNBAN $chan $me }
    .timerJOIN 1 2 join $chan
  }
  IF ($dialog(CCONTROLLER) == CCONTROLLER) {
    IF (($nick == $me) && ($chan == %cps.da.chan) && ($knick == %cps.da.nick)) {
      did -d CCONTROLLER 1 $did(CCONTROLLER,1).sel
    }
  }
}

ON *:CONNECT: {
  .enable #cpsgroup*
  ;.debug -ptn @raw
  .enable #cpsquit*
  .enable #cps*
  ;  IF ($cps.rvi(default,sbjoin) != $null) { sb_open }
}

ON *:SOCKOPEN:SB:{
  ; Clean stuff up and close if there's an error
  IF ($sockerr) { return $sb_cleanup }
  ; Send login info to IRC server
  sb_out NICK $sb_nick
  sb_out USER $sb_identd * * :  $+ $sb_name
}

; Clean stuff up if there's an error
ON *:SOCKWRITE:SB: {
  IF ($sockerr) {
    $iif($window(@sb),echo 4 @sb >> $sock($sockerr).wsmsg)
    return $sb_cleanup
  }
}

; Clean stuff up regardless
ON *:SOCKCLOSE:SB: { return $sb_cleanup }

; The fun part!!
ON *:SOCKREAD:SB:{
  ; Clean stuff up if there's an error
  IF ($sockerr) {
    $iif($window(@sb),echo 4 @sb >> $sock($sockerr).wsmsg)
    return $sb_cleanup
  }
  ; Define %t as a temporary variable -- it will be unset when this event concludes
  var %t
  ; Execute this loop while there is data to be read from the socket
  while ($sock(sb).rq) {
    ; Read a line of data into the temp var, then "tokenize" it with character 32 (space)
    ; tokenizing makes it easy to access the text in space-separated words.
    sockread %t
    tokenize 32 %t
    ; If nothing was read, return. this will ONLY happen if for some reason, say,
    ; Part of a line was sent in one packet, but it got ended before a CRLF combination.
    IF ($sockbr == 0) { return }
    ; If the debug window is open it, inform it of the read data
    IF ($window(@sb)) { echo $color(notice) -ti2 @sb << $1- }
    var %sb.num = $numtok($1-,32)
    while (%sb.num > 0) {
      IF (*!*@* iswm $gettok($1-,%sb.num,32)) {
        var %sb.nick = $remove($gettok($gettok($1-,%sb.num,32),1,33),:)
        var %sb.add = $remove($gettok($1-,%sb.num,32),:)
      }
      dec %sb.num 1
    }
    ; To see if you are connected
    IF ($gettok($1-,2,32) == 376) {
      $iif($server,sb_out NOTICE $me :I am your Anti-Spam Bot, I am Connected now.) 
      set %cps.sbbot.nick $gettok($1-,3,32)
      IF ($cps.rvi(default,sbjoin) == ALL) { 
        var %k = $numtok($cps.rvi(default,controlchan),44)
        while (%k > 0) {
          .timerSBJ [ $+ [ %k ] ] 1 %k sb_out JOIN $gettok($cps.rvi(default,controlchan),%k,44)
          dec %k 1
        }
      }
      ELSE {
        var %k = $numtok($cps.rvi(default,sbjoin),44)
        while (%k > 0) {
          .timerSBJ [ $+ [ %k ] ] 1 $calc(%k + %k) sb_out JOIN $gettok($cps.rvi(default,sbjoin),%k,44)
          dec %k 1
        }
      }
    }
    ; Signal the spam detector if u get a private message
    IF (($gettok($1-,2,32) == JOIN) && ($remove($gettok($1,1,33),:) == %cps.sbbot.nick)) { .timerSBJHOP [ $+ [ $remove($gettok($gettok($1-,3,32),1,33),:) ] ] 0 $calc($cps.rvi($remove($gettok($gettok($1-,3,32),1,33),:),sbhop) * 60) sb_hop $remove($gettok($gettok($1-,3,32),1,33),:) }
    IF (($gettok($1-,2,32) == JOIN) && ($remove($gettok($1,1,33),:) == $me)) {
      IF (%cps.sbbot.nick isop $remove($gettok($gettok($1-,3,32),1,33),:)) { sb_out mode $remove($gettok($gettok($1-,3,32),1,33),:) +o $me }
    }
    ; Signal the spam detector if u get a private message
    IF (($gettok($1-,2,32) == PRIVMSG) && (#* !iswm $1) && (#* !iswm $2) && (#* !iswm $3)) { .signal private.spam %sb.nick $+(*!*,$remove(%sb.add,$gettok(%sb.add,1,64))) $4- }
    ; If the incoming data was a PING from the server, respond immediately!
    IF (($gettok($1-,2,32) == PRIVMSG) && (VERSION isin $1-)) { sb_out privmsg %sb.nick :version-reply Complete Protection System Anti Spam Bot version 7.0 By amit (12reapers_wicked_twin@hotmail.com) }
    ; If the incoming data was a PING from the server, respond immediately!
    IF ($1 == PING) { sb_out PONG $2- }
    ; Otherwise, we send out a signal command based on the second token.
    ; PING is the only command we get from the server where the second token
    ; Does NOT tell us what the line is all about.
    ELSE { .signal -n sbe_ $+ $2 $1- }
    IF (%cpscid == $null) { set %cpscid $cid }
  }
}

ON *:socklisten:identd:{ 
  IF (!$sockerr) { sockaccept identd2 } 
}

ON *:sockread:identd2:{ 
  IF (!$sockerr) { 
    sockread %itemp 
    sockwrite -tn $sockname $gettok(%itemp,1,32) $+ , $+ $gettok(%itemp,3,32) : USERID : Identd : %identd 
  } 
}

ON *:BAN:#:{
  IF ($banmask iswm $address($me,5)) { .raw -q MODE $chan -b $banmask }
}

;=======================================;
; :::          End Of File          ::: ;
;=======================================;
