;===========================================================================================// ; Passive DCC send v0.884 (pasvdcc.mrc) for mIRC 5.7 ; by vague (msandin@hotmail.com) ;===========================================================================================\\ alias psend pasvdcc.send psend $1- ;-------------------------------------------------------------------------------------------/ ; Script interface ;-------------------------------------------------------------------------------------------\ alias pasvdcc.version return 0.884 ; /pasvdcc.send [-qmh|a alias] ; $pasvdcc.send( [-qmh|a alias] ) ; name of alias calling = For syntax printout purposes, please set to anything as fit ; -s = Silent, no status messages echoed ; -n = No window, no DCC send window will be opened ; -m = Opens the window minimized ; -h = Opens the window hidden on the switchbar ; -a alias = The alias is called as / ; The following events are currently supported: ; COMPLETE = The send was completed ; ABORT = The user aborted the transfer ; REMOTE ABORT = The reciever aborted the send ; KILL = A script killed the transfer ; REPLYTIMEOUT = The reply to the DCC SEND request timed out ; UNABLETOCONNECT = No TCP connection could be opened ; CONNECTIONLOST = The TCP connection was lost ; REFRESH = Triggers when data has been is sent or every four second ; and a maximum of once per second. ; When called as an identifier $pasvdcc.send() returns the unique ID the send was assigned alias pasvdcc.send { tokenize 32 $1- var %attr = +,%mark,%alias = $false,%call = $1 tokenize 32 $2- if (-* iswm $1) { if (m isin $1) %attr = %attr $+ m if (s isin $1) %attr = %attr $+ s if (n isin $1) %attr = %attr $+ n if (h isin $1) %attr = %attr $+ h if (a isin $1) { %alias = $2 tokenize 32 $2- } tokenize 32 $2- } if ($1 == $null) { if (s !isin %attr) echo $colour(info) -a *** Can't retrieve filesize (If the file is on a network try mapping a drive to the directory) | return } var %file = $2- if (%file == $null) { %file = $$file="Send to [ [ $1 ] $+ ] " $mircdir } if ($exists(%file)) { var %id = $rand(100000,999999), %size = $file(%file).size if (%size == $null) { if (s !isin %attr) echo $colour(info) -a *** Syntax: / $+ %call [file] | return } .raw PRIVMSG $1 : $+ $chr(1) $+ DCC SEND $replace($nopath(%file),$chr(32),_) $longip(193.10.163.20) 0 %size %id $+ $chr(1) %pasvdcc.id = $addtok(%pasvdcc.id,%id,32) %mark = %id 0 $1 $win(0,$nopath(%file),$1,%id) t0 tu 0 0 %size %alias SEND waiting %attr %file %pasvdcc.new. [ $+ [ %id ] ] = %mark refresh %id .timerPASVDCC. $+ %id 1 240 replytimeout %id return %id } else { if (s !isin %attr) echo $colour(info) -a *** No such file $2- } } ; $pasvdcc.info() ; .telapsed = Time of the send elapsed (in seconds) ; .tleft = Estimated time left (in second). Returns $null if the send hasn't started. ; .bsent = Bytes already ; .bleft = Bytes left to send ; .win = Current window name of send ; .nick = Nick of the person the file is sent to ; .file = File name alias pasvdcc.info { if ($prop == telapsed) return $int($calc(($ticks - $m($1).tstart) / 1000)) if ($prop == tleft) return $int($calc(($m($1).bend - $m($1).bpos) / (($m($1).bpos - $m($1).bstart) / (($ticks - $m($1).tstart) / 1000)))) if ($prop == bsent) return $m($1).bpos if ($prop == bleft) return $calc($m($1).bend - $m($1).bpos) if ($prop == win) return $m($1).win if ($prop == nick) return $m($1).nick if ($prop == file) return $m($1).fname } drawtext -rn %w $rgb(text) "Ms Sans Serif" 13 12 43 $size($m($1).bpos) sent, $size($calc($m($1).bend - $m($1).bpos)) remaining $iif(%t == sending, [ [ $chr(40) ] $+ [ $size(%s) ] $+ /s average $+ [ $chr(41) ] ] ) drawtext -rn %w $rgb(text) "Ms Sans Serif" 13 12 57 $iif(%t == resuming,Resuming...,$iif(%t == connecting,Connecting...,$iif(%t == sending, [ $dur($int($calc(($ticks - $m($1).tstart) / 1000))) ] elapsed,Waiting for reply...))) $+ $iif(%t == sending,$chr(44)) $iif(%t == sending, [ $dur($int($calc(($m($1).bend - $m($1).bpos) / %s))) ] seconds remaining) ; $pasvdcc.id() ; returns the n'th DCC send's unique ID alias pasvdcc.id return $gettok(%pasvdcc.id,$1,32) ; /pasvdcc.control <-amrhuqwk> ; -a = Makes the send window the active ; -m = Minimizes the send window ; -r = Restores a minimized window ; -h = Hides the window ; -u = Unhides the window ; -n = Closes the send window ; -w = Restores the send window ; -s = Silents the send, no status messages will be echoed ; -v = Makes the send verbose again, status messages will be had ; -k = Kills the send, causes the send to be aborted and triggers the KILL event alias pasvdcc.control { if ($m($2).id == $null) return var %w = $m($2).win if (s isin $1) m $2 attr $m($2).attr $+ s if (v isin $1) m $2 attr $remove($m($2).attr,s) if (n isin $1) { window -c %w m $2 attr $m($2).attr $+ n } if (w isin $1) { m $2 attr $remove($m($2).attr,n) refresh -f $1 } if (n !isin $m($2).attr) { if (h isin $1) { m $2 attr $m($2).attr $+ h window -h %w g2.reset %w g2standard.button -n %w 160 90 58 26 Unhide drawdot %w } if (u isin $1) { m $2 attr $remove($m($2).attr,h) window -w %w g2.reset %w g2standard.button -n %w 160 90 58 26 Hide drawdot %w } if (m isin $1) window -m %w if (r isin $1) window -r %w if (a isin $1) window -a %w } if (k isin $1) { kill $2 KILL | return } } ;-------------------------------------------------------------------------------------------/ ; Events ;-------------------------------------------------------------------------------------------\ ctcp *:DCC SEND { if ($istok(%pasvdcc.id,$7,32) && ($5 != 0)) { m $7 sock pasvdcc.send. $+ $7 sockopen pasvdcc.send. $+ $7 $longip($4) $5 tokenize 32 [ %pasvdcc.new. [ $+ [ $7 ] ] ] unset %pasvdcc.new. $+ $1 sockmark pasvdcc.send. $+ $1 $1- m $1 status connecting refresh -f $1 halt } } ctcp *:DCC RESUME { if ($istok(%pasvdcc.id,$6,32)) { var %pos = $5 .raw PRIVMSG $nick : $+ $chr(1) $+ DCC ACCEPT $3- $+ $chr(1) tokenize 32 [ %pasvdcc.new. [ $+ [ $6 ] ] ] m $1 status resuming m $1 bstart %pos m $1 bpos %pos refresh -f $1 halt } } on *:start { unset %pasvdcc.* g2.start } ;-------------------------------------------------------------------------------------------/ ; Sockets ;-------------------------------------------------------------------------------------------\ on *:sockopen:pasvdcc.send.* { tokenize 32 $sock($sockname).mark if ($sockerr) { kill $1 UNABLETOCONNECT DCC send of $nopath($m($1).fname) to $m($1).nick failed, unable to connect! halt } m $1 tstart $ticks m $1 status sending nextchunk $1 } on *:sockwrite:pasvdcc.send.* { tokenize 32 $sock($sockname).mark if ($sockerr) { kill $1 CONNECTIONLOST DCC send of $nopath($m($1).fname) to $m($1).nick failed, connection lost! halt } refresh $1 nextchunk $1 } on *:sockclose:pasvdcc.send.* { tokenize 32 $sock($sockname).mark if ($sockerr) { kill $1 CONNECTIONLOST DCC send of $nopath($m($1).fname) to $m($1).nick failed, connection lost! halt } kill $1 REMOTEABORT DCC send of $nopath($m($1).fname) to $m($1).nick aborted by reciever! } on *:close:@*%?of?*sent?to*[*] { kill $remove($gettok($target,-1,160),$chr(91),$chr(93)) ABORT } alias -l replytimeout { kill $1 REPLYTIMEOUT DCC send of $nopath($m($1).fname) to $m($1).nick failed, reply timed out! } alias -l nextchunk { if ($m($1).bpos < $m($1).bend) { bread " $+ $m($1).fname $+ " $m($1).bpos 4096 &chunk sockwrite $m($1).sock &chunk m $1 bpos $calc($m($1).bpos + $bvar(&chunk,0)) } else { kill $1 COMPLETE DCC send of $nopath($m($1).fname) to $m($1).nick complete! } } alias -l kill { if ($m($1).status == complete) return .timerPASVDCC. $+ $1 off if ($m($1).alias) { .timerPASVDCC.EVENT 1 0 $m($1).alias $2 $m($1).id $m($1).nick $m($1).fname .timerPASVDCC.EVENT -e } if (n !isin $m($1).attr) { window -c $m($1).win g2.reset $m($1).win } if ($3 != $null) secho $1 $3- %pasvdcc.id = $remtok(%pasvdcc.id,$1,32) unset %pasvdcc.new. $+ $1 if ($m($1).sock) { if ($2 == COMPLETE) { m $1 status complete .timer 1 10 sockclose $m($1).sock } else sockclose $m($1).sock } } ;-------------------------------------------------------------------------------------------/ ; Interface ;-------------------------------------------------------------------------------------------\ menu @pasvdcc.send { mouse { g2.mouse pasvdcc.fw pasvdcc.event $mouse.win } sclick { g2.click pasvdcc.fw pasvdcc.event $mouse.win } dclick { g2.click pasvdcc.fw pasvdcc.event $mouse.win } uclick { g2.uclick pasvdcc.fw pasvdcc.event $mouse.win } leave { g2.leave pasvdcc.fw pasvdcc.event $leftwin } } alias pasvdcc.fw { if ($inrect($2,$3,95,90,58,26)) return g2standard.button ABORT 95 90 58 26 Abort if ($inrect($2,$3,160,90,58,26)) { if (h isin $m($remove($gettok($1,-1,160),$chr(91),$chr(93))).attr) return g2standard.button UNHIDE 160 90 58 26 Unhide return g2standard.button Hide 160 90 58 26 Hide } } alias pasvdcc.event { if ($3 == ABORT) kill $remove($gettok($1,-1,160),$chr(91),$chr(93)) ABORT if ($3 == HIDE) pasvdcc.control -h $remove($gettok($1,-1,160),$chr(91),$chr(93)) if ($3 == UNHIDE) pasvdcc.control -u $remove($gettok($1,-1,160),$chr(91),$chr(93)) } alias -l refresh { var %p,%s,%t if (-* iswm $1) { %p = $1 tokenize 32 $2 } if (( [ %pasvdcc. [ $+ [ $1 ] ] ] == $null) || (f isin %p)) { set -u1 %pasvdcc. $+ $1 $true var %renwin,%w = $m($1).win if (n !isin $m($1).attr) { if ($window(%w) == $null) { window -fapk +fnt %w -1 -1 320 120 @pasvdcc.send drawrect -nrf %w $rgb(face) 1 0 0 325 125 g2standard.button -n %w 95 90 58 26 Abort g2standard.button -n %w 160 90 58 26 Hide if (h isin $m($1).attr) window -h %w if (m isin $m($1).attr) window -n %w else window -a %w } drawrect -nrf %w $rgb(face) 1 0 0 320 80 g2standard.percentagebar -n %w 11 22 298 12 $m($1).bend $m($1).bpos drawtext -rn %w $rgb(text) "Ms Sans Serif" 13 12 7 $nopath($m($1).fname) to $m($1).nick %t = $m($1).status %s = $calc(($m($1).bpos - $m($1).bstart) / (($ticks - $m($1).tstart) / 1000)) drawtext -rn %w $rgb(text) "Ms Sans Serif" 13 12 43 $size($m($1).bpos) sent, $size($calc($m($1).bend - $m($1).bpos)) remaining $iif(%t == sending, [ [ $chr(40) ] $+ [ $size(%s) ] $+ /s average $+ [ $chr(41) ] ] ) drawtext -rn %w $rgb(text) "Ms Sans Serif" 13 12 57 $iif(%t == resuming,Resuming...,$iif(%t == connecting,Connecting...,$iif(%t == sending, [ $dur($int($calc(($ticks - $m($1).tstart) / 1000))) ] elapsed,Waiting for reply...))) $+ $iif(%t == sending,$chr(44)) $iif(%t == sending, [ $dur($int($calc(($m($1).bend - $m($1).bpos) / %s))) ] seconds remaining) drawdot %w if ($sock( [ pasvdcc.send. $+ [ $1 ] ] )) { %renwin = $win($int($calc($m($1).bpos / $m($1).bend * 100)),$nopath($m($1).fname),$m($1).nick,$1) if (%renwin != %w) { renwin %w $ifmatch g2.renwin %w $ifmatch m $1 win %renwin } } } if ($m($1).alias) { .timerPASVDCC.EVENT 1 0 $m($1).alias REFRESH $1 $m($1).nick $m($1).fname .timerPASVDCC.EVENT -e } } .timerPASVDCC. $+ $1 1 4 refresh $1 } ;-------------------------------------------------------------------------------------------/ ; Lib ;-------------------------------------------------------------------------------------------\ alias -l win return @ $+ $1 $+ % $+ $chr(160) $+ of $+ $chr(160) $+ $replace($left($2,50),$chr(32),$chr(160)) $+ $chr(160) $+ sent $+ $chr(160) $+ to $+ $chr(160) $+ $3 $+ $chr(160) $+ [[ $+ $4 $+ ]] alias -l m { var %m,%s,%p if ($prop) %m = $prop else %m = $2 if (%m = fname) { %p = 14- } else { %p = $findtok(id.sock.nick.win.tstart.tupdated.bstart.bpos.bend.alias.type.status.attr.fname,%m,1,46) } if ($sock( [ pasvdcc.send. $+ [ $1 ] ] )) { %m = $sock( [ pasvdcc.send. $+ [ $1 ] ] ).mark | %s = 1 } else { %m = [ %pasvdcc.new. [ $+ [ $1 ] ] ] } if ($isid) return $gettok(%m,%p,32) if (%s) { sockmark pasvdcc.send. $+ $1 $puttok(%m,$3-,%p,32) } else { set %pasvdcc.new. $+ $1 $puttok(%m,$3-,%p,32) } } alias -l size if ($round($calc($1 / 1024),1) >= 1000) return $round($calc($1 / 1048576),2) $+ mb | return $round($calc($1 / 1024),2) $+ kb alias -l dur return $remove($duration($1),ecs,ec,ins,in,ours,our,ays,ay) alias -l secho if (s !isin $m($1).attr) echo $colour(info) -a *** $2- ;-------------------------------------------------------------------------------------------/ ; g2 ;-------------------------------------------------------------------------------------------\ alias g2standard.button { drawrect -rnf $2 $rgb(face) 1 $3-4 $calc($5 - 1) $calc($6 - 1) drawtext -rn $2 $rgb(text) "Ms Sans Serif" 13 $calc($3 + ($5 - $width($7-,"Ms Sans Serif",14,0,0)) / 2 + $iif($1 = -i,2,1)) $calc($4 + ($6 - 10) / 2 - $iif($1 = -i,0,1)) $7- if ($1 isin -n.-o.-h) { relief -rn $2 $rgb(face) $rgb(frame) $3-6 relief -rn $2 $rgb(hilight) $rgb(shadow) $calc($3 + 1) $calc($4 + 1) $calc($5 - 2) $calc($6 - 2) } else drawrect -rn $2 $rgb(shadow) 1 $3-6 if ($1 isin -i.-n) drawrect -rn $2 $rgb($iif($1 = -i,frame,face)) 1 $calc($3 - 1) $calc($4 - 1) $calc($5 + 2) $calc($6 + 2) } alias g2standard.percentagebar { relief -rn $2 $rgb(shadow) $rgb(hilight) $3-6 var %a = $iif($7,$round($calc(($8 / $7) * ($5 - 2) / 8),0),$7) - 1 while (%a >= 0) { drawrect -rnf $2 $rgb(0,0,128) 1 $calc($3 + 2 + (8 * %a)) $calc($4 + 2) 6 $calc($6 - 4) dec %a } } alias -l relief drawrect $1 $2 $4 1 $5- | drawline $1 $2 $3 1 $5 $calc($6 + $8 - 1) $5 $6 $calc($5 + $7) $6 alias g2.mouse { set -u %g2.action $2 | if (%g2.lock) g2.unlock if (%g2.s) { if (($gettok(%g2.s,1,32) != $3) || ($calc($mouse.key & 1) = 0)) { $gettok(%g2.s,2,32) -n $gettok(%g2.s,1,32) $gettok(%g2.s,4-,32) drawdot $gettok(%g2.s,1,32) unset %g2.s } else { if ($inrect($mouse.x,$mouse.y,$gettok(%g2.s,4,32),$gettok(%g2.s,5,32),$gettok(%g2.s,6,32),$gettok(%g2.s,7,32))) $gettok(%g2.s,2,32) -i $gettok(%g2.s,1,32) $gettok(%g2.s,4-,32) | else $gettok(%g2.s,2,32) -o $gettok(%g2.s,1,32) $gettok(%g2.s,4-,32) | drawdot $gettok(%g2.s,1,32) } } else { var %g2.newover %g2.newover = $3 [ $ [ $+ [ $1 ] $+ ( [ $3 ] , [ $mouse.x ] , [ $mouse.y ] , [ mouse] ) ] ] ] if (%g2.newover != %g2.o) { if (%g2.o) { $gettok(%g2.o,2,32) -n $gettok(%g2.o,1,32) $gettok(%g2.o,4-,32) | drawdot $gettok(%g2.o,1,32) } set %g2.o %g2.newover if (%g2.o != $3) { $gettok(%g2.o,2,32) -h $gettok(%g2.o,1,32) $gettok(%g2.o,4-,32) | drawdot $gettok(%g2.o,1,32) } else unset %g2.o } } } alias g2.click { set -u %g2.action $2 | if (%g2.lock) g2.unlock if (%g2.s) { $gettok(%g2.s,2,32) -n $gettok(%g2.s,1,32) $gettok(%g2.s,4-,32) | drawdot $gettok(%g2.s,1,32) } %g2.s = $3 [ $ [ $+ [ [ $1 ] [ $+ ( [ $3 ] , [ $mouse.x ] , [ $mouse.y ] ,click) ] ] ] ] if ((%g2.s != %g2.o) && (%g2.o)) { $gettok(%g2.o,2,32) -n $gettok(%g2.o,1,32) $gettok(%g2.o,4-,32) | drawdot $gettok(%g2.o,1,32) } unset %g2.o if (%g2.s != $3) { $gettok(%g2.s,2,32) -i $gettok(%g2.s,1,32) $gettok(%g2.s,4-,32) | drawdot $gettok(%g2.s,1,32) } else unset %g2.s } alias g2.uclick { if (%g2.lock) return if (%g2.s) { %g2.tmp = $iif($inrect($mouse.x,$mouse.y,$gettok(%g2.s,4,32),$gettok(%g2.s,5,32),$gettok(%g2.s,6,32),$gettok(%g2.s,7,32)) && ($3 == $leftwin),1,0) if (%g2.tmp) { .timerg2c 1 0 $2 %g2.s | .timerg2c -e } if (%g2.s) { $gettok(%g2.s,2,32) -n $gettok(%g2.s,1,32) $gettok(%g2.s,4-,32) | drawdot $gettok(%g2.s,1,32) } unset %g2.s if (%g2.tmp) g2.mouse $1- unset %g2.tmp } } alias g2.leave { if (%g2.lock) return if (%g2.s) { $gettok(%g2.s,2,32) -o $gettok(%g2.s,1,32) $gettok(%g2.s,4-,32) | drawdot $gettok(%g2.s,1,32) } if (%g2.o) { $gettok(%g2.o,2,32) -n $gettok(%g2.o,1,32) $gettok(%g2.o,4-,32) | drawdot $gettok(%g2.o,1,32) } unset %g2.o } alias g2.renwin { if ($1 = $gettok(%g2.s,1,32)) %g2.s = $puttok(%g2.s,$2,1,32) if ($1 = $gettok(%g2.o,1,32)) %g2.o = $puttok(%g2.o,$2,1,32) } alias g2.reset { if ($1 = $gettok(%g2.s,1,32)) { if (%g2.lock) g2.unlock unset %g2.s %g2.tmp } if ($1 = $gettok(%g2.o,1,32)) unset %g2.o } alias g2.start unset %g2.* alias g2.lock set %g2.lock %g2.action | .timerg2lock -om 0 100 if ( $!active != $1 ) || ( $!window($gettok(%g2.s,1,32)).state != $window($gettok(%g2.s,1,32)).state ) g2.unlock alias g2.unlock { .timerg2lock off $gettok(%g2.s,2,32) -u $gettok(%g2.s,1,32) $gettok(%g2.s,4-,32) if ($window($gettok(%g2.s,1,32))) { $gettok(%g2.s,2,32) -n $gettok(%g2.s,1,32) $gettok(%g2.s,4-,32) | drawdot $gettok(%g2.s,1,32) } %g2.lock %g2.s unset %g2.s %g2.lock }