From 68a3feb2fe4f5a4be0d64b02095e0c2a96d98fd4 Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 9 Apr 2024 00:12:42 -0700 Subject: [PATCH 1/3] A few typo fixes and NAWS update detection and handling. --- evennia/server/portal/portalsessionhandler.py | 2 +- evennia/server/portal/telnet.py | 8 ++++++-- evennia/server/serversession.py | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/evennia/server/portal/portalsessionhandler.py b/evennia/server/portal/portalsessionhandler.py index 8a5ed53ce2..bd248cc8a7 100644 --- a/evennia/server/portal/portalsessionhandler.py +++ b/evennia/server/portal/portalsessionhandler.py @@ -468,7 +468,7 @@ class PortalSessionHandler(SessionHandler): kwargs (any): Each key is a command instruction to the protocol on the form key = [[args],{kwargs}]. This will call a method send_ on the protocol. If no such - method exixts, it sends the data to a method send_default. + method exits, it sends the data to a method send_default. """ # from evennia.server.profiling.timetrace import timetrace # DEBUG diff --git a/evennia/server/portal/telnet.py b/evennia/server/portal/telnet.py index cb577f3835..eeb00ba053 100644 --- a/evennia/server/portal/telnet.py +++ b/evennia/server/portal/telnet.py @@ -31,6 +31,7 @@ from twisted.internet.task import LoopingCall from evennia.server.portal import mssp, naws, suppress_ga, telnet_oob, ttype from evennia.server.portal.mccp import MCCP, Mccp, mccp_compress from evennia.server.portal.mxp import Mxp, mxp_parse +from evennia.server.portal.naws import NAWS from evennia.utils import ansi from evennia.utils.utils import class_from_module, to_bytes @@ -91,9 +92,12 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, _BASE_SESSION_CLASS): of incoming data. """ - # print(f"telnet dataReceived: {data}") try: - super().dataReceived(data) + # Do we have a NAWS update? + if NAWS in data and len([data[i:i+1] for i in range(0, len(data))]) == 9: + self.sessionhandler.sync(self.sessionhandler.get(self.sessid)) + else: + super().dataReceived(data) except ValueError as err: from evennia.utils import logger diff --git a/evennia/server/serversession.py b/evennia/server/serversession.py index 5177f30f5d..c4048e19ca 100644 --- a/evennia/server/serversession.py +++ b/evennia/server/serversession.py @@ -268,7 +268,7 @@ class ServerSession(_BASE_SESSION_CLASS): Notes: Since protocols can vary, no checking is done - as to the existene of the flag or not. The input + as to the existence of the flag or not. The input data should have been validated before this call. """ From 80117509319154ccb8f78d97686edf34a025fa8a Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 9 Apr 2024 00:39:55 -0700 Subject: [PATCH 2/3] Update didn't work as an if/else. There appears to be a bug when used fullscreen. --- evennia/server/portal/telnet.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/evennia/server/portal/telnet.py b/evennia/server/portal/telnet.py index eeb00ba053..31bf403f85 100644 --- a/evennia/server/portal/telnet.py +++ b/evennia/server/portal/telnet.py @@ -96,8 +96,7 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, _BASE_SESSION_CLASS): # Do we have a NAWS update? if NAWS in data and len([data[i:i+1] for i in range(0, len(data))]) == 9: self.sessionhandler.sync(self.sessionhandler.get(self.sessid)) - else: - super().dataReceived(data) + super().dataReceived(data) except ValueError as err: from evennia.utils import logger From c94b7f47c1012444bc673ddd64ee9191ca4d78cf Mon Sep 17 00:00:00 2001 From: mike Date: Tue, 9 Apr 2024 12:20:52 -0700 Subject: [PATCH 3/3] Added a new flag in the options/protocol_flags to ignore or follow NAWS updates. --- evennia/commands/default/account.py | 6 ++++++ evennia/server/inputfuncs.py | 4 ++++ evennia/server/portal/naws.py | 2 ++ evennia/server/portal/telnet.py | 6 +++++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/evennia/commands/default/account.py b/evennia/commands/default/account.py index 7b966eb7cf..e437fe8ca3 100644 --- a/evennia/commands/default/account.py +++ b/evennia/commands/default/account.py @@ -635,6 +635,11 @@ class CmdOption(COMMAND_DEFAULT_CLASS): self.msg(f"Option |w{new_name}|n was kept as '|w{old_val}|n'.") else: flags[new_name] = new_val + + # If we're manually assign a display size, turn off auto-resizing + if new_name in ['SCREENWIDTH', 'SCREENHEIGHT']: + flags['AUTORESIZE'] = False + self.msg( f"Option |w{new_name}|n was changed from '|w{old_val}|n' to" f" '|w{new_val}|n'." @@ -657,6 +662,7 @@ class CmdOption(COMMAND_DEFAULT_CLASS): "RAW": validate_bool, "SCREENHEIGHT": validate_size, "SCREENWIDTH": validate_size, + "AUTORESIZE": validate_bool, "SCREENREADER": validate_bool, "TERM": utils.to_str, "UTF-8": validate_bool, diff --git a/evennia/server/inputfuncs.py b/evennia/server/inputfuncs.py index ee60643059..d30b06d4a5 100644 --- a/evennia/server/inputfuncs.py +++ b/evennia/server/inputfuncs.py @@ -175,6 +175,7 @@ _CLIENT_OPTIONS = ( "MCCP", "SCREENHEIGHT", "SCREENWIDTH", + "AUTORESIZE", "INPUTDEBUG", "RAW", "NOCOLOR", @@ -201,6 +202,7 @@ def client_options(session, *args, **kwargs): mccp (bool): MCCP compression on/off screenheight (int): Screen height in lines screenwidth (int): Screen width in characters + autoresize (bool): Use NAWS updates to dynamically adjust format inputdebug (bool): Debug input functions nocolor (bool): Strip color raw (bool): Turn off parsing @@ -256,6 +258,8 @@ def client_options(session, *args, **kwargs): flags["SCREENHEIGHT"] = validate_size(value) elif key == "screenwidth": flags["SCREENWIDTH"] = validate_size(value) + elif key == "autoresize": + flags["AUTORESIZE"] = validate_size(value) elif key == "inputdebug": flags["INPUTDEBUG"] = validate_bool(value) elif key == "nocolor": diff --git a/evennia/server/portal/naws.py b/evennia/server/portal/naws.py index ab7e892712..5e52688f2b 100644 --- a/evennia/server/portal/naws.py +++ b/evennia/server/portal/naws.py @@ -57,6 +57,7 @@ class Naws: option (Option): Not used. """ + self.protocol.protocol_flags["AUTORESIZE"] = False self.protocol.handshake_done() def do_naws(self, option): @@ -67,6 +68,7 @@ class Naws: option (Option): Not used. """ + self.protocol.protocol_flags["AUTORESIZE"] = True self.protocol.handshake_done() def negotiate_sizes(self, options): diff --git a/evennia/server/portal/telnet.py b/evennia/server/portal/telnet.py index 31bf403f85..b545e67f7e 100644 --- a/evennia/server/portal/telnet.py +++ b/evennia/server/portal/telnet.py @@ -94,8 +94,12 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, _BASE_SESSION_CLASS): """ try: # Do we have a NAWS update? - if NAWS in data and len([data[i:i+1] for i in range(0, len(data))]) == 9: + if (NAWS in data and + len([data[i:i+1] for i in range(0, len(data))]) == 9 and + # Is auto resizing on? + self.protocol_flags.get('AUTORESIZE')): self.sessionhandler.sync(self.sessionhandler.get(self.sessid)) + super().dataReceived(data) except ValueError as err: from evennia.utils import logger