on *:text:$($me fetch * *):#:{
var %f = $4- $+ $iif(*.map !iswm $4-,.map)
if ($file(c:/winbolo/maps/ $+ %f)) { msg # I already have that map. | return }
if ($sock(fetch)) { msg # Socket busy, try again. | return }
set -e %map.address $remove($3,http://)
set -e %map.name %f
set -e %map.chan #
sockopen fetch $gettok(%map.address,1,47) 80
}
on *:sockopen:fetch:{
if ($sockerr) return
sockwrite -n $sockname GET / $+ $gettok(%map.address,2-,47) HTTP/1.1
sockwrite -n $sockname Host: $sock($sockname).addr
sockwrite -n $sockname Connection: Close
sockwrite -n $sockname
msg %map.chan Downloading %map.name ....
}
on *:sockread:fetch:{
; check if the header has been recieved
; if so read the data to a binvar and bwrite it
if ($sock($sockname).mark) {
sockread -f &a
bwrite $qt(c:/winbolo/maps/ $+ %map.name) -1 -1 &a
}
; Otherwise, read the header data and do nothing with it
else {
var %a | sockread %a
; The header will be followed by a blank line
; If the var is empty the header has been recieved
if (!%a) { sockmark $sockname 1 }
}
}
on *:sockclose:fetch:{
msg %map.chan Download of %map.name $iif($file(c:/winbolo/maps/ $+ %map.name),Complete!,Failed!)
unset %map.*
}