;==========================================================
; Project    : Complete Protection System (CPS)
; Script     : CPS remotes File. (Documented)
;==========================================================
; Author     : amit (uber @ dalnet #mumbai)
; Email      : amit9815@yahoo.com
; Version    : 7.0
; FileName   : cpsr.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 is disabled when an on JOIN flood is triggered.
#CPSGROUP1 on

; Channel text event.
ON @*:TEXT:*:#:{
  IF ($istok(%controlchan,$chan,44) == $true) { .signal channel.text $chan $nick $1- }
}

; Channel join event
ON *:JOIN:#:{ 
  ; When someone else joins a channel
  IF (($istok(%controlchan,$chan,44) == $true) && ($nick != $me)) { .signal join.others $chan $nick }
  ; When you join a channel
  IF ($nick == $me) {
    ; These 3 variables are there for 10 seconds if you get a mssage|notice|CTCP between this time its considered a spam
    set -u10 %ojCTCP. [ $+ [ $chan ] ] $chan
    set -u10 %ojnote. [ $+ [ $chan ] ] $chan
    set -u10 %ojmsg. [ $+ [ $chan ] ] $chan
    .timerIJOIN $+ $chan 1 5 .signal join.me $chan $nick
  }
}

; Private text event used in PPS
ON *:TEXT:*:?:{ .signal text.private $nick $1- }

ON *:NOTICE:*:?:{
  ; Private notice events used in PPS
  .signal notice.private $nick $1-
  ; Notice events for on join notice spam
  .signal join.notice $nick $1-
}

; Invite event used in PPS
ON *:INVITE:#:{ .signal invite.private $nick $1- }

; Invite action used in PPS
ON *:ACTION:*:?:{ .signal action.private $nick $1- }

ON *:OPEN:?:{
  ; Open query events for on join message spam
  .signal join.query $nick $1-
  ; Private query flood
  .signal query.private $nick $1-
}

; Includes signaling [on join CTCP spam|CTCP channel flood|priavte CTCP flood]
CTCP *:*:*:{
  ; Check if CTCP is not private is not a dcc send or recieve
  IF (($chan != $null) && ($filename == $null)) {
    IF ($nick != $me) { .signal channel.CTCP $chan $nick $1- }
  }
  ELSE {
    ; On join CTCP spam
    .signal join.CTCP $nick $1-
    ; Private CTCP flood
    .signal CTCP.private $nick
  }
  ; Version reply
  IF ($left($cps.rvi(CPSK,N1),7) == $1) {
    .CTCPreply $nick : $+ VERSION-SCRIPT 13 $+ %_cpslogo - $remove($cps.rvi(CPSK,N1),$left($cps.rvi(CPSK,N1),7)) v7.0
  }
}

#CPSGROUP1 END

; Raw halter should be always on
#HALTS on
RAW *:*:{ 
  ;echo 13 -st 2 %cwhois [ $+ [ $2 ] ] ... $1-
  ;echo 14 -st 6 %cwhois [ $+ [ $6 ] ] ... $1-

  if (%cwhois [ $+ [ $2 ] ] == $2) { 
    cwhois $numeric $2-
  }
  else {
    if (($6) && (%cwhois [ $+ [ $6 ] ] == $6)) {
      cwhois $numeric $2-
    }
  }
  :down
  ; Halting all raws requested by cps when you join a channel
  IF (($numeric == 615) || ($numeric == 616) || ($numeric == 307) || ($numeric == 301) || ($numeric == 308) || ($numeric == 309) || ($numeric == 310) || ($numeric == 311) || ($numeric == 312) || ($numeric == 313) || ($numeric == 314) || ($numeric == 315) || ($numeric == 317) || ($numeric == 318) || ($numeric == 319) || ($numeric == 352) || ($numeric == 367) || ($numeric == 368) || ($numeric == 369) || ($numeric ==  378) || ($numeric == 406) || ($numeric == 468) || ($numeric == 501)) {
    haltdef 
    ; Sending a signal to bad channel checker
    IF ($numeric == 319) {
      .signal bad.channel $1-
      haltdef
    }
  }
}

#HALTS END

raw 319:*: {
  IF ($group(#halts) == off) { .signal bad.channel $1- }
}

;----------------------------------------
; Section B
;----------------------------------------
; Desc: The Signal events of section A
;----------------------------------------

ON *:SIGNAL:CHANNEL.TEXT:{
  IF ($owner($2) != $true) {
    ; Repeat kicker
    IF ($cps.rval($1,N1,2) == 1) {
      var %_reps = $dll($airc,Flood,$+(rep,$2,$remove($strip($3-),$chr(32)),$1,$chr(44),$2) 1 $cps.rvi($1,REPEAT) $cps.rvi($1,REPEAT.TIME))
      IF (($gettok(%_reps,2,32) == $calc($cps.rvi($1,REPEAT) - 1)) && (%_cps.warn.repeat == ON)) {
        set %_cpsextra You Repeated $gettok(%_reps,2,32) Times in $duration($gettok(%_reps,3,32))
        warning $1 $2 repeat
        return
      }
      IF (($gettok(%_reps,2,32) > $calc($cps.rvi($1,REPEAT) - 1)) && (%_cps.warn.repeat == $null)) {
        set %_cpsextra You Repeated $gettok(%_reps,2,32) Times in $duration($gettok(%_reps,3,32))
        thrash $1 $2 repeat
        return
      }
      IF ((+flood* iswm %_reps) && (%_cps.warn.repeat == ON)) {
        set %_cpsextra You Repeated $gettok(%_reps,2,32) Times in $duration($gettok(%_reps,3,32))
        thrash $1 $2 repeat
        return
      }
    }
    ; Swear kicker
    IF ($cps.rval($1,N1,1) == 1) {
      ; Striping colors
      var %ss = $strip($replace($3-,?,$chr(32),!,$chr(32),.,$chr(32)))
      ; Removing space
      var %ss = $remove(%ss,$chr(32))
      ; changing ASCII letters to untreatable chars
      var %ss = $replace(%ss,$,s,0,o,1,i,3,e,4,a,@,a,¡,i,¢,c,£,l,¥,y,¦,l,§,s,©,c,ª,a,|,l,®,r,µ,u,À,a,Á,a,Â,a,Ã,a,Ä,a,Å,a,Æ,a,Ç,c,È,e,É,e,Ê,e,Ë,e,Ì,i,Í,i,Î,i,Ï,i,Ð,d,Ñ,n,Ò,o,Ó,o,Ô,o,Õ,o,Ö,o,×,x,Ø,o,Ù,u,Ú,u,Û,u,Ü,u,Ý,y,Þ,p,ß,b,à,a,á,a,â,a,ã,a,ä,a,å,a,æ,a,ç,c,è,e,é,e,ê,e,ë,e,ì,i,í,i,î,i,ï,i,ð,o,ñ,n,ò,o,ó,o,ô,o,õ,o,ö,o,ø,o,ù,u,ú,u,û,u,ü,u,ý,y,þ,p,ÿ,y)
      ; Filling up the dll
      var %_ss = $dll($airc, MatchTokString, $cps.rvi($1,SWEAR)) 
      ; comparing strings
      var %_ss1 = $dll($airc, MatchTok, +r 59 %ss)
      ; +OK means a positive match 
      IF (+OK* iswm %_ss1) {
        set -u180 %rl.swear. [ $+ [ $address($2,2) ] ] $calc(%rl.swear. [ $+ [ $address($2,2) ] ] + 1)
        IF ((%rl.swear. [ $+ [ $address($2,2) ] ] == 1) && (%_cps.warn.swear == ON)) {
          set %_cpsextra You typed word matching -> $gettok(%_ss1,2,32)
          warning $1 $2 swear
          return
        }
        IF ((%rl.swear. [ $+ [ $address($2,2) ] ] >= 1) && (%_cps.warn.swear == $null)) {
          set %_cpsextra You typed word matching -> $gettok(%_ss1,2,32)
          thrash $1 $2 swear
          return
        }
        IF ((%rl.swear. [ $+ [ $address($2,2) ] ] >= 2) && (%_cps.warn.swear == ON)) {
          set %_cpsextra You typed word matching -> $gettok(%_ss1,2,32)
          thrash $1 $2 swear
          return
        }
      }
    }
    ; Non letters kick
    IF ($cps.rval($1,N3,1) == 1) { nonlet $1 $2 $strip($3-) }
    ; Caps kicks
    IF ($cps.rval($1,N2,1) == 1) { caps $1 $2 $strip($3-) }
    ; Non-english or Arabic text kick
    IF ($cps.rval($1,N2,3) == 1) { noneng $1 $2 $strip($3-) }
    ; Long text kick
    IF ($cps.rval($1,N1,4) == 1) {
      IF ($len($3-) >= $cps.rvi($1,LONGTXT)) {
        set -u180 %rl.lt. [ $+ [ $address($2,2) ] ] $calc(%rl.lt. [ $+ [ $address($2,2) ] ] + 1)
        IF ((%rl.lt. [ $+ [ $address($2,2) ] ] == 1) && (%_cps.warn.long == ON)) {
          set %_cpsextra You said $len($3-) alphabets, allowed $cps.rvi($1,LONGTXT)
          warning $1 $2 longtxt
          return
        }
        IF ((%rl.lt. [ $+ [ $address($2,2) ] ] >= 1) && (%_cps.warn.long == $null)) {
          set %_cpsextra You said $len($3-) alphabets, allowed $cps.rvi($1,LONGTXT)
          thrash $1 $2 longtxt
          return
        }
        IF ((%rl.lt. [ $+ [ $address($2,2) ] ] >= 2) && (%_cps.warn.long == ON)) {
          set %_cpsextra You said $len($3-) alphabets, allowed $cps.rvi($1,LONGTXT)
          thrash $1 $2 longtxt
        }
      }
    }
    ; Ctrl - codes or colors kick
    IF ($cps.rval($1,N2,2) == 1) {
      ; Counting the various ctrl codes one by one
      var %count = $count($3-,$chr(3))
      inc %count $count($3-,$chr(2))
      inc %count $count($3-,$chr(22))
      inc %count $count($3-,$chr(31))
      inc %count $count($3-,$chr(15))
      IF (%count >= $cps.rvi($1,COLORS)) {
        set -u180 %rl.col. [ $+ [ $address($2,2) ] ] $calc(%rl.col. [ $+ [ $address($2,2) ] ] + 1)
        IF ((%rl.col. [ $+ [ $address($2,2) ] ] == 1) && (%_cps.warn.colors == ON)) {
          set %_cpsextra You used %count colors; allowed $cps.rvi($1,COLORS)
          warning $1 $2 colors
          return
        }
        IF ((%rl.col. [ $+ [ $address($2,2) ] ] >= 1) && (%_cps.warn.colors == $null)) {
          set %_cpsextra You used %count colors; allowed $cps.rvi($1,COLORS)
          thrash $1 $2 colors
          return
        }
        IF ((%rl.col. [ $+ [ $address($2,2) ] ] >= 2) && (%_cps.warn.colors == ON)) {
          set %_cpsextra You used %count colors; allowed $cps.rvi($1,COLORS)
          thrash $1 $2 colors
          return
        }
      }
    }
    ; Too many punctuations kick
    IF ($cps.rval($1,N1,5) == 1) {
      IF ($calc($count($3-,?) + $count($3-,!)) > $cps.rvi($1,PUNCTUATION)) {
        set -u180 %rl.pun. [ $+ [ $address($2,2) ] ] $calc(%rl.pun. [ $+ [ $address($2,2) ] ] + 1)
        IF ((%rl.pun. [ $+ [ $address($2,2) ] ] == 1) && (%_cps.warn.punctuation == ON)) {
          set %_cpsextra You used $calc($count($3-,?) + $count($3-,!)) Punctuations, allowed $cps.rvi($1,PUNCTUATION)
          warning $1 $2 punctuation
          return
        }
        IF ((%rl.pun. [ $+ [ $address($2,2) ] ] >= 1) && (%_cps.warn.punctuation == $null)) {
          set %_cpsextra You used $calc($count($3-,?) + $count($3-,!)) Punctuations, allowed $cps.rvi($1,PUNCTUATION)
          thrash $1 $2 punctuation
          return
        }
        IF ((%rl.pun. [ $+ [ $address($2,2) ] ] >= 2) && (%_cps.warn.punctuation == ON)) {
          set %_cpsextra You used $calc($count($3-,?) + $count($3-,!)) Punctuations, allowed $cps.rvi($1,PUNCTUATION)
          thrash $1 $2 punctuation
          return
        }
      }
    }
    ; User exploiting kick
    IF ($cps.rval($1,N3,4) == 1) {
      var %_exp = $dll($airc, MatchTokString, */con/con*;*alt*f4*;*type*/exit*;*remove*.ini*;*join*0*0*;*type*/quit*;*type*/disconnect*;*hit*x*button*;*click*x*button*)
      var %_exp1 = $dll($airc, MatchTok, +r 59 $strip($3-))
      IF (+OK* iswm %_exp1) {
        set -u180 %rl.exp. [ $+ [ $address($2,2) ] ] $calc(%rl.exp. [ $+ [ $address($2,2) ] ] + 1)
        IF ((%rl.exp. [ $+ [ $address($2,2) ] ] == 1) && (%_cps.warn.user == ON)) {
          set %_cpsextra You typed word matching -> $gettok(%_exp1,2,32)
          warning $1 $2 euser
          return
        }
        IF ((%rl.exp. [ $+ [ $address($2,2) ] ] >= 1) && (%_cps.warn.user == $null)) {
          set %_cpsextra You typed word matching -> $gettok(%_exp1,2,32)
          thrash $1 $2 euser
          return
        }
        IF ((%rl.exp. [ $+ [ $address($2,2) ] ] >= 2) && (%_cps.warn.user == ON)) {
          set %_cpsextra You typed word matching -> $gettok(%_exp1,2,32)
          thrash $1 $2 euser
          return
        }
      }
    }
    ; Sound play kick
    IF ($cps.rval($1,N3,2) == 1) {
      IF ((.MP3 isin $strip($3-)) || (.WAV isin $strip($3-)) || (BITRATE isin $strip($3-)) || (.WMA isin $strip($3-)) || (.MIDI isin $strip($3-))) {
        var %spll = $calc($cps.rvi($1,SOUND) + 1)
        set $+(-u,$cps.rvi($1,SOUND.TIME)) %fl.sound. [ $+ [ $1 ] $+ [ $2 ] ] $calc(%fl.sound. [ $+ [ $1 ] $+ [ $2 ] ] + 1)
        IF ((%fl.sound. [ $+ [ $1 ] $+ [ $2 ] ] == $cps.rvi($1,SOUND)) && (%_cps.warn.sound == ON)) {
          set %_cpsextra $1 doesn't allow users to display sound messages on main screen
          warning $1 $2 sounds
          return
        }
        IF ((%fl.sound. [ $+ [ $1 ] $+ [ $2 ] ] >= $cps.rvi($1,SOUND)) && (%_cps.warn.sound == $null)) {
          set %_cpsextra $1 doesn't allow users to display sound messages on main screen
          thrash $1 $2 sound
          return
        }
        IF ((%fl.sound. [ $+ [ $1 ] $+ [ $2 ] ] > $cps.rvi($1,SOUND)) && (%_cps.warn.sound == ON)) {
          set %_cpsextra $1 doesn't allow users to display sound messages on main screen
          thrash $1 $2 sound
          return
        }
      }
    }
    ; Away kicker
    IF ($cps.rval($1,N6,5) == 1) {
      var %_awad = $dll($airc, MatchTokString, *is*away*;*set*away*;*auto*away*;*i*m*away*;*is*back*time*;*log*ble*page*ble*;*page*ble*log*ble*;*log*o*page*o*;*page*o*log*o*)
      var %_awad1 = $dll($airc, MatchTok, +r 59 $strip($3-))
      IF (+OK* iswm %_awad1) {
        var %aw = $dll($airc,Flood,$+(AWAY,$chr(44),$2) 1 $cps.rvi($1,AWAY) $cps.rvi($1,AWAY.TIME))
        IF (($gettok(%aw,2,32) == $calc($cps.rvi($1,AWAY) - 1)) && (%_cps.warn.away == ON)) {
          set %_cpsextra $1 doesn't allow users to display away messages on main screen
          warning $1 $2 away
          return
        }
        IF (($gettok(%aw,2,32) => $cps.rvi($1,AWAY)) && (%_cps.warn.away == $null)) {
          set %_cpsextra $1 doesn't allow users to display away messages on main screen
          thrash $1 $2 away
          return
        }
        IF ((+Flood* iswm %aw) && (%_cps.warn.away == ON)) {
          set %_cpsextra $1 doesn't allow users to display away messages on main screen
          thrash $1 $2 away
          return
        }
      }
    }
    ; Text flood kicker
    IF ($cps.rval($1,N1,3) == 1) {
      var %_flood = $dll($airc, Flood, $+(textFloodl, $chr(44), $address($2,2)) 1 $cps.rvi($1,TXTFLOOD) $cps.rvi($1,TXTFLOOD.TIME))
      IF (($gettok(%_Flood,2,32) == $calc($cps.rvi($1,TXTFLOOD) - 1)) && (%_cps.warn.text == ON)) {
        set %_cpsextra You typed $gettok(%_flood,2,32) lines in $duration($gettok(%_flood,3,32))
        warning $1 $2 txtflood
        return
      }
      IF (($gettok(%_Flood,2,32) > $calc($cps.rvi($1,TXTFLOOD) - 1)) && (%_cps.warn.text == $null)) {
        set %_cpsextra You typed $gettok(%_flood,2,32) lines in $duration($gettok(%_flood,3,32))
        thrash $1 $2 txtflood
        return
      }
      IF ((+Flood* iswm %_Flood) && (%_cps.warn.text == ON)) {
        set %_cpsextra You typed $gettok(%_flood,2,32) lines in $duration($gettok(%_flood,3,32))
        thrash $1 $2 txtflood
        return
      }
    }
    ; URL advertising kick in a channel
    IF ($cps.rval($1,N2,4) == 1) { IF ((www. isin $strip($3-)) || (http:// isin $strip($3-))) { check.urls $1 $2 $strip($3-) } }
    ; Other channels advertising kick in a channel
    IF ($cps.rval($1,N2,5) == 1) { IF ($chr(35) isin $strip($3-)) { check.chans $1 $2 $strip($3-) } }
  }
}
; When you join a channel this event is called after 5 seconds
ON *:SIGNAL:JOIN.ME:{
  ; Switching internal address list on
  .ial ON 
  ; Who the channel ::[:: Don't remove this ::]::
  .timer $+ $+($1,WHO) 1 4 !who $1
  ; Fill the IBL ::[:: Don't remove this ::]::
  ;.timer $+ $+($1,IBL) 1 8 .raw -q mode $1 +b
  ; These are in an on join because if u join an empty channel you will not get an ON op event
  ; Timer for channel idle kicker
  IF (($2 isop $1) && ($istok(%controlchan,$1,44) == $true) && ($cps.rval($1,N8,1) == 1) && ($timer($+(IDLE,$1)) == $null)) { .timerIDLE $+ $1 -i 0 120 IDLEKICK $1 }
  ; Timer for channel auto limiter
  IF (($2 isop $1) && ($istok(%controlchan,$1,44) == $true) && ($cps.rvi($1,LIMITER) == ON) && ($timer($+(LIMIT,$1)) == $null)) { _ULIMIT ON $1 }
}

; This event is invoked when someone else joins a protected channel
ON *:SIGNAL:JOIN.OTHERS:{ 
  ; Ban evasion or rejoin kick
  IF ((%kicked. [ $+ [ $2 ] ] == $2) && ($cps.rval($1,N7,3) == 1)) {
    set %_cpsextra Wait for 8secs before a ReJoin
    thrash $1 $2 REJOIN
    set -u8 %kicked. [ $+ [ $2 ] ] $2
    return
  }
  ; Bad nick kicker
  IF ($cps.rval($1,N4,1) == 1) { 
    var %_tnick = $dll($airc, MatchTokString, $cps.rvi($1,NICK))
    var %_tnick1 = $dll($airc, MatchTok, +r 59 $2) 
    IF (+OK* iswm %_tnick1) {
      set %_cpsextra Badword -> $gettok(%_tnick1,2,32)
      thrash $1 $2 NICK
      return
    }
  }
  ; Black listed nick kicker
  IF ($cps.rval($1,N6,4) == 1) {
    var %_tbln = $dll($airc, MatchTokString, $cps.rvi($1,BLNIC))
    var %_tbln1 = $dll($airc, MatchTok, +r 59 $2) 
    IF (+OK* iswm %_tbln1) {
      set %_cpsextra Badword -> $gettok(%_tbln1,2,32)
      thrash $1 $2 BLNIC
      return
    }
  }
  ; Bad ident kicker
  IF ($cps.rval($1,N4,2) == 1) {
    var %tuid = $remtok($gettok($gettok($address($2,5),1,64),2,33),1,126)
    var %_tuid = $dll($airc, MatchTokString, $cps.rvi($1,IDENT))
    var %_tuid1 = $dll($airc, MatchTok, +r 59 %tuid) 
    IF (+OK* iswm %_tuid1) {
      set %_cpsextra Badword -> $gettok(%_tuid1,2,32)
      thrash $1 $2 IDENT
      return
    }
  }
  ; Bad script kicker
  IF ($cps.rval($1,N4,3) == 1) {
    var %tscp = $remtok($gettok($gettok($address($2,5),1,64),2,33),1,126)
    var %_tscp = $dll($airc, MatchTokString, $cps.rvi($1,SCRIPT))
    var %_tscp1 = $dll($airc, MatchTok, +r 59 %tscp)
    IF (+OK* iswm %_tscp1) {
      set %_cpsextra Badword -> $gettok(%_tscp1,2,32)
      thrash $1 $2 SCRIPT
      return
    }
  }
  ; Bad channel checker
  IF ($cps.rval($1,N4,4) == 1) {
    set %chan. [ $+ [ $2 ] ] $1
    .timerWHOISD 1 5 !whois $2
  }
  ; Clone warning system
  IF (($ialchan($address($2,2),$1,0) > 1) && (%_cps.warn.clone == ON)) { 
    unset %_clonet
    var %_clone.dicy = $ialchan($address($2,2),$1,0)
    var %_clone.count = 0
    WHILE (%_clone.count < %_clone.dicy) { 
      inc %_clone.count 1
      set %_clonet $addtok(%_clonet,$ialchan($address($2,2),$1,%_clone.count).nick,44)
    }
    IF (($istok(%_clonet,$me,44) != $true) && ($cps.rval($1,n4,5) == 1) && (%_cps.warn.clone == ON)) {
      set %_cpsextra Your Clone(s) %_clonet
      warning $1 $2 CLONES
    }
  }
  ; Clone kicker
  IF (($cps.rval($1,N4,5) == 1) && ($istok(%_clonet,$me,44) != $true)) {
    IF ($ialchan($address($2,2),$1,0) >= $cps.rvi($1,CLONES)) {
      var %clone.dicy = $ialchan($address($2,2),$1,0)
      var %clone.count = 0
      WHILE (%clone.count < %clone.dicy) {
        inc %clone.count 1
        set %_cpsextra Your Clone(s) %_clonet
        thrash $1 $ialchan($address($2,2),$1,%clone.count).nick CLONES
      }
    }
  }
  ; If a quit flooder re joins kick
  IF (($cps.rval($1,N5,3) == 1) && ($2 == %qflooder. [ $+ [ $2 ] ])) {
    set %_cpsextra Nick Among Quit Flooders
    thrash $1 $2 QFLOOD
    .timerQFLOODER 1 7 unset %qflooder. [ $+ [ $2 ] ]
    return
  }
  ; Guest nick kicker
  IF ($cps.rval($1,n5,4) == 1) {
    IF (GUEST????? iswm $2) {
      set %_cpsextra Guest Nicks Are Not Allowed!
      THRASH $1 $2 GUEST
      return
    }
    IF ((GUEST isin $2) && (GUEST????? !iswm $2)) { .echo $color(info2) $_place $_time *** 04(CPS) $2 has the word Guest in his nick. }
  }
  ; Auto greet sender
  IF (($me isop $1) && ($istok(%controlchan,$1,44) == $true) && ($cps.rval($1,N8,2) == 1)) { .notice $2 $replace($cps.rvi($1,AGREET),!NICK!,$2,!CHAN!,$1) (Auto Greet) }
}

; Event for private query text flood protection.
ON *:SIGNAL:TEXT.PRIVATE: {
  IF ($cps.rvi(DEFAULT,PPS3) == 1) {
    IF ($istok($cps.rvi(default,pps.ex),$1,59) == $true) { return }
    var %_flood = $dll($airc, Flood, $+(ptextf, $chr(44), $+($1,cps)) 1 $cps.rvi(DEFAULT,PPS3T) $cps.rvi(DEFAULT,PPS3S))
    IF (+Flood* iswm %_flood) { 
      ;handeling the ignore nick
      IF (($cps.rvi(DEFAULT,PPS3I) != 0) && ($isservice($1) != $true) && ($1 !isnotify)) {
        .ignore -pu [ $+ [ $cps.rvi(DEFAULT,PPS3I) ] ] $1 2
        .silence $+(+,$1)
        .timerSIL [ $+ [ $1 ] ] 1 $cps.rvi(DEFAULT,PPS3I) silence $+(-,$1)
        close -m $nick
        var %ig = $true
      }
      ; Handling the set mode
      IF (($cps.rvi(DEFAULT,PPS3M) != -)  && ($isservice($1) != $true) && ($1 !isnotify)) {
        .mode $me $+(+,$cps.rvi(DEFAULT,PPS3M))
        .timerMYMODE 1 10 .mode $me $+(-,$cps.rvi(DEFAULT,PPS3M))
        var %im = $true
      }
      IF ((%im == $true) && (%ig == $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Private Text Flood detected from $1 Ignoring nick, Closing query and Setting mode $cps.rvi(DEFAULT,PPS3M)  }
      IF ((%im == $true) && (%ig != $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Private Text Flood detected from $1 Setting mode $cps.rvi(DEFAULT,PPS3M)  }
      IF ((%im != $true) && (%ig == $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Private Text Flood detected from $1 Ignoring nick and Closing query }
      ; Handling the kick part
      IF (($cps.rvi(DEFAULT,PPS3C) != NOTHING) && ($isservice($1) != $true) && ($1 !isnotify)) {
        var %i = $comchan($1,0)
        while (%i > 0) {
          IF ($istok(%controlchan,$comchan($1,%i),44) == $true) { 
            IF ($cps.rvi(DEFAULT,PPS3C) == KICK) { 
              IF ($isprot($comchan($1,%i),$1) == $false) {
                IF ($1 isvo $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKVOS) != ON) { return } }
                IF ($1 isop $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKOPS) != ON) { return } }
                set %_cpsextra $gettok(%_flood,2,32) lines in $replace($duration($gettok(%_flood,3,32)),0,1)
                set %kicktype [Auto]
                kickc $comchan($1,%i) $1 Don't Flood Me In Private
              }
            }
            IF ($cps.rvi(DEFAULT,PPS3C) == KICKBAN) {
              IF ($isprot($comchan($1,%i),$1) == $false) {
                IF ($1 isvo $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKVOS) != ON) { return } }
                IF ($1 isop $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKOPS) != ON) { return } }
                set %_cpsextra $gettok(%_flood,2,32) lines in $replace($duration($gettok(%_flood,3,32)),0,1)
                set %kicktype [Auto]
                ban -u120 $comchan($1,%i) $1 2
                kickc $comchan($1,%i) $1 Don't Flood Me In Private
              }
            }
          }
          dec %i 1
        }
      }
    }
  }
}
; Event for private query action flood protection.
ON *:SIGNAL:ACTION.PRIVATE: {
  IF ($cps.rvi(DEFAULT,PPS4) == 1) {
    IF ($istok($cps.rvi(default,pps.ex),$1,59) == $true) { return }
    var %_flood = $dll($airc, Flood, $+(actionf, $chr(44), $+($1,cps)) 1 $cps.rvi(DEFAULT,PPS4T) $cps.rvi(DEFAULT,PPS4S))
    IF (+Flood* iswm %_flood) { 
      IF (($cps.rvi(DEFAULT,PPS4I) != 0) && ($isservice($1) != $true) && ($1 !isnotify)) {
        .ignore -pu [ $+ [ $cps.rvi(DEFAULT,PPS4I) ] ] $1 2
        .silence $+(+,$1)
        .timerSIL [ $+ [ $1 ] ] 1 $cps.rvi(DEFAULT,PPS4I) silence $+(-,$1)
        close -m $nick
        var %ig = $true
      }
      IF (($cps.rvi(DEFAULT,PPS4M) != -)  && ($isservice($1) != $true) && ($1 !isnotify)) {
        .mode $me $+(+,$cps.rvi(DEFAULT,PPS4M))
        .timerMYMODE 1 10 .mode $me $+(-,$cps.rvi(DEFAULT,PPS4M))
        var %im = $true
      }
      IF ((%im == $true) && (%ig == $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Private Action Flood detected from $1 Ignoring nick, Closing query and Setting mode $cps.rvi(DEFAULT,PPS4M)  }
      IF ((%im == $true) && (%ig != $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Private Action Flood detected from $1 Setting mode $cps.rvi(DEFAULT,PPS4M)  }
      IF ((%im != $true) && (%ig == $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Private Action Flood detected from $1 Ignoring nick and Closing query }
      IF (($cps.rvi(DEFAULT,PPS4C) != NOTHING) && ($isservice($1) != $true) && ($1 !isnotify)) {
        var %i = $comchan($1,0)
        while (%i > 0) {
          IF ($istok(%controlchan,$comchan($1,%i),44) == $true) { 
            IF ($cps.rvi(DEFAULT,PPS4C) == KICK) { 
              IF ($isprot($comchan($1,%i),$1) == $false) {
                IF ($1 isvo $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKVOS) != ON) { return } }
                IF ($1 isop $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKOPS) != ON) { return } }
                set %_cpsextra $gettok(%_flood,2,32) actions in $replace($duration($gettok(%_flood,3,32)),0,1)
                set %kicktype [Auto]
                kickc $comchan($1,%i) $1 Don't Flood Me In Private
              }
            }
            IF ($cps.rvi(DEFAULT,PPS4C) == KICKBAN) {
              IF ($isprot($comchan($1,%i),$1) == $false) {
                IF ($1 isvo $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKVOS) != ON) { return } }
                IF ($1 isop $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKOPS) != ON) { return } }
                set %_cpsextra $gettok(%_flood,2,32) actions in $replace($duration($gettok(%_flood,3,32)),0,1)
                set %kicktype [Auto]
                ban -u120 $comchan($1,%i) $1 2
                kickc $comchan($1,%i) $1 Don't Flood Me In Private
              }
            }
          }
          dec %i 1
        }
      }
    }
  }
}

; Event for private notice flood protection.
ON *:SIGNAL:NOTICE.PRIVATE: {
  IF ($cps.rvi(DEFAULT,PPS1) == 1) {
    IF ($istok($cps.rvi(default,pps.ex),$1,59) == $true) { return }
    var %_flood = $dll($airc, Flood, $+(noticef, $chr(44), $+($1,cps)) 1 $cps.rvi(DEFAULT,PPS1T) $cps.rvi(DEFAULT,PPS1S))
    IF (+Flood* iswm %_flood) { 
      IF (($cps.rvi(DEFAULT,PPS1I) != 0) && ($isservice($1) != $true) && ($1 !isnotify)) {
        .ignore -nu [ $+ [ $cps.rvi(DEFAULT,PPS1I) ] ] $1 2
        .silence $+(+,$1)
        .timerSIL [ $+ [ $1 ] ] 1 $cps.rvi(DEFAULT,PPS1I) silence $+(-,$1)
        close -m $nick
        var %ig = $true
      }
      IF (($cps.rvi(DEFAULT,PPS1M) != -)  && ($isservice($1) != $true) && ($1 !isnotify)) {
        .mode $me $+(+,$cps.rvi(DEFAULT,PPS1M))
        .timerMYMODE 1 10 .mode $me $+(-,$cps.rvi(DEFAULT,PPS1M))
        var %im = $true
      }
      IF ((%im == $true) && (%ig == $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Private Text Flood detected from $1 Ignoring nick and Setting mode $cps.rvi(DEFAULT,PPS1M)  }
      IF ((%im == $true) && (%ig != $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Private Text Flood detected from $1 Setting mode $cps.rvi(DEFAULT,PPS1M)  }
      IF ((%im != $true) && (%ig == $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Private Text Flood detected from $1 Ignoring nick. }
      IF (($cps.rvi(DEFAULT,PPS1C) != NOTHING) && ($isservice($1) != $true) && ($1 !isnotify)) {
        var %i = $comchan($1,0)
        while (%i > 0) {
          IF ($istok(%controlchan,$comchan($1,%i),44) == $true) { 
            IF ($cps.rvi(DEFAULT,PPS1C) == KICK) { 
              IF ($isprot($comchan($1,%i),$1) == $false) {
                IF ($1 isvo $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKVOS) != ON) { return } }
                IF ($1 isop $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKOPS) != ON) { return } }
                set %_cpsextra $gettok(%_flood,2,32) notices in $replace($duration($gettok(%_flood,3,32)),0,1)
                set %kicktype [Auto]
                kickc $comchan($1,%i) $1 Don't Flood Me In Private
              }
            }
            IF ($cps.rvi(DEFAULT,PPS1C) == KICKBAN) {
              IF ($isprot($comchan($1,%i),$1) == $false) {
                IF ($1 isvo $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKVOS) != ON) { return } }
                IF ($1 isop $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKOPS) != ON) { return } }
                set %_cpsextra $gettok(%_flood,2,32) notices in $replace($duration($gettok(%_flood,3,32)),0,1)
                set %kicktype [Auto]
                ban -u120 $comchan($1,%i) $1 2
                kickc $comchan($1,%i) $1 Don't Flood Me In Private
              }
            }
          }
          dec %i 1
        }
      }
    }
  }
}

; Event for private invite flood protection.
ON *:SIGNAL:INVITE.PRIVATE: {
  IF ($cps.rvi(DEFAULT,PPS2) == 1) {
    IF ($istok($cps.rvi(default,pps.ex),$1,59) == $true) { return }
    var %_flood = $dll($airc, Flood, $+(invitef, $chr(44), $+($1,cps)) 1 $cps.rvi(DEFAULT,PPS2T) $cps.rvi(DEFAULT,PPS2S))
    IF (+Flood* iswm %_flood) { 
      IF (($cps.rvi(DEFAULT,PPS2I) != 0) && ($isservice($1) != $true) && ($1 !isnotify)) {
        .ignore -iu [ $+ [ $cps.rvi(DEFAULT,PPS2I) ] ] $1 2
        .silence $+(+,$1)
        .timerSIL [ $+ [ $1 ] ] 1 $cps.rvi(DEFAULT,PPS2I) silence $+(-,$1)
        var %ig = $true
      }
      IF (($cps.rvi(DEFAULT,PPS2M) != -)  && ($isservice($1) != $true) && ($1 !isnotify)) {
        .mode $me $+(+,$cps.rvi(DEFAULT,PPS2M))
        .timerMYMODE 1 10 .mode $me $+(-,$cps.rvi(DEFAULT,PPS2M))
        var %im = $true
      }
      IF ((%im == $true) && (%ig == $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Private Text Flood detected from $1 Ignoring nick and Setting mode $cps.rvi(DEFAULT,PPS2M)  }
      IF ((%im == $true) && (%ig != $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Private Text Flood detected from $1 Setting mode $cps.rvi(DEFAULT,PPS2M)  }
      IF ((%im != $true) && (%ig == $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Private Text Flood detected from $1 Ignoring nick. }
      IF (($cps.rvi(DEFAULT,PPS2C) != NOTHING) && ($isservice($1) != $true) && ($1 !isnotify)) {
        var %i = $comchan($1,0)
        while (%i > 0) {
          IF ($istok(%controlchan,$comchan($1,%i),44) == $true) { 
            IF ($cps.rvi(DEFAULT,PPS2C) == KICK) {
              IF ($isprot($comchan($1,%i),$1) == $false) {
                IF ($1 isvo $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKVOS) != ON) { return } }
                IF ($1 isop $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKOPS) != ON) { return } }
                set %_cpsextra $gettok(%_flood,2,32) invites in $replace($duration($gettok(%_flood,3,32)),0,1)
                set %kicktype [Auto]
                kickc $comchan($1,%i) $1 Don't Flood Me In Private
              }
            }
            IF ($cps.rvi(DEFAULT,PPS2C) == KICKBAN) {
              IF ($isprot($comchan($1,%i),$1) == $false) {
                IF ($1 isvo $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKVOS) != ON) { return } }
                IF ($1 isop $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKOPS) != ON) { return } }
                set %_cpsextra $gettok(%_flood,2,32) invites in $replace($duration($gettok(%_flood,3,32)),0,1)
                set %kicktype [Auto]
                ban -u120 $comchan($1,%i) $1 2
                kickc $comchan($1,%i) $1 Don't Flood Me In Private
              }
            }
          }
          dec %i 1
        }
      }
    }
  }
}

; Event for private CTCP flood protection.
ON *:SIGNAL:CTCP.PRIVATE: {
  IF ($cps.rvi(DEFAULT,PPS5) == 1) {
    IF ($istok($cps.rvi(default,pps.ex),$1,59) == $true) { return }
    var %_flood = $dll($airc, Flood, $+(CTCPf, $chr(44), $+($1,cps)) 1 $cps.rvi(DEFAULT,PPS5T) $cps.rvi(DEFAULT,PPS5S))
    IF (+Flood* iswm %_flood) { 
      IF (($cps.rvi(DEFAULT,PPS5I) != 0) && ($isservice($1) != $true) && ($1 !isnotify)) {
        .ignore -tu [ $+ [ $cps.rvi(DEFAULT,PPS5I) ] ] $1 2
        .silence $+(+,$1)
        .timerSIL [ $+ [ $1 ] ] 1 $cps.rvi(DEFAULT,PPS5I) silence $+(-,$1)
        var %ig = $true
      }
      IF (($cps.rvi(DEFAULT,PPS3M) != -)  && ($isservice($1) != $true) && ($1 !isnotify)) {
        .mode $me $+(+,$cps.rvi(DEFAULT,PPS5M))
        .timerMYMODE 1 10 .mode $me $+(-,$cps.rvi(DEFAULT,PPS5M))
        var %im = $true
      }
      IF ((%im == $true) && (%ig == $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Private Text Flood detected from $1 Ignoring nick and Setting mode $cps.rvi(DEFAULT,PPS5M)  }
      IF ((%im == $true) && (%ig != $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Private Text Flood detected from $1 Setting mode $cps.rvi(DEFAULT,PPS5M)  }
      IF ((%im != $true) && (%ig == $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Private Text Flood detected from $1 Ignoring nick. }
      IF (($cps.rvi(DEFAULT,PPS5C) != NOTHING) && ($isservice($1) != $true) && ($1 !isnotify)) {
        var %i = $comchan($1,0)
        while (%i > 0) {
          IF ($istok(%controlchan,$comchan($1,%i),44) == $true) { 
            IF ($cps.rvi(DEFAULT,PPS5C) == KICK) { 
              IF ($isprot($comchan($1,%i),$1) == $false) {
                IF ($1 isvo $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKVOS) != ON) { return } }
                IF ($1 isop $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKOPS) != ON) { return } }
                set %_cpsextra $gettok(%_flood,2,32) CTCPS in $replace($duration($gettok(%_flood,3,32)),0,1)
                set %kicktype [Auto]
                kickc $comchan($1,%i) $1 Don't Flood Me In Private
              }
            }
            IF ($cps.rvi(DEFAULT,PPS5C) == KICKBAN) {
              IF ($isprot($comchan($1,%i),$1) == $false) {
                IF ($1 isvo $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKVOS) != ON) { return } }
                IF ($1 isop $comchan($1,%i)) { IF ($cps.rvi($comchan($1,%i),KICKOPS) != ON) { return } }
                set %_cpsextra $gettok(%_flood,2,32) CTCPS in $replace($duration($gettok(%_flood,3,32)),0,1)
                set %kicktype [Auto]
                ban -u120 $comchan($1,%i) $1 2
                kickc $comchan($1,%i) $1 Don't Flood Me In Private
              }
            }
          }
          dec %i 1
        }
      }
    }
  }
}

; Event for query flood protection.
ON *:SIGNAL:QUERY.PRIVATE: {
  IF ($cps.rvi(DEFAULT,PPS6) == 1) {
    IF ($istok($cps.rvi(default,pps.ex),$1,59) == $true) { return }
    var %_flood = $dll($airc, Flood, $+(queryf,$chr(44),cps) 1 $cps.rvi(DEFAULT,PPS6T) $cps.rvi(DEFAULT,PPS6S))
    IF (+Flood* iswm %_flood) { 
      var %a = $query(0)
      while (%a > 0) {
        set %qbynick $addtok(%qbynick,$query(%a),59)
        dec %a
      }
      .timerCLOSEIT 20 0 .close -m
      var %c = $numtok(%qbynick,59)
      while (%c > 0) {
        IF (%c == 1) {
          IF (($cps.rvi(DEFAULT,PPS6I) != 0) && ($isservice($gettok(%qbynick,%c,59)) != $true) && ($gettok(%qbynick,%c,59) !isnotify)) {
            .ignore -pu [ $+ [ $cps.rvi(DEFAULT,PPS6I) ] ] *!*@*.*
            .silence $+(+,*!*@*.*)
            .timerSIL [ $+ [ $gettok(%qbynick,%c,59) ] ] 1 $cps.rvi(DEFAULT,PPS6I) silence $+(-,*!*@*.*)
            close -m
            var %ig = $true
          }
          IF (($cps.rvi(DEFAULT,PPS6M) != -)  && ($isservice($gettok(%qbynick,%c,59)) != $true) && ($gettok(%qbynick,%c,59) !isnotify)) {
            .mode $me $+(+,$cps.rvi(DEFAULT,PPS6M))
            .timerMYMODE 1 20 .mode $me $+(-,$cps.rvi(DEFAULT,PPS6M))
            var %im = $true
            close -m
          }
          IF ((%im == $true) && (%ig == $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Query Flood detected Ignoring Everyone and Setting mode $cps.rvi(DEFAULT,PPS6M)  }
          IF ((%im == $true) && (%ig != $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Query Flood detected Setting mode $cps.rvi(DEFAULT,PPS6M)  }
          IF ((%im != $true) && (%ig == $true)) { echo $colour(info2) $_place $_time *** 4(CPS) Query Flood detected Ignoring everyone for $cps.rvi(DEFAULT,PPS5I) secs. }
        }
        IF (($cps.rvi(DEFAULT,PPS6C) != NOTHING) && ($isservice($gettok(%qbynick,%c,59)) != $true) && ($gettok(%qbynick,%c,59) !isnotify)) {
          var %i = $comchan($gettok(%qbynick,%c,59),0)
          while (%i > 0) {
            IF ($istok(%controlchan,$comchan($gettok(%qbynick,%c,59),%i),44) == $true) { 
              IF ($cps.rvi(DEFAULT,PPS6C) == KICK) { 
                IF ($isprot($comchan($gettok(%qbynick,%c,59),%i),$gettok(%qbynick,%c,59)) == $false) {
                  IF ($1 isvo $comchan($gettok(%qbynick,%c,59),%i)) { IF ($cps.rvi($comchan($gettok(%qbynick,%c,59),%i),KICKVOS) != ON) { return } }
                  IF ($1 isop $comchan($gettok(%qbynick,%c,59),%i)) { IF ($cps.rvi($comchan($gettok(%qbynick,%c,59),%i),KICKOPS) != ON) { return } }
                  set %_cpsextra $gettok(%_flood,2,32) queries in $replace($duration($gettok(%_flood,3,32)),0,1)
                  set %kicktype [Auto]
                  kickc $comchan($gettok(%qbynick,%c,59),%i) $gettok(%qbynick,%c,59) Don't Flood Me In Private
                }
              }
              IF ($cps.rvi(DEFAULT,PPS6C) == KICKBAN) {
                IF ($isprot($comchan($gettok(%qbynick,%c,59),%i),$gettok(%qbynick,%c,59)) == $false) {
                  IF ($gettok(%qbynick,%c,59) isvo $comchan($gettok(%qbynick,%c,59),%i)) { IF ($cps.rvi($comchan($gettok(%qbynick,%c,59),%i),KICKVOS) != ON) { return } }
                  IF ($gettok(%qbynick,%c,59) isop $comchan($gettok(%qbynick,%c,59),%i)) { IF ($cps.rvi($comchan($gettok(%qbynick,%c,59),%i),KICKOPS) != ON) { return } }
                  set %_cpsextra $gettok(%_flood,2,32) queries in $replace($duration($gettok(%_flood,3,32)),0,1)
                  set %kicktype [Auto]
                  ban -u120 $comchan($gettok(%qbynick,%c,59),%i) $1 2
                  kickc $comchan($gettok(%qbynick,%c,59),%i) $gettok(%qbynick,%c,59) Don't Flood Me In Private
                }
              }
            }
            dec %i 1
          }
        }
        dec %c 1
      }
    }
  }
}

; Event for on join notice spam checker. It needs %ojnote.$chan to be on
ON *:SIGNAL:JOIN.NOTICE:{
  IF ($iservice($1) == $true) { return }
  IF ($1 != $me) {
    var %a = $comchan($1,0)
    while (%a) {
      IF (($istok(%controlchan,$comchan($1,%a),44) == $true) && (%ojnote. [ $+ [ $comchan($1,%a) ] ] == $comchan($1,%a)) && ($me isop $comchan($1,%a)) && ($cps.rval($comchan($1,%a),N6,2) == 1)) {
        set %_cpsextra Notice received within 10secs of join.
        thrash $comchan($1,%a) $1 ojnote
      }
      dec %a 1
    }
  }
}

; Event for on join msg spam checker. It needs %ojmsg.$chan to be on
ON *:SIGNAL:JOIN.QUERY:{
  IF ($iservice($1) == $true) { return }
  IF ($owner($1) == $true) { return }
  IF ($1 != $me) {
    var %b9 = $comchan($1,0)
    var %b8 = 0
    while (%b8 < %b9) {
      inc %b8 1
      IF ((%ojmsg. [ $+ [ $comchan($1,%b8) ] ] == $comchan($1,%b8)) && ($me isop $comchan($1,%b8)) && ($istok(%controlchan,$comchan($1,%b8),44) == $true) && ($cps.rval($comchan($1,%b8),n6,3) == 1)) {
        set %_cpsextra Private Message received within 10secs of join.
        thrash $comchan($1,%b8) $1 ojmsg
      }
    }
  }
}

; Event for on join CTCP spam checker. It needs %ojCTCP.$chan to be on
ON *:SIGNAL:JOIN.CTCP:{
  IF ($iservice($1) == $true) { return }
  IF ($1 != $me) {
    var %b9 = $comchan($1,0)
    var %b8 = 0
    while (%b8 < %b9) {
      inc %b8 1
      IF ((%ojCTCP. [ $+ [ $comchan($1,%b8) ] ] == $comchan($1,%b8)) && ($me isop $comchan($1,%b8)) && ($istok(%controlchan,$comchan($1,%b8),44) == $true) && ($cps.rval($comchan($1,%b8),n6,1) == 1)) {
        set %_cpsextra CTCP received within 10secs of join.
        thrash $comchan($1,%b8) $1 ojCTCP
      }
    }
  }
}

; Channel CTCP flood checker
ON *:SIGNAL:CHANNEL.CTCP:{
  IF (($istok(%controlchan,$1,44) == $true) && ($cps.rval($1,N7,1) == 1)) {
    var %_flood = $dll($airc, Flood, $+(chCTCPf, $chr(44), $+($1,cps)) 1 $cps.rvi($1,CTCPF) $cps.rvi($1,CTCPF.TIME))
    IF (+Flood* iswm %_flood) {
      set %_cpsextra $gettok(%_flood,2,32) CTCPS in $duration($gettok(%_flood,3,32))
      thrash $1 $2 CTCPf
    }
  }
}

; Bad channel kicker
ON *:SIGNAL:BAD.CHANNEL:{
  unset %_bchd
  var %_chans = %chan. [ $+ [ $2 ] ] 
  var %bchan = $cps.rvi(%_chans,CHANNEL) 
  var %bc1 = $numtok($cps.rvi(%_chans,CHANNEL),59)
  while (%bc1 > 0) {
    IF (($+(*,$gettok($cps.rvi(%_chans,CHANNEL),%bc1,59),*) iswm $strip($3-)) || ($gettok($cps.rvi(%_chans,CHANNEL),%bc1,59) isin $strip($3-))) { set %_bchd +OK $gettok($cps.rvi(%_chans,CHANNEL),%bc1,59) }
    dec %bc1 1
  }
  IF (+OK* iswm %_bchd) {
    echo $color(info2) $_place $_time $_time 4(CPS) Bad Channel-Check: $2 is in $gettok(%_bchd,2,32) 
    IF (($me isop %_chans) && ($istok(%controlchan,%_chans,44) == $true) && ($cps.rval(%_chans,n4,4) == 1)) {
      .notice $2 $2 Don't be in those channels of bad nature, it is against our channels rules, and will attract perverted minds that will sour this channel out. 
      set %_cpsextra BadChannel Detected.
      thrash %_chans $2 channel
    }
  }
  unset %chan. [ $+ [ $2 ] ]
  unset %_bchd
}

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

; Input event to detect if you typed /[w|whois|whowas|who]
; It enables whois display for 10 seconds
;ON *:INPUT:*: { 
;  if ((/whois * iswm $1-) || (/who * iswm $1-) || (/w * iswm $1-) || (/whowas * iswm $1-) || (//whois * iswm $1-) || (//who * iswm $1-) || (//w * iswm $1-) || (//whowas * iswm $1-)) {
;    whoon
;    .timerMYWHOIS 1 10 whooff
;  }
;}
alias whois { set %cwhois [ $+ [ $1 ] ] $1 | !whois $1- }
alias who { set %cwhois [ $+ [ $1 ] ] $1 | !who $1- }
alias w { set %cwhois [ $+ [ $1 ] ] $1 | !whois $1- }
alias whowas { set %cwhois [ $+ [ $1 ] ] $1 | !whowas $1- }

alias cwhois {
  ;echo 11 -st $1-
  ;whois
  if ($1 == 311) { linesep | echo $color(whois) -st Info:7 $2 $+  $+($3,@,$4) $5- }
  if ($1 == 615) { echo $color(whois) -st Modes: $3- }
  if ($1 == 616) { echo $color(whois) -st Real Host: $5- }
  if ($1 == 319) { echo $color(whois) -st Channels: $3- }
  if ($1 == 312) { echo $color(whois) -st Using Server: $3- }
  if ($1 == 307) { echo $color(whois) -st Identified Nick: Yes }
  if ($1 == 301) { echo $color(whois) -st Is away with message: $3- }
  if ($1 == 317) { echo $color(whois) -st Idle time: $duration($3) }
  if ($1 == 317) { echo $color(whois) -st Signed on time: $asctime($4) }
  if ($1 == 318) { echo $color(whois) -st End of /whois | unset %cwhois [ $+ [ $2 ] ] }
  ;who
  if ($1 == 352) { linesep | echo $color(whois) -st Who Info:7 $6 $+  $+($3,@,$4) $9- }
  if ($1 == 315) { echo $color(whois) -st End of /who |  unset %cwhois [ $+ [ $2 ] ] }
  ;whowas
  if ($1 == 314) { linesep | echo $color(whois) -st Info:7 $2 $+  $+($3,@,$4) $5- }
  if ($1 == 406) { linesep | echo $color(whois) -st Info:7 $2 $+  $3- }
  if ($1 == 369) { echo $color(whois) -st End of /whowas |  unset %cwhois [ $+ [ $2 ] ] }


}

#CPSGROUP4 on

; Event for Shift + F9 kicks
; Since signal event of quits doesn't support getting nicks address these can't be fully merged in signal events.
ON @*:QUIT:{
  ;excess flood quit
  IF ($nick != $me) {
    IF ((FLOOD isin $strip($1-)) || (*FL??D* iswm $strip($1-))) {
      var %x = $comchan($nick,0)
      var %i = 0
      while (%i < %x) {
        inc %i 1 
        IF (($cps.rval($comchan($nick,%i),N7,4) == 1) && ($istok(%controlchan,$comchan($nick,%i),44))) {
          var %btypey = $left($cps.rvi($comchan($nick,%i),$+(EXCESS,.KTYPE)),1)
          var %addy = $address($nick,%btypey)
          banned $comchan($nick,%i) $nick excess %addy
        }
      }
    }
    ; Spam quit ban
    IF ($chr(35) isin $strip($1-)) {
      var %xo = $comchan($nick,0)
      var %io = 0
      while (%io <= %xo) {
        inc %io 1
        IF (($cps.rval($comchan($nick,%io),N7,5) == 1) && ($istok(%controlchan,$comchan($nick,%io),44) == $true)) {
          var %' = $left($cps.rvi($comchan($nick,%io),$+(SQUIT,.KTYPE)),1)
          var %add = $address($nick,%')
          banned $comchan($nick,%io) $nick squit %add
        }
      }
    }
    ; Kilne quit ban
    IF ((KILLED isin $strip($1-)) || (KLINE isin $strip($1-))) {
      var %xso = $comchan($nick,0)
      var %iso = 0
      while (%iso < %xso) {
        inc %iso 1
        IF (($cps.rval($comchan($nick,%iso),N7,2) == 1) && ($istok(%controlchan,$comchan($nick,%iso),44))) {
          var %btypek = $left($cps.rvi($comchan($nick,%iso),$+(KLINE,.KTYPE)),1)
          var %addk = $address($nick,%btypek)
          banned $comchan($nick,%iso) $nick kline %addk
        }
      }
    }
  }
}
#CPSGROUP4 end
; Event to clear variables of a nick after a kick
ON *:KICK:#:{ 
  IF (($nick == $me) && ($knick != $me)) { 
    unset %rl. [ $+ [ $address($knick,2) ] ] $+ *
    unset %rl. [ $+ [ $address($knick,3) ] ] $+ * 
    unset %fl $+ *
    unset %nf. [ $+ [ $remove($address($2,2),$chr(42)) ] ]
    IF ($nick == %loggednick) { unset %loggednick }
  }
}

; Switching timers off and clearing vars
ON *:DISCONNECT:{
  .timerLIMIT* OFF
  .timerIDLE* OFF
  unset %dcc.*
  unset %rl.*
  unset %rl.* 
  unset %fl*
  unset %nf.*
  unset %loggednick
  IF ($cid == %cpscid) {
    sb_close
    unset %cpscid
  }
}

; Hot link event to make the word double-click a hot link
ON ^*:HOTLINK:*DOUBLE-CLICK*:*:{ 
  IF (*possible rule breakage* iswm $strip($hotline)) { return }
}

; Ban detector is on by default
; Removed the alien ban thingy now it only echoes if someone matches the ban mask.
#bandet on
ON *:BAN:#:{
  unset %banned.nicks 
  var %bant = $ialchan($banmask,$chan,0)
  while (%bant > 0) {
    set %banned.nicks $addtok(%banned.nicks,$ialchan($banmask,$chan,%bant).nick,44)
    dec %bant 1
  }
  IF (%banned.nicks != $null) { echo $color(info2) $_place $_time *** 4(CPS) $nick banned %banned.nicks in ( $+ $chan $+ )! }
}
#bandet end

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