# ====================================================================
# xtreme_prot.tcl for xtreme bot crew
# Purpose: general channel management (anti DCC sends, trout slaps, kickban on excess flood quit msgs,
# CAPS kick, bad nick/ident kick, bot resynch, and channel autovoice) and chanserv auto-op on op-critical
# channels. Combined with netbots.tcl v4.09 by slennox, i made few changes and add some features
# borrowed from other scripts. Please edit the variables carefully before use. (those with set commands)
# Written by nukie (30 July 2001) updated 30 Dec 2003
# ====================================================================

# Settings & Configurations:

# Set your logo here, it will appear when the bot notice you, or when it makes msgs/notices/kicks or scripts loading.
set utladellg "\[4x]:"
set utlawylg "\[4x]:"
set pdcclg "\[4x]:"
set pctcpreplg "\[4x]:"

# Set xtreme_prot.tcl version
set x-prot_ver "v1.3"

# Set this to 1 to load script, and 0 to unload it
set allunban 1
set bawayloaded 1
set dccprotloaded 1
set verprotloaded 1

# Autovoice, voices everyone in a channel when they join
# What channels should this work on? note, "" is for all channels
# note: will not voice users with b (bot) flag
#set avchan "#HaLL #kontemplasi #nukie" (moved to config file)

# Anti Trout Slap 
# what kick method do you want to use in response to trout slaps?
# 0 = kick people who slaps the bot with a trout.
# 1 = kick people who slaps anyone including the bot with a trout.
# 2 = kickban people who slaps the bot with a trout.
# 3 = kickban people who slaps anyone including the bot with a trout.
set troutkickmethod 0
# what kick/kickban reason do you want the bot to use?
set troutkickreason "\[4x]: don't slap people, it's rude!"
# how long do you want bans to last (in minutes) because of trout slapping?
set troutbantime 3

# Anti DCC send viruses
set ext_files {
  ".exe"
  ".vbs"
  ".bat"
  ".com"
  ".shs"
  ".mrc"
  ".ini"
  ".dll"
  ".htm"
}
set hostallowdcc {
  "@dal.net"
  "@DALnet"
  
}
set dcc_bantime 15
set dcc_ignoretime 5
set dcc_vnotice 1
set dcc_kmsgs {
  "you are unintentionally sending out unwanted files! get rid of it! try: http://www.nohack.net for more info"
}
set dcc_imsgs {
  "you are unintentionally sending out unwanted files! get rid of it! try: http://www.nohack.net for more info"
}

# QuitBan
# This bans people who quit with a specified quit message (except +f and +o users) 
# Specify the list of quit messages to ban on. Use lower case characters only. You can use standard wildcards 
# (? and *) in the list. 
set qb_quitmsgs {
  "excess flood"
}
# Channels in which to enable the script.
#set qb_chans "#Bandung" (moved to config file)
# Length of time to ban for (in minutes).
set qb_bantime 30
# Ban reason.
set qb_reason "\[4x]: excess flood on quit message, suspected inviter"

# Chanserv Auto-Op
# Which channels are op-critical? (change this)
#set crits "#tpi" (moved to config file)
set servtype 4
set nserv "NickServ"
set cserv "ChanServ"
set servser "1"
set servserv "services.dal.net"
# report to this channel
set homechan "#dago25"
set chanwarn "1"
# don't selfop if not op on these channels (moved to config file)
#set lurks "#HaLL #kontemplasi"
# don't selfop on these channels
set snoop ""

# Bot Resync (mode #channelname -o+o $botnick)
# Time interval at which the bot should resync itself (in minutes).
set br_time 30
# Channels the bot should resync itself on. This can be one channel like 
# "#red", a list of channels like "#red #green #blue", or "" for all channels.
set br_chans "#dago25"

# Bot Auto-away System
# Set this to "1" if you like to bot automatically set AWAY when start or when you do .rehash.
# Leave this to "0" if you like to wait for the next frequent of AWAY trigger.
set botisaway 0
# Set this as frequent time of your bot Auto Away trigger. Set this in Minute(s) format.
set awaymin 15
# Set this as your bot Auto-Away message target (to whom the bot will tell).
# If it's a channel set to "#channelname" , and set to "bot" if you'd like the bot to msg itself ;)
set awayonoffchan {
  "#dago25"
}
# Set these as your bot Away message. The bot will get random message from this list.
# Set this one as many as you'd like.
set awaym {
  "Powered By Lemontreenet.net"
  "krrr... krrr... krrr..."
  "Dago25 CrEw.."
  "MiMpI BaSaH!"
  "bbl! sex time!"
  "what happen?"
  "autoaway"
  "autodead"
  "drawing a FreeBSD daemon logo"
  "uhmm... uhmm..."
  "installing a new server"
  "studying"
  "and stuff"
  "sleep"
  "collie"
  "home work sucks..."
  "LEAVE ME ALONE!!!#@"
  "I'm tired, aight!!!#@"
  "fixing my tcl script"
  "dinner"
  "f00d is essential"
  "the essence of pi"
  "the transcendence of e"
  "x 1/y"
  "yet i have no life"
  "eating"
  "phone"
  "brb, bathroom"
  "ahh, much better"
  "scanning port"
  "hacking rewt"
  "E = MC˛"
  "BeNgOnG"
  "HuNtInG LaMeRs"
}


######### Please do not edit anything below unless you really know what you are doing #########

# SOF - script start

if {$numversion < 1030700} {
  putlog "\[4x]: can't load 4xtreme_prot.tcl -- At least Eggdrop v1.3.7 required"
  return 0
}

# Auto Voice Utility

bind join - * avjoin

proc avjoin {nick uhost hand chan} {
 global avchan botnick
 if {$nick == $botnick} {return 0}
 if [isop $nick $chan] {return 0}
 if [ishalfop $nick $chan] {return 0}
 if {$avchan == "" && ![matchattr $hand b] &&  [botisop $chan]} {
  pushmode $chan +v $nick
  return 0
 }
 set chan [string tolower $chan]
 foreach i [string tolower $avchan] {
  if {$i == $chan && ![matchattr $hand b] && [botisop $chan]} {
   pushmode $chan +v $nick
   return 0
  }
 }
}

# Auto Delete Bans

bind mode - * autodelban

proc autodelban {nick uhost hand chan modes victim} {
	global botnick allunban unbanchan
	if {[isbotnick $nick]} {return 0}
	if {[string match *-b* $modes]} {
		if {!$allunban} {foreach btestchan [string tolower $unbanchan] {if {$btestchan == [string tolower $chan]} {autoremban $nick $uhost $chan $victim}}
		} else {autoremban $nick $uhost $chan $victim}
	}
}
proc autoremban {nick uhost unbanchan utesthost} {
	global botnick utladellg
	foreach banhosts [banlist $unbanchan] {
		set currbanhost [lindex $banhosts 0]
		if {[string match [string tolower *$currbanhost*] [string tolower $utesthost]]} {
			if {[ischanban $currbanhost $unbanchan]} {
				killchanban $unbanchan $currbanhost
				putlog "$utladellg $currbanhost is in my Local banlist for $unbanchan. Deleting now..." ; return 0
			}
		}
	}
	foreach gbanhosts [banlist] {
		set gcurrbanhost [lindex $gbanhosts 0]
		if {[string match [string tolower *$gcurrbanhost*] [string tolower $utesthost]]} {
			if {[isban $gcurrbanhost]} {
				killban $gcurrbanhost
				putlog "$utladellg $gcurrbanhost is in my Global banlist. Deleting now..." ; return 0
			}
		}
	}
}


# Anti DCC send viruses

proc chk_dccvirus {nick uhost hand dest key arg} {
	global botnick ext_files hostallowdcc dcc_bantime dcc_ignoretime dcc_vnotice dcc_imsgs dcc_kmsgs pdcclg
	if {[isbotnick $nick] || [matchattr $hand o]} {return 0}
	foreach allowhost [string tolower $hostallowdcc] {if {[string match *$allowhost* [string tolower $uhost]]} {return 0}}
	set filename [string tolower [lindex $arg 1]]
	foreach extfile [string tolower $ext_files] {
		set extfile [string tolower [string trim $extfile "\*"]]
		if {[string match *$extfile* $filename]} {
			set banhost *!*@[lindex [split $uhost @] 1]
			set dcc_reason "$pdcclg DCC Virus to $botnick from: $nick."
			newignore $banhost $botnick $dcc_reason $dcc_ignoretime
			foreach x [channels] {
				set chan $x
				if {[botisop $chan]} {
					newchanban $chan $banhost $botnick $dcc_reason $dcc_bantime
					set members [chanlist $chan]
					foreach dccmember $members {
						set selectedhost [getchanhost $dccmember $chan]
						set dccbanhost *!*@[lindex [split $selectedhost @] 1]
						if {$banhost == $dccbanhost} {
							if {[isop $dccmember $chan]} {putquick "MODE $chan -o+b $dccmember $dccmember!*@*"
							} else {if {[isvoice $dccmember $chan]} {putquick "MODE $chan -v+b $dccmember $dccmember!*@*"} else {putquick "MODE $chan +b $dccmember!*@*"}
							} ; newchanban $dccmember!*@* $botnick $dcc_reason $dcc_bantime ; putkick $chan $dccmember "4$pdcclg $nick: [lindex $dcc_kmsgs [rand [llength $dcc_kmsgs]]]"
						}
					}
				}
			}
			if {$dcc_vnotice} {putquick "NOTICE $nick :$pdcclg DCC send: ($filename): [lindex $dcc_imsgs [rand [llength $dcc_imsgs]]]"}
			putlog "$pdcclg DCC Virus to $botnick from: $nick!$uhost. Filename: ($filename)." ; return 0
		}
	} ; return 0
}

if {[info exist dccprotloaded]} {
	if {${dccprotloaded}} {bind ctcp - DCC chk_dccvirus} else {unbind ctcp - DCC chk_dccvirus}
}

# Anti Trout Slap 

bind ctcp - ACTION antitrout:ctcp:action

proc antitrout:ctcp:action {nick uhost hand dest keyword arg} {
 global botnick troutkickmethod troutkickreason troutbantime
 if { [validchan $dest] == 1 && ([string tolower [lindex $arg 0]] == "slaps" || [string tolower [lindex $arg 0]] == "slap") && [lsearch [string tolower $arg] trout] >= 2 && [string tolower $nick] != [string tolower $botnick] && [botisop $dest] == 1 } {
  if { $troutkickmethod == 0 && [string tolower [lindex $arg 1]] == [string tolower $botnick] } {
   putserv "kick $dest $nick :$troutkickreason"
  }
  if { $troutkickmethod == 1 } {
   putserv "kick $dest $nick :$troutkickreason"
  }
  if { $troutkickmethod == 2 && [string tolower [lindex $arg 1]] == [string tolower $botnick] } {
   scan [string tolower [getchanhost $nick $dest]] "%\[^@]@%s" host host
   newchanban $dest *!*@$host $botnick "$troutkickreason" $troutbantime
  }
  if { $troutkickmethod == 3 } {
   scan [string tolower [getchanhost $nick $dest]] "%\[^@]@%s" host host
   newchanban $dest *!*@$host $botnick "$troutkickreason" $troutbantime
  }
 }
 return 0
}

# Ban on specified quit messages


bind sign - * qb_quit

proc qb_quit {nick uhost hand chan reason} {
  global qb_bantime qb_chans qb_quitmsgs qb_reason
  if {(($qb_chans != "") && ([lsearch -exact $qb_chans [string tolower $chan]] == -1))} {return 0}
  if {[matchattr $hand fo|fo $chan]} {return 0}
  set reason [string tolower $reason]
  foreach quitmsg $qb_quitmsgs {
    if {[string match $quitmsg $reason]} {
      newchanban $chan *!*[string tolower [string range $uhost [string first @ $uhost] end]] quitban $qb_reason $qb_bantime
      return 0
    }
  }
  return 0
}
set qb_chans [split [string tolower $qb_chans]]


# CAPS Kick (kick people who use 100% caps lock)
# but will not kick +f users, ops, halfops or voices

bind pubm - * caps_pubm
proc caps_pubm {nick uhost hand chan text} {
  if [matchattr $hand f] {return 0}
  if [isop $nick $chan] {return 0}
  if [ishalfop $nick $chan] {return 0}
  if [isvoice $nick $chan] {return 0}
  set upper 0
  foreach i [split $text {}] {
    if [string match \[A-Z\] $i] {
      incr upper
    }
}
  if {$upper == 0} {
  return 0
}
  if {[string length $text] < 3} {return 0}
  set capchar [string length $text]
  set number $upper/$capchar
  if {[expr 100 * $upper / $capchar] > 99} {
  putserv "KICK $chan $nick :\[4x]: turn off your CAPS lock!"
  }
}


# Bot Resync (mode #channelname -o+o $botnick)

proc br_resync {} {
  global botnick br_chans br_time
  foreach chan [channels] {
    if {(($br_chans != "") && ([lsearch -exact [split [string tolower $br_chans]] [string tolower $chan]] == -1))} {continue}
    if {[onchan $botnick $chan]} {
      putserv "MODE $chan -o+o $botnick $botnick"
    }
  }
  if {![string match *br_resync* [timers]]} {
    timer $br_time br_resync
  }
  return
}

if {![string match *br_resync* [timers]]} {
  timer $br_time br_resync
}


# CTCP Protection and Version Reply simulator
set bmaxctcp 4:10
set verignore 1
set veringmsg {
  "don't CTCP flood me!"
  "too much CTCP from you!"
}
set ircNreplies {
  "just a touch, is not enough"
  "is it bright where you are?"
  "disconnected by your smile"
  "the last song"
  "disarm you with a smile"
  "i dont need your love to disconnect"
  "disarm you with a smile"
  "i wish i was blank"
  "you're an empty promise"
  "life's a bummer, when your a hummer"
  "bury your hands in the sand"
  "jennifer ever"
  "scarecrows and disease haunt us all"
  "are we being punished for fate"
  "the guns of love disastrous"
  "nothing here ever lasts"
  "god is empty just like me"
  "and all along, i knew i was wrong"
  "lost my innocence to a no good girl"
  "the devil may do as the devil may care"
  "i wont deny the pain"
  "time heals but i'm forever broken"
  "can a taste of love be so wrong"
  "the realm of soft delusions"
  "in my mind i am everyone of you"
  "king of horseflies, prince of death"
  "a veiled promise to never die"
  "get back where you belong"
  "come into my life forever"
  "love is suicide"
  "no bodies felt like you"
  "the lonely nights divide you in two"
  "the bitch is back"
  "save me from myself"
  "let me die inside"
  "the night has come to hold us young"
  "i hurt where i cant feel"
  "i feel where i cant hurt"
  "i bleed for me and mine"
  "i am made of shamrocks"
  "i am the forgotten child"
  "we only come out at night"
  "i watch her shadow move"
  "dead eyes, are you just like me?"
  "my life has been empty"
  "my life has been untrue"
  "the sun shines but i dont"
  "cool kids never have the time"
}
set BitchXreplies {
  "a modern client for a old world"
  "a new fragrance for men, by Calvin Klein"
  "all the things phone and hop won't include"
  "anything else would be uncivilized"
  "better than a penis enlargement!"
  "born to raise hell"
  "causing all sorts of havok!"
  "cleaner, drier, protects even better"
  "coming soon to a theatre near you!"
  "don't leave home without it!"
  "double your pleasure, double your fun!"
  "EPIC on steroids."
  "faster than a speeding bullet, more powerful than a locomotive"
  "for distribution only with a new PC"
  "good to the last drop!"
  "it adds that extra uNF to your sex life!"
  "it does a body good"
  "it isn't only my script, its also my client"
  "it keeps going and going and going and going and..."
  "it makes bathtime lots of fun!"
  "it tastes like poo"
  "it won't get you laid"
  "its all day strong, all day long"
  "its everywhere you want to be"
  "its how steak is done"
  "its magically delicious!"
  "its not for the tabkey impaired!"
  "its not your ordinary stick of gum"
  "its shagadellic, baby!"
  "its wax ecstatic"
  "its what's for lunch"
  "Little. Yellow. Better."
  "made with real honey."
  "melts in your mouth, not in your hands"
  "more nutritious than a six-pack."
  "need we say more?"
  "nine out of ten doctors recommend it"
  "nine out of ten gynecologists recommend it"
  "no additives or preservatives"
  "no this is NOT a cybersex client"
  "not from concentrate"
  "now in non-drowsy formula too!"
  "now with 38 percent fewer calories!"
  "now with 42 percent more random quit messages!"
  "now with flavor crystals!"
  "now with Olestra!"
  "now Y2K compatible!"
  "often imitated, never duplicated!"
  "reserve your copy today!"
  "ribbed for her pleasure!"
  "roqz yer nutz!"
  "sanitized for your protection"
  "shaken, not stirred"
  "so real, you'll wet yourself!"
  "stays crunchy in milk!"
  "strong enough for a man, pH-balanced for a woman"
  "TASTES GREAT! LESS FILLING! TASTES GREAT! LESS FILLING!"
  "the Cadillac of all clients"
  "the choice of a GNU generation"
  "the cootiless client"
  "the cure for the common client"
  "the fizzle goes straight to your brain!"
  "the fresh-maker!"
  "the headache medicine"
  "the IRC client with hair on its balls"
  "the NEW form of birth control!"
  "the new hardcore, psycho, nitro client -- in a can"
  "the official sponsor of the 2002 Olympic Winter Games"
  "the ONLY bug-free client"
  "the ONLY IRC client on Viagra!"
  "the ONLY three day cure!"
  "the original point-and-click interface."
  "the OTHER white meat"
  "the quilted quicker picker upper"
  "the right choice for a healthy pet"
  "the un-Cola"
  "to the rescue!"
  "treats external genital warts!"
  "try our lowfat flavor too!"
  "try our Windows 95/98 and Windows NT 4 flavors too!"
  "use it, it makes hair grow in funny places!"
  "use it, it makes you bulletproof"
  "now with wings"
  "your way, right away"
  "by panasync"
  "1996-98 Colten Edwards"
  "just when you thought it couldn't get any better"
}
set mIRCversions {
  "5.9"
  "5.91"
  "6.0"
  "6.1"
  "6.11"
  "6.12"
}
set verreply {
  "ircN 6.04pl.2 + 6.0 for mIRC - %ircNreply -"
  "BitchX-1.0c17+: %BitchXreply"
  "mIRC® %mIRCversion + -xtreme- v1.3"
}
set clnreply {
  "i'm on %shell system"
}

# Don't edit anything below unless you know what you're doing

proc ver_reply {nick uhost hand dest key arg} {
	global botnick verprotloaded bmaxctcp verignore veringmsg ircNreplies BitchXreplies mIRCversions verreply clnreply vercount botname server uptime server-online pctcpreplg
	switch $key {
		VERSION {
			set verrep [lindex $verreply [rand [llength $verreply]]]
			set ircNreply [lindex $ircNreplies [rand [llength $ircNreplies]]]
			regsub -all "%ircNreply" $verrep "$ircNreply" verrep
			set BitchXreply [lindex $BitchXreplies [rand [llength $BitchXreplies]]]
			regsub -all "%BitchXreply" $verrep "$BitchXreply" verrep
			set mIRCversion [lindex $mIRCversions [rand [llength $mIRCversions]]]
			regsub -all "%mIRCversion" $verrep "$mIRCversion" verrep }
		CLIENTINFO {
			set verrep "[lindex $clnreply [rand [llength $clnreply]]] - commands are: VERSION FINGER USERINFO TIME ERRMSG"
			regsub -all "%shell" $verrep "[exec uname -r -s]" verrep }
		FINGER {
			set verrep "$pctcpreplg nickname: ${botnick}, hostname: [lindex [split [lindex [split ${botname} !] 1] @] 1], on: [lindex [split ${server} :] 0], port: [lindex [split ${server} :] 1] for: [expr [unixtime] - ${server-online}] sec(s)." }
		USERINFO {
			set verrep "$pctcpreplg username: [lindex [split [lindex [split ${botname} !] 1] @] 0], shell hostname: [exec hostname], uptime: [expr [unixtime] - ${uptime}] sec(s)." }
		TIME {
			set verrep "current date: [lrange [exec date] 1 2], [lindex [exec date] 5], time: [lrange [exec date] 3 4]" }
		ERRMSG {
			set verrep [lindex [rand [llength "0 59"]] 0] }
	}
	putquick "NOTICE $nick :\001$key $verrep"
	if {!$verprotloaded} {return 1}
	set n [string tolower *!*@[lindex [split $uhost @] 1]]
	if {[info exists vercount($n)]} {
		set vercount{$n} [incr vercount($n)] ; set currvercount $vercount($n) ; set bmaxctcprecv [lindex [split $bmaxctcp :] 0]
		if {$currvercount >= $bmaxctcprecv} {
			set vingrep [lindex $veringmsg [rand [llength $veringmsg]]]
			foreach vertimer [utimers] {if {[string match "unset vercount($n)" [lindex $vertimer 1]]} {killutimer [lindex $vertimer 2]}}
			putquick "NOTICE $nick :$pctcpreplg $vingrep. ($key) Ignored for: $verignore min(s)."
			newignore *!*@[lindex [split $uhost @] 1] $botnick "CTCP $key flood" $verignore
			putlog "$pctcpreplg CTCP $key flood ($vercount($n)), received from $nick. Ignoring for $verignore min(s)." ; unset vercount($n) ; return 1
		} else {
			foreach vertimer [utimers] {if {[string match "unset vercount($n)" [lindex $vertimer 1]]} {return 1}}
			utimer [lindex [split $bmaxctcp :] 1] "unset vercount($n)"
		}
	} else {set vercount($n) 1}
	if {[matchattr $hand m] || [isbotnick $nick]} {unset vercount($n)} ; return 1
}

### below is a modification made by nukie to make the script
### compatible with windrops (tested on v1.6.13/1.6.15)
# script start
if {"[string tolower [lindex [split [lindex [split [info nameofexecutable] /] end] .] end]]" != "exe"} {bind ctcp - USERINFO ver_reply
   } else {set ctcp-userinfo "xchat 2.0.5b linux 2.2.14-5.0 \[i686/2500MHz\]"}
#bind ctcp - USERINFO ver_reply
#script end

bind ctcp - VERSION ver_reply
bind ctcp - CLIENTINFO ver_reply
bind ctcp - VERSION ver_reply
bind ctcp - FINGER ver_reply
bind ctcp - ERRMSG ver_reply
bind ctcp - TIME ver_reply


# BitchX Auto-away Simulation
# Don't edit anything below unless you know what you're doing

proc botsetaway {} {
	global botnick botisaway awaymin awaym awayonoffchan utlawylg
	if {$awaymin < 15} {
		putlog "$utlawylg Auto-away timer sets too low, increasing to minimal setting..."
		set awaymin 15 ; timer [expr [rand $awaymin] + 1] botsetaway ; return 0
	}
	foreach awaytimer [timers] {if {[string match "botsetaway" [lindex $awaytimer 1]]} {killtimer [lindex $awaytimer 2]}}
	if {!$botisaway} {
		set away_msg [lindex $awaym [rand [llength $awaym]]]
		putquick "AWAY :($away_msg) \[4x-msglog [lindex {on off} [rand 2]]\]" ; set botisaway 1
		foreach awchan $awayonoffchan {
			if {[string toupper $awchan] == "BOT"} {putquick "PRIVMSG $botnick :$utlawylg switching BX simulation to on."
			} else {if {[validchan $awchan]} {putquick "PRIVMSG $awchan :$utlawylg switching BX simulation to on."}}
		}
	} else {
		putquick "AWAY" ; set botisaway 0
		foreach awchan $awayonoffchan {
			if {[string toupper $awchan] == "BOT"} {putquick "PRIVMSG $botnick :$utlawylg switching BX simulation to off."
			} else {if {[validchan $awchan]} {putquick "PRIVMSG $awchan :$utlawylg switching BX simulation to off."}}
		}
	} ; timer $awaymin botsetaway ; return 0
}

if {[info exist bawayloaded]} {
	if {${bawayloaded}} {if {${botisaway}} {botsetaway} else {timer ${awaymin} botsetaway}
	} else {foreach awaytimer [timers] {if {[string match "botsetaway" [lindex $awaytimer 1]]} {killtimer [lindex $awaytimer 2]}}}
}

# Refresh Bot Bans
# Checks the bot's banlist when the bot get ops and ensures that matching users are kicked
# also removes any on-channel bans matching protected users
# Don't edit anything below unless you know what you're doing

set pflag "P"

bind mode - *+o* refresh_bot_bans

proc refresh_bot_bans {opingnick uhost hand chan mdechg opednick} {
   global botnick pflag enable_xw_unban logchan_xw
   set chan [string tolower $chan]
   if {[string tolower $opednick] == [string tolower $botnick]} {
      foreach nick [chanlist $chan] {
         if {[matchban $nick![getchanhost $nick $chan] $chan]} {
            foreach banentry [banlist $chan] {
               if {[string match [lindex $banentry 0] $nick![getchanhost $nick $chan]]} {
                  putserv "MODE $chan -o+b $nick [lindex $banentry 0]"
                  putserv "KICK $chan $nick :[lindex $banentry 1]"
                  set nick_banned 1
                  break
               }
            }
            foreach banentry [banlist] {
               if {$nick_banned == 1} {break}
               if {[string match [lindex $banentry 0] $nick![getchanhost $nick $chan]]} {
                  putserv "MODE $chan -o+b $nick [lindex $banentry 0]"
                  putserv "KICK $chan $nick :[lindex $banentry 1]"
                  break
               }
            }
         }
      }
      foreach banentry [chanbans $chan] {
         foreach p_handle [userlist $pflag|$pflag $chan] {
            foreach p_handle_host [getuser $p_handle HOSTS] {
               if {[string match [string tolower [lindex $banentry 0]] [string tolower $p_handle_host]]} {
                  if {[lindex $banentry 1] == "X" || [lindex $banentry 1] == "W"} {
                     if {($enable_xw_unban == 1) && ($logchan_xw($chan) == 1)} {
                        putserv "PRIVMSG [lindex $banentry 1] :unban $chan [lindex $banentry 0]"
                     }
                  } else {putserv "MODE $chan -b [lindex $banentry 0]"}
               }
            }
         }
      }
   }
}

# Banned Nick Changes
# Don't edit anything below unless you know what you're doing
set Banned_Nick_Changes {
	"*fuck*"
	"*bitch*"
	"*asshole*"
	"*kontol*"
	"*contol*"
	"*pepek*"
	"*vevek*"
	"*ngentot*"
	"*kentot*"
	"*jembut*"
	"*zembut*"
	"*pantat*"
	"*totong*"
	"*tetek*"
	"*vagina*"
	"*pukimak*"
	"*bujanginam*"
	"*cibai*"
	"*cibe*"
	"*lanciau*"
	"*lancau*"
	"*memek*"
	"*cipap*"
}

bind nick - * banned_nicks 
proc banned_nicks {nick uhost hand chan newnick} {
   set novonick  "[string range $newnick 0 19]!*@*" 
   if {[matchban $novonick $chan]} {
      set novonick  "*[string range $newnick 0 19]*!*@*"
      putlog "\[4x]: $newnick is banned!! kicking from $chan"
      pushmode $chan +b $novonick
      putserv "kick $chan $newnick :\[4x]: banned nick change"
    }  
}

# Chanserv Auto-Op
# Don't edit anything below unless you know what you're doing

set oppedin ""
set notoppedin ""
set args ""
set noserv "0"
set needlogin "1"

bind RAW - 401 no_services
bind time - "15 * * * *" do_login
bind time - "18 * * * *" check_ops
bind time - "35 * * * *" do_login
bind time - "38 * * * *" check_ops
bind time - "55 * * * *" do_login
bind time - "58 * * * *" check_ops
bind time - "*0 * * * *" say_opped
bind time - "*1 * * * *" say_opped
bind time - "*2 * * * *" say_opped
bind time - "*3 * * * *" say_opped
bind time - "*4 * * * *" say_opped
bind time - "*5 * * * *" say_opped
bind time - "*6 * * * *" say_opped
bind time - "*7 * * * *" say_opped
bind time - "*8 * * * *" say_opped
bind time - "*9 * * * *" say_opped
bind evnt - init-server init_op
bind mode - * do_modes

proc init_op { init-server } {
 utimer 5 "[get_logged_in]"
 if {$botnick != $nick} {
 timer 1 do_login1
 }
}

proc do_login1 { } {
 set nick "1"
 set uhost "2"
 set hand "3"
 set chan "4"
 set args "5"
 do_login $nick $uhost $hand $chan $args
}

proc no_services { from idx text } {
 set noserv "1"
}

proc say_opped { nick uhost hand chan text } {
 global homechan oppedin notoppedin needlogin
    if {$needlogin == "1"} {
      set args ""
      set needlogin "0"
      do_login $nick $uhost $hand $chan $args
     }
   if {$oppedin == ""} {
    return 0
  }
 putserv "PRIVMSG $homechan :\[4x]: I regained ops in $oppedin"
 set oppedin ""
 return 0
}

proc do_modes {nick uhost hand chan arg theone} {
  global home oppedin botnick crits cserv snoop
  if {[string tolower $theone] == [string tolower $botnick]} {
    if {$arg == "-o"} {
    foreach channel $crits {
      if {$channel == $chan} {
        set args ""
        do_login $nick $uhost $hand $chan $args
       }
     }
   }
   if {$nick == "$cserv"} {
    if {$arg == "+o"} {
    if {[string tolower $chan] != [string tolower $snoop]} {
    lappend oppedin $chan 
    set noserv "0" 
    putlog "\[4x]: regained ops in $chan"
    }
   }
  }
  return 0
  }
}

proc check_ops { nick uhost hand chan text } {
  global homechan noserv chanwarn snoop lurks
   set notoppedin ""
   foreach channel [channels] {
      foreach ch $lurks {
         if {[string tolower $ch] == [string tolower $channel]} {
         set channel "FROG"
        }
       }
        if {$channel == "FROG"} {
        } {
    if {![botisop $channel]} {
      if {$channel == $snoop} {
      } {
       lappend notoppedin $channel
       }
      }
     }
    }
   if {$noserv == "1"} {
     return 0
   }
   if {$chanwarn != "1"} {
     return 0
   }
  if {$notoppedin != ""} {
  putserv "PRIVMSG $homechan :\[4x]: failed to regain ops in $notoppedin"
 }
}

proc do_login {nck uhost hand chan args} {
  global nick botnick_pass botnick home lurks noserv nserv servtype servser servserv
    if {$botnick != $nick} {
     putlog "\[4x]: My nickname is in use. Waiting for recovery before identifying."
     puthelp  "PRIVMSG $nserv@$servserv :recover $nick $botnick_pass"
     puthelp  "PRIVMSG $nserv@$servserv :release $nick $botnick_pass"
     timer 1 do_login1
     return 0
    }
    get_logged_in
    set cnn "0"
    set channels [channels]
    foreach channel $channels {
      foreach ch $lurks {
         if {[string tolower $ch] == [string tolower $channel]} {
         set channel "FROG"
        }
       }
        if {$channel == "FROG"} {
        } {
        if {[botisop $channel]} {
        } else {
  set cnn [expr $cnn +1]
  set noserv "0"
  set needlogin "0" 
  do_op $channel $cnn
   }
  }
 }
}

proc get_logged_in { } {
  global nick botnick_pass nserv servserv servser servtype
  if {$servtype == "0"} {
    set identype "AUTH $botnick_pass"
   }
  if {$servtype == "1"} {
    set identype "AUTH $botnick $botnick_pass"
   }
  if {$servtype == "2"} {
    set identype "AUTH $channel $botnick $botnick_pass"
   }
  if {$servtype == "3"} {
    set identype "IDENT $botnick_pass"
   }
  if {$servtype == "4"} {
    set identype "IDENTIFY $botnick_pass"
   }
  if {$servtype == "5"} {
    set identype "IDENTIFY $botnick $botnick_pass"
   }
  if {$servtype == "6"} {
    set identype "LOGIN $botnick_pass"
   }
  if {$servtype == "7"} {
    set identype "LOGIN $botnick $botnick_pass"
   }
  if {$servtype == "8"} {
    set identype "LOGIN $channel $botnick $botnick_pass"
   }
  if {$servser == "1"} {
    puthelp "PRIVMSG $nserv@$servserv :$identype"
   }
  if {$servser != "1"} {
    puthelp  "PRIVMSG $nserv :$identype"
  }
}

proc do_op {channel cnn} {
  global botnick cserv servser servserv
  time_waste $cnn
  set needlogin "0" 
  putlog "\[4x]: identifying to regain ops in $channel"
  if {$servser == "1"} {
   puthelp "PRIVMSG $cserv@$servserv :OP $channel $botnick"
  }
  if {$servser != "1"} {
   puthelp "PRIVMSG $cserv :OP $channel $botnick"
  }
}

proc time_waste { cnn } {
  global nserv servserv
  puthelp "PRIVMSG $nserv@$servserv :access wipe"
}


# Below is a fix for old scripts or old users? :P to make it compatible
# to the new eggdrop commands. If you don't plan on using any old
# scripts, simply delete them.

# $Id: action.fix.tcl,v 1.5 2001/12/07 18:20:30 poptix Exp $
# copied from action.fix.tcl

# fix for mIRC dcc chat /me's
bind filt - "\001ACTION *\001" filt:dcc_action
bind filt - "CTCP_MESSAGE \001ACTION *\001" filt:dcc_action2
proc filt:dcc_action {idx text} {
  return ".me [string trim [join [lrange [split $text] 1 end]] \001]"
}
proc filt:dcc_action2 {idx text} {
  return ".me [string trim [join [lrange [split $text] 2 end]] \001]"
}

# fix for telnet session /me's
bind filt - "/me *" filt:telnet_action
proc filt:telnet_action {idx text} {
  return ".me [join [lrange [split $text] 1 end]]"
}


# $Id: compat.tcl,v 1.7 2001/11/11 20:24:46 guppy Exp $
# This script just quickly maps old Tcl functions to the new ones
# copied from compat.tcl by guppy

proc gethosts {hand} {
  getuser $hand HOSTS
}
proc addhost {hand host} {
  setuser $hand HOSTS $host
}
proc chpass {hand pass} {
  setuser $hand PASS $pass
}
proc chnick {oldnick newnick} { 
  chhandle $oldnick $newnick
}

# setxtra is no longer relevant 
proc getxtra {hand} {
  getuser $hand XTRA
}
proc setinfo {hand info} {
  setuser $hand INFO $info
}
proc getinfo {hand} {
  getuser $hand INFO
}
proc getaddr {hand} {
  getuser $hand BOTADDR
}
proc setaddr {hand addr} {
  setuser $hand BOTADDR $addr
}
proc getdccdir {hand} {
  getuser $hand DCCDIR
}
proc setdccdir {hand dccdir} {
  setuser $hand DCCDIR $dccdir
}
proc getcomment {hand} {
  getuser $hand COMMENT
}
proc setcomment {hand comment} {
  setuser $hand COMMENT $comment
}
proc getemail {hand} {
  getuser $hand XTRA email
}
proc setemail {hand email} {
  setuser $hand XTRA EMAIL $email
}
proc getchanlaston {hand} {
  lindex [getuser $hand LASTON] 1
}
proc time {} {
  strftime "%H:%M"
}
proc date {} {
  strftime "%d %b %Y"
}
proc setdnloads {hand {c 0} {k 0}} {
  setuser $hand FSTAT d $c $k
}
proc getdnloads {hand} {
  getuser $hand FSTAT d
}
proc setuploads {hand {c 0} {k 0}} {
  setuser $hand FSTAT u $c $k
}
proc getuploads {hand} {
  getuser $hand FSTAT u
}

bind dcc - nick *dcc:handle
bind dcc t chnick *dcc:chhandle

# EOF - script end

loadhelp x_prot.help
putlog "${utladellg} 4xtreme_prot.tcl ${x-prot_ver}, Protection and Utilities. Loaded."

return