;---------; ; /GETMAP ; ;_________; ;This one is an exemple of an HTTP sock downloading ;a country's location on the world ;Also in ms.org's snippets ;by bar ; ;Syntex /getmap ;Simple Alias call alias GetMap { ;Checking for errors if ($len($1) !== 2) || ($1 !isalpha) return set %getmap $1 ;SOCKOPEN ; * getmap is the name of the sock ; * worldtimeserver.com is the server ; * 80 is the HTTP port sockopen getmap worldtimeserver.com 80 echo $color(info) -e * /getmap: trying to resolve map } ;Okie, mIRC has attemped to connect the server on the specified ;port, When the sock is activated we can use the SOCKOPEN event to ;handle that. ON 1:SOCKOPEN:getmap: { ;Opening a simple picture window to /drawpic the picture we've downloaded if (!$window(@getmap)) window -pdoC +L @getmap -1 -1 200 200 ;Picture windows what so ever drawfill @getmap 1 1 1 1 drawtext @getmap 0 georgia 20 40 50 Please wait.. ;This %bin var is a flag, it indicate if the data from the SOCKREAD ;event (later) is BINARY or ASCII from the HEADER, when we get the ;CRLF signal we unset the var and use binary save if (%bin) unset %bin ;Dont you just HATE those tutorials when the explain eveyr character ;on the screen? if ($isfile($+(%getmap,.jpg)) == $true) .remove $+(%getmap,.jpg) ;the sockwrite command, sending OUR HEADER to the server ;First, the GET request with the HTTP/1.0 to request a HEADER sockwrite -n getmap GET $+(/images/maps/,%getmap,.jpg) HTTP/1.0 ;Tellin' the server its own address sockwrite -n getmap Host: worldtimeserver.com ;CRLF signal: "I'm done with data, NOW GIMMIE THE FILE" sockwrite getmap $crlf } ON 1:SOCKREAD:getmap: { ;If the %bin var is null we save as ascii if (!%bin) { sockread %temp ;if the CRLF signal arraived we set %bin if ($len(%temp) < 4) set %bin . if (!%bin) return } ;If were here it means we have passed the last statment which indicates ;that %bin is null, now saving binary sockread &getmap bwrite $+(%getmap,.jpg) -1 -1 &getmap } ON 1:SOCKCLOSE:getmap:{ ;The server closed the connection and were /drawpicin' ;Not before we checked if the file is vaild if ($file($+(%getmap,.jpg)).size < 8000) { echo $color(info) -e * /getmap: No country resolved .remove $+(%getmap,.jpg) return } ;Okie, drawpic drawpic -s @getmap 0 0 190 190 $+(%getmap,.jpg) .remove $+(%getmap,.jpg) }