;IrcOp Scanner (ircop-scan.mrc)
;v1.4
;Written by fuzzbuster


;;; Groups
#ircop.netscan off
raw 352:*:{ haltdef | did -a $ircop.scanner 11 $6 }
raw 315:*:{ haltdef | .disable #ircop.netscan }
#ircop.netscan end
#ircop.chanscan off
raw 352:*:{ haltdef | if (* isin $7) did -a $ircop.scanner 12 $6 }
raw 315:*:{ haltdef | .disable #ircop.chanscan }
#ircop.netscan end

;;; Dialogs
dialog IrcOp.scanner.dialog {
  title "XcLusive Script IRCop Taraması"
  size -1 -1 210 111
  option dbu
  icon $mircdirikon\x.ico, 0
  button "Kapat", 1, 79 92 40 15,cancel
  box "Network", 5, 3 2 73 87
  box "Kanal", 6, 79 2 85 87
  box "Ayarlar", 7, 167 3 40 86
  button "Tara", 8, 21 73 35 13
  button "Tara", 9, 84 73 35 13
  button "Yenile", 19, 124 73 35 13
  combo 10, 84 59 76 49, drop
  list 11, 7 10 65 60, sort size
  list 12, 83 10 77 46, sort size
  button "Query", 13, 172 13 30 10
  button "Notice", 14, 172 25 30 10
  button "CTCP", 15, 172 37 30 10
  button "Whois", 16, 172 49 30 10
  button "Ignore", 17, 172 61 30 10
  button "Notify", 18, 172 73 30 10
  text "Text Label", 4, 165 94 25 8,hide
}

Dialog IrcOp.ctcp.dialog {
  Title "IrcOp Scanner - CTCP"
  Size -1 -1 102 74
  Option DBU
  icon $mircdirikon\x.ico, 0
  Button "Gönder", 1, 3 60 30 12, Ok Default
  Button "Iptaş", 2, 36 60 30 12, Cancel

  Box "CTCP Seçenekleri", 4, 3 2 96 55,

  Radio "Ping", 5, 7 11 30 10,
  Radio "Time", 6, 7 22 30 10,
  Radio "Version", 7, 7 33 35 10,
  Radio "Other:", 8, 7 44 30 10,
  Edit "", 9, 39 44 56 10,
}


;;; Aliases
alias ircop-scan { dialog -m $ircop.scanner $ircop.scanner }
alias  ircop.scanner { return ircop.scanner.dialog }
alias  ircop.ctcp { return ircop.ctcp.dialog }
alias  ircop.rechan { 
  did -r $ircop.scanner 10 1 | ircop.addchan | did -c $ircop.scanner 10 1 
  if ($did($ircop.scanner,10) ischan) { did -e $ircop.scanner 9 }
  else { did -b $ircop.scanner 9 }
}
alias  ircop.scan { 
  if ($1 == net) { .enable #ircop.netscan | who 0 o }
  elseif ($1 == chan) { .enable #ircop.chanscan | who $did($ircop.scanner,10,$did($ircop.scanner,10).sel).text }
}
alias  ircop.addchan {
  var %~ircop.channum = 0
  while (%~ircop.channum >= 0) {
    inc %~ircop.channum
    var %~ircop.chan = $chan(%~ircop.channum)
    if (%~ircop.chan == $null) { goto Break }
    did -a $ircop.scanner 10 %~ircop.chan
  }
  :Break
}


;;; Remote Events
on *:DIALOG:ircop.scanner.dialog:init:0:{ 
  idset 19
  did -b $ircop.scanner 4,13,14,15,16,17,18 
  if ($server) { ircop.addchan | did -c $ircop.scanner 10 1 }
  else { did -b $ircop.scanner 8,9,10,19 }
  if ($did(10,$did(10).sel) == $null) { did -b $ircop.scanner 9 }
}
on *:DIALOG:ircop.ctcp.dialog:Init:0:{ idset 10 | did -c $ircop.ctcp 5 | did -b $ircop.ctcp 9 }
on *:DIALOG:ircop.scanner.dialog:Sclick:*:{
  if ($did == 1) { $iif($dialog($ircop.ctcp),dialog -x $ircop.ctcp) | unset %~ircop.* }
  if ($did == 2) { $iif($dialog($ircop.ctcp),dialog -x $ircop.ctcp) | unset %~ircop.* }
  if ($did == 8) { did -r $ircop.scanner 11 | $ircop.scan(net) }
  if ($did == 9) { did -r $ircop.scanner 12 | $ircop.scan(chan) }
  if ($did == 11) { 
    did -e $ircop.scanner 13,14,15,16,17,18
    if ($address($did(11,$did(11).sel),0) isignore) { did -o $ircop.scanner 17 1 UnIgnore } 
    else { did -o $ircop.scanner 17 1 Ignore }
    if ($address($did(11,$did(11).sel),0) isnotify) { did -o $ircop.scanner 18 1 UnNotify }
    else { did -o $ircop.scanner 18 1 Notify }
  }
  if ($did == 13) { query $did(11,$did(11).sel) }
  if ($did == 14) { notice $did(11,$did(11).sel) $$?="Notice to send to user:" }
  if ($did == 15) { 
    if ($dialog($ircop.ctcp)) { dialog -v $ircop.ctcp $ircop.ctcp }
    else { %~ircop.ctcpnick = $did(11,$did(11).sel) | dialog -m $ircop.ctcp $ircop.ctcp }
  }
  if ($did == 16) { whois $did(11,$did(11).sel) }
  if ($did == 17) { 
    if ($address($did(11,$did(11).sel),0) isignore) { ignore -r $address($did(11,$did(11).sel),0) | did -o $ircop.scanner 17 1 Ignore }
    else { ignore -cktinp $address($did(11,$did(11).sel),0) | did -o $ircop.scanner 17 1 UnIgnore }
  }
  if ($did == 18) { 
    if ($address($did(11,$did(11).sel),0) isnotify) { notify -r $address($did(11,$did(11).sel),0) | did -o $ircop.scanner 18 1 Notify }
    else { notify $address($did(11,$did(11).sel),0) | did -o $ircop.scanner 18 1 UnNotify }
  }
  if ($did == 19) { ircop.rechan }
}
on *:DIALOG:ircop.scanner.dialog:DClick:*:{
  if ($did == 11) { if ($server) whois $did(11,$did(11).sel) }
  if ($did == 12) { if ($server) whois $did(12,$did(12).sel) }
}
on *:DIALOG:ircop.ctcp.dialog:Sclick:*:{
  if ($did == 1) { 
    if ($did(5).state) { ctcp %~ircop.ctcpnick Ping }
    if ($did(6).state) { ctcp %~ircop.ctcpnick Time }
    if ($did(7).state) { ctcp %~ircop.ctcpnick Version }
    if ($did(8).state) { 
      if ($did(9)) { ctcp %~ircop.ctcpnick $strip($did(9)) }
      else { echo $colour(Info) -s * /ctcp: insufficient parameters }
    }
    unset %~ircop.ctcpnick
  }
  if (($did == 5) || ($did == 6) || ($did == 7)) { did -b $ircop.ctcp 9 }
  if ($did == 8) { did -e $ircop.ctcp 9 }
}
on *:CONNECT:{ 
  if ($dialog($ircop.scanner)) { 
    did -e $ircop.scanner 8,10,19
    if ($did($ircop.scanner,10)) { did -e $ircop.scanner 9 }
  }
}
on *:DISCONNECT:{ 
  if ($dialog($ircop.scanner)) { did -b $ircop.scanner 8,9,10,19 }
}
on me:JOIN:#:{ ircop.rechan }
on me:PART:#:{ ircop.rechan }
