Did some additions to the MSDP implementation. Added a first test for implementing MSDP commands, but it is not working yet.
This commit is contained in:
parent
9935bff36e
commit
a0a205c945
3 changed files with 78 additions and 4 deletions
|
|
@ -11,6 +11,7 @@ etc.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
|
from src.utils.utils import make_iter
|
||||||
|
|
||||||
# variables
|
# variables
|
||||||
MSDP = chr(69)
|
MSDP = chr(69)
|
||||||
|
|
@ -112,22 +113,89 @@ class Msdp(object):
|
||||||
arrays[array[0]] = dict(regex_varval(array[1]))
|
arrays[array[0]] = dict(regex_varval(array[1]))
|
||||||
variables = dict(regex._varval(regex_array.sub("", regex_table.sub("", data))))
|
variables = dict(regex._varval(regex_array.sub("", regex_table.sub("", data))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# MSDP Commands
|
||||||
# Some given MSDP (varname, value) pairs can also be treated as command + argument.
|
# Some given MSDP (varname, value) pairs can also be treated as command + argument.
|
||||||
# Generic msdp command map. The argument will be sent to the given command.
|
# Generic msdp command map. The argument will be sent to the given command.
|
||||||
# See http://tintin.sourceforge.net/msdp/ for definitions of each command.
|
# See http://tintin.sourceforge.net/msdp/ for definitions of each command.
|
||||||
|
# These are client->server commands.
|
||||||
|
def msdp_cmd_list(self, arg):
|
||||||
|
"""
|
||||||
|
The List command allows for retrieving various info about the server/client
|
||||||
|
"""
|
||||||
|
if arg == 'COMMANDS':
|
||||||
|
return self.func_to_msdp(arg, MSDP_COMMANDS.keys())
|
||||||
|
elif arg == 'LISTS':
|
||||||
|
return self.func_to_msdp(arg, ("COMMANDS", "LISTS",
|
||||||
|
"CONFIGURABLE_VARIABLES",
|
||||||
|
"REPORTED_VARIABLES", "SENDABLE_VARIABLES"))
|
||||||
|
elif arg == 'CONFIGURABLE_VARIABLES':
|
||||||
|
return self.func_to_msdp(arg, ("CLIENT_NAME", "CLIENT_VERSION", "PLUGIN_ID"))
|
||||||
|
elif arg == 'REPORTABLE_VARIABLES':
|
||||||
|
return self.func_to_msdp(arg, MSDP_REPORTABLE.keys())
|
||||||
|
elif arg == 'REPORTED_VARIABLES':
|
||||||
|
return self.func_to_msdp(arg, MSDP_REPORTED.keys())
|
||||||
|
elif arg == 'SENDABLE_VARIABLES':
|
||||||
|
return self.func_to_msdp(arg, MSDP_SEND.keys())
|
||||||
|
else:
|
||||||
|
return self.func_to_msdp("LIST", arg)
|
||||||
|
|
||||||
|
def msdp_cmd_report(self, arg):
|
||||||
|
"""
|
||||||
|
The report command instructs the server to start reporting a
|
||||||
|
reportable variable to the client.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
MSDP_REPORTABLE[arg](report=True)
|
||||||
|
except Exception:
|
||||||
|
logger.log_trace()
|
||||||
|
|
||||||
|
def msdp_cmd_unreport(self, arg):
|
||||||
|
"""
|
||||||
|
Unreport a previously reported variable
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
MSDP_REPORTABLE[arg](eport=False)
|
||||||
|
except Exception:
|
||||||
|
logger.log_trace()
|
||||||
|
|
||||||
|
def msdp_cmd_reset(self, arg):
|
||||||
|
"""
|
||||||
|
The reset command resets a variable to its initial state.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
MSDP_REPORTABLE[arg](reset=True)
|
||||||
|
except Exception:
|
||||||
|
logger.log_trace()
|
||||||
|
|
||||||
|
def msdp_cmd_send(self, arg):
|
||||||
|
"""
|
||||||
|
Request the server to send a particular variable
|
||||||
|
to the client.
|
||||||
|
|
||||||
|
arg - this is a list of variables the client wants.
|
||||||
|
"""
|
||||||
|
ret = []
|
||||||
|
for var in makeiter(arg):
|
||||||
|
try:
|
||||||
|
ret.append(MSDP_REPORTABLE[arg](send=True))
|
||||||
|
except Exception:
|
||||||
|
logger.log_trace()
|
||||||
|
return ret
|
||||||
|
|
||||||
MSDP_COMMANDS = {
|
MSDP_COMMANDS = {
|
||||||
"LIST": "msdp_list",
|
"LIST": self.msdp_list,
|
||||||
"REPORT":"mspd_report",
|
"REPORT":"mspd_report",
|
||||||
"RESET":"mspd_reset",
|
"RESET":"mspd_reset",
|
||||||
"SEND":"mspd_send",
|
"SEND":"mspd_send",
|
||||||
"UNREPORT":"mspd_unreport"
|
"UNREPORT":"mspd_unreport"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# MSDP_MAP is a standard suggestions for making it easy to create generic guis.
|
# MSDP_MAP is a standard suggestions for making it easy to create generic guis.
|
||||||
# this maps MSDP command names to Evennia commands found in OOB_FUNC_MODULE. It
|
# this maps MSDP command names to Evennia commands found in OOB_FUNC_MODULE. It
|
||||||
# is up to these commands to return data on proper form.
|
# is up to these commands to return data on proper form.
|
||||||
MSDP_MAP = {
|
MSDP_REPORTABLE = {
|
||||||
# General
|
# General
|
||||||
"CHARACTER_NAME": "get_character_name",
|
"CHARACTER_NAME": "get_character_name",
|
||||||
"SERVER_ID": "get_server_id",
|
"SERVER_ID": "get_server_id",
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ class ServerSessionHandler(SessionHandler):
|
||||||
and see if any are dead.
|
and see if any are dead.
|
||||||
"""
|
"""
|
||||||
tcurr = time.time()
|
tcurr = time.time()
|
||||||
reason= _("Idle timeout exceeded, disconnecting."))
|
reason= _("Idle timeout exceeded, disconnecting.")2
|
||||||
for session in (session for session in self.sessions.values()
|
for session in (session for session in self.sessions.values()
|
||||||
if session.logged_in and IDLE_TIMEOUT > 0
|
if session.logged_in and IDLE_TIMEOUT > 0
|
||||||
and (tcurr - session.cmd_last) > IDLE_TIMEOUT):
|
and (tcurr - session.cmd_last) > IDLE_TIMEOUT):
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,12 @@ def is_iter(iterable):
|
||||||
"""
|
"""
|
||||||
return hasattr(iterable, '__iter__')
|
return hasattr(iterable, '__iter__')
|
||||||
|
|
||||||
|
def make_iter(obj):
|
||||||
|
"Makes sure that the object is always iterable."
|
||||||
|
if not hasattr(iterable, '__iter__'):
|
||||||
|
return [obj]
|
||||||
|
return obj
|
||||||
|
|
||||||
def fill(text, width=78, indent=0):
|
def fill(text, width=78, indent=0):
|
||||||
"""
|
"""
|
||||||
Safely wrap text to a certain number of characters.
|
Safely wrap text to a certain number of characters.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue