dialog abc_login { title "ABC" size -1 -1 250 109 option pixels edit "", 1, 116 4 130 20, %abc.host edit "", 2, 116 26 130 20, %abc.port edit "", 3, 116 48 130 20, %abc.id text "Host:", 4, 4 6 100 17 text "Port:", 5, 4 28 100 17 text "Unique ID:", 6, 4 50 100 17 button "Connect", 7, 80 76 90 25 } dialog abc { title "ABC" size -1 -1 400 108 option dbu list 1, 1 1 199 97, vsbar size edit "", 2, 201 21 198 77, read multi return vsbar box "", 6, -3 96 405 13 button "Start", 3, 201 1 33 20 button "Stop", 4, 234 1 33 20 button "Pause", 5, 267 1 33 20 button "Delete", 7, 300 1 33 20 button "Open Torrent", 8, 333 1 33 20, multi button "Options", 9, 366 1 33 20 text "", 10, 2 100 396 8 } dialog abc_open { title "Open Torrent..." size -1 -1 137 30 option dbu edit "", 1, 23 2 70 10, autohs button "Browse", 2, 94 1 41 12 text "Torrent:", 3, 2 3 22 9 button "Ok", 5, 35 15 32 12 button "Cancel", 6, 71 15 32 12 } dialog abc_error { title "Error" size -1 -1 200 90 option pixels icon 1, 3 3 40 40, abc\dialog-error.png, 0 edit "", 2, 47 3 150 83, read multi return vsbar } on *:dialog:abc_login:*:*: { if ($devent == init) { did -a abc_login 1 %abc.host did -a abc_login 2 %abc.port did -a abc_login 3 %abc.id } if ($devent == sclick) && ($did == 7) { if ($hget(abc)) { hfree abc } hmake abc %abc.i = 1 dialog -c abc_login dialog -md abc abc sockopen abc. $+ $rand(1,999999999) %abc.host %abc.port ;if (!$timer(abc)) .timerabc 0 3 abc_refresh } } on *:dialog:abc_error:*:*: { if ($devent == close) && ($did == 0) && ($dialog(abc)) { dialog -o abc } } on *:dialog:abc:*:*: { ;if ($devent != mouse) { echo -a $devent $did } if ($devent == close) && ($did == 0) { sockclose abc.* | .timerabc off } if ($devent == sclick) && ($did == 1) { %abc.sel = $did(1).sel did -o abc 2 1 $trim($hget(abc,%abc.sel).item,55) did -o abc 2 2 Status: $gettok($hget(abc,$hget(abc,%abc.sel).item),2,124) did -o abc 2 3 Size: $gettok($hget(abc,$hget(abc,%abc.sel).item),3,124) did -o abc 2 4 ETA: $gettok($hget(abc,$hget(abc,%abc.sel).item),4,124) did -o abc 2 5 DL Speed: $gettok($hget(abc,$hget(abc,%abc.sel).item),5,124) did -o abc 2 6 UL Speed: $gettok($hget(abc,$hget(abc,%abc.sel).item),6,124) did -o abc 2 7 Downloaded: $gettok($hget(abc,$hget(abc,%abc.sel).item),9,124) did -o abc 2 8 Uploaded: $gettok($hget(abc,$hget(abc,%abc.sel).item),10,124) did -o abc 2 9 DL/UL Ratio: $round($calc($ckb($gettok($hget(abc,$hget(abc,%abc.sel).item),10,124)) / $ckb($gettok($hget(abc,$hget(abc,%abc.sel).item),9,124))),2) did -o abc 2 10 Seeds: $gettok($hget(abc,$hget(abc,%abc.sel).item),8,124) did -o abc 2 11 Peers: $gettok($hget(abc,$hget(abc,%abc.sel).item),7,124) did -o abc 2 12 AVG Peer Progress: $gettok($hget(abc,$hget(abc,%abc.sel).item),11,124) did -o abc 2 13 Swarm Speed: $gettok($hget(abc,$hget(abc,%abc.sel).item),12,124) did -o abc 2 14 Info Hash: $gettok($hget(abc,$hget(abc,%abc.sel).item),13,124) } if ($devent == sclick) { %abc.rid = $rand(1,999999999) %abc.retry = 2 if ($did == 3) { sockopen abca. $+ %abc.rid %abc.host %abc.port sockmark abca. $+ %abc.rid RESUME| $+ $gettok($hget(abc,$hget(abc,%abc.sel).item),13,124) } if ($did == 4) { sockopen abca. $+ %abc.rid %abc.host %abc.port sockmark abca. $+ %abc.rid STOP| $+ $gettok($hget(abc,$hget(abc,%abc.sel).item),13,124) } if ($did == 5) { sockopen abca. $+ %abc.rid %abc.host %abc.port sockmark abca. $+ %abc.rid PAUSE| $+ $gettok($hget(abc,$hget(abc,%abc.sel).item),13,124) } if ($did == 7) { sockopen abca. $+ %abc.rid %abc.host %abc.port sockmark abca. $+ %abc.rid DELETE| $+ $gettok($hget(abc,$hget(abc,%abc.sel).item),13,124) } if ($did == 8) { dialog -ma abc_open abc_open } if ($did == 9) { ;$sfile(%abc.torrentdir $+ \*.torrent) } } } on *:dialog:abc_open:*:*: { ;if ($devent != mouse) { echo -a $devent $did } if ($devent == sclick) && ($did == 5) { if ($did(abc_open,1).text) { if (http://* iswm $did(abc_open,1).text) { %abc.rid = $rand(1,999999999) %abc.retry = 2 sockopen abca. $+ %abc.rid %abc.host %abc.port sockmark abca. $+ %abc.rid ADD| $+ $did(abc_open,1).text dialog -c abc_open halt } if ($file($did(abc_open,1).text)) { dialog -c abc_open } else { dialog -m abc_error abc_error did -a abc_error 2 File not found. dialog -c abc_open } } } } on *:sockopen:abc.*: { if ($sockerr) { if (%abc.i) { dialog -m abc_error abc_error did -a abc_error 2 Error connecting to $sock($sockname).ip $+ : $+ $sock($sockname).port $crlf $crlf unset %abc.i did -a abc_error 2 $sock($sockname).wsmsg dialog -c abc } .timer 1 3 abc_refresh halt } if ($hget(abctemp)) { hfree abctemp } hmake abctemp sockwrite $sockname ID| $+ %abc.id $+ $chr(10) $+ QUERY|filename,progress,btstatus,totalsize,eta,dlspeed,ulspeed,peers,seeds,dlsize,ulsize,peeravgprogress,totalspeed unset %abc.i } on *:sockread:abc.*: { while (1) { sockread %abc tokenize 32 %abc while ($chr(124) $+ $chr(124) isin $1-) { tokenize 32 $replace($1-,||,|N/A|) } if (!$sockbr) { break } ;echo %abc if (*|*|*|* iswm $1-) { if ($gettok($1-,1,124) != title) { hadd abctemp $replace($gettok($1-,1,124),$chr(32),.) $gettok($1-,2-,124) } } } } on *:sockclose:abc.*: { hfree abc hmake abc %a = 1 while ($hget(abctemp,%a).item) { hadd abc $hget(abctemp,%a).item $hget(abctemp,$hget(abctemp,%a).item) inc %a } did -r abc 1 %a = 1 %td = 0 %tu = 0 while ($hget(abc,%a).item) { if ($gettok($hget(abc,$hget(abc,%a).item),2,124) == completed/seeding) { did -a abc 1 $trim($hget(abc,%a).item,40) (seeding @ $gettok($hget(abc,$hget(abc,%a).item),6,124)) $+ ) } elseif ($gettok($hget(abc,$hget(abc,%a).item),2,124) == stop) { did -a abc 1 $trim($hget(abc,%a).item,40) (stopped) } else { did -a abc 1 $trim($hget(abc,%a).item,40) ( $+ $gettok($hget(abc,$hget(abc,%a).item),1,124) @ $gettok($hget(abc,$hget(abc,%a).item),5,124) $+ ) } inc %td $ckb($gettok($hget(abc,$hget(abc,%a).item),5,124)) inc %tu $ckb($gettok($hget(abc,$hget(abc,%a).item),6,124)) inc %a } did -a abc 10 Total Download: $bus(%td) $str($chr(160),10) Total Upload: $bus(%tu) did -c abc 1 %abc.sel did -o abc 2 1 $trim($hget(abc,%abc.sel).item,55) did -o abc 2 2 Status: $gettok($hget(abc,$hget(abc,%abc.sel).item),2,124) did -o abc 2 3 Size: $gettok($hget(abc,$hget(abc,%abc.sel).item),3,124) did -o abc 2 4 ETA: $gettok($hget(abc,$hget(abc,%abc.sel).item),4,124) did -o abc 2 5 DL Speed: $gettok($hget(abc,$hget(abc,%abc.sel).item),5,124) did -o abc 2 6 UL Speed: $gettok($hget(abc,$hget(abc,%abc.sel).item),6,124) did -o abc 2 7 Downloaded: $gettok($hget(abc,$hget(abc,%abc.sel).item),9,124) did -o abc 2 8 Uploaded: $gettok($hget(abc,$hget(abc,%abc.sel).item),10,124) did -o abc 2 9 DL/UL Ratio: $round($calc($ckb($gettok($hget(abc,$hget(abc,%abc.sel).item),10,124)) / $ckb($gettok($hget(abc,$hget(abc,%abc.sel).item),9,124))),2) did -o abc 2 10 Seeds: $gettok($hget(abc,$hget(abc,%abc.sel).item),8,124) did -o abc 2 11 Peers: $gettok($hget(abc,$hget(abc,%abc.sel).item),7,124) did -o abc 2 12 AVG Peer Progress: $gettok($hget(abc,$hget(abc,%abc.sel).item),11,124) did -o abc 2 13 Swarm Speed: $gettok($hget(abc,$hget(abc,%abc.sel).item),12,124) did -o abc 2 14 Info Hash: $gettok($hget(abc,$hget(abc,%abc.sel).item),13,124) .timer 1 3 abc_refresh } on *:sockopen:abca.*: { if ($sockerr) { if (%abc.retry) { dec %abc.retry %abc.rid = $rand(1,999999999) sockopen abca. $+ %abc.rid sockmark abca. $+ %abc.rid $sock($sockname).mark } halt } sockwrite $sockname ID| $+ %abc.id $+ $chr(10) $+ $sock($sockname).mark } on *:sockread:abca.*: { while (1) { sockread -f %abca tokenize 32 %abca if (!$sockbr) { break } } } on *:socklisten:abc_wserv: { if (!%abc.wserv) { halt } sockaccept abc_wclient. $+ $rand(1,99999999) } on *:sockread:abc_wclient.*: { sockread %w tokenize 32 %w echo -a $sock($sockname).ip $1- if ($1- == GET / $+ %abc.id HTTP/1.1) { %abc.upos = 0 sockwrite -n $sockname HTTP/1.1 200 OK sockwrite -n $sockname Connection: close sockwrite -n $sockname Transfer-Encoding: chunked sockwrite -n $sockname Content-Type: application/x-bittorrent sockwrite $sockname Content-Disposition: attachment; filename=" $+ $nopath(%abc.torrentfile) $+ " $crlf $crlf %ti = $rand(1,999999) .timer 1 1 .timer $+ %ti -m 0 50 abc_wsend $sockname %ti } } alias -l abc_refresh { sockopen abc. $+ $rand(1,999999999) %abc.host %abc.port } alias -l abc_wsend { if (%abc.upos > $file(%abc.torrentfile).size) || (!$sock($1)) { timer $+ $2 off | halt } if ($sock($1).sq < 8192) { bread $shortfn(%abc.torrentfile) %abc.upos 8192 &x sockwrite $1 &x inc %abc.upos 8192 } } alias -l trim { if ($len($1-) > $2) { return $left($1,$2) $+ ... } else return $1 } alias -l ckb { tokenize 32 $1- if ($1 !isnum) { return 0 } if ($left($2,2) == kb) { return $1 } if ($left($2,2) == mb) { return $calc($1 * 1024) } if ($left($2,2) == gb) { return $calc($1 * 1024 * 1024) } } alias -l bus { if ($1 < 1024) { return $1 KB/s } if ($1 > 1024) { return $round($calc($1 / 1024),2) MB/s } } alias -l but { if ($1 < 1024) { return $1 KB } if ($1 > 1024) && ($1 < $calc(1024 * 1024)) { return $calc($1 / 1024) MB } if ($1 > $calc(1024 * 1024)) { return $calc($1 / 1024 / 1024) GB } }