Allow to disable MXP or make it one-directional. Resolve #2169.
This commit is contained in:
parent
3474ffa008
commit
6fef01a3b1
5 changed files with 53 additions and 5 deletions
|
|
@ -38,10 +38,24 @@ _GA = object.__getattribute__
|
|||
_SA = object.__setattr__
|
||||
|
||||
|
||||
_STRIP_INCOMING_MXP = settings.MXP_ENABLED and settings.MXP_OUTGOING_ONLY
|
||||
_STRIP_MXP = None
|
||||
|
||||
|
||||
|
||||
def _NA(o):
|
||||
return "N/A"
|
||||
|
||||
|
||||
def _maybe_strip_incoming_mxp(txt):
|
||||
global _STRIP_MXP
|
||||
if _STRIP_INCOMING_MXP:
|
||||
if not _STRIP_MXP:
|
||||
from evennia.utils.ansi import strip_mxp as _STRIP_MXP
|
||||
return _STRIP_MXP(txt)
|
||||
return txt
|
||||
|
||||
|
||||
_ERROR_INPUT = "Inputfunc {name}({session}): Wrong/unrecognized input: {inp}"
|
||||
|
||||
|
||||
|
|
@ -74,6 +88,9 @@ def text(session, *args, **kwargs):
|
|||
if txt.strip() in _IDLE_COMMAND:
|
||||
session.update_session_counters(idle=True)
|
||||
return
|
||||
|
||||
txt = _maybe_strip_incoming_mxp(txt)
|
||||
|
||||
if session.account:
|
||||
# nick replacement
|
||||
puppet = session.puppet
|
||||
|
|
@ -112,6 +129,9 @@ def bot_data_in(session, *args, **kwargs):
|
|||
if txt.strip() in _IDLE_COMMAND:
|
||||
session.update_session_counters(idle=True)
|
||||
return
|
||||
|
||||
txt = _maybe_strip_incoming_mxp(txt)
|
||||
|
||||
kwargs.pop("options", None)
|
||||
# Trigger the execute_cmd method of the corresponding bot.
|
||||
session.account.execute_cmd(session=session, txt=txt, **kwargs)
|
||||
|
|
@ -122,6 +142,9 @@ def echo(session, *args, **kwargs):
|
|||
"""
|
||||
Echo test function
|
||||
"""
|
||||
if _STRIP_INCOMING_MXP:
|
||||
txt = strip_mxp(txt)
|
||||
|
||||
session.data_out(text="Echo returns: %s" % args)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ http://www.gammon.com.au/mushclient/addingservermxp.htm
|
|||
|
||||
"""
|
||||
import re
|
||||
from django.conf import settings
|
||||
|
||||
LINKS_SUB = re.compile(r"\|lc(.*?)\|lt(.*?)\|le", re.DOTALL)
|
||||
URL_SUB = re.compile(r"\|lu(.*?)\|lt(.*?)\|le", re.DOTALL)
|
||||
|
|
@ -60,7 +61,8 @@ class Mxp:
|
|||
"""
|
||||
self.protocol = protocol
|
||||
self.protocol.protocol_flags["MXP"] = False
|
||||
self.protocol.will(MXP).addCallbacks(self.do_mxp, self.no_mxp)
|
||||
if settings.MXP_ENABLED:
|
||||
self.protocol.will(MXP).addCallbacks(self.do_mxp, self.no_mxp)
|
||||
|
||||
def no_mxp(self, option):
|
||||
"""
|
||||
|
|
@ -81,6 +83,9 @@ class Mxp:
|
|||
option (Option): Not used.
|
||||
|
||||
"""
|
||||
self.protocol.protocol_flags["MXP"] = True
|
||||
self.protocol.requestNegotiation(MXP, b"")
|
||||
if settings.MXP_ENABLED:
|
||||
self.protocol.protocol_flags["MXP"] = True
|
||||
self.protocol.requestNegotiation(MXP, b"")
|
||||
else:
|
||||
self.protocol.wont(MXP)
|
||||
self.protocol.handshake_done()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue