mirror of
https://github.com/evennia/evennia.git
synced 2026-04-06 07:57:16 +02:00
Added GMCP-to-inputfunc name conversion as Module.Cmdname -> Module_CmdName. Also made Session.protocol_flags into a flat dict, by putting all TTYPE properties in the top level (the TTYPE key now only indicates if TTYPE has finished or not). Also started to convert the screenreader/enconding properties of the session into protocol_flags. (not fully working yet)
This commit is contained in:
parent
f3512971e3
commit
df674f687a
9 changed files with 52 additions and 46 deletions
|
|
@ -405,7 +405,7 @@ class CmdOption(MuxPlayerCommand):
|
|||
pencoding = self.session.encoding or "None"
|
||||
sencodings = settings.ENCODINGS
|
||||
string += " Custom: %s\n Server: %s" % (pencoding, ", ".join(sencodings))
|
||||
string += "\n{wScreen Reader mode:{n %s" % self.session.screenreader
|
||||
string += "\n{wScreen Reader mode:{n %s" % self.session.protocol_flags.get("SCREENREADER", False)
|
||||
self.msg(string)
|
||||
return
|
||||
|
||||
|
|
@ -413,6 +413,8 @@ class CmdOption(MuxPlayerCommand):
|
|||
self.msg("Usage: @option [name = [value]]")
|
||||
return
|
||||
|
||||
sync = False
|
||||
|
||||
if self.lhs == "encoding":
|
||||
# change encoding
|
||||
old_encoding = self.session.encoding
|
||||
|
|
@ -429,9 +431,12 @@ class CmdOption(MuxPlayerCommand):
|
|||
|
||||
if self.lhs == "screenreader":
|
||||
onoff = self.rhs.lower() == "on"
|
||||
self.session.screenreader = onoff
|
||||
self.session.protocol_flags["SCREENREADER"] = onoff
|
||||
self.msg("Screen reader mode was turned {w%s{n." % ("on" if onoff else "off"))
|
||||
|
||||
if sync:
|
||||
self.session.sessionhandler.session_portal_sync(self.session)
|
||||
|
||||
|
||||
class CmdPassword(MuxPlayerCommand):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -506,8 +506,9 @@ class CmdUnconnectedScreenreader(MuxCommand):
|
|||
|
||||
def func(self):
|
||||
"Flips screenreader setting."
|
||||
self.session.screenreader = not self.session.screenreader
|
||||
string = "Screenreader mode turned {w%s{n." % ("on" if self.session.screenreader else "off")
|
||||
new_setting = not self.session.protocol_flags.get("SCREENREADER", False)
|
||||
self.session.protocol_flags["SCREENREADER"] = new_setting
|
||||
string = "Screenreader mode turned {w%s{n." % ("on" if new_setting else "off")
|
||||
self.caller.msg(string)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -112,22 +112,21 @@ def client_settings(session, *args, **kwargs):
|
|||
|
||||
"""
|
||||
flags = session.protocol_flags
|
||||
tflags = flags["TTYPE"]
|
||||
for key, value in kwargs.iteritems():
|
||||
key = key.lower()
|
||||
if key == "client":
|
||||
tflags["CLIENTNAME"] = to_str(value)
|
||||
flags["CLIENTNAME"] = to_str(value)
|
||||
elif key == "version":
|
||||
if "CLIENTNAME" in tflags:
|
||||
tflags["CLIENTNAME"] = "%s %s" % (tflags["CLIENTNAME"], to_str(value))
|
||||
if "CLIENTNAME" in flags:
|
||||
flags["CLIENTNAME"] = "%s %s" % (flags["CLIENTNAME"], to_str(value))
|
||||
elif key == "ansi":
|
||||
tflags["ANSI"] = bool(value)
|
||||
flags["ANSI"] = bool(value)
|
||||
elif key == "xterm256":
|
||||
tflags["256 COLORS"] = bool(value)
|
||||
flags["256 COLORS"] = bool(value)
|
||||
elif key == "mxp":
|
||||
flags["MXP"] = bool(value)
|
||||
elif key == "utf-8":
|
||||
tflags["UTF-8"] = bool(value)
|
||||
flags["UTF-8"] = bool(value)
|
||||
elif key == "screenreader":
|
||||
flags["SCREENREADER"] = bool(value)
|
||||
elif key == "mccp":
|
||||
|
|
@ -136,11 +135,10 @@ def client_settings(session, *args, **kwargs):
|
|||
flags["SCREENHEIGHT"] = int(value)
|
||||
elif key == "screenwidth":
|
||||
flags["SCREENWIDTH"] = int(value)
|
||||
else:
|
||||
elif not key == "options":
|
||||
err = _ERROR_INPUT.format(
|
||||
name="client_settings", session=session, inp=key)
|
||||
session.msg(text=err)
|
||||
flags["TTYPE"] = tflags
|
||||
session.protocol_flags = flags
|
||||
# we must update the portal as well
|
||||
session.sessionhandler.session_portal_sync(session)
|
||||
|
|
|
|||
|
|
@ -234,7 +234,7 @@ class SshProtocol(Manhole, session.Session):
|
|||
options (dict): Send-option flags
|
||||
- mxp: Enforce MXP link support.
|
||||
- ansi: Enforce no ANSI colors.
|
||||
- xterm256: Enforce xterm256 colors, regardless of TTYPE.
|
||||
- xterm256: Enforce xterm256 colors, regardless of TTYPE setting.
|
||||
- noxterm256: Enforce no xterm256 color support, regardless of TTYPE.
|
||||
- nomarkup: Strip all ANSI markup. This is the same as noxterm256,noansi
|
||||
- raw: Pass string through without any ansi processing
|
||||
|
|
@ -253,13 +253,13 @@ class SshProtocol(Manhole, session.Session):
|
|||
|
||||
# handle arguments
|
||||
options = kwargs.get("options", {})
|
||||
ttype = self.protocol_flags.get('TTYPE', {})
|
||||
xterm256 = options.get("xterm256", ttype.get('256 COLORS', False) if ttype.get("init_done") else True)
|
||||
useansi = options.get("ansi", ttype and ttype.get('ANSI', False) if ttype.get("init_done") else True)
|
||||
flags = self.protocol_flags
|
||||
xterm256 = options.get("xterm256", flags.get('256 COLORS', False) if flags["TTYPE"] else True)
|
||||
useansi = options.get("ansi", flags.get('ANSI', False) if flags["TTYPE"] else True)
|
||||
raw = options.get("raw", False)
|
||||
nomarkup = options.get("nomarkup", not (xterm256 or useansi))
|
||||
#echo = options.get("echo", None)
|
||||
screenreader = options.get("screenreader", self.screenreader)
|
||||
screenreader = options.get("screenreader", flags.get("SCREENREADER", False))
|
||||
|
||||
if screenreader:
|
||||
# screenreader mode cleans up output
|
||||
|
|
|
|||
|
|
@ -303,15 +303,16 @@ class TelnetProtocol(Telnet, StatefulTelnetProtocol, Session):
|
|||
|
||||
# handle arguments
|
||||
options = kwargs.get("options", {})
|
||||
ttype = self.protocol_flags.get('TTYPE', {})
|
||||
xterm256 = options.get("xterm256", ttype.get('256 COLORS', False) if ttype.get("init_done") else True)
|
||||
useansi = options.get("ansi", ttype and ttype.get('ANSI', False) if ttype.get("init_done") else True)
|
||||
flags = self.protocol_flags
|
||||
xterm256 = options.get("xterm256", flags.get('256 COLORS', False) if flags["TTYPE"] else True)
|
||||
useansi = options.get("ansi", flags.get('ANSI', False) if flags["TTYPE"] else True)
|
||||
raw = options.get("raw", False)
|
||||
nomarkup = options.get("nomarkup", not (xterm256 or useansi))
|
||||
echo = options.get("echo", None)
|
||||
mxp = options.get("mxp", self.protocol_flags.get("MXP", False))
|
||||
screenreader = options.get("screenreader", self.screenreader)
|
||||
mxp = options.get("mxp", flags.get("MXP", False))
|
||||
screenreader = options.get("screenreader", flags.get("SCREENREADER", False))
|
||||
|
||||
print "screenreader:", screenreader, options, flags
|
||||
if screenreader:
|
||||
# screenreader mode cleans up output
|
||||
text = ansi.parse_ansi(text, strip_ansi=True, xterm256=False, mxp=False)
|
||||
|
|
|
|||
|
|
@ -339,16 +339,16 @@ class TelnetOOB(object):
|
|||
data (str or list): GMCP data.
|
||||
|
||||
Notes:
|
||||
Clients tend to send data on the form "cmdname <structure>".
|
||||
Clients send data on the form "Module.Submodule.Cmdname <structure>".
|
||||
We assume the structure is valid JSON.
|
||||
|
||||
The following is parsed into Evennia's formal structure:
|
||||
|
||||
cmdname -> [cmdname, [], {}]
|
||||
cmdname string -> [cmdname, [string], {}]
|
||||
cmdname [arg, arg,...] -> [cmdname, [args], {}]
|
||||
cmdname {key:arg, key:arg, ...} -> [cmdname, [], {kwargs}]
|
||||
cmdname [[args], {kwargs}] -> [cmdname, [args], {kwargs}]
|
||||
Module.Name -> [Module_Name, [], {}]
|
||||
Module.Name string -> [Module_Name, [string], {}]
|
||||
Module.Name [arg, arg,...] -> [Module_Name, [args], {}]
|
||||
Module.Name {key:arg, key:arg, ...} -> [Module_Name, [], {kwargs}]
|
||||
Module.Name [[args], {kwargs}] -> [Module_Name, [args], {kwargs}]
|
||||
|
||||
"""
|
||||
if hasattr(data, "__iter__"):
|
||||
|
|
@ -361,6 +361,7 @@ class TelnetOOB(object):
|
|||
except ValueError:
|
||||
self.protocol.data_in(**{data: [[],{}]})
|
||||
return
|
||||
cmdname = cmdname.replace(".", "_")
|
||||
try:
|
||||
structure = json.loads(structure)
|
||||
except ValueError:
|
||||
|
|
|
|||
|
|
@ -48,9 +48,9 @@ class Ttype(object):
|
|||
"""
|
||||
self.ttype_step = 0
|
||||
self.protocol = protocol
|
||||
self.protocol.protocol_flags['TTYPE'] = {"init_done": False}
|
||||
self.protocol.protocol_flags['TTYPE'] = False
|
||||
# is it a safe bet to assume ANSI is always supported?
|
||||
self.protocol.protocol_flags['TTYPE']['ANSI'] = True
|
||||
self.protocol.protocol_flags['ANSI'] = True
|
||||
# setup protocol to handle ttype initialization and negotiation
|
||||
self.protocol.negotiationMap[TTYPE] = self.will_ttype
|
||||
# ask if client will ttype, connect callback if it does.
|
||||
|
|
@ -64,7 +64,7 @@ class Ttype(object):
|
|||
option (Option): Not used.
|
||||
|
||||
"""
|
||||
self.protocol.protocol_flags['TTYPE']["init_done"] = True
|
||||
self.protocol.protocol_flags['TTYPE'] = True
|
||||
self.protocol.handshake_done()
|
||||
|
||||
def will_ttype(self, option):
|
||||
|
|
@ -81,9 +81,9 @@ class Ttype(object):
|
|||
stored on protocol.protocol_flags under the TTYPE key.
|
||||
|
||||
"""
|
||||
options = self.protocol.protocol_flags.get('TTYPE')
|
||||
options = self.protocol.protocol_flags
|
||||
|
||||
if options and options.get('init_done') or self.ttype_step > 3:
|
||||
if options and options.get('TTYPE', False) or self.ttype_step > 3:
|
||||
return
|
||||
|
||||
try:
|
||||
|
|
@ -119,9 +119,9 @@ class Ttype(object):
|
|||
"BEIP")) # > 2.00.206 (late 2009) (BeipMu)
|
||||
|
||||
# all clients supporting TTYPE at all seem to support ANSI
|
||||
self.protocol.protocol_flags['TTYPE']['ANSI'] = True
|
||||
self.protocol.protocol_flags['TTYPE']['256 COLORS'] = xterm256
|
||||
self.protocol.protocol_flags['TTYPE']['CLIENTNAME'] = clientname
|
||||
self.protocol.protocol_flags['ANSI'] = True
|
||||
self.protocol.protocol_flags['256 COLORS'] = xterm256
|
||||
self.protocol.protocol_flags['CLIENTNAME'] = clientname
|
||||
self.protocol.requestNegotiation(TTYPE, SEND)
|
||||
|
||||
elif self.ttype_step == 2:
|
||||
|
|
@ -132,9 +132,9 @@ class Ttype(object):
|
|||
or term.endswith("xterm") and # old Tintin, Putty
|
||||
not term.endswith("-color"))
|
||||
if xterm256:
|
||||
self.protocol.protocol_flags['TTYPE']['ANSI'] = True
|
||||
self.protocol.protocol_flags['TTYPE']['256 COLORS'] = xterm256
|
||||
self.protocol.protocol_flags['TTYPE']['TERM'] = term
|
||||
self.protocol.protocol_flags['ANSI'] = True
|
||||
self.protocol.protocol_flags['256 COLORS'] = xterm256
|
||||
self.protocol.protocol_flags['TERM'] = term
|
||||
# request next information
|
||||
self.protocol.requestNegotiation(TTYPE, SEND)
|
||||
|
||||
|
|
@ -146,12 +146,12 @@ class Ttype(object):
|
|||
# a number - determine the actual capabilities
|
||||
option = int(option)
|
||||
support = dict((capability, True) for bitval, capability in MTTS if option & bitval > 0)
|
||||
self.protocol.protocol_flags['TTYPE'].update(support)
|
||||
self.protocol.protocol_flags.update(support)
|
||||
else:
|
||||
# some clients send erroneous MTTS as a string. Add directly.
|
||||
self.protocol.protocol_flags['TTYPE'][option.upper()] = True
|
||||
self.protocol.protocol_flags[option.upper()] = True
|
||||
|
||||
self.protocol.protocol_flags['TTYPE']['init_done'] = True
|
||||
self.protocol.protocol_flags['TTYPE'] = True
|
||||
# we must sync ttype once it'd done
|
||||
self.protocol.handshake_done()
|
||||
self.ttype_step += 1
|
||||
|
|
|
|||
|
|
@ -156,12 +156,13 @@ class WebSocketClient(Protocol, Session):
|
|||
text = args[0]
|
||||
if text is None:
|
||||
return
|
||||
flags = self.protocol_flags
|
||||
text = to_str(text, force_string=True)
|
||||
|
||||
options = kwargs.get("options", {})
|
||||
raw = options.get("raw", False)
|
||||
nomarkup = options.get("nomarkup", False)
|
||||
screenreader = options.get("screenreader", False)
|
||||
screenreader = options.get("screenreader", flags.get("SCREENREADER", False))
|
||||
prompt = options.get("send_prompt", False)
|
||||
|
||||
if screenreader:
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class Session(object):
|
|||
|
||||
# names of attributes that should be affected by syncing.
|
||||
_attrs_to_sync = ('protocol_key', 'address', 'suid', 'sessid', 'uid',
|
||||
'uname', 'logged_in', 'puid', 'encoding', 'screenreader',
|
||||
'uname', 'logged_in', 'puid', 'encoding',
|
||||
'conn_time', 'cmd_last', 'cmd_last_visible', 'cmd_total',
|
||||
'protocol_flags', 'server_data', "cmdset_storage_string")
|
||||
|
||||
|
|
@ -80,7 +80,6 @@ class Session(object):
|
|||
self.cmd_last = self.conn_time
|
||||
self.cmd_total = 0
|
||||
self.encoding = "utf-8"
|
||||
self.screenreader = False
|
||||
|
||||
self.protocol_flags = {}
|
||||
self.server_data = {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue