aIRC — File Browser

aIRCv0.8.69 / aIRCv0.8.69 / script / dcc.mrc

dcc.mrc — 23.5 KB — Download this file

;/**********************************************************************
; *
; * aIRC
; * DCC
; *
; **********************************************************************/
;
alias _dcctotal.fserv {
  var %match = $1,%i = $fserv(0),%r = 0
  if (%match == $null) || (%match isin &*) { %match = & }
  while (%i) {
    if ($fserv(%i).status != inactive) && (%match iswm $fserv(%i)) { inc %r }
    dec %i
  }
  return %r
}
alias _dcctotal.chat {
  var %match = $1,%i = $chat(0),%r = 0
  if (%match == $null) || (%match isin &*) { %match = & }
  while (%i) {
    if ($chat(%i).status != inactive) && (%match iswm $chat(%i)) { inc %r }
    dec %i
  }
  return %r
}
alias _dcctotal.send {
  var %match = $1,%i,%r = 0,%win = @__WaitingforDCCSend
  if (%match == $null) || (%match isin &*) { %match = & }
  if (%match == &) {
    %i = $send(0)
    while (%i) {
      if ($send(%i).status != inactive) { inc %r }
      dec %i
    }
  }
  else {
    %i = $send(%match,0)
    while (%i) {
      if ($send(%match,%i).status != inactive) { inc %r }
      dec %i
    }
  }
  if ($window(%win)) {
    %match = %match ?*
    if ($fline(%win,%match,0)) { inc %r $ifmatch }
  }
  return %r
}
alias _dcctotal.get {
  var %match = $1,%i = $get(0),%r = 0
  if (%match == $null) || (%match isin &*) { %match = & }
  while (%i) {
    if ($get(%i).status != inactive) && (%match iswm $get(%i)) { inc %r }
    dec %i
  }
  return %r
}
; /_dccsend <nick> <filename>
; %var = $_dccsend(nick,filename)
;
; returns:
;
; $null         - sending...
; N             - queuing in pos N
; ERR_nofile    - file not found
; ERR_insend    - file already being sent to user
; ERR_inqueue   - file already in user queue
; ERR_maxQtotal - queue full
; ERR_maxQuser  - queue for user full
; ERR_maxStotal - send slots full
; ERR_maxSuser  - send slots for user full
; ERR_nocomchan - no common channels with user
;
;
alias _dccsend {
  var %queuefile = $_sendqueue.file,%file,%i,%ERR_maxStotal = 0,%ERR_maxSuser = 0,%win = @__WaitingforDCCSend

  ; ERR_nofile
  if ($isfile($2-) == $false) { return ERR_nofile }

  ; ERR_insend
  %i = $send($1,0)
  while (%i) {
    if ($send($1,%i).status != inactive) {
      %file = $send($1,%i).path $+ $send($1,%i).file
      if (%file == $2-) { return ERR_insend }
    }
    dec %i
  }
  if ($window(%win)) && ($fline(%win,$1-,0)) { return ERR_insend }

  ; ERR_inqueue
  var %queuel = $read -ns" $+ $1 $2- $+ " %queuefile
  if ($readn) { return ERR_inqueue }

  ; maxS* - max sends
  ; maxQ* - max queues

  var %currTsend = $_dcctotal.send(*),%currUsend = $_dcctotal.send($1)
  if (%currTsend >= $_getsetup(dcc,maxStotal)) { %ERR_maxStotal = 1 }
  if (%currUsend >= $_getsetup(dcc,maxSuser)) { %ERR_maxSuser = 1 }

  if (%ERR_maxStotal) || (%ERR_maxSuser) {
    if ($_getsetup(dcc,sendqueue)) {

      ; ERR_maxQtotal
      if ($_sendqueue.queues >= $_getsetup(dcc,maxQtotal)) { return ERR_maxQtotal }

      ; ERR_maxQuser
      if ($_sendqueue.queues($1) >= $_getsetup(dcc,maxQuser)) { return ERR_maxQuser }

      ; ERR_nocomchan
      if ($_getsetup(dcc,clearqueueonnochan)) && ($comchan($1,0) == 0) { return ERR_nocomchan }

      ; queuing in pos N
      write " $+ %queuefile $+ " $1-
      .timer_dccsendqueue -o 1 0 _sendqueue.sex
      return $_sendqueue.queues
    }

    ; ERR_maxStotal
    if (%ERR_maxStotal) { return ERR_maxStotal }

    ; ERR_maxSuser
    return ERR_maxSuser
  }
  _sendqueue.presend.add $1-
}

; /_sendqueue.presend.add <nick> <filename>
alias _sendqueue.presend.add {
  var %win = @__WaitingforDCCSend
  if ($isfile($2-) == $false) || ($_not($_connected)) || ($fline(%win,$1-,0)) { return }
  window -hl %win
  aline %win $1-
  if ($timer(_sendqueuepresendcheck) == $null) { .timer_sendqueuepresendcheck 1 5 _sendqueue.presend.check }
}
alias _sendqueue.presend.check {
  var %win = @__WaitingforDCCSend,%line
  if ($_not($_connected)) || ($window(%win) == $null) {
    close -@ %win
    return
  }
  if ($line(%win,0) != $null) {
    %line = $line(%win,1)
    dline %win 1
  }
  if ($line(%win,0) == 0) { close -@ %win }
  else { .timer_sendqueuepresendcheck 1 5 _sendqueue.presend.check }
  if (%line != $null) { _sendqueue.send %line }
}

; /_sendqueue.send <nick> <file>
alias _sendqueue.send {
  if ($isfile($2-) == $false) || ($_not($_connected)) { return }
  var %old = $send(0),%flags
  .timer_dccsendqueue -o 1 0 _sendqueue.sex
  if ($_getsetup(dcc,maxcps.state)) && ($_isint($_getsetup(dcc,maxcps.value))) { %flags = -l $+ $ifmatch }
  dcc send %flags $1-
  if (%old != $send(0)) { window -n "Send $1 $nopath($2-) $+ " }
  .timer_sendqueuepresendcheck 1 5 _sendqueue.presend.check
}

;;
; $_dcc.firstsendfree
; returns number of seconds to wait for a free send slot
; returns -1 if N/A
alias _dcc.firstsendfree {
  var %r = 0,%i = $send(0),%toks,%left,%cps,%lra,%sent,%size,%totalsends = $_dcctotal.send,%maxsends = $_getsetup(dcc,maxStotal),%toks,%z = 0
  if (%totalsends < %maxsends) { return 0 }
  if (%i) {
    while (%i) {
      if ($send(%i).status != inactive) {
        var %cps = $send(%i).cps,%lra = $send(%i).lra,%sent = $send(%i).sent,%size = $send(%i).size
        if (%cps isnum) { %toks = %toks $round($calc((%size - $iif(%lra isnum,%lra,%sent)) / %cps),0) }
        else { %toks = %toks N/A }
        inc %z
      }
      dec %i
    }
  }
  %i = $line(@__WaitingforDCCSend,0)
  while (%i) {
    %toks = %toks N/A
    inc %z
    dec %i
  }
  if (%z) { %left = $gettok($sorttok(%toks,32,n),$calc(%totalsends - %maxsends + 1),32) }
  if (%left == $null) || (%left == N/A) { %left = -1 }
  return $round(%left,0)
}
;;
; $_dcc.verbosefirstsendfree
;
alias _dcc.verbosefirstsendfree {
  var %tmp = $_dcc.firstsendfree
  if (%tmp == -1) { return N/A }
  if (%tmp == 0) { return NOW }
  return $remove($_duratio(%tmp),$chr(32))
}

;;
;
; /_dccsend.nowaiting [nick]
;   close all waiting dcc sends
alias _dccsend.nowaiting {
  var %n = $send(0),%i = 0,%m = $1,%win = @__WaitingforDCCSend
  if (%m == $null) || (%m isin &*) { %m = & }
  while (%n) {
    if (%m iswm $send(%n)) && ($send(%n).status == waiting) {
      close -s $+ %n
      inc %i
    }
    dec %n
  }
  if ($window(%win)) {
    %n = $line(%win,0)
    %m = %m ?*
    while (%n) {
      if (%m iswm $line(%win,%n)) {
        dline %win %n
        inc %i
      }
      dec %n
    }
  }
  return %i
}

;;
;
; /_dccsend.noinactive [nick]
;   close all inactive dcc sends
alias _dccsend.noinactive {
  var %n = $send(0),%i = 0,%m = *
  if ($1 != $null) { %m = $1 }
  while (%n) {
    if (%m iswm $send(%n)) && ($send(%n).status == inactive) {
      close -s $+ %n
      inc %i
    }
    dec %n
  }
  return %i
}

; $_dcc.totalcps(sg)
alias _dcc.totalcps {
  var %r = 0,%f = $1,%i
  if (%f == $null) { %f = sg }
  if (s isin %f) {
    %i = $send(0)
    while (%i) {
      if ($send(%i).status == active) && ($send(%i).cps isnum) { inc %r $ifmatch }
      dec %i
    }
  }
  if (g isin %f) {
    %i = $send(0)
    while (%i) {
      if ($get(%i).status == active) && ($get(%i).cps isnum) { inc %r $ifmatch }
      dec %i
    }
  }
  return %r
}

alias _sendqueue.file { return $_chfile($_tmpdir(send.queue)) }

;;
;
; $_sendqueue.nickhasqueues(nick)
alias _sendqueue.nickhasqueues {
  var %t = $read -ns $+ $1 " $+ $_sendqueue.file $+ "
  if (%t != $null) { return 1 }
  return 0
}

;;
;
; $_sendqueue.queues(nick|*)
alias _sendqueue.queues {
  var %file = $_sendqueue.file,%win = @__sendqueuetotal,%t
  if ($1 != *) && ($1 != $null) {
    %t = $read -ns $+ $1 %file
    if (%t == $null) { return }
  }
  if ($1 != $null) && ($1 != *) {
    _openwins %win
    filter -fw $"(%file) %win $1 *
    close -@ %win
    return $filtered
  }
  return $lines(%file)
}

;;
;
; $_sendqueue.pos(nick)
;
alias _sendqueue.pos {
  var %queuefile = $_sendqueue.file,%result,%win = @__sendqueuepos,%wc = $1 *,%i
  _openwins %win
  loadbuf %win %queuefile
  %i = $fline(%win,%wc,0)
  while (%i) {
    %result = $addtok(%result,$fline(%win,%wc,%i),44)
    dec %i
  }
  close -@ %win
  if (%result != $null) { return $sorttok(%result,44) }
}

; /_sendqueue.sex
alias _sendqueue.sex {
  var %queuefile = $_sendqueue.file,%maxStotal = $_getsetup(dcc,maxStotal),%maxSuser = $_getsetup(dcc,maxSuser),%win = @__sendqt,%t,%currentsends,%i,%dels = 0
  .timer_dccsendqueue off
  if ($_not($lines(%queuefile))) || ($_not($_connected)) { return }
  _dccsend.noinactive
  %currentsends = $_dcctotal.send(*)
  if (%currentsends >= %maxStotal) {
    _dccquemon.refresh
    .timer_dccsendqueue 1 10 _sendqueue.sex
    return
  }
  _openwins %win
  clear %win
  loadbuf %win " $+ %queuefile $+ "
  %i = 1
  while (%currentsends < %maxStotal) && ($line(%win,%i) != $null) {
    %t = $ifmatch
    if ($_dcctotal.send($gettok(%t,1,32)) < %maxSuser) {
      inc %currentsends
      inc %dels
      _sendqueue.presend.add %t
      dline %win %i
      break
    }
    inc %i
  }
  if ($line(%win,0)) { .timer_dccsendqueue 1 10 _sendqueue.sex }
  if (%dels) { savebuf %win " $+ %queuefile $+ " }
  close -@ %win
  _dccquemon.refresh
}
;;
;
; /dccqueue [<list|llist|send|cancel|flush> [*|nick|n1,n2-n3...] [file mask]]
;
alias dccqueue {
  _dccqueue $1-
  return $result
}
alias _dccqueue {
  if ($1- == $null) {
    dccquemon
    return DIALOG
  }
  var %qfile = " $+ $_sendqueue.file $+ ",%totalq = 0,%winm = @__queuequeuem,%winl = @__queuequeuel,%winr = @__queuequeuer,%close = close -@ %winm %winl %winr,%match = 0,%nick,%file,%nm = $2,%removed,%longnick = 0,%number,%echo = echo2 $colour(info) $_actwin(it) $^***,%longlist = 0
  _openwins %winm %winl %winr
  loadbuf %winm %qfile
  %totalq = $line(%winm,0)
  if ($1 == send) { %longlist = 1 }
  if ($1 == llist) {
    %longlist = 1
    tokenize 32 list $2-
  }
  if ($istok(list flush,$1,32)) || (($istok(cancel send,$1,32)) && ($2- != $null)) {
    if (%totalq == 0) {
      if ($show) { error.a There are no queue entries }
      %close
      return ERR_noqueues
    }
    if ($1 == flush) {
      write -c " $+ %qfile $+ "
      %close
      return FLUSH %totalq
    }
    if ($1 == send) && ($_not($_connected)) {
      if ($show) { error.a You are disconnected! }
      %close
      return ERR_disconnected
    }
    if ($remove(%nm,$chr(44),-) isnum) { %nm = $_range(%nm,100) }
    %i = 1
    %n = $line(%winm,0)
    if (%nm == $null) { %nm = * }
    while (%i <= %n) {
      %match = 0
      %nick = $gettok($line(%winm,%i),1,32)
      %file = $gettok($line(%winm,%i),2-,32)
      if (%nm == *) || (%nm == %nick) || (($_isint($remove(%nm,$chr(44)))) && ($istok(%nm,%i,44))) {
        if ($3- == $null) || ($3- iswm $nopath(%file)) { %match = 1 }
      }
      if (%match) && ($istok(list send,$1,32)) {
        if (%longlist) { aline %winl %i $line(%winm,%i) }
        else { aline %winl %i %nick $nopath(%file) }
      }
      elseif ($_not(%match)) && ($istok(cancel send,$1,32)) { aline %winr $line(%winm,%i) }
      if ($len(%nick) > %longnick) { %longnick = $ifmatch }
      inc %i
    }
    if ($1 == list) {
      %i = 1
      %n = $line(%winl,0)
      if (%n) {
        linesep $_actwin
        if (%n == %totalq) { %echo DCC Send Queue: }
        else { %echo DCC Send Queue: (showing %n of %totalq $+ , matching $2-3 $+ ) }
        inc %longnick
        %echo $_filleft(3, ,#) $_filleft(%longnick, ,Nick) File
        while (%i <= %n) {
          %number = $gettok($line(%winl,%i),1,32)
          %nick = $gettok($line(%winl,%i),2,32)
          %file = $gettok($line(%winl,%i),3-,32)
          %echo $_filleft(3, ,%number) $_filleft(%longnick, ,%nick) %file
          inc %i
        }
        %close
        return LIST
      }
      else {
        if ($show) { error.a No queues matching $^'($2-3) }
        %close
        return ERR_nomatch $2-3
      }
    }
    elseif ($1 == send) {
      if ($line(%winl,0)) {
        var %sending = $line(%winl,0),%i = 1,%currsends = $_dcctotal.send(*),%maxsends = $_getsetup(dcc,maxStotal),%fsends = %sending + %currsends,%tmpsendtext
        if (%fsends > %maxsends) {
          if (%sending == 1) { %tmpsendtext = Do you want to DCC send this waiting queue? }
          else { %tmpsendtext = Do you want to DCC send these %senfing waiting queues? }
          %tmpsendtext = %tmpsendtext $+ <CRLF>[The dcc send count will be %fsends $+ / $+ %maxsends $+ ]
          if ($_not($_yesno(1,DCC Queue [/dccqueue],1,%tmpsendtext))) { return ERR_SENDCANCELLED }
        }
        while (%i <= %sending) {
          _sendqueue.presend.add $gettok($line(%winl,%i),2-,32)
          inc %i
        }
        savebuf %winr %qfile
        if ($show) { info.a Sending $_nsingoplur(%sending,file,files) from the queue }
        %close
        _dccquemon.refresh
        return SEND %sending
      }
      else {
        if ($show) { error.a No queues matching $^'($2-3) }
        %close
        return ERR_nomatch $2-3
      }
    }
    else {
      %removed = $calc(%n - $line(%winr,0))
      savebuf %winr %qfile
      if ($show) { info.a Removed $_nsingoplur(%removed,file,files) from the send queue }
      %close
      _dccquemon.refresh
      return CANCEL %removed
    }
  }
  else {
    if ($show) { error.a Syntax: /dccqueue [<list|llist|send|cancel|flush> [*|nick|n1,n2-n3...] [file mask]] }
    %close
    return ERR_syntax
  }
  %close
  return ERR_QUECARAJO?
}
;;
;
; /dccminspeed [kb/s]
;   sets the minspeed for DCC sends
;   0 to disable
;
alias dccminspeed {
  _dccminspeed $1-
  return $result
}
alias _dccminspeed {
  var %line,%s,%n
  if ($1 isnum) && ($1 >= 0) {
    if ($1 == 0) { _setsetup dcc minspeed_s 0 }
    else {
      _setsetup dcc minspeed_s 1
      _setsetup dcc minspeed_n $1
    }
  }
  %n = $_getsetup(dcc,minspeed_n)
  if (%n !isnum) || (%n < 0.1) { _setsetup dcc minspeed_n 0.1 }
  var %s = $_getsetup(dcc,minspeed_s),%n = $_getsetup(dcc,minspeed_n)
  %line = DCC Send Minspeed is $iif(%s,ON,Off)
  if (%s) { %line = %line ( $+ %n kb/s) }
  if ($show) { info.a %line }
  return %s %n
}
alias _dcc.checkminspeed {
  var %min = $_dcc.minspeed,%i,%n,%file,%nick
  if (%min)  {
    %min = %min * 1024
    %i = $send(0)
    while (%i) {
      if ($send(%i).status == inactive) { close -s $+ %i }
      elseif ($send(%i).status == active) && ($send(%i).secs > 10) && ($send(%i).cps < %min) {
        %file = $nopath($send(%i).file)
        %nick = $send(%i)
        _puthelp %nick & _qnotice %nick Autoclosing slow DCC Send: ' $+ %file $+ ' (require $_size(%min) $+ /s - got $_size($send(%i).cps) $+ /s $+ )
        info.a Autoclosing slow DCC Send: ' $+ %file $+ ' to %nick (require $_size(%min) $+ /s - got $_size($send(%i).cps) $+ /s $+ )
        close -s $+ %i
      }
      dec %i
    }
  }
}
alias _dcc.minspeed {
  var %min
  if ($_getsetup(dcc,minspeed_s)) {
    %min = $_getsetup(dcc,minspeed_n)
    if (%min isnum) && (%min > 0)  {
      return $_round(%min,3)
    }
  }
  return 0
}
alias _sendqueue.gcheck {
  var %file = $_sendqueue.file,%win = @__sendqueuetotal,%t,%i
  _openwins %win
  filter -fw $"(%file) %win *
  while ($line(%win,0)) {
    _sendqueue.check $gettok($line(%win,1),1,32) 1
    dline %win 1
  }
  close -@ %win
  _sendqueue.sex
}
alias _sendqueue.check {
  if ($1 == $me) { return }
  if ($comchan($1,0) == 0) && ($_sendqueue.nickhasqueues($1)) {
    if ($_sendqueue.removenick($1,*)) {
      var %n = $ifmatch
      info.a Cancelled $^b(%n) queued $_singoplur(%n,file,files) to $^b($1) (no common channels)
    }
  }
  if ($_not($2)) { _sendqueue.sex }
}
; /_sendqueue.changenick <oldnick> <newnick>
alias _sendqueue.changenick {
  var %file = $_sendqueue.file,%win = @__sendqueuechangenick,%i,%r = 0,%mods = 0
  _openwins %win
  loadbuf %win $"(%file)
  %i = $line(%win,0)
  if (%i) {
    if ($gettok($line(%win,%i),1,32) == $1) {
      rline %win %i $2 $line(%win,%i),2-,32)
      inc %r
      inc %mods
    }
    dec %i
  }
  if (%mods) { savebuf %win $"(%file) }
  close -@ %win
  return %r
}

; /_sendqueue.removenick <nick> [only files matching this|number]
alias _sendqueue.removenick {
  var %file = $_sendqueue.file,%win = @__sendqueueremovenick,%i,%n,%r = 0,%wc = *,%nfile = 0,%dels = 0
  if ($2- != $null) { %wc = $ifmatch }
  _openwins %win
  loadbuf %win $"(%file)
  if ($remove(%wc,$chr(44),-) isnum) { %wc = $_range(%wc,$line(%win,0)) }
  %i = 1
  while (%i <= $line(%win,0)) {
    if ($gettok($line(%win,%i),1,32) == $1) {
      inc %nfile
      if (%wc iswm $gettok($line(%win,%i),2-,32)) || (($_isint($remove(%wc,$chr(44)))) && ($istok(%wc,%nfile,44))) {
        dline %win %i
        inc %dels
        dec %i
        inc %r
      }
    }
    inc %i
  }
  if (%dels) {
    savebuf %win $"(%file)
    _dccquemon.refresh
  }
  close -@ %win
  return %r
}
; /_nickqueue2win [-in] <window> <nick> [only files matching this]
;  -n = nopath
;  -i = include nick on list
alias _nickqueue2win {
  var %flags
  if (-* iswm $1) {
    %flags = $1
    tokenize 32 $2-
  }
  var %rwin = $1,%nick = $2,%match = *,%twin = @__nickqueue2win,%i,%n,%file
  if ($3- != $null) { %match = $ifmatch }
  if ($window(%rwin) == $null) { _openwins %rwin %twin }
  else { _openwins %twin }
  filter -fw " $+ $_sendqueue.file $+ " %twin $2 *
  %i = 1
  %n = $line(%twin,0)
  while (%i <= %n) {
    var %line = $line(%twin,%i),%tnick = $gettok(%line,1,32),%file = $gettok(%line,2-,32)
    if (i !isin %flags) { var %tnick }
    if (%match iswm %file) {
      if (n isin %flags) { aline %rwin %tnick $nopath(%file) }
      else { aline %rwin %tnick %file }
    }
    inc %i
  }
  close -@ %twin
  return %n
}
alias dccquemon { _dialog -m _dccquemon _dccquemon }
dialog _dccquemon {
  size -1 -1 154 87
  option dbu
  title "DCC Queue Monitor [/dccqueue]"

  list 1003,5 5 30 63,size

  box "",1101,38 2 112 38
  box "",1102,38 2 112 65
  text "Nick:",1103,42 12 12 8
  edit "",1104,56 10 90 10,autohs read
  text "File:",1105,42 27 12 8
  edit "",1106,56 25 90 10,autohs read
  button "&Up",1107,42 42 24 10
  button "&Down",1108,68 42 24 10
  button "&Top",1109,94 42 24 10
  button "&Bottom",1110,120 42 24 10
  button "&Remove",1111,68 54 24 10
  button "&Send",1112,94 54 24 10

  button "&Flush!",2990,56 70 30 15
  button "&Help",2991,88 70 30 15,disable
  button "&Close",2992,120 70 30 15,cancel
}
ON *:DIALOG:_dccquemon:init:0:{
  _mdx.init $_icofile(dccquemon.ico)
  _dccquemon.refresh -l -
  _dummy $_lang.loaddialog($dname,$dname,00086969,main.lang,$scriptdir)
}
ON *:DIALOG:_dccquemon:sclick:1003:{ _dccquemon.refresh - - }
ON *:DIALOG:_dccquemon:sclick:1107,1108,1109,1110:{ _dccquemon.move $did }
ON *:DIALOG:_dccquemon:sclick:1111:{
  if ($did($dname,1003,1).sel) && ($_yesno(1,DCC Queues [/dccqueue],1,Remove this queue?)) { dccqueue cancel $did($dname,1003,1).sel }
}
ON *:DIALOG:_dccquemon:sclick:1112:{
  if ($did($dname,1003,1).sel) { dccqueue send $ifmatch }
}
ON *:DIALOG:_dccquemon:sclick:2990:{
  if ($_yesno(1,DCC Queues [/dccqueue],1,Remove all queues?)) {
    write -c $"($_sendqueue.file)
    _dccquemon.refresh - -
  }
}
alias -l _dccquemon.move {
  var %d = $dname,%sel = $did(%d,1003,1).sel,%old,%new,%line,%qfile,%total
  if (%sel) {
    _dccquemon.refresh - %sel
    %total = $did(%d,1003).lines
    if (%sel <= %total) {
      %qfile = $_sendqueue.file
      %old = %sel
      if ($1 == 1107) { %new = %old - 1 }
      elseif ($1 == 1108) { %new = %old + 1 }
      elseif ($1 == 1109) { %new = 1 }
      elseif ($1 == 1110) { %new = %total }
      else { return }
      if (%new < 1) { %new = 1 }
      if (%new > %total) { %new = %total }
      if (%old != %new) {
        %line = $read -nl $+ %sel " $+ %qfile $+ "
        write -dl $+ %old " $+ %qfile $+ "
        write -il $+ %new " $+ %qfile $+ " %line
        _dccquemon.refresh - %new
      }
    }
  }
}
alias -l _dccquemon.refresh {
  var %d = _dccquemon,%flags = $1,%sel = $2,%nums,%tmp,%z
  if ($dialog(%d) == $null) { return }
  var %qfile = $_sendqueue.file,%total = $lines(%qfile)
  if (%sel !isnum) { %sel = $did(%d,1003,1).sel }
  if (%total != $did(%d,1003).lines) {
    %nums = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
    did -r %d 1003
    if (%total) {
      %tmp = 1- $+ %total
      didtok %d 1003 32 $gettok(%nums,%tmp,32)
      if (%total > $numtok(%nums,32)) {
        var %i = $numtok(%nums,32) + 1
        while (%i <= %total) {
          did -a %d 1003 %i
          inc %i
        }
      }
    }
  }
  if (%sel isnum) {
    %sel = $round(%sel,0)
    if (%sel < 1) { %sel = 1 }
    if (%sel > %total) { %sel = %total }
    if (%sel) { did -c %d 1003 %sel }
  }
  %sel = $did(%d,1003,1).sel
  if (%sel) { %z = $read -nl $+ %sel " $+ %qfile $+ " }
  if (%z != $null) {
    did -o %d 1104 1 $gettok(%z,1,32)
    did -o %d 1106 1 $gettok(%z,2-,32)
    did -e %d 1103,1104,1105,1106,1107,1108,1109,1110,1111,1112
  }
  else {
    did -r %d 1104,1106
    did -b %d 1103,1104,1105,1106,1107,1108,1109,1110,1111,1112
  }
  did $iif(%total,-e,-b) %d 2990
}
ON *:NICK:{
  if ($_sendqueue.nickhasqueues($nick)) {
    _sendqueue.changenick $nick $newnick
    .timer_dccsendqueue -o 1 0 _sendqueue.sex
  }
}
raw 401:* No such nick*:{
  var %m = $2 *
  if (($send($2,0)) || ($fline(@__WaitingforDCCSend,%m,0))) && ($_getsetup(dcc,cancelwsendsonnosuch)) {
    if ($_dccsend.nowaiting($2)) {
      var %n = $ifmatch
      info.a Cancelled $^b(%n) waiting DCC $_singoplur(%n,Send,Sends) to $^b($2) (no such nick)
    }
  }
  .timer_dccsendqueue -o 1 0 _sendqueue.sex
}
ON *:QUIT:{
  var %m = $nick *
  if (($send($nick,0)) || ($fline(@__WaitingforDCCSend,%m,0))) && ($_getsetup(dcc,cancelwsendsonnosuch)) {
    if ($_dccsend.nowaiting($nick)) {
      var %n = $ifmatch
      info.a Cancelled $^b(%n) waiting DCC $_singoplur(%n,Send,Sends) to $^b($nick) (quit)
    }
  }
  if (($_getsetup(dcc,clearqueueonnochan))) { .timer_sendqueue.check $+ $nick -o 1 3 _sendqueue.check $nick }
}
ON *:PART:#:{
  if (($_getsetup(dcc,clearqueueonnochan))) {
    if ($nick == $me) { .timer_sendqueue.gcheck $+ $nick -o 1 3 _sendqueue.gcheck $nick }
    else { .timer_sendqueue.check $+ $nick -o 1 3 _sendqueue.check $nick }
  }
}
ON *:KICK:#:{
  if (($_getsetup(dcc,clearqueueonnochan))) {
    if ($knick == $me) { .timer_sendqueue.gcheck $+ $knick -o 1 3 _sendqueue.gcheck $knick }
    else { .timer_sendqueue.check $+ $knick -o 1 3 _sendqueue.check $knick }
  }
}
ON *:CONNECT:{
  close -@ @__WaitingforDCCSend
  .timer_dccsendqueue -o 1 0 _sendqueue.sex
}
ON *:DISCONNECT:{
  close -@ @__WaitingforDCCSend
  if ($_getsetup(dcc,cancelqueuesondisconnect)) {
    if ($_sendqueue.queues(*)) { info.a Clearing DCC Queue (disconnected) }
    write -c $"($_sendqueue.file)
    _dccquemon.refresh - -
  }
}
ON *:SENDFAIL:*:{ .timer_dccsendqueue -o 1 0 _sendqueue.sex }
ON *:FILESENT:*:{ .timer_dccsendqueue -o 1 0 _sendqueue.sex }