diff --git a/src/commands/cmdparser.py b/src/commands/cmdparser.py index 6be2305892..75412b7c51 100644 --- a/src/commands/cmdparser.py +++ b/src/commands/cmdparser.py @@ -5,6 +5,8 @@ replacing cmdparser function. The replacement parser must return a CommandCandidates object. """ +from src.utils.logger import log_trace + def cmdparser(raw_string, cmdset, caller, match_index=None): """ This function is called by the cmdhandler once it has @@ -46,11 +48,15 @@ def cmdparser(raw_string, cmdset, caller, match_index=None): # match everything that begins with a matching cmdname. l_raw_string = raw_string.lower() for cmd in cmdset: - matches.extend([create_match(cmdname, raw_string, cmd) - for cmdname in [cmd.key] + cmd.aliases - if cmdname and l_raw_string.startswith(cmdname.lower()) - and (not cmd.arg_regex or - cmd.arg_regex.match(l_raw_string[len(cmdname):]))]) + try: + matches.extend([create_match(cmdname, raw_string, cmd) + for cmdname in [cmd.key] + cmd.aliases + if cmdname and l_raw_string.startswith(cmdname.lower()) + and (not cmd.arg_regex or + cmd.arg_regex.match(l_raw_string[len(cmdname):]))]) + except Exception: + log_trace() + if not matches: # no matches found. if '-' in raw_string: diff --git a/src/server/telnet.py b/src/server/telnet.py index b0e05c3afe..77365bb6cb 100644 --- a/src/server/telnet.py +++ b/src/server/telnet.py @@ -133,23 +133,23 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session): """ generic hook method for engine to call in order to send data through the telnet connection. - Data Evennia -> Player. 'data' argument is not used + Data Evennia -> Player. + data argument may contain a dict with output flags. """ try: string = utils.to_str(string, encoding=self.encoding) except Exception, e: self.sendLine(str(e)) return - xterm256 = self.protocol_flags.get('TTYPE', {}).get('256 COLORS') - nomarkup = not (xterm256 or not self.protocol_flags.get('TTYPE') - or self.protocol_flags.get('TTYPE', {}).get('ANSI')) - raw = False + ttype = self.protocol_flags.get('TTYPE', {}) + nomarkup = not (ttype.get('256 COLORS') or ttype.get('ANSI') or not ttype.get("init_done")) + raw = False if type(data) == dict: # check if we want escape codes to go through unparsed. raw = data.get("raw", False) - # check if we want to remove all markup + # check if we want to remove all markup (TTYPE override) nomarkup = data.get("nomarkup", False) if raw: self.sendLine(string) else: - self.sendLine(ansi.parse_ansi(string, strip_ansi=nomarkup, xterm256=xterm256)) + self.sendLine(ansi.parse_ansi(string, strip_ansi=nomarkup, xterm256=ttype.get('256 COLORS'))) diff --git a/src/server/ttype.py b/src/server/ttype.py index 14c727a387..095c7eee63 100644 --- a/src/server/ttype.py +++ b/src/server/ttype.py @@ -41,7 +41,7 @@ class Ttype(object): """ self.ttype_step = 0 self.protocol = protocol - self.protocol.protocol_flags['TTYPE'] = {} + self.protocol.protocol_flags['TTYPE'] = {"init_done":False} # setup protocol to handle ttype initialization and negotiation self.protocol.negotiationMap[TTYPE] = self.do_ttype @@ -52,7 +52,7 @@ class Ttype(object): """ Callback if ttype is not supported by client. """ - pass + self.protocol.protocol_flags['TTYPE'] = False def do_ttype(self, option): """ @@ -65,6 +65,9 @@ class Ttype(object): stored on protocol.protocol_flags under the TTYPE key. """ + if self.protocol.protocol_flags['TTYPE']['init_done']: + return + self.ttype_step += 1 if self.ttype_step == 1: @@ -89,5 +92,7 @@ class Ttype(object): self.protocol.protocol_flags['TTYPE'][standard] = status if status: option = option % codenum + self.protocol.protocol_flags['TTYPE']['init_done'] = True + #print "ttype results:", self.protocol.protocol_flags['TTYPE']