mirror of
https://github.com/evennia/evennia.git
synced 2026-03-31 21:17:17 +02:00
Addition of a re-usable CommandTable class. We still have two global command tables that are now instances of this class. Game developers will use methods on CommandTable to add their own commands without modifying the base server code.
This is also in preparation of allowing commands to be present on objects via their script parents.
This commit is contained in:
parent
d38f2bd2f8
commit
37d66093cc
3 changed files with 116 additions and 76 deletions
169
src/cmdtable.py
169
src/cmdtable.py
|
|
@ -15,75 +15,106 @@ import commands.comsys
|
|||
import commands.unloggedin
|
||||
import commands.info
|
||||
import commands.objmanip
|
||||
import logger
|
||||
|
||||
# -- Unlogged-in Command Table --
|
||||
# Command Name Command Function Privilege Tuple
|
||||
uncon_ctable = {
|
||||
"connect": (commands.unloggedin.cmd_connect, None),
|
||||
"create": (commands.unloggedin.cmd_create, None),
|
||||
"quit": (commands.unloggedin.cmd_quit, None),
|
||||
}
|
||||
|
||||
|
||||
# -- Command Table --
|
||||
# Command Name Command Function Privilege Tuple
|
||||
ctable = {
|
||||
"addcom": (commands.comsys.cmd_addcom, None),
|
||||
"comlist": (commands.comsys.cmd_comlist, None),
|
||||
"delcom": (commands.comsys.cmd_delcom, None),
|
||||
"drop": (commands.general.cmd_drop, None),
|
||||
"examine": (commands.general.cmd_examine, None),
|
||||
"get": (commands.general.cmd_get, None),
|
||||
"help": (commands.general.cmd_help, None),
|
||||
"idle": (commands.general.cmd_idle, None),
|
||||
"inventory": (commands.general.cmd_inventory, None),
|
||||
"look": (commands.general.cmd_look, None),
|
||||
"page": (commands.general.cmd_page, None),
|
||||
"pose": (commands.general.cmd_pose, None),
|
||||
"quit": (commands.general.cmd_quit, None),
|
||||
"say": (commands.general.cmd_say, None),
|
||||
"time": (commands.info.cmd_time, None),
|
||||
"uptime": (commands.info.cmd_uptime, None),
|
||||
"version": (commands.info.cmd_version, None),
|
||||
"who": (commands.general.cmd_who, None),
|
||||
"@alias": (commands.objmanip.cmd_alias, None),
|
||||
"@boot": (commands.privileged.cmd_boot, ("genperms.manage_players")),
|
||||
"@ccreate": (commands.comsys.cmd_ccreate, ("objects.add_commchannel")),
|
||||
"@cdestroy": (commands.comsys.cmd_cdestroy, ("objects.delete_commchannel")),
|
||||
"@cemit": (commands.comsys.cmd_cemit, None),
|
||||
"@clist": (commands.comsys.cmd_clist, None),
|
||||
"@create": (commands.objmanip.cmd_create, ("genperms.builder")),
|
||||
"@describe": (commands.objmanip.cmd_description, None),
|
||||
"@destroy": (commands.objmanip.cmd_destroy, ("genperms.builder")),
|
||||
"@dig": (commands.objmanip.cmd_dig, ("genperms.builder")),
|
||||
"@emit": (commands.general.cmd_emit, ("genperms.announce")),
|
||||
# "@pemit": (commands.general.cmd_pemit, None),
|
||||
"@find": (commands.objmanip.cmd_find, ("genperms.builder")),
|
||||
"@link": (commands.objmanip.cmd_link, ("genperms.builder")),
|
||||
"@list": (commands.info.cmd_list, ("genperms.process_control")),
|
||||
"@name": (commands.objmanip.cmd_name, None),
|
||||
"@nextfree": (commands.objmanip.cmd_nextfree, ("genperms.builder")),
|
||||
"@newpassword": (commands.privileged.cmd_newpassword, ("genperms.manage_players")),
|
||||
"@open": (commands.objmanip.cmd_open, ("genperms.builder")),
|
||||
"@password": (commands.general.cmd_password, None),
|
||||
"@ps": (commands.info.cmd_ps, ("genperms.process_control")),
|
||||
"@reload": (commands.privileged.cmd_reload, ("genperms.process_control")),
|
||||
"@set": (commands.objmanip.cmd_set, None),
|
||||
"@shutdown": (commands.privileged.cmd_shutdown, ("genperms.process_control")),
|
||||
"@stats": (commands.info.cmd_stats, None),
|
||||
"@teleport": (commands.objmanip.cmd_teleport, ("genperms.builder")),
|
||||
"@unlink": (commands.objmanip.cmd_unlink, ("genperms.builder")),
|
||||
"@wall": (commands.general.cmd_wall, ("genperms.announce")),
|
||||
"@wipe": (commands.objmanip.cmd_wipe, None),
|
||||
}
|
||||
|
||||
def return_cmdtuple(func_name, unlogged_cmd=False):
|
||||
class CommandTable(object):
|
||||
"""
|
||||
Returns a reference to the command's tuple. If there are no matches,
|
||||
returns false.
|
||||
Stores command tables and performs lookups.
|
||||
"""
|
||||
if not unlogged_cmd:
|
||||
cfunc = ctable.get(func_name, False)
|
||||
else:
|
||||
cfunc = uncon_ctable.get(func_name, False)
|
||||
return cfunc
|
||||
ctable = {}
|
||||
|
||||
def add_command(self, command_string, function, priv_tuple=None):
|
||||
"""
|
||||
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.
|
||||
"""
|
||||
self.ctable[command_string] = (function, priv_tuple)
|
||||
|
||||
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)
|
||||
|
||||
"""
|
||||
Global command table for logged in users.
|
||||
"""
|
||||
GLOBAL_CMD_TABLE = CommandTable()
|
||||
GLOBAL_CMD_TABLE.add_command("addcom", commands.comsys.cmd_addcom),
|
||||
GLOBAL_CMD_TABLE.add_command("comlist", commands.comsys.cmd_comlist),
|
||||
GLOBAL_CMD_TABLE.add_command("delcom", commands.comsys.cmd_delcom),
|
||||
GLOBAL_CMD_TABLE.add_command("drop", commands.general.cmd_drop),
|
||||
GLOBAL_CMD_TABLE.add_command("examine", commands.general.cmd_examine),
|
||||
GLOBAL_CMD_TABLE.add_command("get", commands.general.cmd_get),
|
||||
GLOBAL_CMD_TABLE.add_command("help", commands.general.cmd_help),
|
||||
GLOBAL_CMD_TABLE.add_command("idle", commands.general.cmd_idle),
|
||||
GLOBAL_CMD_TABLE.add_command("inventory", commands.general.cmd_inventory),
|
||||
GLOBAL_CMD_TABLE.add_command("look", commands.general.cmd_look),
|
||||
GLOBAL_CMD_TABLE.add_command("page", commands.general.cmd_page),
|
||||
GLOBAL_CMD_TABLE.add_command("pose", commands.general.cmd_pose),
|
||||
GLOBAL_CMD_TABLE.add_command("quit", commands.general.cmd_quit),
|
||||
GLOBAL_CMD_TABLE.add_command("say", commands.general.cmd_say),
|
||||
GLOBAL_CMD_TABLE.add_command("time", commands.info.cmd_time),
|
||||
GLOBAL_CMD_TABLE.add_command("uptime", commands.info.cmd_uptime),
|
||||
GLOBAL_CMD_TABLE.add_command("version", commands.info.cmd_version),
|
||||
GLOBAL_CMD_TABLE.add_command("who", commands.general.cmd_who),
|
||||
GLOBAL_CMD_TABLE.add_command("@alias", commands.objmanip.cmd_alias),
|
||||
GLOBAL_CMD_TABLE.add_command("@boot", commands.privileged.cmd_boot,
|
||||
priv_tuple=("genperms.manage_players")),
|
||||
GLOBAL_CMD_TABLE.add_command("@ccreate", commands.comsys.cmd_ccreate,
|
||||
priv_tuple=("objects.add_commchannel")),
|
||||
GLOBAL_CMD_TABLE.add_command("@cdestroy", commands.comsys.cmd_cdestroy,
|
||||
priv_tuple=("objects.delete_commchannel")),
|
||||
GLOBAL_CMD_TABLE.add_command("@cemit", commands.comsys.cmd_cemit),
|
||||
GLOBAL_CMD_TABLE.add_command("@clist", commands.comsys.cmd_clist),
|
||||
GLOBAL_CMD_TABLE.add_command("@create", commands.objmanip.cmd_create,
|
||||
priv_tuple=("genperms.builder")),
|
||||
GLOBAL_CMD_TABLE.add_command("@describe", commands.objmanip.cmd_description),
|
||||
GLOBAL_CMD_TABLE.add_command("@destroy", commands.objmanip.cmd_destroy,
|
||||
priv_tuple=("genperms.builder")),
|
||||
GLOBAL_CMD_TABLE.add_command("@dig", commands.objmanip.cmd_dig,
|
||||
priv_tuple=("genperms.builder")),
|
||||
GLOBAL_CMD_TABLE.add_command("@emit", commands.general.cmd_emit,
|
||||
priv_tuple=("genperms.announce")),
|
||||
#GLOBAL_CMD_TABLE.add_command("@pemit", commands.general.cmd_pemit, None),
|
||||
GLOBAL_CMD_TABLE.add_command("@find", commands.objmanip.cmd_find,
|
||||
priv_tuple=("genperms.builder")),
|
||||
GLOBAL_CMD_TABLE.add_command("@link", commands.objmanip.cmd_link,
|
||||
priv_tuple=("genperms.builder")),
|
||||
GLOBAL_CMD_TABLE.add_command("@list", commands.info.cmd_list,
|
||||
priv_tuple=("genperms.process_control")),
|
||||
GLOBAL_CMD_TABLE.add_command("@name", commands.objmanip.cmd_name),
|
||||
GLOBAL_CMD_TABLE.add_command("@nextfree", commands.objmanip.cmd_nextfree,
|
||||
priv_tuple=("genperms.builder")),
|
||||
GLOBAL_CMD_TABLE.add_command("@newpassword", commands.privileged.cmd_newpassword,
|
||||
priv_tuple=("genperms.manage_players")),
|
||||
GLOBAL_CMD_TABLE.add_command("@open", commands.objmanip.cmd_open,
|
||||
priv_tuple=("genperms.builder")),
|
||||
GLOBAL_CMD_TABLE.add_command("@password", commands.general.cmd_password),
|
||||
GLOBAL_CMD_TABLE.add_command("@ps", commands.info.cmd_ps,
|
||||
priv_tuple=("genperms.process_control")),
|
||||
GLOBAL_CMD_TABLE.add_command("@reload", commands.privileged.cmd_reload,
|
||||
priv_tuple=("genperms.process_control")),
|
||||
GLOBAL_CMD_TABLE.add_command("@set", commands.objmanip.cmd_set),
|
||||
GLOBAL_CMD_TABLE.add_command("@shutdown", commands.privileged.cmd_shutdown,
|
||||
priv_tuple=("genperms.process_control")),
|
||||
GLOBAL_CMD_TABLE.add_command("@stats", commands.info.cmd_stats),
|
||||
GLOBAL_CMD_TABLE.add_command("@teleport", commands.objmanip.cmd_teleport,
|
||||
priv_tuple=("genperms.builder")),
|
||||
GLOBAL_CMD_TABLE.add_command("@unlink", commands.objmanip.cmd_unlink,
|
||||
priv_tuple=("genperms.builder")),
|
||||
GLOBAL_CMD_TABLE.add_command("@wall", commands.general.cmd_wall,
|
||||
priv_tuple=("genperms.announce")),
|
||||
GLOBAL_CMD_TABLE.add_command("@wipe", commands.objmanip.cmd_wipe),
|
||||
|
||||
"""
|
||||
Global unconnected command table, for unauthenticated users.
|
||||
"""
|
||||
GLOBAL_UNCON_CMD_TABLE = CommandTable()
|
||||
GLOBAL_UNCON_CMD_TABLE.add_command("connect", commands.unloggedin.cmd_connect)
|
||||
GLOBAL_UNCON_CMD_TABLE.add_command("create", commands.unloggedin.cmd_create)
|
||||
GLOBAL_UNCON_CMD_TABLE.add_command("quit", commands.unloggedin.cmd_quit)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue