; ; Sockets example - Complex ; ; This script allows a user to download files from the WWW with a simple ; /getdata command. Script currently only supports the WWW ; (HTTP/1.1) protocol. It doesn't completely support it so may barf on ; some servers. It supports simultaneous downloads, up to 260. ON 1:LOAD: { if ($isdir(WWWTemp) == $false) { mkdir WWWTemp } } ON 1:SOCKREAD:wwwGet: { .remove $+(",$mircdir,WWWTemp\Temp") echo -st Opening connection, and downloading $gettok($sock($sockname).mark,3,44) if ($sockerr > 0) return :nextread sockread %WWW.Temp if ($sockbr != 0) { if (%WWW.Temp != $Null) { write $+(",$mircdir,WWWTemp\Temp") %WWW.Temp } goto nextread } if (HTTP/1.*20* iswm $read($+(",$mircdir,WWWTemp\Temp"), 1)) { if ($exists($gettok($sock($sockname).mark,2,44))) { .remove $gettok($sock($sockname).mark,2,44) } :GenNew set -u0 %WWW.Temp www $+ $rand(A,Z) $+ $rand(0,9) if ($sock(%WWW.Temp) != $null) { goto GenNew } sockopen %WWW.Temp $gettok($gettok($gettok($sock($sockname).mark,3,44),2,47),1,58) $iif($gettok($gettok($gettok($sock($sockname).mark,3,44),3,47),2,58) != $Null, $gettok($gettok($gettok($sock($sockname).mark,3,44),3,47),1,58), 80) if (text/* iswm $read($+(",$mircdir,WWWTemp\Temp"), s,Content-Type:)) { sockmark %WWW.Temp Text, $+ $gettok($sock($sockname).mark,2-,44) } | else { sockmark %WWW.Temp Bin, $+ $gettok($sock($sockname).mark,2-,44) } sockclose wwwget } | else { echo -st $read($+(",$mircdir,WWWTemp\Temp"), 2) } unset %WWW.Temp } ON 1:SOCKREAD:www*: { if ($sockerr > 0) return :nextread if ($gettok($sock($sockname).mark,1,44) == bin) { sockread &Temp if ($sockbr == 0) return if ($bvar(&Temp,0) != 0) { bwrite $gettok($sock($SockName).Mark,2,44) -1 $bvar(&Temp,0) &temp } } | else { sockread %WWW.Temp if ($sockbr == 0) return if (%WWW.Temp != $Null) { write $gettok($sock($SockName).Mark,2,44) %WWW.Temp } unset %WWW.Temp } goto nextread } alias GetData { if ($sock(wwwGet) == $null) { if ($gettok($$1,1,47) == http:) { sockopen wwwGet $gettok($gettok($1,2,47),1,58) $iif($gettok($gettok($1,3,47),2,58) != $Null, $gettok($gettok($1,3,47),1,58), 80) } | else { sockopen wwwGet $gettok($1,1,47) $iif($gettok($gettok($1,1,47),2,58) != $Null, $gettok($gettok($1,1,47),1,58), 80) } if ($GetTok($1,$numtok($1,47),47) != $null) { set -u0 %WWW.File $+(", $mircdir,WWWTemp\,$GetTok($1,-1,47), ") } | else { set -u0 %WWW.File $+(",$mircdir,WWWTemp\_root_") } sockmark wwwGet unknown, $+ %WWW.File $+ , $+ $iif($gettok($$1,1,47) == http:, $1, [ http:// $+ [ $1 ] ] ) } | else { .timer 1 1 getdata $1 } } ON 1:SOCKOPEN:wwwGet: { sockwrite -tn wwwGet HEAD $gettok($sock($sockname).mark,3,44) HTTP/1.1 sockwrite -tn wwwGet Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */* sockwrite -tn wwwGet Accept-Language: en-au sockwrite -tn wwwGet Accept-Encoding: deflate sockwrite -tn wwwGet User-Agent: mIRCInstaller WWW Edition v0.0.1 sockwrite -tn wwwGet Host: $gettok($gettok($sock($sockname).mark,3,44),2,$asc(/)) sockwrite -tn wwwGet Connection: Keep-Alive sockwrite -tn wwwGet $lf } ON *:SOCKOPEN:www*: { sockwrite -tn $sockname GET $gettok($sock($sockname).mark,3,44) } ON 1:SOCKCLOSE:www*: { if ($sockname != wwwget) { echo -st File $gettok($sock($sockname).mark,3-,44) downloaded. Length: $file($gettok($sock($sockname).mark,2,44)).size if ($exists($+(",$mircdir,WWWTemp\Temp"))) { .remove $+(",$mircdir,WWWTemp\Temp") } unset %WWW* } }