Iron Realms has just added a nifty feature to their new Flash client that allows it to download a map image and display your current subsection of it in a tiny floating window. Since this URL is sent in an ATCP message, I'm hoping it might be possible to do the same using a miniwindow in MUSHclient.
Is there any feasible way I can download an image from a URL and load a portion of it into a miniwindow? I'm sure I could handle the latter part if I knew how to do the former. :)
If you're using Lua, you can use the LuaSocket library:
http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/http.html#request
That requests the data at a given URL and returns it as a string. You could then output it to a file, and do your image drawing from there.
Yes, and see this post:
http://www.gammon.com.au/forum/bbshowpost.php?id=4935
That shows pulling in stuff from a URL.
Wow... hard to believe that it's already been four years since we started talking about using Lua. But there you have it. :-)
Thanks for the link! I guess I should've done a better search before posting, but I wasn't thinking it would be done through a Lua add-on, hoping maybe there was a MUSHclient function for it that I just hadn't seen yet.
So, it should work fine storing an image, as a binary, in a variable and then writing that to a file? I'm planning to make my own local cache that gets refreshed maybe once a week automatically, to keep from downloading the files every single time I move to a new room in the same zone.
Keep in mind that LuaSocket is blocking, there's some code for an asynchronous server in the same Kepler project that LuaSocket is part of, but you'd have to extract and adapt for a client. Otherwise, you might hang the client on a poor connection. The maps seem to be around 30-40KB on average and there's probably around a 100 of them in total, so that runs up to almost half a megabyte, which is guaranteed to give Mushclient a serious "hiccup" even on broadband.
Instead of mucking with scraping IRE maps, I am thinking of a different approach: make a basic automapper and build the maps yourself using the coordinates supplied through ATCP.
I've already got a plugin to capture and display the in-game maps, but that lags me a bit, and I think it would actually be speedier to move with the graphical maps once I get past the initial downloading step.
I'm actually contemplating just using a brute force approach to the downloading, however, to avoid hanging the client, as you say. I'll just use a small tool I develop to batch download all the available areas and store them locally.
It would probably be acceptable to hang the client just once per map, and then never download it again, instead of trying to work out a cleverer scheme of scraping etc., no?
Incidentally you can tell the socket library to not block. See the example in here:
http://www.lua.org/pil/9.4.html
This shows how you can use coroutines to concurrently download several files.
That's a bit more complicated, but it looks like an interesting challenge! I know you're right about downloading these files being a fairly small block, but I was worried about cases where it has troubles connecting and just waits for the maximum timeout.
Thanks again.
I'm not sure about the binary download - the data may just be in binary or you may need to interpret it somehow (eg. base64).
Doing the asynchronous stuff isn't that hard, it is just a bit fiddly - you have to initiate the IO, then have some way of knowing when it is complete.