From 48db73dda51b729cf60c59ec5e7491ae5136c906 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sat, 1 Feb 2020 23:00:29 +0100 Subject: [PATCH] Fix annoying OptionRefused error when connecting from many clients --- evennia/server/portal/telnet.py | 42 +++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/evennia/server/portal/telnet.py b/evennia/server/portal/telnet.py index 02a4808a2d..fa46c366f8 100644 --- a/evennia/server/portal/telnet.py +++ b/evennia/server/portal/telnet.py @@ -76,26 +76,20 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session): super().__init__(*args, **kwargs) def dataReceived(self, data): - print(f"indata: {data}") + """ + Unused by default, but a good place to put debug printouts + of incoming data. + """ + # print(f"telnet dataReceived: {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. """ # important in order to work normally with standard telnet - self.do(LINEMODE) + self.do(LINEMODE).addErrback(self._wont_linemode) # initialize the session self.line_buffer = b"" client_address = self.transport.client @@ -140,6 +134,15 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session): self.nop_keep_alive = None self.toggle_nop_keepalive() + def _wont_linemode(self, *args): + """ + Client refuses do(linemode). This is common for MUD-specific + clients, but we must ask for the sake of raw telnet. We ignore + this error. + """ + print("client refuses line mode") + pass + def _send_nop_keepalive(self): """Send NOP keepalive unless flag is set""" if self.protocol_flags.get("NOPKEEPALIVE"): @@ -195,7 +198,8 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session): 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") + LINEMODE, MODE + bytes(chr(ord(LINEMODE_EDIT) + + ord(LINEMODE_TRAPSIG)), "ascii") ) return True else: @@ -207,6 +211,16 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session): or option == suppress_ga.SUPPRESS_GA ) + def disableRemote(self, option): + return ( + option == LINEMODE + or option == ttype.TTYPE + or option == naws.NAWS + or option == MCCP + or option == mssp.MSSP + or option == suppress_ga.SUPPRESS_GA + ) + def enableLocal(self, option): """ Call to allow the activation of options for this protocol @@ -233,6 +247,8 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session): option (char): The telnet option to disable locally. """ + if option == LINEMODE: + return True if option == ECHO: return True if option == MCCP: