Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ MUSHclient
➜ Lua
➜ File questions.
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Wed 28 Feb 2007 05:59 PM (UTC) Amended on Wed 28 Feb 2007 06:04 PM (UTC) by Shaun Biggs
|
Message
| Is there any way I can get Lua to download a file so that it can be read as data into my script? I'd like to have a file that's updated every now and then change automatically for the users without them having to deal with updating it themselves. I don't mind if it's in some type of backgrounded process, since it doesn't have a definite time to it, and it's honestly not all that important to the script.
The main question I have though is with IO. Do I have to get sandbox permissions changed in order to read a file? I'd rather not have to muck about with sandbox permissions if at all possible, since I don't want people using my script to end up compromising the security of their client for my plugins. And yes, I know you can set certain plugins to trusted, but I have this feeling that a lot of people set global permissions rather than individual ones because it's easier. |
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| Shadowfyr
USA (1,788 posts) Bio
|
Date
| Reply #1 on Wed 28 Feb 2007 07:59 PM (UTC) |
Message
| Umm. The answer to this is yes and no. I have used windows sockets once to load the HTML for a page of voting results, so I could display them when I wanted with an alias. The problem is, there is no such thing as a "background" process in Mushclient. All script executes in the same thread as the client, so anything happening "in" the script interrupts the client itself until finished. In the case of sockets, that means your download has to finish before the client can do anything. Now... One solution is to use something like IE, or a download manager like Getright, etc. to handle the "download", then somehow check every few seconds in the script (using a timer) to see if the download finished. Should be possible with IE, assuming its downloads are treated like pages and you can check the "is loading complete" attribute for it, maybe Getright, etc... But not sure. I have no idea if any download manage, including the one I use, supports asking it if it finished. Probably not. That leaves:
1. Using an FTP client that does support this.
2. Creating your own FTP client to support this.
3. Trying to go "real deep" into the socket code and building your own interruptable method of getting the data.
#3 would mean the script would need to function as an FTP client and exit "in between" packets, with a timer to re-enter every second, in order to request and recieve the next packet. Its probably not impossible to do that, and there are bound to be unknown problems, like possible server time outs, that would fowl it up. Sane people would try 1 or 2 *first*. lol
But by itself, without coding an entire FTP client in it somehow, any download you try using Lua is going to freeze the client until the download completes, *unless* you use something "outside" Mushclient to do it. | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #2 on Wed 28 Feb 2007 09:17 PM (UTC) |
Message
|
Quote:
Do I have to get sandbox permissions changed in order to read a file?
Yes you do. The sandbox was specifically designed to disallow all IOs, and also loading DLLs, as a security precaution.
If you mean by "download a file" to get one from the web, then you need to allow LuaSocket, which has provision for network access.
If you mean to read a disk file, you would need to enable the IO library. Conceivably, allowing read-only IOs would have been reasonably safe, however there are various ways files can be opened, and the difference between reading and writing is simply in an argument to the file open, so it was safer to disallow all file IO.
As with many security issues you either have security or ease of use. It is hard to have both simultaneously.
You might just have to give detailed instructions, to edit the Lua sandbox, and add one extra line to trust that plugin. With an example it shouldn't be too bad.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #3 on Wed 28 Feb 2007 09:58 PM (UTC) |
Message
|
Quote: 1. Using an FTP client that does support this.
2. Creating your own FTP client to support this.
3. Trying to go "real deep" into the socket code and building your own interruptable method of getting the data.
or 4) The option I have in place already, which is to supply a hyperlink to the file as a line displayed to the user to download him/herself. Simple solutions before coding a new client. Also interesting to note that you are supplying suggestions on a forum for a language you admitted to not knowing on a seperate board.
Quote: If you mean by "download a file" to get one from the web, then you need to allow LuaSocket, which has provision for network access.
That was my original plan, but I was wondering how hard it would be to tell if the file is taking a long time to download.
Quote: If you mean to read a disk file, you would need to enable the IO library. Conceivably, allowing read-only IOs would have been reasonably safe, however there are various ways files can be opened, and the difference between reading and writing is simply in an argument to the file open, so it was safer to disallow all file IO
Well, the whole idea is to download a file, and then read it at the start of each session. I know IO permissions would have to be set, and I could probably just get away with not having the download done by the script and just let the script read the file. I figured out how to allow read and write, but I was wondering how to get it to just allow reading. |
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #4 on Thu 01 Mar 2007 12:18 AM (UTC) |
Message
| You would need to use asynchronous sockets in order to check up on their status from time to time and see what's going on. I don't know off-hand if this is possible with LuaSockets, but I don't see why not. Also I seem to recall an example in PiL 1st Ed. that has to do with downloads, and making things much, much faster by supporting several at a time. You might want to look at that. (www.lua.org/pil) |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #5 on Thu 01 Mar 2007 12:58 AM (UTC) |
Message
| I've already got through PiL, and it doesn't have much that's not in the core Lua, which makes sense. I think what you're refering to is the file IO, where you can chunk a large file into smaller bits to make it load a bit quicker. I haven't poked at LuaSockets yet, since it's not needed at all for my project. I just thought it would be a nice addition. I'm already doing strange enough things like parsing scripts for another client here. |
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #6 on Thu 01 Mar 2007 03:54 AM (UTC) |
Message
|
Quote:
I was wondering how hard it would be to tell if the file is taking a long time to download
I think LuaSockets has an asynchronous mode for some or all things. For example, I started writing a MUD server using Lua and LuaSockets, and didn't have any problems with that aspect.
Judging by what I have read so far, it does indeed work with HTTP (and presumable FTP) requests. See this page:
http://lua-users.org/wiki/FiltersSourcesAndSinks
It seems you supply a "sink" argument, which is a function which is passed the data during the course of a long download. I haven't experimented with it, but that sounds right.
As for storing the data, one approach is to simply serialize it into the plugin's state file. You are allowed to do that without changing the sandbox. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #7 on Thu 01 Mar 2007 04:54 AM (UTC) |
Message
| Thanks for the link. I think that might be the same one a friend of mine showed me, which I forgot to bookmark. He too is planning on writing a MUD server with Lua.
I'll tinker with LuaSockets and see what I come up with. I'll probably get quite confused and come back asking for help in a week.
I had thought about serializing it, but I saw two problems. 1) if the server I have goes down, how will people just starting the plugin ever use it? 2) how well does MC deal with a 30k variable? The first one isn't terribly important, as a text file can be bundled into a zipped archive. |
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #8 on Thu 01 Mar 2007 05:40 AM (UTC) |
Message
|
Quote:
1) if the server I have goes down, how will people just starting the plugin ever use it?
I'm not sure I understand the question. If the variable isn't defined, or is empty, you just download it.
Quote:
2) how well does MC deal with a 30k variable?
It should be fine. I tried this:
/SetVariable ("x", string.rep ("x", 40000))
It is a bit slow to open the edit window if you try to edit "x" in the variable editor, but otherwise it is ok. I saved the world, and reloaded it without noticeable delay.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Shadowfyr
USA (1,788 posts) Bio
|
Date
| Reply #9 on Thu 01 Mar 2007 06:44 AM (UTC) |
Message
| Shaun, languages are just different ways of doing the same things, with some variations. While I may not "know" Lua, I do know enough about it to guess that it has sockets functions or that you can do the same thing I did with VBScript, which **doesn't** support them natively. I don't need to know the language to make reasonable guesses about what is possible in it. Now, if you where talking about trying to do it with one like COBOL 42, I might agree that making informed guesses is a problem.
Ones I know: Pascal, VB, some C, a smidgen of C++, some python, etc. When I say I don't know Lua I mean I don't know tricks that only "it" does, like some table manipulation, not that I can't do basic stuff in it. Its not *that* different from Basic or even Pascal.
That said, yeah. Using a hyperlink to let them do the downloading works too. Its just the, "Use IE to do it", option done a different way. Now, lets back off from each other on this before one or both of us get so irritated that we say something we regret way more than anything already said... | Top |
|
Posted by
| Shaun Biggs
USA (644 posts) Bio
|
Date
| Reply #10 on Thu 01 Mar 2007 10:06 AM (UTC) |
Message
| The first issue was phrased poorly. I meant to say the first time the plugin is run. And I did mention bundling a startup file with all the data with it, even if it's not the most current version. |
It is much easier to fight for one's ideals than to live up to them. | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #11 on Thu 01 Mar 2007 07:42 PM (UTC) |
Message
| Yes you could do that, but then you have to enable file IO to read such a file in. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
28,508 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top