Adds in support for links
This commit is contained in:
parent
ef23cfceb9
commit
cde64692ff
5 changed files with 96 additions and 7 deletions
57
src/server/portal/mxp.py
Normal file
57
src/server/portal/mxp.py
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
"""
|
||||
MXP - Mud eXtension Protocol.
|
||||
|
||||
Partial implementation of the MXP protocol.
|
||||
The MXP protocol allows more advanced formatting options for telnet clients
|
||||
that supports it (mudlet, zmud, mushclient are a few)
|
||||
|
||||
This only implements the SEND tag.
|
||||
|
||||
More information can be found on the following links:
|
||||
http://www.zuggsoft.com/zmud/mxp.htm
|
||||
http://www.mushclient.com/mushclient/mxp.htm
|
||||
http://www.gammon.com.au/mushclient/addingservermxp.htm
|
||||
"""
|
||||
import re
|
||||
|
||||
LINKS_SUB = re.compile(r'\{lc(.*?)\{lt(.*?)\{le', re.DOTALL)
|
||||
|
||||
MXP = "\x5B"
|
||||
MXP_TEMPSECURE = "\x1B[4z"
|
||||
MXP_SEND = MXP_TEMPSECURE + \
|
||||
"<SEND HREF='\\1'>" + \
|
||||
"\\2" + \
|
||||
MXP_TEMPSECURE + \
|
||||
"</SEND>"
|
||||
|
||||
def mxp_parse(text):
|
||||
"""
|
||||
Replaces links to the correct format for MXP.
|
||||
"""
|
||||
text = LINKS_SUB.sub(MXP_SEND, text)
|
||||
return text
|
||||
|
||||
class Mxp(object):
|
||||
"""
|
||||
Implements the MXP protocol.
|
||||
"""
|
||||
|
||||
def __init__(self, protocol):
|
||||
"""Initializes the protocol by checking if the client supports it."""
|
||||
self.protocol = protocol
|
||||
self.protocol.protocol_flags["MXP"] = False
|
||||
self.protocol.will(MXP).addCallbacks(self.do_mxp, self.no_mxp)
|
||||
|
||||
def no_mxp(self, option):
|
||||
"""
|
||||
Client does not support MXP.
|
||||
"""
|
||||
self.protocol.protocol_flags["MXP"] = False
|
||||
|
||||
def do_mxp(self, option):
|
||||
"""
|
||||
Client does support MXP.
|
||||
"""
|
||||
self.protocol.protocol_flags["MXP"] = True
|
||||
self.protocol.handshake_done()
|
||||
self.protocol.requestNegotiation(MXP, '')
|
||||
|
|
@ -12,6 +12,7 @@ from twisted.conch.telnet import Telnet, StatefulTelnetProtocol, IAC, LINEMODE,
|
|||
from src.server.session import Session
|
||||
from src.server.portal import ttype, mssp, msdp, naws
|
||||
from src.server.portal.mccp import Mccp, mccp_compress, MCCP
|
||||
from src.server.portal.mxp import MXP, Mxp, mxp_parse
|
||||
from src.utils import utils, ansi, logger
|
||||
|
||||
_RE_N = re.compile(r"\{n$")
|
||||
|
|
@ -47,6 +48,8 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
|
|||
self.mssp = mssp.Mssp(self)
|
||||
# msdp
|
||||
self.msdp = msdp.Msdp(self)
|
||||
# mxp support
|
||||
self.mxp = Mxp(self)
|
||||
# add this new connection to sessionhandler so
|
||||
# the Server becomes aware of it.
|
||||
self.sessionhandler.connect(self)
|
||||
|
|
@ -199,6 +202,8 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
|
|||
given, ttype result is used. If
|
||||
client does not suport xterm256, the
|
||||
ansi fallback will be used
|
||||
mxp=True/False - enforce mxp setting. If not given, enables if we
|
||||
detected client support for it
|
||||
ansi=True/False - enforce ansi setting. If not given,
|
||||
ttype result is used.
|
||||
nomarkup=True - strip all ansi markup (this is the same as
|
||||
|
|
@ -234,6 +239,7 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
|
|||
nomarkup = kwargs.get("nomarkup", not (xterm256 or useansi))
|
||||
prompt = kwargs.get("prompt")
|
||||
echo = kwargs.get("echo", None)
|
||||
mxp = kwargs.get("mxp", "MXP" in self.protocol_flags)
|
||||
|
||||
#print "telnet kwargs=%s, message=%s" % (kwargs, text)
|
||||
#print "xterm256=%s, useansi=%s, raw=%s, nomarkup=%s, init_done=%s" % (xterm256, useansi, raw, nomarkup, ttype.get("init_done"))
|
||||
|
|
@ -244,7 +250,10 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
|
|||
# we need to make sure to kill the color at the end in order
|
||||
# to match the webclient output.
|
||||
#print "telnet data out:", self.protocol_flags, id(self.protocol_flags), id(self), "nomarkup: %s, xterm256: %s" % (nomarkup, xterm256)
|
||||
self.sendLine(ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nomarkup, xterm256=xterm256))
|
||||
linetosend = ansi.parse_ansi(_RE_N.sub("", text) + "{n", strip_ansi=nomarkup, xterm256=xterm256, mxp=mxp)
|
||||
if mxp:
|
||||
linetosend = mxp_parse(linetosend)
|
||||
self.sendLine(linetosend)
|
||||
|
||||
if prompt:
|
||||
# Send prompt separately
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue