mirror of
https://github.com/evennia/evennia.git
synced 2026-03-21 23:36:30 +01:00
GLOBAL_STATE_TABLE.add_state() before adding commands to it. The state can now be much more configured by including as much or as little of the normal default commands into it as wanted (so you can now have states which are almost as normal, except some commands are missing or change their behaviour ... illness or darkness comes to mind). The possibilities here are limitless. * States now also optionally allow traversing exits as well as using command tables defined on objects. * States now better handle error messages (so if you try 'look' in a state which does not contain a look command you will no longer get the 'Huh?' but will be told that the command is not available at the moment). * All examples in commands/examples/ have been updated to use the new State system. Also added a @test_state function for trying out the functionality. * Added hooks at_before_move() and at_after_move(), useful for character based move-restrictions and checks (e.g. movement speed) * Minor tweaks to the event system; avoiding the counters to go negative should they hit an uncaught traceback. * Small fixes of typos and minor extra safety checks. /Griatch
77 lines
3.2 KiB
Python
77 lines
3.2 KiB
Python
"""
|
|
Command Table Module
|
|
|
|
Each command entry consists of a key and a tuple containing a reference to the
|
|
command's function, and a tuple of the permissions to match against. The user
|
|
only need have one of the permissions in the permissions tuple to gain
|
|
access to the command. Obviously, super users don't have to worry about this
|
|
stuff. If the command is open to all (or you want to implement your own
|
|
privilege checking in the command function), use None in place of the
|
|
permissions tuple.
|
|
|
|
Commands are located under evennia/src/commands. server.py imports these
|
|
based on the value of settings.COMMAND_MODULES and
|
|
settings.CUSTOM_COMMAND_MODULES. Each module imports cmdtable.py and runs
|
|
add_command on the command table each command belongs to.
|
|
"""
|
|
|
|
from src.helpsys.management.commands.edit_helpfiles import add_help
|
|
|
|
class CommandTable(object):
|
|
"""
|
|
Stores commands and performs lookups.
|
|
"""
|
|
ctable = None
|
|
|
|
def __init__(self):
|
|
# This ensures there are no leftovers when the class is instantiated.
|
|
self.ctable = {}
|
|
|
|
def add_command(self, command_string, function, priv_tuple=None,
|
|
extra_vals=None, auto_help=False, staff_help=False):
|
|
"""
|
|
Adds a command to the command table.
|
|
|
|
command_string: (string) Command string (IE: WHO, QUIT, look).
|
|
function: (reference) The command's function.
|
|
priv_tuple: (tuple) String tuple of permissions required for command.
|
|
extra_vals: (dict) Dictionary to add to the Command object.
|
|
|
|
Auto-help system:
|
|
auto_help (bool): If true, automatically creates/replaces a help topic with the
|
|
same name as the command_string, using the functions's __doc__ property
|
|
for help text.
|
|
staff_help (bool): Only relevant if auto_help is activated; If True, makes the
|
|
help topic (and all eventual subtopics) only visible to staff.
|
|
|
|
Note: the auto_help system also supports limited markup. If you divide your __doc__
|
|
with markers of the form <<TOPIC:MyTopic>>, the system will automatically create
|
|
separate help topics for each topic. Your initial text (if you define no TOPIC)
|
|
will still default to the name of your command.
|
|
You can also custon-set the staff_only flag for individual subtopics by
|
|
using the markup <<TOPIC:STAFF:MyTopic>> and <<TOPIC:NOSTAFF:MyTopic>>.
|
|
"""
|
|
self.ctable[command_string] = (function, priv_tuple, extra_vals)
|
|
|
|
if auto_help:
|
|
#add automatic help text from the command's doc string
|
|
topicstr = command_string
|
|
entrytext = function.__doc__
|
|
add_help(topicstr, entrytext, staff_only=staff_help,
|
|
force_create=True, auto_help=True)
|
|
|
|
def get_command_tuple(self, func_name):
|
|
"""
|
|
Returns a reference to the command's tuple. If there are no matches,
|
|
returns false.
|
|
"""
|
|
return self.ctable.get(func_name, False)
|
|
|
|
|
|
"""
|
|
Command tables
|
|
"""
|
|
# Global command table, for authenticated users.
|
|
GLOBAL_CMD_TABLE = CommandTable()
|
|
# Global unconnected command table, for unauthenticated users.
|
|
GLOBAL_UNCON_CMD_TABLE = CommandTable()
|