Sign in to follow this  

Programming a Lua MUD server, trying to accept keyboard input

This topic is 1971 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to program a MUD server in Lua, as I've had a good bit of experience in writing scripts for the Mudlet client and Lua is the language I'm currently most comfortable with. I've run into a bit of a brick wall though. I'd like for the server, a console application, to accept keyboard input, so when I'm running the games i can interact as an admin from the server itself. The problem is, all the functions for accepting input in Lua are blocking functions. Should I just program a backdoor into the server, so I can connect as an admin from any telnet client? Or is there a simple way to accept keyboard input to the console app without blocking the rest of the script from running?

Share this post


Link to post
Share on other sites
What environment are you using to host your Lua scripts? If it doesn't already provide a non-blocking console API, it should be possible to add one, depending on the hosting program and OS.

Share this post


Link to post
Share on other sites
Bah, stupid phone.

Its the Lua for Windows package, if that's what you're asking.(Sorry, I'm new at this thing... all my Lua experience has been scripting in Mudlet, which auto compiles/runs the scripts for you. Over there, you just type the code out and save it.) Edited by WackyWormer

Share this post


Link to post
Share on other sites
Gotcha. So LFW has support for some useful libraries that you might check out, including CUI (console-mode UI package) and LuaInterface (which lets you interact with .Net software). You could try using CUI to do the console stuff, or just write a full-blown UI in C# or something and rig it up with LuaInterface.

Share this post


Link to post
Share on other sites
It's a bit unclear what exactly are you asking for. Have you got a MUD server already? If what you mean scripts for it, then you'r probably be writing the script, uploading it to the server (or writing it on the server directly) and then reloading it in the Lua VM. There isn't a problem of blocking user input here, so perhaps I'm misunderstanding you.

For a Lua MUD server, check out [url="https://github.com/endgame/MudCore"]MudCore[/url], which is build on pretty good stuff. I can't vouch for how well it would perform, I've only fiddled with it a bit, but the tech behind it is pretty solid.

It's cross-platform as well so you wouldn't be getting tied down to finding a Windows server for your hosting. Edited by Vadi

Share this post


Link to post
Share on other sites
If I understand the question correctly: "Is there some way to read console input on Windows with LUA without blocking the running thread?"
It does look like the CUI library has a "nodelay" option to allow polled input.
However, if I were to do this personally, I would add an attribute to users for whether they are allowed admin options or not, and just do it using regular logins.
If this scales up to a bigger system, you'd want to replace "is_admin" with a list of specific granted privileges, and test different privileges for different management functions. This would allow certain users to be "wizards" without being "admins."

Share this post


Link to post
Share on other sites
I've decided to go with the "client with admin privileges" idea. Now the only thing that concerns me is closing the server without shutting down the client connections. Is there any way to call a function when the console window is destroyed, like the WM_DESTROY event I remember using in my c++ apps?

Share this post


Link to post
Share on other sites
Not sure I'm understanding your question. What exactly is it you want to avoid? Do you mean you want the server to keep running even if you close the console?

Share this post


Link to post
Share on other sites
No, I'm worried that I'm never calling the client: close function, because I have no way of exiting the game loop because I don't have input directly to the server. Though I suppose that the client with admin privs could send a shutdown command.



Share this post


Link to post
Share on other sites
[quote]Yep, a shutdown command is the typical way to handle that.
[/quote]

If your game is designed to require a "clean" shutdown, then the first "hard" crash you get will destroy your game.
Design your game to survive any "hard" failure. If you need to shut down the server, just kill the process. (You may want to tell users a few minutes before, of course ;-)

Netflix takes this one step further: Because systems will fail, and all systems should be written to survive failure, they have a "chaos monkey" that will randomly kill servers/services. You have to design your code so that you survive this. It's a different way of thinking.

Share this post


Link to post
Share on other sites
This is a good point.

However, especially during development clean shutdowns can be extremely useful as you can use them to spot-check for leaks, things that don't clean up properly, and so on. In my experience making sure things can shutdown cleanly is a good first step to making sure they are also recoverable in the worst-case scenario.

Share this post


Link to post
Share on other sites

This topic is 1971 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this