Implemented xterm256 colours. If not supported by client, converts to normal ANSI, as per kaViir's snippet. Integrates into Evennia's normal ansi parser and collaborates with TTYPE protocol to determine if the client supports it.

This commit is contained in:
Griatch 2011-11-20 14:56:07 +01:00
parent fb78758356
commit 4cd80284c9
6 changed files with 194 additions and 146 deletions

View file

@ -48,7 +48,6 @@ class Mssp(object):
"""
This is the normal operation.
"""
print "no mssp"
pass
def do_mssp(self, option):
@ -182,6 +181,3 @@ class Mssp(object):
# send to crawler by subnegotiation
self.protocol.requestNegotiation(MSSP, varlist)

View file

@ -36,7 +36,7 @@ class Session(object):
_attrs_to_sync = ['protocol_key', 'address', 'suid', 'sessid', 'uid', 'uname',
'logged_in', 'cid', 'encoding',
'conn_time', 'cmd_last', 'cmd_last_visible', 'cmd_total',
'protocol_flags', 'server_data']
'server_data']
def init_session(self, protocol_key, address, sessionhandler):
"""

View file

@ -36,9 +36,11 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
# negotiate mssp (crawler communication)
self.mssp = mssp.Mssp(self)
# add us to sessionhandler
self.sessionhandler.connect(self)
# add this new connection to sessionhandler so
# the Server becomes aware of it.
self.sessionhandler.connect(self)
def enableRemote(self, option):
"""
@ -137,8 +139,10 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
string = utils.to_str(string, encoding=self.encoding)
except Exception, e:
self.sendLine(str(e))
return
nomarkup = False
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
if type(data) == dict:
# check if we want escape codes to go through unparsed.
@ -147,5 +151,5 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
nomarkup = data.get("nomarkup", False)
if raw:
self.sendLine(string)
else:
self.sendLine(ansi.parse_ansi(string, strip_ansi=nomarkup))
else:
self.sendLine(ansi.parse_ansi(string, strip_ansi=nomarkup, xterm256=xterm256))

View file

@ -47,7 +47,7 @@ class Ttype(object):
self.protocol.negotiationMap[TTYPE] = self.do_ttype
# ask if client will ttype, connect callback if it does.
self.protocol.will(TTYPE).addCallbacks(self.do_ttype, self.no_ttype)
def no_ttype(self, option):
"""
Callback if ttype is not supported by client.
@ -79,7 +79,7 @@ class Ttype(object):
elif self.ttype_step == 3:
self.protocol.protocol_flags['TTYPE']['TERM'] = option
self.protocol.requestNegotiation(TTYPE, SEND)
elif self.ttype_step == 4 and option.startswith('MTTS'):
elif self.ttype_step == 4:
option = int(option.strip('MTTS '))
self.protocol.protocol_flags['TTYPE']['MTTS'] = option
for codenum, standard in MTTS: