mirror of
https://github.com/evennia/evennia.git
synced 2026-03-25 09:16:32 +01:00
Changed inputhandler/oochandler to monitorhandler and made inputhandler_funcs into just inputfuncs.py
This commit is contained in:
parent
67b84c2431
commit
4ab049709d
6 changed files with 33 additions and 151 deletions
|
|
@ -1,32 +1,33 @@
|
|||
"""
|
||||
Inputhandler functions
|
||||
Input functions
|
||||
|
||||
Inputcommands are always called from the client (they handle server
|
||||
Input functions are always called from the client (they handle server
|
||||
input, hence the name).
|
||||
|
||||
This module is loaded by being included in
|
||||
`settings.INPUT_HANDLER_MODULES`.
|
||||
This module is loaded by being included in the
|
||||
`settings.INPUT_FUNC_MODULES` tuple.
|
||||
|
||||
All *global functions* included in this module are
|
||||
considered input-handler functions and can be called
|
||||
by the client to handle input.
|
||||
All *global functions* included in this module are considered
|
||||
input-handler functions and can be called by the client to handle
|
||||
input.
|
||||
|
||||
An inputhandler function must have the following call signature:
|
||||
An input function must have the following call signature:
|
||||
|
||||
cmdname(session, *args, **kwargs)
|
||||
|
||||
Where session will be the active session and *args, **kwargs are extra
|
||||
incoming arguments and keyword properties.
|
||||
|
||||
A special command is the "default" command, which is called when
|
||||
no other cmdname matches:
|
||||
A special command is the "default" command, which is will be called
|
||||
when no other cmdname matches. It also receives the non-found cmdname
|
||||
as argument.
|
||||
|
||||
default(session, cmdname, *args, **kwargs)
|
||||
|
||||
"""
|
||||
|
||||
# import the contents of the default inputhandler_func module
|
||||
#from evennia.server.inputhandler_funcs import *
|
||||
#from evennia.server.inputfuncs import *
|
||||
|
||||
|
||||
# def oob_echo(session, *args, **kwargs):
|
||||
|
|
@ -1,14 +1,17 @@
|
|||
"""
|
||||
OOBHandler - Out Of Band Handler
|
||||
Monitors - handle input-commands from the client.
|
||||
|
||||
The INPUT_HANDLER singleton from this module is meant as a resource
|
||||
for input functions to use. The handler is never executed
|
||||
automatically unless called from an input function. The handler offers
|
||||
the following features:
|
||||
|
||||
- Field-monitor - track a object's specific database field and perform
|
||||
an action whenever that field *changes* for whatever reason.
|
||||
- Attribute-monitor track an object's specific Attribute and perform
|
||||
an action whenever that Attribute *changes* for whatever reason.
|
||||
|
||||
The OOBHandler.execute_cmd is called by the sessionhandler when it
|
||||
detects an `oob` keyword in the outgoing data (usually called via
|
||||
`msg(oob=...)`
|
||||
|
||||
How this works is that the handler executes an oobfunction, which is
|
||||
defined in a user-supplied module. This function can then make use of
|
||||
the oobhandler's functionality to return data, register a monitor on
|
||||
an object's properties or start a repeating action.
|
||||
|
||||
"""
|
||||
from builtins import object
|
||||
|
|
@ -415,74 +418,5 @@ class OOBHandler(TickerHandler):
|
|||
return [(unpack_dbobj(key[0]), key[2], stored[0], stored[1])
|
||||
for key, stored in self.oob_monitor_storage.items() if key[1] == sessid]
|
||||
|
||||
|
||||
# access method - called from session.msg()
|
||||
|
||||
def execute_cmd(self, session, oobfuncname, *args, **kwargs):
|
||||
"""
|
||||
Execute an oob command
|
||||
|
||||
Args:
|
||||
session (Session or int): Session or Session.sessid calling
|
||||
the oob command
|
||||
oobfuncname (str): The name of the oob command (case sensitive)
|
||||
|
||||
Notes:
|
||||
If the oobfuncname is a valid oob function, `args` and
|
||||
`kwargs` are passed into the oob command.
|
||||
|
||||
"""
|
||||
if not session:
|
||||
errmsg = "OOB Error: execute_cmd(%s,%s,%s,%s) - no valid session" % \
|
||||
(session, oobfuncname, args, kwargs)
|
||||
raise RuntimeError(errmsg)
|
||||
|
||||
try:
|
||||
oobfunc = _OOB_FUNCS[oobfuncname]
|
||||
except Exception:
|
||||
errmsg = "'%s' is not a valid OOB command. Commands available:\n %s" % (oobfuncname, ", ".join(_OOB_FUNCS))
|
||||
if _OOB_ERROR:
|
||||
_OOB_ERROR(session, errmsg, *args, **kwargs)
|
||||
errmsg = "OOB ERROR: %s" % errmsg
|
||||
logger.log_trace(errmsg)
|
||||
return
|
||||
|
||||
# we found an oob command. Execute it.
|
||||
try:
|
||||
oobfunc(session, *args, **kwargs)
|
||||
except Exception as err:
|
||||
errmsg = "Exception in %s(*%s, **%s):\n%s" % (oobfuncname, args, kwargs, err)
|
||||
if _OOB_ERROR:
|
||||
_OOB_ERROR(session, errmsg, *args, **kwargs)
|
||||
errmsg = "OOB ERROR: %s" % errmsg
|
||||
logger.log_trace(errmsg)
|
||||
|
||||
|
||||
# access object
|
||||
INPUT_HANDLER = OOBHandler()
|
||||
|
||||
## load resources from plugin module. This must happen
|
||||
## AFTER the OOB_HANDLER has been initialized since the
|
||||
## commands will want to import it.
|
||||
#_OOB_FUNCS = {}
|
||||
#for modname in make_iter(settings.OOB_PLUGIN_MODULES):
|
||||
# _OOB_FUNCS.update(mod_import(modname).CMD_MAP)
|
||||
#
|
||||
## get the command to receive eventual error strings
|
||||
#_OOB_ERROR = _OOB_FUNCS.get("oob_error", None)
|
||||
#if not _OOB_ERROR:
|
||||
# # no custom error set; create default oob error message function
|
||||
# def oob_error(session, errmsg, *args, **kwargs):
|
||||
# """
|
||||
# Fallback error handler. This will be used if no custom
|
||||
# oob_error is defined and just echoes the error back to the
|
||||
# session.
|
||||
#
|
||||
# Args:
|
||||
# errmsg (str): Error message to echo.
|
||||
# args, kwargs (any): Not used.
|
||||
#
|
||||
# """
|
||||
# session.msg(oob=("err", ("ERROR ", errmsg)))
|
||||
# _OOB_ERROR = oob_error
|
||||
#
|
||||
|
|
@ -1,58 +1,5 @@
|
|||
"""
|
||||
Out-of-band default plugin commands available for OOB handler.
|
||||
|
||||
This module implements commands as defined by the MSDP standard
|
||||
(http://tintin.sourceforge.net/msdp/), but is independent of the
|
||||
actual transfer protocol (webclient, MSDP, GMCP etc). It also
|
||||
implements several OOB commands unique to Evennia (both some
|
||||
external and some for testing)
|
||||
|
||||
The available OOB commands can be extended by changing
|
||||
|
||||
`settings.OOB_PLUGIN_MODULES`
|
||||
|
||||
This module must contain a global dictionary CMD_MAP. This is a
|
||||
dictionary that maps the call available in the OOB call to a function
|
||||
in this module (this allows you to map multiple oob cmdnames to a
|
||||
single actual Python function, for example).
|
||||
|
||||
For example, if the OOB strings received looks like this:
|
||||
|
||||
MDSP.LISTEN [desc, key] # GMCP (wrapping to MSDP)
|
||||
LISTEN ARRAY VAL desc VAL key # MSDP
|
||||
|
||||
and CMD_MAP = {"LISTEN", listen} then this would result in a call to a
|
||||
function "listen" in this module, with the arguments *("desc", "key").
|
||||
|
||||
oob functions have the following call signature:
|
||||
|
||||
function(session, *args, **kwargs)
|
||||
|
||||
where session is the active session and *args, **kwargs are extra
|
||||
arguments sent with the oob command.
|
||||
|
||||
A function mapped to the key "oob_error" will retrieve error strings
|
||||
if it is defined. It will get the error message as its 1st argument.
|
||||
|
||||
oob_error(session, error, *args, **kwargs)
|
||||
|
||||
This allows for customizing error handling.
|
||||
|
||||
Data is usually returned to the user via a return OOB call:
|
||||
|
||||
session.msg(oob=(oobcmdname, (args,), {kwargs}))
|
||||
|
||||
Oobcmdnames (like "MSDP.LISTEN" / "LISTEN" above) are case-sensitive.
|
||||
Note that args, kwargs must be iterable. Non-iterables will be
|
||||
interpreted as a new command name (you can send multiple oob commands
|
||||
with one msg() call)
|
||||
|
||||
Evennia introduces two internal extensions to MSDP, and that is the
|
||||
MSDP_ARRAY and MSDP_TABLE commands. These are never sent across the
|
||||
wire to the client (so this is fully compliant with the MSDP
|
||||
protocol), but tells the Evennia OOB Protocol that you want to send a
|
||||
"bare" array or table to the client, without prepending any command
|
||||
name.
|
||||
Handlers for input commands
|
||||
|
||||
"""
|
||||
from future.utils import viewkeys
|
||||
|
|
@ -68,10 +68,10 @@ _MODEL_MAP = None
|
|||
|
||||
# input handlers
|
||||
|
||||
_INPUT_HANDLER_FUNCS = {}
|
||||
for modname in make_iter(settings.INPUT_HANDLER_MODULES):
|
||||
_INPUT_FUNCS = {}
|
||||
for modname in make_iter(settings.INPUT_FUNC_MODULES):
|
||||
print modname
|
||||
_INPUT_HANDLER_FUNCS.update(callables_from_module(modname))
|
||||
_INPUT_FUNCS.update(callables_from_module(modname))
|
||||
|
||||
def delayed_import():
|
||||
"""
|
||||
|
|
@ -629,11 +629,11 @@ class ServerSessionHandler(SessionHandler):
|
|||
if session:
|
||||
for cmdname, (cmdargs, cmdkwargs) in kwargs.iteritems():
|
||||
try:
|
||||
if cmdname in _INPUT_HANDLER_FUNCS:
|
||||
if cmdname in _INPUT_FUNCS:
|
||||
print "sessionhandler: data_in", cmdname, cmdargs, cmdkwargs
|
||||
_INPUT_HANDLER_FUNCS[cmdname](session, *cmdargs, **cmdkwargs)
|
||||
_INPUT_FUNCS[cmdname](session, *cmdargs, **cmdkwargs)
|
||||
else:
|
||||
_INPUT_HANDLER_FUNCS["default"](session, cmdname, *cmdargs, **cmdkwargs)
|
||||
_INPUT_FUNCS["default"](session, cmdname, *cmdargs, **cmdkwargs)
|
||||
except Exception:
|
||||
log_trace()
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ TELNET_INTERFACES = ['0.0.0.0']
|
|||
# special commands and data with enabled Telnet clients. This is used
|
||||
# to create custom client interfaces over a telnet connection. To make
|
||||
# full use of OOB, you need to prepare functions to handle the data
|
||||
# server-side (see INPUT_HANDLER_MODULES). TELNET_ENABLED is required for this
|
||||
# server-side (see INPUT_FUNC_MODULES). TELNET_ENABLED is required for this
|
||||
# to work.
|
||||
TELNET_OOB_ENABLED = False
|
||||
# Start the evennia django+twisted webserver so you can
|
||||
|
|
@ -279,7 +279,7 @@ LOCK_FUNC_MODULES = ("evennia.locks.lockfuncs", "server.conf.lockfuncs",)
|
|||
# Module holding handlers for managing incoming data from the client. These
|
||||
# will be loaded in order, meaning functions in later modules may overload
|
||||
# previous ones if having the same name.
|
||||
INPUT_HANDLER_MODULES = ["evennia.server.inputhandler_funcs", "server.conf.inputhandler_funcs"]
|
||||
INPUT_FUNC_MODULES = ["evennia.server.inputfuncs", "server.conf.inputfuncs"]
|
||||
# Module holding settings/actions for the dummyrunner program (see the
|
||||
# dummyrunner for more information)
|
||||
DUMMYRUNNER_SETTINGS_MODULE = "evennia.server.profiling.dummyrunner_settings"
|
||||
|
|
|
|||
|
|
@ -349,7 +349,7 @@ class CmdEditorGroup(CmdEditorBase):
|
|||
offset=lstart,
|
||||
linenums=False, options={"raw":True})
|
||||
else:
|
||||
editor.display_buffer(linenums=False, {options={"raw":True})
|
||||
editor.display_buffer(linenums=False, options={"raw":True})
|
||||
elif cmd == ":::":
|
||||
# Insert single colon alone on a line
|
||||
editor.update_buffer(editor.buffer + "\n:")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue