Telnet linebreaks

Jean-Paul Calderone exarkun at divmod.com
Thu May 25 15:08:47 EDT 2006


>>On 5/24/06, Patrick M. Nielsen <thirsteh at gmail.com > wrote:
>> >
>> > Hey guys.
>> >
>> > I have begun playing with the Simple MUD server example from the
>> > Stackless website
>> > ( http://www.stackless.com/Members/rmtew/code/mud.py )
>> > and it's all good so far, however, I've come to notice something that I
>> > remember from back
>> > in the days (some old mud code), but I don't remember what I did to fix
>> > it.
>> >
>> > While the MUD reads lines from Telnet clients just fine, clients such as
>> > Gmud are practically ignored,
>> > probably because Gmud doesn't send Telnet-valid data ('\x08'?).

\x08 is \b is backspace.  Servers support this character so that clients that don't actually delete the previous input character when you hit backspace will work as the user expects.  Gmud doesn't send it because Gmud has a GUI input area and actually deletes characters when you hit backspace.

>> >
>> > However, a MUD that is not accessible to one such client or others isn't
>> > much good, so I'd appreciate
>> > some help in pinpointing the problem.

I don't think you've correctly identified the root cause of the problem.

>> >
>> > These are the code blocks that need modification (I believe)
>> >
>> >     def read(self): # TELNET
>> >         ret = self.readChannel.receive()
>> >         if self.echo:
>> >             if ret == '\x08':
>> >                 self.send(ret+" ")

Here the server takes extra pains to actually erase the "deleted" character that the client sent.

>> >             self.send(ret)
>> >         return ret
>> >
>> >     def readline(self): # TELNET
>> >         buf = self.readBuffer
>> >
>> >         while True:
>> >             if buf.find('\r\n') > -1: # MUD clients that aren't using
>> > the telnet protocol
>> >                 i = buf.index('\r\n') # need to be able to do stuff.
>> >                 ret = buf[:i+2]
>> >                 self.readBuffer = buf[i+2:]
>> >                 while '\x08' in ret:
>> >                     i = ret.index('\x08')
>> >                     if i == 0:
>> >                         ret = ret[1:]
>> >                     else:
>> >                         ret = ret[:i-1]+ret[i+1:]
>> >                 return ret

And here it deletes it from the input which it is actually processing, so that a user who types "wield sq\bword" will wield their sword instead of being told they don't have a "sq\bword" to wield (which will probably be rendered as "sword" on their terminal, which would be pretty confusing).

>> >
>> >             buf += self.read()
>> >
>> > I'm suspecting that Gmud doesn't send '\x08', since from looking at some
>> > old DIKU code,
>> > I see that the if '\n' || '\r' are there as well, but there is no check
>> > for '\x08'. If this is indeed
>> > the cause of my problem, how would I go about doing it?

It sounds to me as though the cause of the problem lies elsewhere.

Twisted includes a rather complete telnet implementation (as well as an SSH implementation and a VT102 implementation).  You may want to take a look at it, either to use for your server, or at least to see the correct way to gather input from your clients.

Jean-Paul



More information about the Python-list mailing list