Writing a MUD Console


J

Jonathan Gardner

I had this idea on an easy way to write a MUD console.

Basically, you start a program written in Python. This will connect to
the MUD of your choice, and otherwise behave like Telnet. In fact, it
will just spawn telnet to do all the hard work for you.

As you type commands, they are piped directly into the telnet process
as MUD input commands. Commands that start with ! or maybe # will be
intercepted, however, and interpreted as special commands

Also, as output comes back, you can put hooks in to react to the data
and execute Python functions, or pipe the data to subprocesses you may
spawn. For instance, you might spawn a subprocess that opens up a
window to show your current map location. When the MUD sends the map,
it is intercepted and directed to this map subprocess. Your status
line could be interpreted and displayed in another window in graphical
format.

I have the feeling that this isn't that hard to do. It's just a matter
of getting the right combination of subprocesses working.

My preliminary experiments with the telnet subprocess have had curious results:

CODE:
import subprocess
import sys
import traceback

host = 'midkemiaonline.com'
port = '23'

conn = subprocess.Popen(
['/usr/bin/telnet', host, port],
stdin=subprocess.PIPE,
stdout=sys.stdout,
stderr=sys.stderr)

def do_command(cmd):
print "\n>>> {}".format(cmd)
try:
result = eval(cmd)
except Exception:
traceback.print_exc()
else:
if result is not None:
print repr(result)

while True:
cmd = raw_input()

if cmd[:1] == '!':
do_command(cmd[1:])
else:
conn.stdin.write(cmd)

conn.terminate()
END CODE

It seems all goes well, except certain input sequences are being
intercepted. For instance, CTRL-C throws a KeyboardInterrupt.

Also, I only get to enter one command:

$ ./telnetsubprocess.py
Trying 209.212.147.74...
Connected to midkemiaonline.com.
Escape character is '^]'.
Rapture Runtime Environment v2.1.6 -- (c) 2010 -- Iron Realms Entertainment
Multi-User License: 100-0004-000

*****************************************

-- Midkemia Online --

*****************************************

[Open Beta]

Based on the novels by Raymond E. Feist

Midkemia Online's IP address is 209.212.147.74
For general questions e-mail (e-mail address removed)
There are 20 people currently on-line.

1. Enter the game.
2. Create a new character.
3. Quit.

Enter an option or your character's name. 1
Traceback (most recent call last):
File "./telnetsubprocess.py", line 17, in <module>
cmd = raw_input()
EOFError
Connection closed by foreign host.

Any ideas on what is going on here?
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top