Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10085

Writing a MUD Console

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <jgardner@jonathangardner.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'python.': 0.04; 'escape': 0.04; 'instance,': 0.05; 'sys': 0.05; 'behave': 0.07; 'python': 0.08; 'exception:': 0.09; 'hooks': 0.09; 'host,': 0.09; 'none:': 0.09; 'runtime': 0.09; 'spawn': 0.09; 'subprocess': 0.09; 'displayed': 0.11; 'output': 0.11; 'conn': 0.16; 'ctrl-c': 0.16; 'experiments': 0.16; 'license:': 0.16; 'on-line.': 0.16; 'piped': 0.16; 'react': 0.16; 'subject:Console': 0.16; 'throws': 0.16; 'def': 0.16; 'written': 0.17; 'functions,': 0.19; 'working.': 0.19; 'raymond': 0.19; 'seems': 0.20; 'input': 0.21; '(most': 0.21; 'skip:* 40': 0.22; 'maybe': 0.22; 'trying': 0.23; 'here?': 0.23; 'interpreted': 0.23; 'opens': 0.23; 'code': 0.24; 'traceback': 0.25; 'skip:[ 10': 0.26; 'host': 0.28; 'character': 0.28; 'message-id:@mail.gmail.com': 0.28; 'import': 0.29; 'combination': 0.29; 'sends': 0.29; 'environment': 0.29; 'do.': 0.30; 'basically,': 0.30; 'character.': 0.30; 'cmd': 0.30; 'commands,': 0.30; 'subject:Writing': 0.30; 'received:209.85.216.46': 0.31; 'received:mail- qw0-f46.google.com': 0.31; 'connected': 0.32; 'print': 0.32; 'skip:" 20': 0.33; 'to:addr:python-list': 0.34; 'there': 0.34; 'however,': 0.34; '17,': 0.35; 'curious': 0.35; 'last):': 0.35; 'preliminary': 0.35; 'try:': 0.35; "isn't": 0.35; 'format.': 0.35; 'certain': 0.36; 'idea': 0.36; 'connection': 0.36; 'file': 0.36; 'option': 0.37; 'jonathan': 0.37; 'could': 0.37; 'another': 0.38; 'getting': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'put': 0.38; 'data': 0.39; 'except': 0.39; 'skip:s 20': 0.39; 'goes': 0.39; 'to:addr:python.org': 0.39; 'might': 0.39; 'received:209': 0.40; 'your': 0.60; 'matter': 0.61; 'address': 0.61; 'closed': 0.62; 'you.': 0.62; 'foreign': 0.66; 'show': 0.67; 'special': 0.67; 'online': 0.70; 'email name:support': 0.77; 'directed': 0.80; 'commands.': 0.84; 'intercepted,': 0.84; 'novels': 0.84; 'rapture': 0.91
MIME-Version 1.0
Date Fri, 22 Jul 2011 01:20:46 -0700
Subject Writing a MUD Console
From Jonathan Gardner <jgardner@jonathangardner.net>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1352.1311322848.1164.python-list@python.org> (permalink)
Lines 100
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1311322848 news.xs4all.nl 23864 [2001:888:2000:d::a6]:46516
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:10085

Show key headers only | View raw


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 support@midkemiaonline.com
           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
jgardner@jonathangardner.net

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Writing a MUD Console Jonathan Gardner <jgardner@jonathangardner.net> - 2011-07-22 01:20 -0700

csiph-web