From 5aa9dfc24c9dac902363d511268444232059a3a2 Mon Sep 17 00:00:00 2001 From: Vincent Le Goff Date: Tue, 12 Dec 2017 18:56:36 +0100 Subject: [PATCH 1/4] Add a setting to change telnet default encoding --- evennia/server/portal/telnet.py | 5 +++-- evennia/server/session.py | 7 ++++++- evennia/settings_default.py | 6 ++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/evennia/server/portal/telnet.py b/evennia/server/portal/telnet.py index 4112d85e2a..86199ae4ac 100644 --- a/evennia/server/portal/telnet.py +++ b/evennia/server/portal/telnet.py @@ -24,7 +24,7 @@ _RE_LEND = re.compile(r"\n$|\r$|\r\n$|\r\x00$|", re.MULTILINE) _RE_LINEBREAK = re.compile(r"\n\r|\r\n|\n|\r", re.DOTALL + re.MULTILINE) _RE_SCREENREADER_REGEX = re.compile(r"%s" % settings.SCREENREADER_REGEX_STRIP, re.DOTALL + re.MULTILINE) _IDLE_COMMAND = settings.IDLE_COMMAND + "\n" - +_TELNET_ENCODING = settings.TELNET_ENCODING class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session): """ @@ -49,7 +49,8 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session): # this number is counted down for every handshake that completes. # when it reaches 0 the portal/server syncs their data self.handshakes = 8 # suppress-go-ahead, naws, ttype, mccp, mssp, msdp, gmcp, mxp - self.init_session(self.protocol_name, client_address, self.factory.sessionhandler) + self.init_session(self.protocol_name, client_address, self.factory.sessionhandler, + override_flags={"ENCODING": _TELNET_ENCODING}) # suppress go-ahead self.sga = suppress_ga.SuppressGA(self) diff --git a/evennia/server/session.py b/evennia/server/session.py index 70be0708d7..dc816ee59b 100644 --- a/evennia/server/session.py +++ b/evennia/server/session.py @@ -41,7 +41,7 @@ class Session(object): 'conn_time', 'cmd_last', 'cmd_last_visible', 'cmd_total', 'protocol_flags', 'server_data', "cmdset_storage_string") - def init_session(self, protocol_key, address, sessionhandler): + def init_session(self, protocol_key, address, sessionhandler, override_flags=None): """ Initialize the Session. This should be called by the protocol when a new session is established. @@ -52,6 +52,7 @@ class Session(object): address (str): Client address. sessionhandler (SessionHandler): Reference to the main sessionhandler instance. + override_flags (optional, dict): a dictionary of protocol flags to override. """ # This is currently 'telnet', 'ssh', 'ssl' or 'web' @@ -87,6 +88,10 @@ class Session(object): "INPUTDEBUG": False, "RAW": False, "NOCOLOR": False} + + if override_flags: + self.protocol_flags.update(override_flags) + self.server_data = {} # map of input data to session methods diff --git a/evennia/settings_default.py b/evennia/settings_default.py index fd213d333d..bb8e07fe44 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -166,6 +166,12 @@ IDLE_TIMEOUT = -1 # command-name is given here; this is because the webclient needs a default # to send to avoid proxy timeouts. IDLE_COMMAND = "idle" +# The encoding (character set) specific to Telnet. This will not influence +# other encoding settings: namely, the webclient, the website, the +# database encoding will remain (utf-8 by default). This setting only +# affects the telnet encoding and will be overridden by user settings +# (through one of their client's supported protocol or their account options). +TELNET_ENCODING = "utf-8" # The set of encodings tried. An Account object may set an attribute "encoding" on # itself to match the client used. If not set, or wrong encoding is # given, this list is tried, in order, aborting on the first match. From f3c909ed6aef62a60c130d9d63b0cb9977f69258 Mon Sep 17 00:00:00 2001 From: Vincent Le Goff Date: Tue, 12 Dec 2017 19:46:28 +0100 Subject: [PATCH 2/4] Remove TELNET_ENCODING and set ENCODINGS[0] --- evennia/server/portal/telnet.py | 2 +- evennia/settings_default.py | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/evennia/server/portal/telnet.py b/evennia/server/portal/telnet.py index 86199ae4ac..9d7b31929d 100644 --- a/evennia/server/portal/telnet.py +++ b/evennia/server/portal/telnet.py @@ -24,7 +24,7 @@ _RE_LEND = re.compile(r"\n$|\r$|\r\n$|\r\x00$|", re.MULTILINE) _RE_LINEBREAK = re.compile(r"\n\r|\r\n|\n|\r", re.DOTALL + re.MULTILINE) _RE_SCREENREADER_REGEX = re.compile(r"%s" % settings.SCREENREADER_REGEX_STRIP, re.DOTALL + re.MULTILINE) _IDLE_COMMAND = settings.IDLE_COMMAND + "\n" -_TELNET_ENCODING = settings.TELNET_ENCODING +_TELNET_ENCODING = settings.ENCODINGS[0] class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session): """ diff --git a/evennia/settings_default.py b/evennia/settings_default.py index bb8e07fe44..5469fd46db 100644 --- a/evennia/settings_default.py +++ b/evennia/settings_default.py @@ -166,17 +166,12 @@ IDLE_TIMEOUT = -1 # command-name is given here; this is because the webclient needs a default # to send to avoid proxy timeouts. IDLE_COMMAND = "idle" -# The encoding (character set) specific to Telnet. This will not influence -# other encoding settings: namely, the webclient, the website, the -# database encoding will remain (utf-8 by default). This setting only -# affects the telnet encoding and will be overridden by user settings -# (through one of their client's supported protocol or their account options). -TELNET_ENCODING = "utf-8" # The set of encodings tried. An Account object may set an attribute "encoding" on # itself to match the client used. If not set, or wrong encoding is # given, this list is tried, in order, aborting on the first match. # Add sets for languages/regions your accounts are likely to use. # (see http://en.wikipedia.org/wiki/Character_encoding) +# Telnet default encoding, unless specified by the client, will be ENCODINGS[0]. ENCODINGS = ["utf-8", "latin-1", "ISO-8859-1"] # Regular expression applied to all output to a given session in order # to strip away characters (usually various forms of decorations) for the benefit From 94e271c6931cf7c603dc06954f5b9b8da7d56188 Mon Sep 17 00:00:00 2001 From: Vincent Le Goff Date: Tue, 12 Dec 2017 20:51:16 +0100 Subject: [PATCH 3/4] Simplify telnet edefault encoding --- evennia/server/portal/telnet.py | 6 +++--- evennia/server/session.py | 8 +------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/evennia/server/portal/telnet.py b/evennia/server/portal/telnet.py index 9d7b31929d..08267f0ee9 100644 --- a/evennia/server/portal/telnet.py +++ b/evennia/server/portal/telnet.py @@ -24,7 +24,6 @@ _RE_LEND = re.compile(r"\n$|\r$|\r\n$|\r\x00$|", re.MULTILINE) _RE_LINEBREAK = re.compile(r"\n\r|\r\n|\n|\r", re.DOTALL + re.MULTILINE) _RE_SCREENREADER_REGEX = re.compile(r"%s" % settings.SCREENREADER_REGEX_STRIP, re.DOTALL + re.MULTILINE) _IDLE_COMMAND = settings.IDLE_COMMAND + "\n" -_TELNET_ENCODING = settings.ENCODINGS[0] class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session): """ @@ -49,8 +48,9 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session): # this number is counted down for every handshake that completes. # when it reaches 0 the portal/server syncs their data self.handshakes = 8 # suppress-go-ahead, naws, ttype, mccp, mssp, msdp, gmcp, mxp - self.init_session(self.protocol_name, client_address, self.factory.sessionhandler, - override_flags={"ENCODING": _TELNET_ENCODING}) + self.init_session(self.protocol_name, client_address, self.factory.sessionhandler) + # change encoding to ENCODINGS[0] which reflects Telnet default encoding + self.protocol_flags["ENCODING"] = settings.ENCODINGS[0] # suppress go-ahead self.sga = suppress_ga.SuppressGA(self) diff --git a/evennia/server/session.py b/evennia/server/session.py index dc816ee59b..96b68662a5 100644 --- a/evennia/server/session.py +++ b/evennia/server/session.py @@ -7,7 +7,6 @@ from builtins import object import time - #------------------------------------------------------------ # Server Session #------------------------------------------------------------ @@ -41,7 +40,7 @@ class Session(object): 'conn_time', 'cmd_last', 'cmd_last_visible', 'cmd_total', 'protocol_flags', 'server_data', "cmdset_storage_string") - def init_session(self, protocol_key, address, sessionhandler, override_flags=None): + def init_session(self, protocol_key, address, sessionhandler): """ Initialize the Session. This should be called by the protocol when a new session is established. @@ -52,7 +51,6 @@ class Session(object): address (str): Client address. sessionhandler (SessionHandler): Reference to the main sessionhandler instance. - override_flags (optional, dict): a dictionary of protocol flags to override. """ # This is currently 'telnet', 'ssh', 'ssl' or 'web' @@ -88,10 +86,6 @@ class Session(object): "INPUTDEBUG": False, "RAW": False, "NOCOLOR": False} - - if override_flags: - self.protocol_flags.update(override_flags) - self.server_data = {} # map of input data to session methods From 7fb30c5bc3a4991fa5b1a701051f21822f5f6d68 Mon Sep 17 00:00:00 2001 From: Vincent Le Goff Date: Tue, 12 Dec 2017 20:59:55 +0100 Subject: [PATCH 4/4] Add a little check in case ENCODINGS is empty --- evennia/server/portal/telnet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evennia/server/portal/telnet.py b/evennia/server/portal/telnet.py index 08267f0ee9..dd07512b70 100644 --- a/evennia/server/portal/telnet.py +++ b/evennia/server/portal/telnet.py @@ -50,7 +50,7 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session): self.handshakes = 8 # suppress-go-ahead, naws, ttype, mccp, mssp, msdp, gmcp, mxp self.init_session(self.protocol_name, client_address, self.factory.sessionhandler) # change encoding to ENCODINGS[0] which reflects Telnet default encoding - self.protocol_flags["ENCODING"] = settings.ENCODINGS[0] + self.protocol_flags["ENCODING"] = settings.ENCODINGS[0] if settings.ENCODINGS else 'utf-8' # suppress go-ahead self.sga = suppress_ga.SuppressGA(self)