####################################################
# by wiebe @ QuakeNet
#
# when a netsplit happens, or a user with +S (chan or global) parts or quits
# op all +N users (chan or global) who have omn|omn
# +netsplitop (enable)
# +netsplitop-all (op all users with omn|omn, even if they do not have N|N)
#
# script can use: idle.tcl script.tcl
####################################################

setudef flag netsplitop
setudef flag netsplitop-all

####################################################
# netsplitop
####################################################
bind splt -|- * netsplitop:split
bind sign S|S * netsplitop:split
bind part S|S * netsplitop:split
proc netsplitop:split { n u h c {m ""} } {
  if {![validchan $c] || [channel get $c inactive] || ![channel get $c netsplitop] || ![botisop $c]} { return 0 }
  if {![isop $n $c] && ![matchattr $h omn|omn $c]} { return 0 }
# Q rejoining channel(s)
  if {[string equal -nocase $m "cycling channel."]} { return 0 }
  set z [channel get $c netsplitop-all]
  foreach m [chanlist $c omn|omn] {
    if {[string equal $m $n] || [onchansplit $m $c] || [isop $m $c]} { continue }
    set g [nick2hand $m $c]
    if {[matchattr $g kdZ|kd $c]} { continue }
    if {!$z && ![matchattr $g N|N $c]} { continue }
    pushmode $c +o $m
# reset idle time
    if {[info procs idle:set] != ""} { idle:set $m $c } 
  }
}


####################################################
# set info for userflag.tcl
####################################################
set ::userflagdb(netsplitop) {
  "netsplitop.tcl: S=service (user's part or quit triggers netsplit)    N=op user when a netsplit is detected"
}


####################################################
# set info for script.tcl
####################################################
set ::scriptdb(netsplitop) {
  "provides channel setting +netsplitop, when an op on the channel splits, or a user with S|S flags (service, should only be set for channel services) quits or parts, this scripts ops all users with omn|omn flags that also have N|N flags. +netsplitop-all (op all users with omn|omn, even if they do not have N|N)."
}

