advanced_telopt
index
/mud/nakedmud-mod/lib/pymodules/advanced_telopt.py

advanced_telopt.py
 
Adds advanced TELOPT negotiations to the MUD, including support for:
 
* TELOPT_NAWS  - Negotiate About Window Size
    Determine the size of the client window in columns and rows.
 
* TELOPT_TTYPE - Terminal Type
    Determine the connected client to estimate its capabilities.
 
* TELOPT_EOR   - End-of-Record
    Mark the end of text transmission from the server with IAC EOR to let a
    client know the exact point. If enabled, this is automatically appended
    to the end of the prompt.
 
* TELOPT_MSP   - MUD Sound Protocol
    Trigger the playback of sounds and music on the client. Only basic support
    is included... negotiation and the triggering of hooks when it's enabled
    or disabled. The rest of the implementation is up to the MUD creator, though
    it consists merely of sending your own MSP commands to the client.
    
* TELOPT_MSDP  - MUD Server Data Protocol
    MSDP allows you to easilly send variables to the client.
 
* TELOPT_MXP   - MUD eXtension Protocol
    MXP is, for those who don't know, an application of HTML-like tags to the
    MUD itself, allowing for richer interaction with the user. It is in no way
    critical to playing and enjoying the game, but it is a nice touch.
    
    Note that this implementation of MXP isn't complete, as it doesn't handle
    asking the client which tags it supports. I'd recommend keeping yourself
    limited to simple tags like <SEND> if you don't add <SUPPORTS> support.
    
    For more information about MXP, visit http://www.zuggsoft.com/zmud/mxp.htm
 
* Window Title Text
    Set a custom string to the window's title bar. This also works together
    with TELOPT_TTYPE to avoid sending the code to clients that wouldn't
    properly interpret it.
    
    If the bell() function of a socket is called, the title will be flashed
    with two prepended asterisks until the next command is recieved. This can
    be used to notify a distracted player when the MUD needs their input.
    
* XTERM 256 and ANSI Colors
    This file also handles color code parsing, taking that functionality away
    from colour.py as to combine color formatting and MXP conversion into one
    post-processing function. I haven't tested it, but I can only assume that
    one less function call makes things easier on the server.

 
Modules
       
auxiliary
event
hooks
mud
mudsock
mudsys
random
re
storage
telnetlib

 
Classes
       
TeloptAux
VariableData

 
class TeloptAux
     Methods defined here:
__init__(self, set=None)
copy(self)
copyTo(self, to)
load(self, set=None)
store(self)

 
class VariableData
    ################################################################################
# Auxiliary Data for the Socket
################################################################################
 
  Methods defined here:
__delitem__(self, key)
__getitem__(self, key)
__init__(self)
__setitem__(self, key, val)
__str__(self)
copy(self)
has_key(self, key)

 
Functions
       
__unload__()
Detatch our hooks from the game.
ansi_color(match)
Replace a matching color code with the simplified ANSI escape sequence.
begin_negotiations(info)
Sends the initial negotiation strings to new sockets.
c256_color(match)
Replace a matching color code with the proper 256-color escape sequence.
cmd_colors(ch, cmd, arg)
Usage: {Wcolors{n
 
Displays a table of avaliable colors and the code used to select them.
copyover()
Saves the telopt auxiliary data of all active connections with set players
to be restored after the copyover is complete.
copyover_complete(info)
Loads socket auxiliary data for the active connections from a file.
flash_title(owner, data, arg)
Scheduled event that, once per second, toggles the titlebar notification flag and sends the updated title to the client.
msdp_start_hook(info)
Send out all the current MSDP variables.
mxp_color(match)
Replace a matching color code with an MXP tag. This is for zMUD.
mxp_start_hook(info)
Send out our notice that MXP is starting, along with the MXP tags.
mxp_stop_hook(info)
Send a wont MXP string.
mxp_tag(sock, text='', tag='', args='', closing=False)
Output a MXP tag. If it's a secure tag, flag the socket so it's next line is sent secure.
 
If closing is true and text is not supplied, only a closing tag will be returned. Be sure that args is None if you're making a closing tag.
If text is None, only a single tag will be created. This can be useful for sending things like the <IMAGE> tag.
post_command(info)
Hook that will stop flashing the titlebar once a command is recieved.
process_iac_sequence(info)
Process the IAC sequence to see if it was one of the options supported.
process_outbound_prompt(info)
Process outbound prompt to add END-OF-RECORD on the end if necessary.
process_outbound_text(info)
Process outbound text by replacing color codes and escaping MXP tags.
register_mxp_flag(name, flag)
Add a new MXP flag to the list of tags. This is good for easilly setting a list of
variables for things like the prompt, or adding custom tags for flagging room
names and descriptions and the like.
register_mxp_tag(name, args=None, secure=False)
Add a new MXP tag to the list of tags. The name must be an alphanumeric string, and
args should be a string of the element's arguments, though it could be None. If secure
is true, the tag will be added to a list of flags that are sent via an MXP secure line.
rgb2hsv(r, g, b)
Convert an RGB color to HSV.
send_title(sock)
Sends the current title string to the socket.
simplecolor(c, html=False)
Simplify an xterm 256 color code down to ANSI 16. It isn't perfect,
but it works a whole lot better than stripping all color, or letting
people with poor client choices from seeing a screen of garbled mess.
 
Will return an HTML hex color code if html is true

 
Data
        MSDP = 'E'
MSDP_VAL = '\x02'
MSDP_VAR = '\x01'
MSP = 'Z'
MXP = '['
client_do_eor = '\xff\xfd\x19'
client_do_msdp = '\xff\xfdE'
client_do_msp = '\xff\xfdZ'
client_do_mxp = '\xff\xfd['
client_dont_eor = '\xff\xfe\x19'
client_dont_msdp = '\xff\xfeE'
client_dont_msp = '\xff\xfeZ'
client_dont_mxp = '\xff\xfe['
client_naws = '\xff\xfa\x1f'
client_ttype_is = '\xff\xfa\x18'
client_will_naws = '\xff\xfb\x1f'
client_will_ttype = '\xff\xfb\x18'
clients = ['jmud', 'xterm', 'fmud', 'zmud', 'mushclient', 'tintin++', 'ansi', 'unknown']
clients256 = ['jmud', 'zmud', 'mushclient', 'tintin++', 'xterm']
coloreg = <_sre.SRE_Pattern object>
colorletters = 'drgybpcwDRGYBPCW'
colors = {'b': '34', 'c': '36', 'd': '30', 'g': '32', 'n': '0', 'p': '35', 'r': '31', 'w': '37', 'y': '33'}
colorvalues = [0, 95, 135, 175, 215, 255]
copyover_file = '../lib/misc/copyover'
extcolors = ['0;30', '0;31', '0;32', '0;33', '0;34', '0;35', '0;36', '0;37', '1;30', '1;31', '1;32', '1;33', '1;34', '1;35', '1;36', '1;37', '0;30', '0;34', '0;34', '0;34', ...]
htmlcolors = ['#000000', '#800000', '#008000', '#808000', '#000080', '#800080', '#008080', '#C0C0C0', '#808080', '#FF0000', '#00FF00', '#FFFF00', '#0000FF', '#FF00FF', '#00FFFF', '#FFFFFF', '#000000', '#00005f', '#000087', '#0000af', ...]
linkreg = <_sre.SRE_Pattern object>
msdp_end = '\xff\xf0'
msdp_start = '\xff\xfaE'
mxp_and = '\x04MXP\x03'
mxp_escape = '\x1b['
mxp_lock_locked = '\x1b[7z'
mxp_lock_open = '\x1b[5z'
mxp_lock_secure = '\x1b[6z'
mxp_locked_line = '\x1b[2z'
mxp_open_line = '\x1b[0z'
mxp_reset = '\x1b[3z'
mxp_secure_line = '\x1b[1z'
mxp_secure_tags = ['SEND', 'A', 'VAR', 'NOBR', 'P', 'BR', 'SBR', 'EXPIRE', 'VERSION', 'SUPPORT', 'GAUGE', 'STAT', 'SOUND', 'MUSIC', 'FRAME', 'DEST', 'RELOCATE', 'IMAGE', 'FILTER']
mxp_tag_end = '\x02MXP\x03'
mxp_tag_start = '\x01MXP\x03'
mxp_tags = []
mxp_temp_secure = '\x1b[4z'
mxpreg = <_sre.SRE_Pattern object>
no_title = ['fmud', 'zmud', 'mushclient', 'ansi', 'unknown']
server_do_naws = '\xff\xfd\x1f'
server_do_ttype = '\xff\xfd\x18'
server_eor_code = '\xff\xef'
server_send_ttype = '\xff\xfa\x18\x01\xff\xf0'
server_start_mxp = '\xff\xfa[\xff\xf0'
server_will_eor = '\xff\xfb\x19'
server_will_msdp = '\xff\xfbE'
server_will_msp = '\xff\xfbZ'
server_will_mxp = '\xff\xfb['
server_wont_eor = '\xff\xfc\x19'
server_wont_msp = '\xff\xfcZ'
server_wont_mxp = '\xff\xfc['