Enforce LINEMODE state for vanilla telnet. Resolve #1942

This commit is contained in:
Griatch 2019-09-22 19:22:48 +02:00
parent dafec2e720
commit bb370c89fe
2 changed files with 20 additions and 10 deletions

View file

@ -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

View file

@ -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)