Fix MSDP byte conversion errors, as per #2044

This commit is contained in:
Griatch 2020-02-01 21:32:26 +01:00
parent 29f78ae601
commit 03356465db
9 changed files with 68 additions and 36 deletions

View file

@ -576,8 +576,7 @@ def msdp_list(session, *args, **kwargs):
fieldnames = [tup[1] for tup in monitor_infos]
session.msg(reported_variables=(fieldnames, {}))
if "sendable_variables" in args_lower:
# no default sendable variables
session.msg(sendable_variables=([], {}))
session.msg(sendable_variables=(_monitorable, {}))
def msdp_report(session, *args, **kwargs):
@ -597,6 +596,16 @@ def msdp_unreport(session, *args, **kwargs):
unmonitor(session, *args, **kwargs)
def msdp_send(session, *args, **kwargs):
"""
MSDP SEND command
"""
out = {}
for varname in args:
if varname.lower() in _monitorable:
out[varname] = _monitorable[varname.lower()]
session.msg(send=((), out))
# client specific

View file

@ -15,9 +15,10 @@ This protocol is implemented by the telnet protocol importing
mccp_compress and calling it from its write methods.
"""
import zlib
from twisted.python.compat import _bytesChr as chr
# negotiations for v1 and v2 of the protocol
MCCP = b"\x56"
MCCP = chr(86) # b"\x56"
FLUSH = zlib.Z_SYNC_FLUSH

View file

@ -12,10 +12,11 @@ active players and so on.
"""
from django.conf import settings
from evennia.utils import utils
from twisted.python.compat import _bytesChr as bchr
MSSP = b"\x46"
MSSP_VAR = b"\x01"
MSSP_VAL = b"\x02"
MSSP = bchr(70) # b"\x46"
MSSP_VAR = bchr(1) # b"\x01"
MSSP_VAL = bchr(2) # b"\x02"
# try to get the customized mssp info, if it exists.
MSSPTable_CUSTOM = utils.variable_from_module(settings.MSSP_META_MODULE, "MSSPTable", default={})
@ -85,7 +86,7 @@ class Mssp(object):
"NAME": settings.SERVERNAME,
"PLAYERS": self.get_player_count,
"UPTIME": self.get_uptime,
"PORT": list(
"PORT": list(str(port) for port in
reversed(settings.TELNET_PORTS)
), # most important port should be last in list
# Evennia auto-filled
@ -119,10 +120,10 @@ class Mssp(object):
if utils.is_iter(value):
for partval in value:
varlist += (
MSSP_VAR + bytes(variable, "utf-8") + MSSP_VAL + bytes(partval, "utf-8")
MSSP_VAR + bytes(str(variable), "utf-8") + MSSP_VAL + bytes(str(partval), "utf-8")
)
else:
varlist += MSSP_VAR + bytes(variable, "utf-8") + MSSP_VAL + bytes(value, "utf-8")
varlist += MSSP_VAR + bytes(str(variable), "utf-8") + MSSP_VAL + bytes(str(value), "utf-8")
# send to crawler by subnegotiation
self.protocol.requestNegotiation(MSSP, varlist)

View file

@ -14,11 +14,12 @@ http://www.gammon.com.au/mushclient/addingservermxp.htm
"""
import re
from twisted.python.compat import _bytesChr as bchr
LINKS_SUB = re.compile(r"\|lc(.*?)\|lt(.*?)\|le", re.DOTALL)
# MXP Telnet option
MXP = b"\x5b"
MXP = bchr(91) # b"\x5b"
MXP_TEMPSECURE = "\x1B[4z"
MXP_SEND = MXP_TEMPSECURE + '<SEND HREF="\\1">' + "\\2" + MXP_TEMPSECURE + "</SEND>"

View file

@ -11,9 +11,10 @@ client and update it when the size changes
"""
from codecs import encode as codecs_encode
from django.conf import settings
from twisted.python.compat import _bytesChr as bchr
NAWS = b"\x1f"
IS = b"\x00"
NAWS = bchr(31) # b"\x1f"
IS = bchr(0) # b"\x00"
# default taken from telnet specification
DEFAULT_WIDTH = settings.CLIENT_DEFAULT_WIDTH
DEFAULT_HEIGHT = settings.CLIENT_DEFAULT_HEIGHT

View file

@ -13,7 +13,9 @@ It is set as the NOGOAHEAD protocol_flag option.
http://www.faqs.org/rfcs/rfc858.html
"""
SUPPRESS_GA = b"\x03"
from twisted.python.compat import _bytesChr as bchr
SUPPRESS_GA = bchr(3) # b"\x03"
# default taken from telnet specification

View file

@ -75,6 +75,20 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
self.protocol_key = "telnet"
super().__init__(*args, **kwargs)
def dataReceived(self, data):
print(f"indata: {data}")
super().dataReceived(data)
def wont_no_true(self, state, option):
from evennia.utils import logger
logger.log_err(f"wont_no_true {self}, {state}, {option}")
super().wont_no_true(state, options)
def dont_no_true(self, state, option):
from evennia.utils import logger
logger.log_err(f"dont_no_true {self}, {state}, {option}")
super().dont_no_true(state, options)
def connectionMade(self):
"""
This is called when the connection is first established.

View file

@ -28,22 +28,24 @@ header where applicable.
import re
import json
from evennia.utils.utils import is_iter
# MSDP-relevant telnet cmd/opt-codes
MSDP = b"\x45"
MSDP_VAR = b"\x01" # ^A
MSDP_VAL = b"\x02" # ^B
MSDP_TABLE_OPEN = b"\x03" # ^C
MSDP_TABLE_CLOSE = b"\x04" # ^D
MSDP_ARRAY_OPEN = b"\x05" # ^E
MSDP_ARRAY_CLOSE = b"\x06" # ^F
# GMCP
GMCP = b"\xc9"
from twisted.python.compat import _bytesChr as bchr
# General Telnet
from twisted.conch.telnet import IAC, SB, SE
# MSDP-relevant telnet cmd/opt-codes
MSDP = bchr(69)
MSDP_VAR = bchr(1)
MSDP_VAL = bchr(2)
MSDP_TABLE_OPEN = bchr(3)
MSDP_TABLE_CLOSE = bchr(4)
MSDP_ARRAY_OPEN = bchr(5)
MSDP_ARRAY_CLOSE = bchr(6)
# GMCP
GMCP = bchr(201)
# pre-compiled regexes
# returns 2-tuple
@ -168,7 +170,7 @@ class TelnetOOB(object):
"""
msdp_cmdname = "{msdp_var}{msdp_cmdname}{msdp_val}".format(
msdp_var=MSDP_VAR, msdp_cmdname=cmdname, msdp_val=MSDP_VAL
msdp_var=MSDP_VAR.decode(), msdp_cmdname=cmdname, msdp_val=MSDP_VAL.decode()
)
if not (args or kwargs):
@ -186,9 +188,9 @@ class TelnetOOB(object):
"{msdp_array_open}"
"{msdp_args}"
"{msdp_array_close}".format(
msdp_array_open=MSDP_ARRAY_OPEN,
msdp_array_close=MSDP_ARRAY_CLOSE,
msdp_args="".join("%s%s" % (MSDP_VAL, json.dumps(val)) for val in args),
msdp_array_open=MSDP_ARRAY_OPEN.decode(),
msdp_array_close=MSDP_ARRAY_CLOSE.decode(),
msdp_args="".join("%s%s" % (MSDP_VAL.decode(), val) for val in args),
)
)
@ -199,10 +201,10 @@ class TelnetOOB(object):
"{msdp_table_open}"
"{msdp_kwargs}"
"{msdp_table_close}".format(
msdp_table_open=MSDP_TABLE_OPEN,
msdp_table_close=MSDP_TABLE_CLOSE,
msdp_table_open=MSDP_TABLE_OPEN.decode(),
msdp_table_close=MSDP_TABLE_CLOSE.decode(),
msdp_kwargs="".join(
"%s%s%s%s" % (MSDP_VAR, key, MSDP_VAL, json.dumps(val))
"%s%s%s%s" % (MSDP_VAR.decode(), key, MSDP_VAL.decode(), val)
for key, val in kwargs.items()
),
)

View file

@ -10,11 +10,12 @@ etc. If the client does not support TTYPE, this will be ignored.
All data will be stored on the protocol's protocol_flags dictionary,
under the 'TTYPE' key.
"""
from twisted.python.compat import _bytesChr as bchr
# telnet option codes
TTYPE = b"\x18"
IS = b"\x00"
SEND = b"\x01"
TTYPE = bchr(24) # b"\x18"
IS = bchr(0) # b"\x00"
SEND = bchr(1) # b"\x01"
# terminal capabilities and their codes
MTTS = [