From bb370c89fe8d36a8fca60405065c3fda07c8659d Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 22 Sep 2019 19:22:48 +0200 Subject: [PATCH] Enforce LINEMODE state for vanilla telnet. Resolve #1942 --- evennia/commands/default/system.py | 4 ++-- evennia/server/portal/telnet.py | 26 ++++++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/evennia/commands/default/system.py b/evennia/commands/default/system.py index 088503df41..fded209d90 100644 --- a/evennia/commands/default/system.py +++ b/evennia/commands/default/system.py @@ -298,8 +298,8 @@ class CmdPy(COMMAND_DEFAULT_CLASS): being parsed as HTML in the webclient but not in telnet clients) Without argument, open a Python console in-game. This is a full console, - accepting multi-line Python code for testing and debugging. Type `exit` to - return to the game. If Evennia is reloaded, thek console will be closed. + accepting multi-line Python code for testing and debugging. Type `exit()` to + return to the game. If Evennia is reloaded, the console will be closed. Enter a line of instruction after the 'py' command to execute it immediately. Separate multiple commands by ';' or open the code editor diff --git a/evennia/server/portal/telnet.py b/evennia/server/portal/telnet.py index b82754f37a..19ac5d10d8 100644 --- a/evennia/server/portal/telnet.py +++ b/evennia/server/portal/telnet.py @@ -11,7 +11,8 @@ import re from twisted.internet import protocol from twisted.internet.task import LoopingCall from twisted.conch.telnet import Telnet, StatefulTelnetProtocol -from twisted.conch.telnet import IAC, NOP, LINEMODE, GA, WILL, WONT, ECHO, NULL +from twisted.conch.telnet import (IAC, NOP, LINEMODE, GA, WILL, WONT, ECHO, NULL, + MODE, LINEMODE_EDIT, LINEMODE_TRAPSIG) from django.conf import settings from evennia.server.session import Session from evennia.server.portal import ttype, mssp, telnet_oob, naws, suppress_ga @@ -51,6 +52,8 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session): This is called when the connection is first established. """ + # important in order to work normally with standard telnet + self.do(LINEMODE) # initialize the session self.line_buffer = b"" client_address = self.transport.client @@ -146,12 +149,18 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session): enable (bool): If this option should be enabled. """ - return (option == LINEMODE or - option == ttype.TTYPE or - option == naws.NAWS or - option == MCCP or - option == mssp.MSSP or - option == suppress_ga.SUPPRESS_GA) + if option == LINEMODE: + # make sure to activate line mode with local editing for all clients + self.requestNegotiation(LINEMODE, MODE + + bytes(chr(ord(LINEMODE_EDIT) + + ord(LINEMODE_TRAPSIG)), 'ascii')) + return True + else: + return (option == ttype.TTYPE or + option == naws.NAWS or + option == MCCP or + option == mssp.MSSP or + option == suppress_ga.SUPPRESS_GA) def enableLocal(self, option): """ @@ -164,7 +173,8 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session): enable (bool): If this option should be enabled. """ - return (option == MCCP or + return (option == LINEMODE or + option == MCCP or option == ECHO or option == suppress_ga.SUPPRESS_GA)