Cleaned up oobhandler input.

This commit is contained in:
Griatch 2013-11-28 16:26:04 +01:00
parent 9839e0ba1f
commit 242a0f17f8
4 changed files with 76 additions and 102 deletions

View file

@ -1,97 +1,36 @@
"""
OOB configuration.
** OBS This module is not yet used by Evennia **
This module should be included in (or replace) the
default module set in settings.OOB_PLUGIN_MODULES
Example module holding functions for out-of-band protocols to
import and map to given commands from the client. This module
is selected by settings.OOB_FUNC_MODULE.
All functions defined in this module are made available
to be called by the OOB handler.
All functions defined global in this module will be available
for the oob system to call. They will be called in the following
way:
See src/server/oob_msdp.py for more information.
a session/character
as first argument (depending on if the session is logged in or not),
following by any number of extra arguments. The return value will
be packed and returned to the oob protocol and can be on any form.
function execution - the oob protocol can execute a function directly on
the server. The available functions must be defined
as global functions via settings.OOB_PLUGIN_MODULES.
repeat func execution - the oob protocol can request a given function be
executed repeatedly at a regular interval. This
uses an internal script pool.
tracking - the oob protocol can request Evennia to track changes to
fields on objects, as well as changes in Attributes. This is
done by dynamically adding tracker-objects on entities. The
behaviour of those objects can be customized via
settings.OOB_PLUGIN_MODULES.
oob functions have the following call signature:
function(caller, session, *args, **kwargs)
oob trackers should inherit from the OOBTracker class in src/server.oob_msdp.py
and implement a minimum of the same functionality.
a global function oob_error will be used as optional error management.
"""
# import the contents of the default msdp module
from src.server/oob_msdp import *
def testoob(character, *args, **kwargs):
"Simple test function"
print "Called testoob: %s" % args
return "testoob did stuff to the input string '%s'!" % args
# 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
# is up to these commands to return data on proper form.
MSDP_REPORTABLE = {
# General
"CHARACTER_NAME": "get_character_name",
"SERVER_ID": "get_server_id",
"SERVER_TIME": "get_server_time",
# Character
"AFFECTS": "char_affects",
"ALIGNMENT": "char_alignment",
"EXPERIENCE": "char_experience",
"EXPERIENCE_MAX": "char_experience_max",
"EXPERIENCE_TNL": "char_experience_tnl",
"HEALTH": "char_health",
"HEALTH_MAX": "char_health_max",
"LEVEL": "char_level",
"RACE": "char_race",
"CLASS": "char_class",
"MANA": "char_mana",
"MANA_MAX": "char_mana_max",
"WIMPY": "char_wimpy",
"PRACTICE": "char_practice",
"MONEY": "char_money",
"MOVEMENT": "char_movement",
"MOVEMENT_MAX": "char_movement_max",
"HITROLL": "char_hitroll",
"DAMROLL": "char_damroll",
"AC": "char_ac",
"STR": "char_str",
"INT": "char_int",
"WIS": "char_wis",
"DEX": "char_dex",
"CON": "char_con",
# Combat
"OPPONENT_HEALTH": "opponent_health",
"OPPONENT_HEALTH_MAX": "opponent_health_max",
"OPPONENT_LEVEL": "opponent_level",
"OPPONENT_NAME": "opponent_name",
# World
"AREA_NAME": "area_name",
"ROOM_EXITS": "area_room_exits",
"ROOM_NAME": "room_name",
"ROOM_VNUM": "room_dbref",
"WORLD_TIME": "world_time",
# Configurable variables
"CLIENT_ID": "client_id",
"CLIENT_VERSION": "client_version",
"PLUGIN_ID": "plugin_id",
"ANSI_COLORS": "ansi_colours",
"XTERM_256_COLORS": "xterm_256_colors",
"UTF_8": "utf_8",
"SOUND": "sound",
"MXP": "mxp",
# GUI variables
"BUTTON_1": "button1",
"BUTTON_2": "button2",
"BUTTON_3": "button3",
"BUTTON_4": "button4",
"BUTTON_5": "button5",
"GAUGE_1": "gauge1",
"GAUGE_2": "gauge2",
"GAUGE_3": "gauge3",
"GAUGE_4": "gauge4",
"GAUGE_5": "gauge5"}

View file

@ -3,6 +3,32 @@ Out-of-band default plugin commands available for OOB handler. This
follows the standards defined by the MSDP out-of-band protocol
(http://tintin.sourceforge.net/msdp/)
This module is pointed to by settings.OOB_PLUGIN_MODULES. All functions
(not classes) defined globally in this module will be made available
to the oob mechanism.
function execution - the oob protocol can execute a function directly on
the server. The available functions must be defined
as global functions via settings.OOB_PLUGIN_MODULES.
repeat func execution - the oob protocol can request a given function be
executed repeatedly at a regular interval. This
uses an internal script pool.
tracking - the oob protocol can request Evennia to track changes to
fields on objects, as well as changes in Attributes. This is
done by dynamically adding tracker-objects on entities. The
behaviour of those objects can be customized via
settings.OOB_PLUGIN_MODULES.
What goes into the OOB_PLUGIN_MODULES is a list of modules with input
for the OOB system.
oob functions have the following call signature:
function(caller, session, *args, **kwargs)
oob trackers should build upon the OOBTracker class in this module
module and implement a minimum of the same functionality.
a global function oob_error will be used as optional error management.
"""
from django.conf import settings
from src.utils.utils import to_str
@ -10,12 +36,12 @@ _GA = object.__getattribute__
_SA = object.__setattr__
_NA = lambda o: (None, "N/A") # not implemented
# mapper for which properties may be requested/sent to the client and how
# to do so. Each entry should define a function that returns two values - the
# name of the property being returned (a string) and the value. If tracking
# database fields, make sure to enter the full database field name (e.g.
# db_key rather than just key) since the db_ prefix is used by trackers
# to know which tracking mechanism to activate.
# default properties defined by the MSDP protocol. These are
# used by the SEND oob function below. Each entry should point
# to a function that takes the relevant object as input and
# returns the data it is responsible for. Most of these
# are commented out, but kept for reference for each
# game to implement.
OOB_SENDABLE = {
## General
@ -131,6 +157,7 @@ class OOBFieldTracker(TrackerBase):
new_value = new_value.key
except AttributeError:
new_value = to_str(new_value, force_string=True)
# this is a wrapper call for sending oob data back to session
self.oobhandler.msg(self.sessid, "report", self.fieldname,
new_value, *args, **kwargs)
@ -156,6 +183,7 @@ class OOBAttributeTracker(TrackerBase):
new_value = new_value.dbobj
except AttributeError:
new_value = to_str(new_value, force_string=True)
# this is a wrapper call for sending oob data back to session
self.oobhandler.msg(self.sessid, "report", self.attrname, new_value, *args, **kwargs)
@ -183,7 +211,7 @@ def oob_error(oobhandler, session, errmsg, *args, **kwargs):
session.msg(oob=("send", {"ERROR": errmsg}))
def LIST(oobhandler, session, mode, *args, **kwargs):
def list(oobhandler, session, mode, *args, **kwargs):
"""
List available properties. Mode is the type of information
desired:

View file

@ -5,16 +5,19 @@ The OOBHandler is called directly by out-of-band protocols. It supplies three
pieces of functionality:
function execution - the oob protocol can execute a function directly on
the server. Only functions specified in
settings.OOB_PLUGIN_MODULE.OOB_FUNCS are valid
for this use.
the server. The available functions must be defined
as global functions via settings.OOB_PLUGIN_MODULES.
repeat func execution - the oob protocol can request a given function be
executed repeatedly at a regular interval.
executed repeatedly at a regular interval. This
uses an internal script pool.
tracking - the oob protocol can request Evennia to track changes to
fields on objects, as well as changes in Attributes. This is
done by dynamically adding tracker-objects on entities. The
behaviour of those objects can be customized via
settings.OOB_PLUGIN_MODULE
settings.OOB_PLUGIN_MODULES.
What goes into the OOB_PLUGIN_MODULES is a list of modules with input
for the OOB system.
oob functions have the following call signature:
function(caller, *args, **kwargs)
@ -22,6 +25,8 @@ oob functions have the following call signature:
oob trackers should inherit from the OOBTracker class in this
module and implement a minimum of the same functionality.
a global function oob_error will be used as optional error management.
"""
from inspect import isfunction
@ -32,14 +37,16 @@ from src.scripts.scripts import Script
from src.utils.create import create_script
from src.utils.dbserialize import dbserialize, dbunserialize, pack_dbobj, unpack_dbobj
from src.utils import logger
from src.utils.utils import all_from_module
from src.utils.utils import all_from_module, make_iter
_SA = object.__setattr__
_GA = object.__getattribute__
_DA = object.__delattr__
# load from plugin module
_OOB_FUNCS = dict((key.lower(), func) for key, func in all_from_module(settings.OOB_PLUGIN_MODULE).items() if isfunction(func))
_OOB_FUNCS = {}
for mod in make_iter(settings.OOB_PLUGIN_MODULES):
_OOB_FUNCS.update(dict((key.lower(), func) for key, func in all_from_module(mod) if isfunction(func)))
_OOB_ERROR = _OOB_FUNCS.get("oob_error", None)

View file

@ -207,7 +207,7 @@ LOCK_FUNC_MODULES = ("src.locks.lockfuncs",)
# Module holding OOB (Out of Band) hook objects. This allows for customization
# and expansion of which hooks OOB protocols are allowed to call on the server
# protocols for attaching tracker hooks for when various object field change
OOB_PLUGIN_MODULE = "src.server.oob_msdp"
OOB_PLUGIN_MODULES = ["src.server.oob_msdp"]
######################################################################
# Default command sets