Writing a MUD Console

Discussion in 'Python' started by Jonathan Gardner, Jul 22, 2011.

  1. 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
    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?

    --
    Jonathan Gardner
     
    Jonathan Gardner, Jul 22, 2011
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Hsu

    mud(telnet) connection using Java

    Kevin Hsu, Apr 11, 2004, in forum: Java
    Replies:
    3
    Views:
    2,476
    steve
    Apr 15, 2004
  2. TheWater

    about the mud

    TheWater, Jul 17, 2003, in forum: C++
    Replies:
    3
    Views:
    382
    Mark K
    Jul 21, 2003
  3. Discipulus
    Replies:
    1
    Views:
    821
    Jack Diederich
    May 23, 2005
  4. Miktor
    Replies:
    7
    Views:
    12,192
    Joe Bacigalupa
    Aug 9, 2005
  5. Replies:
    5
    Views:
    3,469
    James Kanze
    Mar 4, 2008
Loading...

Share This Page