# ChanProt v1.0 - Lamego
# This small tcl script to gives tour BOT extra protection when registered in ChanServ with level 5 at least
# This is a great security improvement against TakeOvers
# You simply need to load the script in your eggdrop configuration file
# To protect a user when being deoped or kicked from a channel you just have to set a his flag +P
# a good idea is to protect the bot itself like this: .chattr bot_nick +P
# 
#
# Note: This script had just been tested on (PTNET) the PorTuguese Network, but it will work on any server
# usign ChanServ operator with the same sintaxe
#
# I have a few more .tcl that I will release soon
# If you want to contact me for some epxplation about the script or just to change some ideias
# look fo me on irc server irc.rccn.net:6667, channel #Lamego, nick Lamego
# or email me to joaoluis.pinto@barco until 15/Jan/99 or to joao_pinto@hotmail.com if later
#
# I would like to give credits also to Expresso's Eggdrop site, because it was my lauching pad on eggdrop tcl scripting
putlog "ChanProt.tcl - Lamego 1998" 
set tclver "1.1"
bind mode - * prot:deop 
bind kick - * prot:kick

proc prot:deop {nick uhost handle channel mchange theone} {
 global botnick
  if {[string tolower $nick] == "chanserv"} { return 0 }
  if {$nick == $theone || [matchattr $handle b] } { return 0 }
  set mode [lindex $mchange 0]
  if {[matchattr $handle m] && [string tolower $theone] != [string tolower $botnick] } { return 0 } 
  set mode [lindex $mchange 0]
  if {$mode != "-o" || ![matchattr [nick2hand $theone $channel] P] } { return 0}
  putlog "in deop protect"
  pushmode $channel +o $theone
  pushmode $channel -o $nick
  putserv "PRIVMSG ChanServ :DEOP $channel $nick"
  putserv "NOTICE $nick :Never DEOP a protected OPerator"
  putlog "## Activated deop protection, $nick trying to deop $theone"
  return 0
}
proc prot:kick {nick uhost handle channel theone arg} {
  global botnick
  if {$nick == $theone || [matchattr $handle b]} { return 0 }
  if {[matchattr $handle m] && [string tolower $theone] != [string tolower $botnick] } { return 0 } 
  if {![matchattr [nick2hand $theone $channel] P] } { return 0 }
  if {[matchattr handle o]} { return 0 }
  pushmode $channel -o $nick
  putlog "on kick protect"
  putserv "PRIVMSG ChanServ :DEOP $channel $nick"
  chattr [nick2hand $nick $channel] +d
  putserv "NOTICE $nick :Never kick a protected OPerator"   
  putlog "## Activated kick protection, $nick kicked $theone"
  return 0
}
