Skip to main content
GameDev.net gamedev.net
🔒 Locked

Programming a Lua MUD server, trying to accept keyboard input

Started by WackyWormer Aug 21, 2012 at 6:17 PM 12 replies 4.9k views
Original Post
WackyWormer
WackyWormer
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?
ApochPiQ
ApochPiQ
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.
WackyWormer
WackyWormer
I'm developing in Windows 7, using SCite
WackyWormer
WackyWormer
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.)
ApochPiQ
ApochPiQ
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.
Vadi
Vadi
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 MudCore, 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.
hplus0603
hplus0603
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."
enum Bool { True, False, FileNotFound };
WackyWormer
WackyWormer
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?
ApochPiQ
ApochPiQ
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?
WackyWormer
WackyWormer
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.



hplus0603
hplus0603
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.
enum Bool { True, False, FileNotFound };
ApochPiQ
ApochPiQ
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.