aIRC — File Browser

aIRCv0.8.69 / aIRCv0.8.69 / script / script2.mrc

script2.mrc — 33.44 KB — Download this file

;/**********************************************************************
; *
; * aIRC
; * Events in this file
; *
; **********************************************************************/

ON *:CONNECT:{ _idle.onconnect&ondisconnect }
ON *:DISCONNECT:{ _idle.onconnect&ondisconnect }
ON ^*:NICK:{ _orignick.onnick }
ON ^*:QUIT:{ _orignick.onquit }
ON ME:*:JOIN:#:{
  _hmake _IIL $+ $chan 300
  .fjoin -r $chan
}
ON *:JOIN:#:{ _idle.refresh $chan $nick }
ON *:TEXT:*:#:{ _idle.refresh $chan $nick }
ON *:ACTION:*:#:{ _idle.refresh $chan $nick }
ON ME:*:PART:#:{ _idle.remchan $chan }
ON *:PART:#:{ _idle.del $chan $nick }
ON *:KICK:#:{
  if ($knick == $me) { _idle.remchan $chan }
  else { _idle.del $chan $nick }
}

;/**********************************************************************
; *
; * aIRC
; * Idle
; *
; **********************************************************************/

; _idle.refresh #chan nick
alias _idle.onconnect&ondisconnect { _idle.remchan * }
alias _idle.refresh {
  var %ht = _IIL $+ $1
  if ($hget(%ht)) { hadd %ht $2 $ctime }
}

; _idle.del #chan nick
alias _idle.del {
  var %ht = _IIL $+ $1
  if ($hget(%ht)) { hdel %ht $2 }
}

; _idle.ren #chan nick newnick
alias _idle.ren {
  var %ht = _IIL $+ $1
  if ($hget(%ht)) {
    if ($hget(%ht,$2) != $null) {
      hadd %ht $3 $ifmatch
      hdel %ht $2
    }
  }
}

; idle.remchan <#chan|*>
alias _idle.remchan { hfree -w _IIL $+ $1 }

; _idle.get #chan nick
alias _idle.get {
  var %ht = _IIL $+ $1
  return $calc($ctime - $hget(%ht,$2))
}

;/**********************************************************************
; *
; * aIRC
; * Netsplits
; *
; **********************************************************************/

; $_isnetsplit(quit reason)
alias _isnetsplit {
  if ($count($1,.)) && ($count($2,.)) && ($ !isin $1-2) && ($len($3-) == 0) && ($1 != $2) && ($_ishost($1)) && (($_ishost($2)) || ($iif($gettok($2,1,46) == *,$_ishost($puttok($2,tmp,1,46)),0))) { return 1 }
  return 0
}
alias _netsplit.waitime {
  if ($_isint($_getsetup(script,wait-split))) { return $ifmatch }
  _setsetup script wait-split 300
  return 300
}

; _netsplit.addnick nick address server1 server2 $ctime chans
alias _netsplit.addnick { _sets netsplits $1- }

; _netsplit.remnick nick
alias _netsplit.remnick { _sets netsplits $1 }

;
alias _usersplit {
  var %var = $_get(netsplits,$1),%t = $gettok(%var,4,32)
  if (%var != $null) {
    if ($calc($ctime - %t) > $_netsplit.waitime) {
      _netsplit.remnick $1
      var %var
    }
  }
  if ($2 == addy) { return $gettok(%var,1,32) }
  if ($2 == server1) { return $gettok(%var,2,32) }
  if ($2 == server2) { return $gettok(%var,3,32) }
  if ($2 == splittime) { return %t }
  if ($2 == chans) { return $gettok(%var,5,32) }
  if (%var != $null) { return 1 }
  return 0
}

;/**********************************************************************
; *
; * aIRC
; * orignick
; *
; **********************************************************************/

; /orignick [nick|-]
alias orignick {
  unset %.fporignick
  if ($server == $null) {
    error.a You are not connected!
    return
  }
  if ($1 == $null) {
    if (%.orignick != $null) { info.a Attempting to gain " $+ $ifmatch $+ " }
  }
  elseif ($1 == -) {
    if (%.orignick != $null) { info.a Removing gain nick [[ $+ $ifmatch $+ ]]. Timer will expire. }
    else { error.a Not trying to gain a nick }
    _orignick.off
  }
  else {
    if ($1 == $me) {
      info.a Your nick already is $1
      _orignick.off
    }
    elseif ($1 == %.orignick) { info.a Already attempting that nick $1 }
    elseif ($_isvalidircnickname($1)) {
      %.orignick = $1
      info.a Trying to regain nick [[ $+ $1 $+ ]] every 15 seconds. Press $_addfkey(o,600,orignick -) to cancel.
    }
    else {
      error.a Nickname was bad.
      _orignick.off
    }
  }
  if (%.orignick != $null) {
    if ($timer(_orignick) == $null) { ._nickhost %.orignick 5 _orignick.change _orignick.timer <NICK> }
  }
  else { _orignick.off }
}
alias -l _orignick.off {
  unset %.orignick
  .timer_orignick off
  .timer_chorignick off
}
alias _orignick.change {
  if (%.fporignick) || (%.orignick == $null) { return }
  set -u5 %.fporignick 1
  if (%.orignick == $1) && (%.orignick != $me) { nick %.orignick }
}
alias _orignick.timer {
  if (%.orignick != $null) { .timer_orignick 1 15 ._nickhost %.orignick 5 _orignick.change _orignick.timer <NICK> }
  else { _orignick.off }
}
alias _orignick.onnick {
  if (%.orignick == $null) { return }
  if ($nick == $me) {
    if ($newnick == %.orignick) {
      info.a Regained nick [[ $+ $newnick $+ ]]
      _orignick.off
    }
  }
  elseif ($nick == %.orignick) { _orignick.change $nick }
}
alias _orignick.onquit {
  if ($nick == %.orignick) { _orignick.change }
}

;/**********************************************************************
; *
; * aIRC
; * Ident client
; *
; **********************************************************************/

alias ident {
  unset %c.ident.*
  %c.ident.n = $_parameter($1,1,Ident Client [/ident],1,$_activequery,Nick | IP | Host:)
  %c.ident.ip = $iif(. isin %c.ident.n,%c.ident.n,$_gethost(%c.ident.n))
  if (%c.ident.ip == $null) { .dns %c.ident.n }
  else {
    if ($sock(IDENT [ $+ [ %c.ident.ip ] ] ) == $null) {
      sockopen IDENT $+ %c.ident.ip %c.ident.ip 113
      sockmark IDENT $+ %c.ident.ip %c.ident.ip
    }
    unset %c.ident.*
  }
}
ON *:SOCKOPEN:IDENT*:{
  if ($sockerr) {
    error.a Ident connection $sock($sockname).mark : $_sockerr
    return
  }
  sockwrite $sockname 0,0
}
ON *:SOCKWRITE:IDENT*:{
  if ($sockerr) { error.a Ident connection $sock($sockname).mark : $_sockerr }
}
ON *:SOCKREAD:IDENT*:{
  if ($sockerr) {
    error.a Ident connection $sock($sockname).mark : $_sockerr
    return
  }
  var %sr
  sockread %sr
  lecho.s $colour(other) $^*** Ident reply from $sock($sockname).mark
  echo.s $colour(other) $^*** Reply: %sr
  echo.s $chr(160)
}
ON *:DNS:{
  if (%c.ident.n != $null) && ($nick == %c.ident.n) {
    if ($iaddress) {
      .sockopen IDENT $+ $iaddress $iaddress 113
      .sockmark IDENT $+ $iaddress $iaddress
    }
    else { error.a $nick - Ident request cancelled. Couldn't resolve address }
    unset %c.ident.n
    halt
  }
}

;/**********************************************************************
; *
; * aIRC
; * Notify
; *
; **********************************************************************/

ON ^*:NOTIFY:{
  haltdef
  if ($_notify.get($nick).net != $null) && (%.network != $null) && ($istok($_notify.get($nick).net,%.network,44) == $false) { halt }
  if ($_notify.get($nick).mask != $null) && ($fulladdress == $null) { ._nickhost $nick 5 _donothing _notify.onotify <NICK> <ADDR> }
  else { _notify.onotify $nick $fulladdress }
  halt
}
ON *:UNOTIFY:{
  haltdef
  if ($_notify.get($nick).net != $null) && (%.network != $null) && ($istok($_notify.get($nick).net,%.network,44) == $false) { halt }
  _notify.onunotify $nick $fulladdress
  halt
}
; /_notify.onotify <nick> <fulladdress>
alias _notify.onotify {
  var %net = $_notify.get($1).net,%mask = $_notify.get($1).mask,%addyverf = 1,%note = $_notify.get($1).note
  if (%mask != $null) && (%mask !iswm $2) { %addyverf = 0 }
  %::nick        = $1
  %::address     = $gettok($2,2,33)
  %::fulladdress = $2
  %::site        = $gettok($2,2,64)
  %::network     = %net
  %::mask        = %mask
  %::verified    = %addyverf
  %::note        = %note
  %:echo = echo.a $colour(notify)
  _hook.call onnotify
  ^notify
  if ($_notify.get($1).sound != $null) { .splay " $+ $ifmatch $+ " }
  elseif (%mask == $null) || (%addyverf) {
    ^playthemesound ONNOTIFY
    _notify.nicksvars -p $1
  }
  else {
    ^playthemesound ONBADNOTIFY
    _notify.nicksvars -f $1
  }
  if ($_notify.get($1).whois) { whois $1 }
  _nicklist.col.nick $1 $2
}
; /_notify.onunotify <nick> [fulladdress]
alias _notify.onunotify {
  var %net = $_notify.get($1).net,%mask = $_notify.get($1).mask,%addyverf = 1,%note = $_notify.get($1).note
  if (%mask != $null) && (%mask !iswm $2) { %addyverf = 0 }
  %::nick        = $1
  %::address     = $gettok($2,2,33)
  %::fulladdress = $2
  %::site        = $gettok($2,2,64)
  %::network     = %net
  %::mask        = %mask
  %::verified    = %addyverf
  %::note        = %note
  %:echo = echo.a $colour(notify)
  _hook.call onunotify
  ^unotify
  _notify.nicksvars -r $1
  if (%mask == $null) || (%addyverf) { ^playthemesound ONUNOTIFY }
  else { ^playthemesound ONBADUNOTIFY }
}
alias _notify.nicksvars {
  var %flags
  if (-* iswm $1) {
    %flags = $1
    tokenize 32 $2-
  }
  if ($_not($notify($1))) { %flags = -r }
  if (%flags == -r) || (%flags == -p) { %c.notifynicks.failed = $remtok(%c.notifynicks.failed,$1,32) }
  if (%flags == -r) || (%flags == -f) { %c.notifynicks.passed = $remtok(%c.notifynicks.passed,$1,32) }
  if (%flags == -f) { %c.notifynicks.failed = $addtok(%c.notifynicks.failed,$1,32) }
  if (%flags == -p) { %c.notifynicks.passed = $addtok(%c.notifynicks.passed,$1,32) }
  if (%c.notifynicks.failed == $null) { unset %c.notifynicks.failed }
  if (%c.notifynicks.passed == $null) { unset %c.notifynicks.passed }
  if ($istok(%c.notifynicks.failed,$1,32)) { return failed }
  if ($istok(%c.notifynicks.passed,$1,32)) { return passed }
}


;
;
;
alias _notify.get {
  if ($1 isnum) && ($notify($1) isnotify) { tokenize 32 $notify($1) }
  if ($1 !isnotify) { return }
  if ($prop == $null) || ($prop == nick) { return $1 }
  if ($prop == ison) { return $notify($1).ison }
  if ($prop == sound) { return $notify($1).sound }
  if ($prop == whois) { return $notify($1).whois }
  tokenize 32 $1 $null $null $notify($1).note
  if ([?*] iswm $4) { tokenize 32 $1 $right($left($4,-1),-1) $null $5- }
  if ($_ismask($4)) { tokenize 32 $1 $2 $4 $5- }
  if ($prop == net) { return $iif($2,$2) }
  if ($prop == mask) { return $iif($3,$3) }
  if ($prop == note) { return $4- }
  return $1
}
alias notifyd {
  _dialog -m notifyuser notifyuser
  if ($1 != $null) { notifyd.init $1 $2 }
}
alias notifyd.init {
  var %d = notifyuser,%n
  did -r %d 50,57,120,131
  did -u %d 54,56,115
  did -b %d 57,120
  tokenize 32 $1 $iif($_notify.get($1).mask,$_notify.get($1).mask,$null) $iif($2,$2,$iif($_address($1,5),$_address($1,5),$null))
  if ($2 == $null) && ($_mask($3,%_masknorm)) { tokenize 32 $1 $_mask($3,%_masknorm) $3 }
  if ($2) {
    if ($3) {
      %n = 0
      while (%n <= 9) {
        _dialog.addandselectmatch %d 120 $_mask($3,$ifmatch) $2 250
        inc %n
      }
    }
    if ($did(%d,120).sel == $null) { _dialog.addandselectmatch %d 120 $2 $2 250 }
  }
  did -o %d 50 1 $1
  if ($_notify.get($1).mask) {
    did -c %d 115
    did -e %d 120
  }
  if ($_notify.get($1).whois) { did -c %d 54 }
  if ($_notify.get($1).net != $null) {
    did -eo %d 57 1 $ifmatch
    did -c %d 56
  }
  elseif (%.network != $null) { did -o %d 57 1 $ifmatch }
  if ($_notify.get($1).note != $null) { did -o %d 131 1 $ifmatch }
  did -o %d 250 1 $did(%d,120,$did(%d,120,1).sel)
  _notifyd.refresh
}
alias _notifyd.refresh {
  var %d = notifyuser
  if ($dialog(%d) == $null) { return }
  tokenize 32 $did(%d,250,1)
  if ($did(%d,115).state) {
    if ($1- == $null) || ($_ismask2($1-)) { did -e %d 241 }
    else { did -b %d 241 }
  }
  else { did -e %d 241 }
  tokenize 32 $did(%d,50,1)
  did $iif($1- isnotify,-e,-b) %d 235
  did $iif($did(%d,56).state,-e,-b) %d 57
  did $iif($did(%d,115).state,-e,-b) %d 120
}
alias _notifyd.add {
  var %t = $2-
  if ($1 !isnotify) { notify %t }
  else {
    tokenize 32 $1 $iif($_notify.get($1).whois,+) $+ $1
    if ($_notify.get($1).net != $null) { tokenize 32 $1- [[ $+ $ifmatch $+ ]] }
    if ($_notify.get($1).mask != $null) { tokenize 32 $1- $ifmatch }
    if ($_notify.get($1).note != $null) { tokenize 32 $1- $ifmatch }
    if (%t != $2-) {
      .notify -r $1
      notify %t
    }
  }
}
dialog notifyuser {
  size -1 -1 125 115
  option dbu
  title "Notify"

  box "",1,-5 15 900 75

  text "&Nick:",49,5 5 13 8
  edit "",50,20 3 100 11,edit autohs

  check "&Whois",54,5 25 30 8

  check "Only in &network[s]",56,5 37 55 8
  edit "",57,60 35 60 11,autohs


  check "Match &mask:",115,5 49 55 8
  combo 120,60 47 60 100,drop edit

  text "C&omment:",130,5 63 30 8
  edit "",131,5 73 115 11,autohs

  button "&Remove",235,5 95 33 15
  button "&OK",241,47 95 33 15,ok disable
  button "&Cancel",242,87 95 33 15,cancel

  edit "",248,999 999 1 1,hide
  edit "",249,999 999 1 1,hide
  edit "",250,999 999 1 1,hide
}
ON *:DIALOG:notifyuser:*:*:{
  if ($devent == init) {
    _mdx.init $_icofile(notify.ico)
    _dummy $_lang.loaddialog($dname,_notifyuser,00086969,main.lang,$scriptdir)
  }
  elseif ($devent == edit) {
    if ($did == 120) { did -o $dname 250 1 $did(120).text }
  }
  elseif ($devent == sclick) {
    if ($did == 120) { did -o $dname 250 1 $did(120,$did(120,1).sel) }
    elseif ($did == 235) {
      notify -r $did(50,1)
      dialog -c $dname
    }
    elseif ($did == 241) {
      if ($did(56).state) && ($_text($did(57)) != $null) { tokenize 32 [[ $+ $remove($replace($did(57),$chr(32),$chr(44)),[,],(,),<,>) $+ ]] }
      if ($did(115).state) && ($did(241).enabled) { tokenize 32 $1- $did(250) }
      if ($did(131) != $null) { tokenize 32 $1- $ifmatch }
      _notifyd.add $gettok($did(50),1,32) $iif($did(54).state,+) $+ $gettok($did(50),1,32) $1-
    }
  }
  _notifyd.refresh
}

;/**********************************************************************
; *
; * aIRC
; * misc stuff
; *
; **********************************************************************/

; $_mochafile(<file>,column,flags,number)
alias _mochafile {
  var %file = $1,%col = $2,%flags = $3,%number = $4,%win = @__mochafile,%method,%lines,%removed = 0,%last,%i,%n,%time
  if (l isin %flags) { %method = l }
  else { %method = d }
  if ($isfile(%file) == $false) { return }
  %lines = $lines(%file)
  if (%lines < 1) || ($_not($_isint(%col))) || ($_not($_isint(%number))) { return }
  _openwins %win
  filter -fwut %col 32 " $+ %file $+ " %win *
  %lines = $line(%win,0)
  if (%lines == 0) { return 0 }
  if (%method == l) {
    if (%number < %lines) { %last = %number }
    else { return 0 }
  }
  else {
    %i = 1
    %time = $calc($ctime - $calc(%number * 24 * 60 * 60))
    while (%i <= %lines) {
      if ($gettok($line(%win,%i),3,32) >= %time) {
        if (%i == 1) { return 0 }
        break
      }
      inc %i
    }
    if (%i == %lines) { return 0 }
    %last = %lines - %i
  }
  if (%last > 0) && (%last < %lines) {
    %removed = %lines - %last
    savebuf %last %win %file
    return %removed
  }
  close -@ %win
  return 0
}
;
; $`usermode.net(<mode>,[$usermode],[%.usermodes])
;
alias `usermode.net {
  var %t
  tokenize 32 $$1 $iif($2,$2,$usermode) $iif($3,$3,%.usermodes)
  tokenize 32 $1-2 $iif($3,$3,iwso)
  if ($1 !isincs $3) { return }
  if ($1 === i) { %t = invisible }
  elseif ($1 === w) { %t = wallops }
  elseif ($1 === s) { %t = server notices }
  elseif ($1 === o) { %t = ircop }
  return $iif($1 isincs $2,$^popupon,$^popupoff) %t $+ $chr(9) $+ $iif($1 isincs $2,+,-) $+ $1
}


alias _wmens.nick {
  if ($active == notify list) { return $snotify }
  if (=* iswm $active) { return $right($active,-1) }
  if ($query($active)) { return $active }
  if ($active ischan) { return $snick(#,1) }
  if (@Q_* iswm $active) || (@DCC CHAT* iswm $active) { return $gettok($active,2,160) }
  if (@CH_* iswm $active) {
    if ($remove($strip($sline($active,1)),.,@,+) != $null) { return $ifmatch }
  }
}
alias _archtexto { return $_archtext($1-) }
alias _archtext {
  if ($isfile($1-)) {
    var %t = $read -l $+ $calc($lines($1-) - 1) $1-,%t = $iif( isin %t,$remove(%t,)) $read $1-
    if (%t != $null) { return $ifmatch }
  }
}
alias _wmens.snicks {
  if ($active == notify list) { return $snotify }
  if (=* iswm $active) { return $right($active,-1) }
  if ($query($active)) { return $active }
  if ($active ischan) { return $replace($snicks,$chr(44),$chr(32)) }
  if (@Q_* iswm $active) || (@DCC CHAT* iswm $active) { return $gettok($active,2,160) }
  if (@CH_* iswm $active) { return $_irc.snicks }
}
alias _wmens.msg {
  if ($_irc.ircnum) { _irc.com msg $1- }
  else { msg $1- }
}
alias _wmens.me {
  if ($_irc.ircnum) { _irc.com me $1- }
  elseif ($active == notify list) { describe $snotify $1- }
  else { me $1- }
}
alias _wmens.say {
  if ($1- == $null) { return }
  if ($_irc.ircnum) {
    if (@CH_* iswm $active) { _irc.com msg $gettok($active,2,160) $1- }
    else { _irc.com msg $_wmens.nick $1- }
  }
  elseif ($active == notify list) { msg $snotify $1- }
  else { say $1- }
}
alias _wmens.menu.nick {
  if (@CH_* iswm $active) {
    if ($mouse.lb) && ($sline($active,1) != $null) { return $1- }
    return
  }
  if ($_not($_connected)) || ($menu == channel) || (($menu == nicklist) && ($snick(#,0) == 0)) { return }
  return $1-
}
alias _wmens.menu.chan {
  if (@CH_* iswm $active) {
    if ($_not($mouse.lb)) { return $1- }
    return
  }
  if ($_connected) && ($menu == channel) { return $1- }
}
;/**********************************************************************
; *
; * aIRC
; * fjoin!
; *
; **********************************************************************/

; /fjoin [-r|uN|tN] [#channel]
alias fjoin {
  if (-* iswm $1) { var %pre = $1,%chan = $2 }
  else { var %pre,%chan = $1 }
  if (%pre = -r) {
    if (%chan != $null) {
      if ($show) {
        if ($_fjoin.ischan(%chan)) { info.a Cancelled %chan fjoin }
        else { info.a There was no fjoin for %chan }
      }
      .timer_fjoin_ $+ %chan off
    }
    else {
      if ($show) {
        if ($_fjoin.chans != $null) { info.a Cancelled all fjoins }
        else { info.a Your fjoin list was already empty }
      }
      .timer_fjoin_* off
    }
  }
  elseif (%chan != $null) {
    var %duration,%times = 0,%line = Attemping to join %chan every 10 seconds.
    if (-t* iswm %pre) && ($_isint($remove(%pre,-,t))) { %times = $ifmatch }
    elseif (-u* iswm %pre) && ($_isint($remove(%pre,-,u)) >= 10) {
      %duration = $ifmatch
      %times = $round($calc(%duration / 10),0)
    }
    if (%duration) { %line = %line Give up after %duration seconds ( $+ $_nsingoplur(%times,attemp,attemps) $+ ). }
    elseif (%times) { %line = %line Give up after $_nsingoplur(%times,attemp,attemps) $+ . }
    if ($show) { info.a %line Use '/fjoin -r %chan $+ ' to cancel. }
    _fjoin.join %chan %times 1
  }
  else {
    if ($_fjoin.chans != $null) { info.a Attemping to rejoin: $ifmatch }
    else { info.a Your fjoin list is empty. }
  }
}
alias _fjoin.chans {
  var %i = 1,%n = $timer(0),%timer,%result
  while (%i <= %n) {
    %timer = $timer(%i)
    if (_fjoin_* iswm %timer) { %result = $addtok(%result,$gettok(%timer,2,95),44) }
    inc %i
  }
  return %result
}
alias _fjoin.ischan {
  var %timer = _fjoin_ $+ $1
  if ($timer(%timer)) { return 1 }
  return 0
}
alias _fjoin.join {
  join $1
  if ($2 == 0) || ($calc($3 + 1) <= $2) { .timer_fjoin_ $+ $1 1 10 _fjoin.join $1 $2 $calc($3 + 1) }
}
alias _fjoin.raw {
  if ($_fjoin.ischan($1)) { halt }
  _addfkey o 600 fjoin $1
  .timer -o 1 0 info.s Press ' $+ $result $+ ' to try to join every 10 seconds
}
raw 437:*:{ _fjoin.raw $2 }
raw 471:*:{ _fjoin.raw $2 }
raw 473:*:{ _fjoin.raw $2 }
raw 474:*:{ _fjoin.raw $2 }
raw 475:*:{ _fjoin.raw $2 }
raw 476:*:{ _fjoin.raw $2 }
raw 477:*:{ _fjoin.raw $2 }

;/**********************************************************************
; *
; * aIRC
; * Event Sounds
; *
; **********************************************************************/

alias esounds { _dialog -m esounds _eventsounds }
dialog _eventsounds {
  size -1 -1 290 122
  option dbu
  title "Event Sounds"

  list 1001,5 5 100 100
  list 1002,5 5 100 100,hide
  list 1003,5 5 100 100,hide

  box "",1101,110 2 175 97

  radio "No sound",1201,115 12 55 7

  radio "Play File",1301,115 27 55 7
  button "",1302,130 37 150 10

  radio "Play Random File from dir:",1401,115 52 80 7
  button "",1402,130 62 150 10
  text "matching",1403,130 75 25 8
  edit "",1404,155 74 125 10,autohs

  radio "Beep",1501,115 87 80 7

  button "&Listen!",2990,177 103 30 15
  button "&Ok",2991,217 103 30 15,ok
  button "&Cancel",2992,257 103 30 15,cancel
  edit "",3000,1 1 1 1,autohs hide
}
ON *:DIALOG:esounds:*:*:{
  if ($devent == init) {

    ;###translate

    _mdx.init $_icofile(esounds.ico)
    _esounds.load START aIRC startup
    _esounds.load OK Ok/Accept
    _esounds.load CANCEL Action cancelled
    _esounds.load ERROR Error
    _esounds.load QUESTION Question
    _esounds.load CONNECT Connection
    _esounds.load MEQUIT You Quit IRC
    _esounds.load DISCONNECT Disconnection
    _esounds.load INVITE When you're invited
    _esounds.load QUERY Query received
    _esounds.load CHATREQUEST Chat Request
    _esounds.load SENDREQUEST Send Request
    _esounds.load FILESENT File Sent
    _esounds.load FILERCVD File Received
    _esounds.load SENDFAIL Send Failed
    _esounds.load GETFAIL Get Failed
    _esounds.load ONNOTIFY On Notify
    _esounds.load ONBADNOTIFY On Bad Notify
    _esounds.load ONUNOTIFY On Unotify
    _esounds.load ONBADUNOTIFY On Bad Unotify
    _esounds.load SETAWAY Set Away
    _esounds.load SETAUTOAWAY Set AutoAway
    _esounds.load SETBACK Set Back
    _esounds.load PAGE Pager Sound
    _esounds.load MEOP When you are opped
    _esounds.load MEDEOP When you are deopped
    _esounds.load MEJOIN When you join
    _esounds.load MEKICK When you are kicked
    _esounds.load MENICK When you change your nick
    _esounds.load MEPART When you leave a channel
    _esounds.load JOIN User joins a channel
    _esounds.load KICK User kicked
    _esounds.load PART User leaves a channel
    _esounds.load QUIT User quits IRC
    did -c $dname 1001 1
    _esounds.sel
  }
  elseif ($devent == sclick) {
    if ($did == 1001) { _esounds.sel }
    elseif ($did == 2990) { _esounds.listen }
    elseif ($did == 1302) { _esounds.filesel }
    elseif ($did == 1402) { _esounds.dirsel }
    elseif ($istok(1201 1301 1401 1501,$did,32)) { _esounds.savebuf $did }
    elseif ($did == 2991) { _esounds.ok }
  }
  elseif ($devent == edit) { _esounds.savebuf $left($did,3) $+ 1 }
  did $iif($did($dname,1301).state,-e,-b) $dname 1302
  did $iif($did($dname,1401).state,-e,-b) $dname 1402,1403,1404
}
alias -l _esounds.load {
  did -a $dname 1001 $2-
  did -a $dname 1002 $1
  var %tmp = ^sound. $+ $1
  if ($hget(_airctheme,%tmp) != $null) { did -a $dname 1003 $ifmatch }
  else { did -a $dname 1003 $null }
}
alias -l _esounds.sel {
  var %tmp = $did($dname,1003,$did($dname,1001).sel),%sel,%file = [no file],%dir = [mircdir],%mask = *.wav,%td,%tf
  if (%tmp == $null) { %sel = 1201 }
  elseif (%tmp == <BEEP>) { %sel = 1501 }
  else {
    %tmp = $_fixfilename(%tmp,n)
    if (* isin %tmp) || (? isin %tmp) { var %sel = 1401,%dir = $nofile(%tmp),%mask = $nopath(%tmp) }
    else { var %sel = 1301,%file = $_fixfilename(%tmp,m) }
  }
  if (%dir == $mircdir) || (%dir == [mircdir]) { %dir = [mircdir] }
  else { %dir = $_fixdir(%dir,m) }
  did -u $dname $replace($remtok(1201.1301.1401.1501,%sel,1,46),.,$chr(44))
  did -c $dname %sel
  did -o $dname 1302 1 %file
  did -o $dname 1402 1 %dir
  did -o $dname 1404 1 %mask
}
alias -l _esounds.listen {
  var %f
  if ($did($dname,1501).state) { .beep }
  elseif ($did($dname,1301).state) && ($did($dname,1302) != [no file]) { %f = $_fixfilename($ifmatch) }
  elseif ($did($dname,1401).state) {
    var %dir = $did($dname,1402),%mask = $did($dname,1404)
    if (%dir == [mircdir]) { %dir = $mircdir }
    if (%mask == $null) { %mask = * }
    if (*.wav !iswm %mask) { %mask = %mask $+ .wav }
    if ($isdir(%dir)) {
      if ($findfile(%dir,%mask,0,1)) { %f = $findfile(%dir,%mask,$rand(1,$ifmatch),1) }
    }
  }
  if (%f != $null) && ($isfile(%f)) { splay " $+ %f $+ " }
}
alias -l _esounds.savebuf {
  var %dname = esounds
  if ($1 == 1201) { did -o %dname 1003 $did(%dname,1001).sel $null }
  elseif ($1 == 1301) { did -o %dname 1003 $did(%dname,1001).sel $iif($did(%dname,1302) != [no file],$did(%dname,1302),$null) }
  elseif ($1 == 1401) {
    var %d = $did(%dname,1402),%m = $did(%dname,1404),%tmp
    if (%d == [mircdir]) { %d = $mircdir }
    if (%m == $null) { %m = * }
    if (*.wav !iswm %m) { %m = %m $+ .wav }
    %tmp = %d $+ \ $+ %m
    while (\\ isin %tmp) { %tmp = $replace(%tmp,\\,\) }
    did -o %dname 1003 $did(%dname,1001).sel %tmp
  }
  elseif ($1 == 1501) { did -o %dname 1003 $did(%dname,1001).sel <BEEP> }
}
alias -l _esounds.filesel {
  var %dname = esounds,%t = $did(%dname,1302),%file
  if (%t == [no file]) { %t = $mircdir $+ *.wav }
  else { %t = $nofile(%t) $+ *.wav }
  %file = $$dir="Select sound file:" %t
  if (*.wav iswm %file) {
    did -o %dname 1003 $did(%dname,1001).sel %file
    _esounds.sel
  }
}
alias -l _esounds.dirsel {
  var %dname = esounds,%t = $did(%dname,1402),%dir,%m = $did(%dname,1404)
  if (%t == [mircdir]) { %t = $mircdir }
  if (%m == $null) { %m = * }
  if (*.wav !iswm %m) { %m = %m $+ .wav }
  %dir = $$sdir="Select sound dir:" %t
  did -o %dname 1003 $did(%dname,1001).sel %dir $+ %m
  _esounds.sel
}
alias -l _esounds.ok {
  var %d = $dname,%i = 1,%n = $did(%d,1001).lines
  while (%i <= %n) {
    _sets theme ^sound. $+ $did(%d,1002,%i) $did(%d,1003,%i)
    inc %i
  }
  _themes.savehash
}
;/**********************************************************************
; *
; * aIRC
; * Ircop List/$_isircop()
; *
; **********************************************************************/

alias _ircoplist.add { %c.ircoplist = $addtok(%c.ircoplist,$1,32) }
alias _ircoplist.del {
  %c.ircoplist = $remtok(%c.ircoplist,$1,1,32)
  if (%c.ircoplist == $null) { _ircoplist.clear }
}
alias _ircoplist.clear { unset %c.ircoplist }
alias _ircoplist.chnick {
  if ($_isircop($1)) {
    _ircoplist.del $1
    _ircoplist.add $2
  }
}
alias _isircop {
  if ($istok(%c.ircoplist,$1,32)) { return 1 }
  return 0
}
;/**********************************************************************
; *
; * aIRC
; * Channel synch time
; *
; **********************************************************************/

; /_synchtime.set <0=main|#=irc client session> <#channel>
alias _synchtime.set {
  _synchtime.del $1 $2
  _setd junk synchtime $1 $+ -joind $+ $2 $ticks
}

; /_synchtime.calc <0=main|#=irc client session> <#channel>
alias _synchtime.calc {
  var %t = synchtime_ $+ $1 $+ -joind $+ $2
  _setd junk synchtime $1 $+ -synch $+ $2 $calc(($ticks - $hget(_aircjunk,%t)) / 1000)
}

; /_synchtime.del <0=main|#=irc client session> <#channel>
alias _synchtime.del {
  _setd junk synchtime $1 $+ -synch $+ $2
  _setd junk synchtime $1 $+ -joind $+ $2
}

; $_synchtime.get([0=main|#=irc client session],<#channel>)
alias _synchtime.get {
  if ($1 isnum) || ($1 == $null) { var %in = $1,%chan = $2 }
  else { var %in = %::ircnum,%chan = $1 }
  if (%in == $null) { %in = 0 }
  return $_get(junk,synchtime,$_nospaces(%in,-synch,$2))
}

; /_synchtime.flush [0=main|#=irc client session]
alias _synchtime.flush {
  var %h = _aircjunk,%m = synchtime*
  if ($1 != $null) { %m = synchtime_ $+ $1 $+ -* }
  if ($hget(%h)) { hdel -w %h %m }
}
;/**********************************************************************
; *
; * aIRC
; * Built-in HTTP support
; *
; **********************************************************************/
alias _airchttp {
  var %sock,%n,%server = $1,%port = $2,%dirfile = $3,%localfile = $4,%resume = $5,%command = $6
  while (1) {
    inc %n
    %sock = http $+ %n
    if ($sock(%sock) == $null) { break }
  }
  .timer $+ %sock off
  sockopen HTTP $+ %n %server %port
  ; SOCKMARKS:
  ; 1- server
  ; 2- remote dir + file
  ; 3- local file
  ; 4- $ticks
  ; 5- Local file: 1-has been erased 0-has NOT been erased
  ; 6- 1-requested resume 0-resume NOT requested
  ; 7- 0-binary (downloading file) 1-first line 2-header
  ; 8- size of the file
  ; 9- size of the text
  ;10- 1-server support resumes 0-server doesn't support resumes
  ;11- port
  ;12- command handler
  ;13- numeric returned
  ;14- cache server
  ;15- loops
  sockmark %sock %server $+ $chr(9) $+ %dirfile $+ $chr(9) $+ %localfile $+ $chr(9) $+ $ticks $+ $chr(9) $+ 1 $+ $chr(9) $+ $iif(%resume,1,0) $+ $chr(9) $+ 1 $+ $chr(9) $+ 0 $+ $chr(9) $+ 0 $+ $chr(9) $+ 0 $+ $chr(9) $+ %port $+ $chr(9) $+ %command $+ $chr(9) $+ 0 $+ $chr(9) $+ $null $+ $chr(9) $+ 0
  var %alias = %command $+ .init
  if ($isalias(%alias)) { %alias HTTP $+ %n }
  return HTTP $+ %n
}
;  handler.init              sockname
;  handler.errsockopen       sockname
;  handler.errsockwrite      sockname
;  handler.errsockread       sockname
;  handler.errhttp           sockname errstring
;  handler.startget          sockname
;  handler.nohttp11          sockname
;  handler.noresumesupported sockname
;  handler.startresuming     sockname
;  handler.downloading       sockname
;  handler.sockclose         sockname
;
ON *:SOCKOPEN:HTTP*:{
  if ($sockerr) {
    var %alias = $_sockmark(12) $+ .errsockopen
    if ($isalias(%alias)) { %alias $sockname }
    return
  }
  var %tmp = $chr(37) $+ 20,%host = $iif($host,$host,$ip)
  sockwrite -n $sockname GET $replace($_sockmark(2),$chr(32),%tmp) HTTP/0.9
  sockwrite -n $sockname Accept: *.*, */*
  sockwrite -n $sockname User-Agent: aIRC/ $+ $_vers (compatible; Windows $os $+ ; $me $+ )
  if ($_sockmark(6)) && ($file($_sockmark(3)).size > 0) { sockwrite -n $sockname Range: bytes= $+ $file($_sockmark(3)).size $+ - }
  else { sockwrite -n $sockname Range: bytes=0- }
  sockwrite -n $sockname Host: $iif(%host,%host,$_sockmark(1))
  sockwrite -n $sockname Referrer: $_sockmark(1)
  sockwrite -n $sockname $crlf
}
ON *:SOCKWRITE:HTTP*:{
  if ($sockerr) {
    var %alias = $_sockmark(12) $+ .errsockwrite
    if ($isalias(%alias)) { %alias $sockname }
  }
}
ON *:SOCKREAD:HTTP*:{
  var %alias
  if ($sockerr) {
    %alias = $_sockmark(12) $+ .errsockread
    if ($isalias(%alias)) { %alias $sockname }
    return
  }
  while (1) {
    if ($_sockmark(7)) {
      var %sr
      sockread %sr
      tokenize 32 %sr
      if ($sockbr == 0) { return }
      if ($_sockmark(7) == 1) {
        if (http/* iswm $1-) {
          sockmark $sockname $puttok($sock($sockname).mark,$right($1,3),13,9)
          var %get = 0
          if (4?? iswm $2) || (5?? iswm $2) {
            %alias = $_sockmark(12) $+ .errhttp
            if ($isalias(%alias)) { %alias $sockname $1- }
            sockclose $sockname
            return
          }
          elseif ($2 == 206) {
            sockmark $sockname $puttok($sock($sockname).mark,1,10,9)
            inc %get
          }
          else {
            sockmark $sockname $puttok($sock($sockname).mark,0,10,9)
            inc %get
          }
          sockmark $sockname $puttok($sock($sockname).mark,2,7,9)
          if (%get) {
            %alias = $_sockmark(12) $+ .startget
            if ($isalias(%alias)) { %alias $sockname }
          }
        }
        else {
          %alias = $_sockmark(12) $+ .nohttp11
          if ($isalias(%alias)) { %alias $sockname }
          sockclose $sockname
          return
        }
      }
      elseif ($1 == Content-Length:) { sockmark $sockname $puttok($sock($sockname).mark,$2,8,9) }
      elseif (Location:* iswm $1-) {
        var %tmp = $remove($gettok($1-,2-,58),http://),%host,%port = 80,%get = /,%count = $calc($_sockmark(15) + 1)
        if (%count <= 2) {
          if (/ isin %tmp) { var %host = $gettok(%tmp,1,47),%get = / $+ $gettok(%tmp,2-,47) }
          else { var %host = %tmp,%get = / }
          if (: isin %host) { var %port = $gettok(%host,2,58),%host = $gettok(%host,1,58) }
          var %tmpsock = $_airchttp(%host,%port,%get,$_sockmark(3),0,$_sockmark(12))
          sockmark %tmpsock $puttok($sock(%tmpsock).mark,%count,15,9)
        }
        else { error.a HTTP looping! }
        sockclose $sockname
        return
      }
      elseif ($1- == $null) {
        if ($_sockmark(6)) {
          if ($_sockmark(10) == 0) && ($file($_sockmark(3)).size != $_sockmark(8)) { %alias = $_sockmark(12) $+ .noresumesupported }
          elseif ($_sockmark(10)) { %alias = $_sockmark(12) $+ .startresuming }
          if (%alias != $null) && ($isalias(%alias)) { %alias $sockname }
        }
        if ($_sockmark(5)) && ($isfile($_sockmark(3))) && ((($_sockmark(6)) && ($_sockmark(10) == 0)) || ($_sockmark(6) == 0)) {
          .remove " $+ $_sockmark(3) $+ "
          sockmark $sockname $puttok($sock($sockname).mark,0,5,9)
        }
        sockmark $sockname $puttok($puttok($puttok($sock($sockname).mark,0,7,9),$ticks,4,9),$sock($sockname).rcvd,9,9)
      }
    }
    else {
      sockread &sr
      if ($sockbr == 0) { return }
      bwrite " $+ $_sockmark(3) $+ " -1 &sr
      %alias = $_sockmark(12) $+ .downloading
      if ($isalias(%alias)) { %alias $sockname }
      .timer $+ $sockname -o 1 5 _airchttp.timeout $sockname
    }
    if ($sock($sockname) == $null) { break }
  }
}
alias -l _airchttp.timeout {
  if ($sock($1)) {
    var %left = $calc($_sockmark($1,8) - ($sock($1).rcvd - $_sockmark($1,9)))
    if (%left <= 0) {
      var %alias = $_sockmark($1,12) $+ .sockclose
      if ($isalias(%alias)) { %alias $1 }
      sockclose $1
    }
    else {
      ; shit! idle connection... wtf can we do now? we'll wait...
    }
  }
}
ON *:SOCKCLOSE:HTTP*:{
  var %alias = $_sockmark(12) $+ .sockclose
  if ($isalias(%alias)) { %alias $sockname }
}