Jump to content

  • Log In with Google      Sign In   
  • Create Account

Programming a Lua MUD server, trying to accept keyboard input


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 WackyWormer   Members   -  Reputation: 126

Like
0Likes
Like

Posted 21 August 2012 - 12:17 PM

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?

Sponsor:

#2 ApochPiQ   Moderators   -  Reputation: 15699

Like
0Likes
Like

Posted 21 August 2012 - 04:57 PM

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.

#3 WackyWormer   Members   -  Reputation: 126

Like
0Likes
Like

Posted 21 August 2012 - 06:15 PM

I'm developing in Windows 7, using SCite

#4 ApochPiQ   Moderators   -  Reputation: 15699

Like
0Likes
Like

Posted 21 August 2012 - 06:18 PM

OK, but what are you using to run your actual Lua scripts?

#5 WackyWormer   Members   -  Reputation: 126

Like
0Likes
Like

Posted 21 August 2012 - 06:19 PM

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, 21 August 2012 - 06:25 PM.


#6 ApochPiQ   Moderators   -  Reputation: 15699

Like
1Likes
Like

Posted 21 August 2012 - 06:51 PM

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.

#7 Vadi   Members   -  Reputation: 101

Like
0Likes
Like

Posted 22 August 2012 - 06:00 AM

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.

Edited by Vadi, 22 August 2012 - 06:03 AM.


#8 hplus0603   Moderators   -  Reputation: 5303

Like
1Likes
Like

Posted 23 August 2012 - 12:16 PM

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 };

#9 WackyWormer   Members   -  Reputation: 126

Like
0Likes
Like

Posted 23 August 2012 - 06:37 PM

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?

#10 ApochPiQ   Moderators   -  Reputation: 15699

Like
0Likes
Like

Posted 23 August 2012 - 06:40 PM

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?

#11 WackyWormer   Members   -  Reputation: 126

Like
0Likes
Like

Posted 23 August 2012 - 10:19 PM

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.





#12 ApochPiQ   Moderators   -  Reputation: 15699

Like
0Likes
Like

Posted 23 August 2012 - 11:25 PM

Yep, a shutdown command is the typical way to handle that.

#13 hplus0603   Moderators   -  Reputation: 5303

Like
0Likes
Like

Posted 24 August 2012 - 10:29 AM

Yep, a shutdown command is the typical way to handle that.


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 };

#14 ApochPiQ   Moderators   -  Reputation: 15699

Like
0Likes
Like

Posted 24 August 2012 - 10:49 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS