Implement the MSDP/GMCP wrappers for the backend inlinefuncs as per #924. It's not fully tested yet though.
This commit is contained in:
parent
8709ffefb8
commit
4f02ec1cbe
3 changed files with 74 additions and 20 deletions
|
|
@ -159,11 +159,21 @@ def client_options(session, *args, **kwargs):
|
||||||
|
|
||||||
def get_client_options(session, *args, **kwargs):
|
def get_client_options(session, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Alias wrapper for getting options
|
Alias wrapper for getting options.
|
||||||
"""
|
"""
|
||||||
client_options(session, get=True)
|
client_options(session, get=True)
|
||||||
|
|
||||||
|
|
||||||
|
def get_inputfuncs(session, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Get the keys of all available inputfuncs. Note that we don't get
|
||||||
|
it from this module alone since multiple modules could be added.
|
||||||
|
So we get it from the sessionhandler.
|
||||||
|
"""
|
||||||
|
inputfuncsdict = dict((key, func.__doc__) for key, func in session.sessionhandler.get_inputfuncs().iterkeys())
|
||||||
|
session.msg(get_inputfuncs=inputfuncsdict)
|
||||||
|
|
||||||
|
|
||||||
def login(session, *args, **kwargs):
|
def login(session, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Peform a login. This only works if session is currently not logged
|
Peform a login. This only works if session is currently not logged
|
||||||
|
|
@ -212,12 +222,13 @@ def _testrepeat(**kwargs):
|
||||||
session (Session): Session to return to.
|
session (Session): Session to return to.
|
||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
kwargs["session"].msg("Repeat called: %s" % time.time())
|
kwargs["session"].msg(repeat="Repeat called: %s" % time.time())
|
||||||
|
|
||||||
|
|
||||||
_repeatable = {"test1": _testrepeat, # example only
|
_repeatable = {"test1": _testrepeat, # example only
|
||||||
"test2": _testrepeat} # "
|
"test2": _testrepeat} # "
|
||||||
|
|
||||||
|
|
||||||
def repeat(session, *args, **kwargs):
|
def repeat(session, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Call a named function repeatedly. Note that
|
Call a named function repeatedly. Note that
|
||||||
|
|
@ -258,6 +269,7 @@ _monitorable = {
|
||||||
"desc": "desc"
|
"desc": "desc"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _on_monitor_change(**kwargs):
|
def _on_monitor_change(**kwargs):
|
||||||
fieldname = kwargs["fieldname"]
|
fieldname = kwargs["fieldname"]
|
||||||
obj = kwargs["obj"]
|
obj = kwargs["obj"]
|
||||||
|
|
@ -265,6 +277,7 @@ def _on_monitor_change(**kwargs):
|
||||||
session = kwargs["session"]
|
session = kwargs["session"]
|
||||||
session.msg(monitor={"name": name, "value": _GA(obj, fieldname)})
|
session.msg(monitor={"name": name, "value": _GA(obj, fieldname)})
|
||||||
|
|
||||||
|
|
||||||
def monitor(session, *args, **kwargs):
|
def monitor(session, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Adds monitoring to a given property or Attribute.
|
Adds monitoring to a given property or Attribute.
|
||||||
|
|
@ -289,6 +302,7 @@ def monitor(session, *args, **kwargs):
|
||||||
MONITOR_HANDLER.add(obj, field_name, _on_monitor_change, idstring=session.sessid,
|
MONITOR_HANDLER.add(obj, field_name, _on_monitor_change, idstring=session.sessid,
|
||||||
persistent=False, name=name, session=session)
|
persistent=False, name=name, session=session)
|
||||||
|
|
||||||
|
|
||||||
def unmonitor(session, *args, **kwargs):
|
def unmonitor(session, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Wrapper for turning off monitoring
|
Wrapper for turning off monitoring
|
||||||
|
|
@ -298,21 +312,20 @@ def unmonitor(session, *args, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
# aliases for GMCP
|
# aliases for GMCP
|
||||||
core_hello = client_options # Core.Hello
|
gmcp_core_hello = client_options # Core.Hello
|
||||||
core_supports_set = client_options # Core.Supports.Set
|
gmcp_core_supports_set = client_options # Core.Supports.Set
|
||||||
core_supports_get = get_client_options # Core.Supports.Get
|
gmcp_core_supports_get = get_client_options # Core.Supports.Get
|
||||||
char_login = login # Char.Login
|
gmcp_core_commands_get = get_inputfuncs # Core.Commands.Get
|
||||||
char_value_get = get_value # Char.Value.Get
|
gmcp_char_login = login # Char.Login
|
||||||
char_repeat_on = repeat # Char.Repeat.On
|
gmcp_char_value_get = get_value # Char.Value.Get
|
||||||
char_repeat_off = unrepeat # Char.Repeat.Off
|
gmcp_char_repeat_on = repeat # Char.Repeat.On
|
||||||
char_monitor_on = monitor # Char.Monitor.On
|
gmcp_char_repeat_off = unrepeat # Char.Repeat.Off
|
||||||
char_monitor_off = unmonitor # Char.Monitor.Off
|
gmcp_char_monitor_on = monitor # Char.Monitor.On
|
||||||
|
gmcp_char_monitor_off = unmonitor # Char.Monitor.Off
|
||||||
|
|
||||||
# aliases for MSDP
|
# aliases for MSDP
|
||||||
msdp_send = get_value # SEND
|
SEND = get_value # SEND
|
||||||
msdp_repeat = repeat # REPEAT
|
REPEAT = repeat # REPEAT
|
||||||
msdp_unrepeat = unrepeat # UNREPEAT
|
UNREPEAT = unrepeat # UNREPEAT
|
||||||
msdp_report = monitor # REPORT
|
MONITOR = monitor # REPORT
|
||||||
mspd_unreport = unmonitor # UNREPORT
|
LIST = get_inputfuncs # LIST
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,19 @@ msdp_regex_array = re.compile(r"%s\s*(\w*?)\s*%s\s*%s(.*?)%s" % (MSDP_VAR, MSDP_
|
||||||
msdp_regex_var = re.compile(r"%s" % MSDP_VAR)
|
msdp_regex_var = re.compile(r"%s" % MSDP_VAR)
|
||||||
msdp_regex_val = re.compile(r"%s" % MSDP_VAL)
|
msdp_regex_val = re.compile(r"%s" % MSDP_VAL)
|
||||||
|
|
||||||
|
EVENNIA_TO_MSDP = {"client_options": "OPTIONS",
|
||||||
|
"get_inputfuncs": "LIST",
|
||||||
|
"get_value": "SEND",
|
||||||
|
"repeat": "REPEAT",
|
||||||
|
"monitor": "REPORT"}
|
||||||
|
|
||||||
|
EVENNIA_TO_GMCP = {"client_options": "Core.Supports.Get",
|
||||||
|
"get_inputfuncs": "Core.Commands.Get",
|
||||||
|
"get_value": "Char.Value.Get",
|
||||||
|
"repeat": "Char.Repeat.Update",
|
||||||
|
"monitor": "Char.Monitor.Update"}
|
||||||
|
|
||||||
|
|
||||||
# MSDP output templates
|
# MSDP output templates
|
||||||
|
|
||||||
# cmdname
|
# cmdname
|
||||||
|
|
@ -374,6 +387,14 @@ class TelnetOOB(object):
|
||||||
args = list(structure)
|
args = list(structure)
|
||||||
else:
|
else:
|
||||||
args = (structure,)
|
args = (structure,)
|
||||||
|
if cmdname.startswith("Custom.Cmd."):
|
||||||
|
# if Custom.Cmd.Cmdname, then use Cmdname
|
||||||
|
cmdname = cmdname[11:]
|
||||||
|
else:
|
||||||
|
# not a custom command - convert the input name to a
|
||||||
|
# Python form such that Core.Supports.Get ->
|
||||||
|
# gmcp_core_supports_get
|
||||||
|
cmdname = "gmcp_%s" % "_".join(part.lower() for part in cmdname.split("."))
|
||||||
print "gmcp data in:", {cmdname: [args, kwargs]}
|
print "gmcp data in:", {cmdname: [args, kwargs]}
|
||||||
self.protocol.data_in(**{cmdname: [args, kwargs]})
|
self.protocol.data_in(**{cmdname: [args, kwargs]})
|
||||||
|
|
||||||
|
|
@ -389,10 +410,21 @@ class TelnetOOB(object):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if self.MSDP:
|
if self.MSDP:
|
||||||
encoded_oob = self.encode_msdp(cmdname, *args, **kwargs)
|
if cmdname in EVENNIA_TO_MSDP:
|
||||||
|
msdp_cmdname = EVENNIA_TO_MSDP[cmdname]
|
||||||
|
else:
|
||||||
|
msdp_cmdname = "CUSTOM"
|
||||||
|
kwargs["cmdname"] = cmdname
|
||||||
|
encoded_oob = self.encode_msdp(msdp_cmdname, *args, **kwargs)
|
||||||
print "sending MSDP:", encoded_oob
|
print "sending MSDP:", encoded_oob
|
||||||
self.protocol._write(IAC + SB + MSDP + encoded_oob + IAC + SE)
|
self.protocol._write(IAC + SB + MSDP + encoded_oob + IAC + SE)
|
||||||
|
|
||||||
if self.GMCP:
|
if self.GMCP:
|
||||||
encoded_oob = self.encode_gmcp(cmdname, *args, **kwargs)
|
if cmdname in EVENNIA_TO_GMCP:
|
||||||
|
gmcp_cmdname = EVENNIA_TO_GMCP[cmdname]
|
||||||
|
else:
|
||||||
|
gmcp_cmdname = "Custom.Cmd"
|
||||||
|
kwargs["cmdname"] = cmdname
|
||||||
|
encoded_oob = self.encode_gmcp(gmcp_cmdname, *args, **kwargs)
|
||||||
print "sending GMCP:", encoded_oob
|
print "sending GMCP:", encoded_oob
|
||||||
self.protocol._write(IAC + SB + GMCP + encoded_oob + IAC + SE)
|
self.protocol._write(IAC + SB + GMCP + encoded_oob + IAC + SE)
|
||||||
|
|
|
||||||
|
|
@ -621,6 +621,15 @@ class ServerSessionHandler(SessionHandler):
|
||||||
self.server.amp_protocol.send_MsgServer2Portal(session,
|
self.server.amp_protocol.send_MsgServer2Portal(session,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
|
def get_inputfuncs(self):
|
||||||
|
"""
|
||||||
|
Get all registered inputfuncs (access function)
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
inputfuncs (dict): A dict of {key:inputfunc,...}
|
||||||
|
"""
|
||||||
|
return _INPUT_FUNCS
|
||||||
|
|
||||||
def data_in(self, session, **kwargs):
|
def data_in(self, session, **kwargs):
|
||||||
"""
|
"""
|
||||||
Data Portal -> Server.
|
Data Portal -> Server.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue