From 03356465db6afe8f15b792f26a1f0c62d3bc5c51 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 1 Feb 2020 21:32:26 +0100 Subject: [PATCH] Fix MSDP byte conversion errors, as per #2044 --- evennia/server/inputfuncs.py | 13 +++++++-- evennia/server/portal/mccp.py | 3 +- evennia/server/portal/mssp.py | 13 +++++---- evennia/server/portal/mxp.py | 3 +- evennia/server/portal/naws.py | 5 ++-- evennia/server/portal/suppress_ga.py | 4 ++- evennia/server/portal/telnet.py | 14 ++++++++++ evennia/server/portal/telnet_oob.py | 42 +++++++++++++++------------- evennia/server/portal/ttype.py | 7 +++-- 9 files changed, 68 insertions(+), 36 deletions(-) diff --git a/evennia/server/inputfuncs.py b/evennia/server/inputfuncs.py index bdf82c07c..04135a630 100644 --- a/evennia/server/inputfuncs.py +++ b/evennia/server/inputfuncs.py @@ -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 diff --git a/evennia/server/portal/mccp.py b/evennia/server/portal/mccp.py index 3ca35ff4d..2d00e479b 100644 --- a/evennia/server/portal/mccp.py +++ b/evennia/server/portal/mccp.py @@ -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 diff --git a/evennia/server/portal/mssp.py b/evennia/server/portal/mssp.py index 20331741e..81095b0cd 100644 --- a/evennia/server/portal/mssp.py +++ b/evennia/server/portal/mssp.py @@ -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) diff --git a/evennia/server/portal/mxp.py b/evennia/server/portal/mxp.py index c1d9e7422..8ff773036 100644 --- a/evennia/server/portal/mxp.py +++ b/evennia/server/portal/mxp.py @@ -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 + '' + "\\2" + MXP_TEMPSECURE + "" diff --git a/evennia/server/portal/naws.py b/evennia/server/portal/naws.py index 737ba7484..caa9f7340 100644 --- a/evennia/server/portal/naws.py +++ b/evennia/server/portal/naws.py @@ -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 diff --git a/evennia/server/portal/suppress_ga.py b/evennia/server/portal/suppress_ga.py index 2e8f38808..a295582a2 100644 --- a/evennia/server/portal/suppress_ga.py +++ b/evennia/server/portal/suppress_ga.py @@ -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 diff --git a/evennia/server/portal/telnet.py b/evennia/server/portal/telnet.py index 657c59c66..02a4808a2 100644 --- a/evennia/server/portal/telnet.py +++ b/evennia/server/portal/telnet.py @@ -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. diff --git a/evennia/server/portal/telnet_oob.py b/evennia/server/portal/telnet_oob.py index f6e156f5a..d160ed9e5 100644 --- a/evennia/server/portal/telnet_oob.py +++ b/evennia/server/portal/telnet_oob.py @@ -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() ), ) diff --git a/evennia/server/portal/ttype.py b/evennia/server/portal/ttype.py index fb946bf9a..01e7ebf74 100644 --- a/evennia/server/portal/ttype.py +++ b/evennia/server/portal/ttype.py @@ -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 = [