lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Jul 14, 2012 10:43 PM, "Paco Willers" <paco.willers@gmail.com> wrote:
>
> I couldn't find this in the mailing list archives, nor anywhere else, so I'm asking this here though. :-) I searched anywhere. Not finding it makes me feel like:
>
> - either nobody asks because the solution is simple
> - my approach is faulty
> - or nobody ever wanted to know :-)
>
> What I need is a character based input without an end of line symbol. Like in BASIC: INKEY$.
>
> Anyway... I am writing a multiple user telnet (game) server in Lua using LuaSocket and/or Copas libraries.
>
> By the way, I said "telnet game", but I didn't mean the telnet protocol. Telnet is just an example of a client application. I mean raw IP traffic. The client uses "Telnet" or "PuTTY" .
>
> So I encounter two challenges:
>
> 1.) On the client side passwords must be discretely displayed as asterisks.
> 2.) The game simulates time consuming processes, so an animated busy - \ | / cursor or a 0%-100% process bar should be run without blocking other clients (coroutines).
>
> I could have a completely wrong understanding of the concept, but the LuaSocket and Copas libraries only have line-based entries:
>
> 1.) The client types it's password which is directly echoed to the client's screen, and is sent to the server after pressing <enter>. So no asterisks can be echoed.
> 2.) A socket's coroutine can of course display busy cursors or progress bars, but they block other client's coroutines while counting.
>
> The solution should be: character-orientent traffic instead of line-oriented traffic. In case of passwords, the server should echo an asterisk directly after typing a character on the client side. The server should also be able to yield to another client (coroutine) to be able to display progress bars (characters) without blocking.
>
> In my opinion, character based communication is the solution (yield or read one character and send one), instead of line-based, but how to accomplish that? The Copas manual says that copas.read() has arguments, but it refers to the LuaSocket manual. It says: line/all/number. Line is standard. That sounds OK, because io.read() has something similar. So I tried it with a number like 1. It works! Copas.read() really processes the input as separated characters. The LuaSocket equivalent also does, and so does io.read(). But... the real processing of these characters begins after the function reaches end of line (or <enter>).
>
> How can I process character input from copas.read(), socket.read() or io.read() or whatever without first having to reach an end of line character? Or is my approach completely wrong?
>
>
> Have a nice day,
> --
> Paco

Which Telnet client are you using? Last I used the Windows client, it [was terrible and] defaulted to line-input mode (nothing is sent until you press enter); you have to go to the settings (using ^] or some such) and change it to character mode and turn off local echo. Then your server can echo asterisks. There should be ANSI escape codes the server can use to change the modes, but I'm not sure Windows supports them or they even exist.

To display progress bars, you probably want some kind of event loop. Your simulated process can then register a timer callback event in which it draws a progress bar. Coroutines can be nice here, but you don't really need them.