Peace & Protection 4.00 — File Browser

PeaceProtection4.00v4.0 / PeaceProtection4.00v4.0 / ADDONS / XDCC.MRC

XDCC.MRC — 15.24 KB — Download this file

; #= ppxdcc -rs
; ########################################
; Peace & Protection
; XDCC (standard addon)
; ########################################

;;; second version- multiple pack sets, copy/move between, select for diff groups of users, passwords
;;; second version- allow LIST N to get file list of one pack
;;; /xdcc add/del/etc?
;;; saving/loading/deleting of 'presets'? more presets?

; Section one- Pack editing
dialog xdcc {
  title "XDCC Pack Setup"
  size -1 -1 400 270

  box "Select a pack...", 1, 8 8 180 210
  list 2, 18 28 160 150, extsel

  button "Add...", 3, 18 186 48 21
  button "Copy", 4, 73 186 48 21, disable
  button "Remove", 5, 128 186 50 21, disable

  box "... then edit file(s)", 21, 198 8 180 210
  list 6, 208 28 160 70, extsel disable

  button "Add...", 7, 208 95 48 21, disable
  button "Edit...", 8, 263 95 48 21, disable
  button "Remove", 9, 318 95 50 21, disable

  text "Description of pack:", 26, 206 138 150 16
  edit "", 10, 207 155 160 22, autohs disable

  text "Total requests:", 28, 206 190 80 16
  text "n/a", 29, 286 190 40 16
  button "Reset", 11, 326 186 40 21, disable

  edit "", 200, 1 1 1 1, hide

  button "Done", 100, 18 233 80 25, OK default
}
on *:DIALOG:xdcc:init:*:{
  did -o $dname 10 1 (no packs selected)
  var %line,%pack = 1,%file = $_cfg(xdcc.dat)
  if ($exists(%file) == $false) return
  :loop
  %line = $read -nl [ $+ [ %pack ] ] %file
  if ($gettok(%line,1,9)) {
    did -a $dname 2 [[ $+ %pack $+ ]] $ifmatch
    inc %pack | goto loop
  }
}
on *:DIALOG:xdcc:sclick:2:{
  _xdccsave
  if ($did(2,0).sel == 0) {
    did -b $dname 4,5,6,7,8,9,10,11
    did -r $dname 6
    did -o $dname 10 1 (no packs selected)
    did -o $dname 29 1 n/a
  }
  elseif ($did(2,0).sel > 1) {
    did -b $dname 4,6,7,8,9,10
    did -e $dname 5
    did -r $dname 6
    did -o $dname 10 1 ( $+ $did(2,0).sel packs selected)
    var %line,%where = 1,%total = 0,%file = $_cfg(xdcc.dat)
    :loopc
    %line = $read -nl [ $+ [ $did(2,%where).sel ] ] %file
    inc %total $gettok(%line,2,9)
    if (%where < $did(2,0).sel) { inc %where | goto loopc }
    did -o $dname 29 1 %total
    did $iif(%total,-e,-b) $dname 11
  }
  else {
    did -e $dname 4,5,6,7,10
    did -b $dname 8,9
    var %num = 3,%line = $read -nl [ $+ [ $did(2,1).sel ] ] $_cfg(xdcc.dat)
    did -o $dname 10 1 $gettok($did(2,$did(2,1).sel),2-,32)
    did -o $dname 29 1 $gettok(%line,2,9)
    did $iif($gettok(%line,2,9),-e,-b) $dname 11
    did -r $dname 6
    :loopf
    if ($gettok(%line,%num,9)) {
      did -a $dname 6 $ifmatch
      inc %num | goto loopf
    }
  }
}
on *:DIALOG:xdcc:sclick:3:{
  _xdccsave
  did -ac $dname 2 [[ $+ $calc($did(2).lines + 1) $+ ]] (empty)
  write $_cfg(xdcc.dat) (empty)	0
  did -e $dname 4,5,6,7,10
  did -b $dname 8,9,11
  did -o $dname 29 1 0
  did -r $dname 6
  did -rf $dname 10
  _juryrig2 _xdcced 1
}
on *:DIALOG:xdcc:sclick:4:{
  _xdccsave
  did -ac $dname 2 [[ $+ $calc($did(2).lines + 1) $+ ]] $did(10) (copy)
  did -b $dname 11
  did -o $dname 29 1 0
  did -of $dname 10 1 $did(10) (copy)
  did -o $dname 200 1 $did(2,1).sel
  _xdccsave
}
on *:DIALOG:xdcc:sclick:5:{
  did -r $dname 200
  var %file = $_cfg(xdcc.dat)
  :loopr
  if ($did(2,1).sel) {
    did -d $dname 2 $ifmatch
    write -dl [ $+ [ $ifmatch ] ] %file
    goto loopr
  }
  did -b $dname 4,5,6,7,8,9,10,11
  did -r $dname 6
  did -o $dname 10 1 (no packs selected)
  did -o $dname 29 1 n/a
  did -f $dname 2
  var %num = $did(2).lines
  :loopn
  if (%num) {
    did -o $dname 2 %num [[ $+ %num $+ ]] $gettok($did(2,%num),2-,32)
    dec %num | goto loopn
  }
}
on *:DIALOG:xdcc:sclick:6:{
  if ($did(6,0).sel == 0) did -b $dname 8,9
  elseif ($did(6,0).sel > 1) { did -b $dname 8 | did -e $dname 9 }
  else did -e $dname 8,9
}
on *:DIALOG:xdcc:dclick:6:_juryrig2 _xdcced $did(6,1).sel
on *:DIALOG:xdcc:sclick:7:_juryrig2 _xdcced $calc($did(6).lines + 1)
on *:DIALOG:xdcc:sclick:8:_juryrig2 _xdcced $did(6,1).sel
on *:DIALOG:xdcc:sclick:9:{
  did -o $dname 200 1 $did(2,1).sel
  :loop | if ($did(6,1).sel) { did -d $dname 6 $ifmatch | goto loop }
  did -f $dname 6
  did -b $dname 8,9
}
on *:DIALOG:xdcc:edit:10:did -o $dname 200 1 $did(2,1).sel | did -oc $dname 2 $did(2,1).sel $gettok($did(2,$did(2,1).sel),1,32) $did(10)
on *:DIALOG:xdcc:sclick:11:{
  if ($did(2,0).sel > 1) {
    var %line,%num = 1,%file = $_cfg(xdcc.dat)
    :loopr
    if ($did(2,%num).sel) {
      %line = $read -nl [ $+ [ $ifmatch ] ] %file
      write -l [ $+ [ $ifmatch ] ] %file $puttok(%line,0,2,9)
      inc %num | goto loopr
    }
  }
  else did -o $dname 200 1 $did(2,1).sel
  did -o $dname 29 1 0
  did -b $dname 11
}
on *:DIALOG:xdcc:sclick:100:_xdccsave
alias _xdcced {
  var %old = $did(xdcc,6,$1)
  if (%old == $null) %old = $_dlgi(xdccpack)
  if (%old == $null) %old = $mircdir
  var %new = $$dir="Select pack file:" %old
  _dlgw xdccpack $nofile(%new)
  did -o xdcc 200 1 $did(xdcc,2,1).sel
  if ($did(xdcc,6).lines == 0) {
    did -fo xdcc 10 1 $gettok($nopath(%new),1,46)
    did -oc xdcc 2 $did(xdcc,2,1).sel $gettok($did(xdcc,2,$did(xdcc,2,1).sel),1,32) $did(xdcc,10)
  }
  did -oc xdcc 6 $1 %new
  did -e xdcc 8,9
  dialog -v xdcc
}
alias -l _xdccsave {
  if ($did(200) !isnum) return
  var %num = 1,%curr = $did(10)
  if (%curr == $null) %curr = (empty)
  %curr = %curr $+ 	 $+ $did(29)
  :loop
  if ($did(6,%num)) {
    %curr = %curr $+ 	 $+ $ifmatch
    inc %num | goto loop
  }
  write -l [ $+ [ $did(200) ] ] $_cfg(xdcc.dat) %curr
  did -r $dname 200
}

; Section two- Other options
dialog xdcccfg {
  title "XDCC Options"
  size -1 -1 300 315

  check "Enable XDCC:", 1, 10 10 100 16
  text "Presets:", 11, 120 10 40 16
  combo 12, 162 6 100 100, drop
  box "", 2, 10 30 280 235
  text "First line of advertise / LIST: (optional)", 3, 20 50 250 16
  edit "", 4, 20 68 260 22
  text "Packet (middle) lines of advertise / LIST:", 5, 20 95 250 16
  edit "", 6, 20 113 260 22
  text "Last line of advertise / LIST: (optional)", 7, 20 140 250 16
  edit "", 8, 20 158 260 22
  text "Single line advertise:", 9, 20 185 250 16
  edit "", 10, 20 203 260 22
  text "Show XDCC requests:", 13, 20 235 110 16
  combo 14, 130 231 130 100, drop

  button "OK", 100, 10 278 80 25, OK default
  button "Cancel", 101, 110 278 80 25, cancel
  button "Help", 102, 210 278 80 25, disable
}
on *:DIALOG:xdcccfg:init:*:{
  loadbuf -otxdcctarg $dname 14 " $+ $scriptdirxdcc.ppa"
  if ($_cfgx(xdcc,enable)) did -c $dname 1
  else did -b $dname 3,4,5,6,7,8,9,10,13,14
  did -o $dname 4 1 $_readprep($_cfgx(xdcc,ad-pre))
  did -o $dname 6 1 $_readprep($_cfgx(xdcc,ad-mid))
  if ($did(6) == $null) did -o $dname 6 1 [&num&] &desc& - &size& (&request& d/ls)
  did -o $dname 8 1 $_readprep($_cfgx(xdcc,ad-post))
  did -o $dname 10 1 $_readprep($_cfgx(xdcc,ad-line))
  did -c $dname 14 $findtok(* -si2 @XDCC hide,$_cfgx(xdcc,route),32)
  did -a $dname 12 Minimal
  did -a $dname 12 Basic
  did -a $dname 12 Colorful
}
on *:DIALOG:xdcccfg:sclick:1:did $iif($did(1).state,-e,-b) $dname 3,4,5,6,7,8,9,10,13,14
on *:DIALOG:xdcccfg:edit:*:did -u $dname 12
on *:DIALOG:xdcccfg:sclick:12:{
  goto $did(12)
  :Minimal
  did -r $dname 4,8
  did -o $dname 6 1 [&num&] &desc& - &size& (&request& d/ls)
  did -o $dname 10 1 &total& XDCC packs available (&request& d/ls) Use XDCC LIST to request a list
  return
  :Basic
  did -o $dname 4 1 &total& packs available: (&request& total dls)
  did -o $dname 6 1 [&num&]: &desc& / &size& / &request& dls
  did -o $dname 8 1 Use XDCC GET # to request a pack
  did -o $dname 10 1 &total& XDCC packs available (&request& total dls) Use XDCC LIST to request a list
  return
  :Colorful
  did -o $dname 4 1 &col1&&total& packs available:
  did -o $dname 6 1 [&col1&&num&] &col2&&desc& - &size& (&request& d/ls)
  did -o $dname 8 1 Use &col1&XDCC GET # to request a pack
  did -o $dname 10 1 &col1&&total& XDCC packs available - Use &col2&XDCC LIST to request a list
  return
}
on *:DIALOG:xdcccfg:sclick:100:{
  _cfgxw xdcc enable $did(1).state
  _cfgxw xdcc ad-pre $_writeprep($did(4))
  _cfgxw xdcc ad-mid $_writeprep($did(6))
  _cfgxw xdcc ad-post $_writeprep($did(8))
  _cfgxw xdcc ad-line $_writeprep($did(10))
  _cfgxw xdcc route $gettok(* -si2 @XDCC hide,$did(14).sel,32)
}

; Section three- CTCP/msg receipt and reply
ctcp *:XDCC:*:_xdcc $2- | if ($result) { <ctcp.other3> $nick $address $1- | halt }
on ^*:OPEN:?:XDCC *:_xdcc $2-
on ^*:TEXT:XDCC *:?:_xdcc $2-
alias -l _xdcc {
  if ($_not($_cfgx(xdcc,enable))) return
  if ($1 == LIST) { _xdccfloodp 6 | _sendad _qnotice $nick }
  elseif ((($1 == GET) || ($1 == SEND)) && ($2- isnum)) { _xdccfloodp 2 | _xdccsend $nick $2 }
  elseif (($1 == GET) || ($1 == SEND)) { _xdccfloodp 2 | _linedance _qnotice $nick Usage: XDCC $upper($1) N (where N is the pack number to be sent) }
  elseif ($1 == HELP) { _xdccfloodp 4 | _linedance _qnotice $nick Use XDCC LIST to get a listing of offered packs (files) | _linedance _qnotice $nick Use XDCC GET N to get a pack, where N is the pack number to be sent }
  elseif ($1 == CANCEL) { _xdccfloodp 2 | _cancel.dcc $nick | if ($result) _linedance _qnotice $nick $result queued files to you have been canceled | else _linedance _qnotice $nick No files are currently queued for you }
  else return 0
  ; display
  var %to = $_cfgx(xdcc,route)
  if (%to == *) return 1
  if ((%to == @XDCC) && ($window(@XDCC) == $null)) _window 1 -n + @XDCC -1 -1 -1 -1 @XDCC
  var %say = XDCC request from $:s($nick) $+ : $1-
  _win.log @XDCC %say
  if (%to == hide) halt
  dispr %to %say
  halt
}
alias -l _xdccfloodp {
  if (%-xdccfl. [ $+ [ $site ] ] >= 7) halt
  inc -z %-xdccfl. $+ $site $1
  if (%-xdccfl. [ $+ [ $site ] ] >= 7) {
    inc -z %-dccfl. $+ $site 30
    _linedance _qnotice $nick Sorry, you are now being ignored for 30 seconds for too many requests.
    halt
  }
}
alias -l _xdccsend {
  var %file,%valid = 0,%num = 3,%line = $read -nl [ $+ [ $2 ] ] $_cfg(xdcc.dat)
  if ($numtok(%line,9) < 3) _linedance _qnotice $1 Sorry, there is no pack number $2
  else {
    :loop
    %file = $gettok(%line,%num,9)
    if (%file) {
      _send.dcc $1 $ifmatch
      if ($result >= 0) %valid = 1
      if ($result > 0) _linedance _qnotice $1 Too many transfers- File ' $+ $nopath(%file) $+ ' has been queued; Queue position- $result
      elseif ($result == -4) _linedance _qnotice $1 Error sending ' $+ $nopath(%file) $+ '
      elseif ($result == -5) _linedance _qnotice $1 ' $+ $nopath(%file) $+ ' is already queued to be sent to you
      elseif ($result == -6) _linedance _qnotice $1 ' $+ $nopath(%file) $+ ' is already being sent to you
      elseif ($result < 0) _linedance _qnotice $1 Cannot send ' $+ $nopath(%file) $+ ' - Too many transfers
      inc %num | goto loop
    }
    if (%valid) write -l [ $+ [ $2 ] ] $_cfg(xdcc.dat) $puttok(%line,$calc(1 + $gettok(%line,2,9)),2,9)
  }
}

; Section four- Advertising
alias -l _sendad {
  var %fname,%num,%size,%line,%where = 1,%total = 0,%file = $_cfg(xdcc.dat),%mid = $_readprep($_cfgx(xdcc,ad-mid))
  if (%mid == $null) %mid = [&num&] &desc& - &size& (&request& d/ls)
  :loopc
  %line = $read -nl [ $+ [ %where ] ] %file
  if (%line) {
    inc %total $gettok(%line,2,9)
    inc %where | goto loopc
  }
  var %packs = $lines(%file),%where = 1
  if ($_readprep($_cfgx(xdcc,ad-pre))) _linedance $1-2 $_finalmsg($replace($_premsg($ifmatch),&nick&,$2,&total&,%packs,&request&,%total))
  :loopa
  %line = $read -nl [ $+ [ %where ] ] %file
  if (%line) {
    ; &desc& &size& &count& &file& &request& &num& &nick&
    ; &file& is (x files) if multiple &count& is 1 or more
    if ($numtok(%line,9) > 2) {
      %size = 0 | %num = 3
      :loopf
      if ($gettok(%line,%num,9)) { if ($exists($ifmatch)) inc %size $lof($gettok(%line,%num,9)) | inc %num | goto loopf }
      if (%num == 4) %fname = $gettok(%line,3,9)
      else %fname = ( $+ $calc($numtok(%line,9) - 2) files)
      _linedance $1-$2 $_finalmsg($replace($_premsg(%mid),&nick&,$2,&total&,%packs,&request&,$gettok(%line,2,9),&desc&,$gettok(%line,1,9),&file&,%fname,&size&,$_size(%size),&num&,%where))
    }
    inc %where | goto loopa
  }
  if ($_readprep($_cfgx(xdcc,ad-post))) _linedance $1-$2 $_finalmsg($replace($_premsg($ifmatch),&nick&,$2,&total&,%packs,&request&,%total))
}

alias -l _shortad {
  var %line,%where = 1,%total = 0,%file = $_cfg(xdcc.dat)
  var %ad = $_readprep($_cfgx(xdcc,ad-line))
  if (%ad == $null) %ad = &total& XDCC packs available (&request& d/ls) Use XDCC LIST to request a list
  :loopc
  %line = $read -nl [ $+ [ %where ] ] %file
  if (%line) {
    inc %total $gettok(%line,2,9)
    inc %where | goto loopc
  }
  var %packs = $lines(%file)
  return $_finalmsg($replace($_premsg(%ad),&nick&,$1,&total&,%packs,&request&,%total))
}

; Section five- popups and /xdcc
alias -l _validact if (($chr(32) !isin $active) && (@* !iswm $active)) return $1-
menu menubar {
  XDCC
  .$_dynpop($_cfgx(xdcc,enable)) XDCC enabled:xdcc on
  .$_dynpopn($_cfgx(xdcc,enable)) XDCC disabled:xdcc off
  .-
  .$_validact(Send full list to,$replace($active,&,&&)):xdcc list $active
  .$_validact(Send ad to,$replace($active,&,&&)):xdcc ad $active
  .-
  .$_validact($iif($timer(.xdccad) == $null,Timered ad to,$replace($active,&,&&))):xdcc timer $_entry(-2,15,Send XDCC ad how often? (in minutes)) $active
  .$_validact($iif($timer(.xdccad) == $null,Timered ad to all channels)):xdcc timer $_entry(-2,15,Send XDCC ad how often? (in minutes)) all
  .$iif($timer(.xdccad),Disable timered ad):xdcc timer off
  .-
  .$iif($window(@DCCQueue).state == hidden,View queue):window -aw @DCCQueue
  .-
  .Pack setup...:xdcc edit
  .XDCC options...:xdcc cfg
  .DCC queue options...:dcc queue
}
alias xdcc {
  if ($1 == on) {
    dispa XDCC enabled.
    _cfgxw xdcc enable 1
  }
  elseif ($1 == off) {
    dispa XDCC disabled.
    _cfgxw xdcc enable 0
  }
  elseif ($1 == list) {
    if ($2) var %targ = $2
    else var %targ = $active
    if (($chr(32) isin %targ) || (@* iswm %targ)) _error Cannot send an XDCC list to that window
    if (%targ == all) _sendad amsg *
    else _sendad msg %targ
  }
  elseif ($1 == ad) {
    if ($2) var %targ = $2
    else var %targ = $active
    if (($chr(32) isin %targ) || (@* iswm %targ)) _error Cannot send an XDCC ad to that window
    if (%targ == all) amsg $_shortad(*)
    else msg %targ $_shortad(%targ)
  }
  elseif ($1 == timer) {
    if ($2 !isnum) {
      .timer.xdccad off
      dispa XDCC ad timer disabled.
    }
    else {
      if ($3) var %targ = $3
      else var %targ = $active
      if (($chr(32) isin %targ) || (@* iswm %targ)) _error Cannot send XDCC ads to that window
      .timer.xdccad 0 $calc($2 * 60) xdcc ad %targ
      dispa XDCC ad will be sent to $:t(%targ) every $:s($2) minutes. ( $+ $:s(/xdcc timer off) to disable)
    }
  }
  elseif ($1 == cfg) _dialog -am xdcccfg xdcccfg
  elseif ($1 == edit) _dialog -am xdcc xdcc
  else {
    dispa $:s(/xdcc edit) to edit packs
    dispa $:s(/xdcc cfg) to configure options
    dispa $:s(/xdcc on|off) to enable or disable
    dispa $:s(/xdcc list [nick|#chan]) to send a list of packs
    dispa $:s(/xdcc ad [nick|#chan]) to send a short advertisement
    dispa $:s(/xdcc timer n|off [nick|#chan|all]) to send short advertisement every n minutes
  }
}