Multiple fixes and cleanups - command parser excludes inaccessible commands already at parse level now. Fixed the functionality of a few of the lock functions to be more intuitive. Added functionality to the examine command to better show the commands available to an object.

This commit is contained in:
Griatch 2011-06-26 14:35:02 +00:00
parent 334c0b1d08
commit 95d672763b
17 changed files with 207 additions and 165 deletions

View file

@ -218,8 +218,8 @@ class CmdBatchCommands(MuxCommand):
if not commands:
string = "'%s' not found.\nYou have to supply the python path "
string += "of the file relative to \nyour batch-file directory (%s)."
caller.msg(string % (python_path, settings.BASE_BATCHPROCESS_PATH))
string += "of the file relative to \none of your batch-file directories (%s)."
caller.msg(string % (python_path, ", ".join(settings.BASE_BATCHPROCESS_PATHS)))
return
switches = self.switches
@ -404,9 +404,10 @@ class CmdStateRR(MuxCommand):
def func(self):
caller = self.caller
if caller.ndb.batch_batchmode == "batch_code":
BATCHCODE.parse_file(caller.ndb.batch_pythonpath)
new_data = BATCHCODE.parse_file(caller.ndb.batch_pythonpath)
else:
BATCHCMD.parse_file(caller.ndb.batch_pythonpath)
new_data = BATCHCMD.parse_file(caller.ndb.batch_pythonpath)
caller.ndb.batch_stack = new_data
caller.msg(format_code("File reloaded. Staying on same command."))
show_curr(caller)

View file

@ -350,6 +350,7 @@ class CmdCreate(ObjManipCommand):
switch:
drop - automatically drop the new object into your current location (this is not echoed)
this also sets the new object's home to the current location rather than to you.
Creates one or more new objects. If typeclass is given, the object
is created as a child of this typeclass. The typeclass script is
@ -405,6 +406,7 @@ class CmdCreate(ObjManipCommand):
obj.db.desc = "You see nothing special."
if 'drop' in self.switches:
if caller.location:
obj.home = caller.location
obj.move_to(caller.location, quiet=True)
caller.msg(string)
@ -482,7 +484,7 @@ class CmdDesc(MuxCommand):
return
desc = self.rhs
else:
obj = caller
obj = caller.location
desc = self.args
# storing the description
obj.db.desc = desc
@ -494,14 +496,17 @@ class CmdDestroy(MuxCommand):
@destroy - remove objects from the game
Usage:
@destroy[/<switches>] obj [,obj2, obj3, ...]
@delete ''
@destroy[/switches] [obj, obj2, obj3, [dbref-dbref], ...]
switches:
override - The @destroy command will usually avoid accidentally destroying
player objects. This switch overrides this safety.
examples:
@destroy house, roof, door, 44-78
@destroy 5-10, flower, 45
Destroys one or many objects.
Destroys one or many objects. If dbrefs are used, a range to delete can be
given, e.g. 4-10. Also the end points will be deleted.
"""
key = "@destroy"
@ -515,22 +520,22 @@ class CmdDestroy(MuxCommand):
caller = self.caller
if not self.args or not self.lhslist:
caller.msg("Usage: @destroy[/switches] obj [,obj2, obj3, ...]")
return
caller.msg("Usage: @destroy[/switches] [obj, obj2, obj3, [dbref-dbref],...]")
return ""
string = ""
for objname in self.lhslist:
def delobj(objname):
# helper function for deleting a single object
string = ""
obj = caller.search(objname)
if not obj:
self.caller.msg(" (Objects to destroy must either be local or specified with a unique dbref.)")
return
return ""
objname = obj.name
if not obj.access(caller, 'delete'):
string += "\nYou don't have permission to delete %s." % objname
continue
return "\nYou don't have permission to delete %s." % objname
if obj.player and not 'override' in self.switches:
string += "\nObject %s is controlled by an active player. Use /override to delete anyway." % objname
continue
return "\nObject %s is controlled by an active player. Use /override to delete anyway." % objname
had_exits = hasattr(obj, "exits") and obj.exits
had_objs = hasattr(obj, "contents") and any(obj for obj in obj.contents
if not (hasattr(obj, "exits") and obj not in obj.exits))
@ -544,9 +549,21 @@ class CmdDestroy(MuxCommand):
string += " Exits to and from %s were destroyed as well." % objname
if had_objs:
string += " Objects inside %s were moved to their homes." % objname
return string
string = ""
for objname in self.lhslist:
if '-' in objname:
# might be a range of dbrefs
dmin, dmax = [utils.dbref(part) for part in objname.split('-', 1)]
if dmin and dmax:
for dbref in range(int(dmin),int(dmax+1)):
string += delobj(str(dbref))
else:
string += delobj(objname)
if string:
caller.msg(string.strip())
class CmdDig(ObjManipCommand):
"""
@ -619,7 +636,7 @@ class CmdDig(ObjManipCommand):
to_exit = self.rhs_objs[0]
if not to_exit["name"]:
exit_to_string = \
"\nYou didn't give a name for the exit to the new room."
"\nNo exit created to new room."
elif not location:
exit_to_string = \
"\nYou cannot create an exit from a None-location."
@ -646,7 +663,7 @@ class CmdDig(ObjManipCommand):
back_exit = self.rhs_objs[1]
if not back_exit["name"]:
exit_back_string = \
"\nYou didn't give a name for the exit back here."
"\nNo back exit created."
elif not location:
exit_back_string = \
"\nYou cannot create an exit back to a None-location."
@ -1506,7 +1523,8 @@ class CmdExamine(ObjManipCommand):
"destination":"\n{wDestination{n: %s",
"perms":"\n{wPermissions{n: %s",
"locks":"\n{wLocks{n:",
"cmdset":"\n{wCurrent Cmdset (including permission checks){n:\n %s",
"cmdset":"\n{wCurrent Cmdset(s){n:\n %s",
"cmdset_avail":"\n{wActual commands available to %s (incl. lock-checks, external cmds etc){n:\n %s",
"scripts":"\n{wScripts{n:\n %s",
"exits":"\n{wExits{n: ",
"characters":"\n{wCharacters{n: ",
@ -1520,7 +1538,8 @@ class CmdExamine(ObjManipCommand):
"destination":"\nDestination: %s",
"perms":"\nPermissions: %s",
"locks":"\nLocks:",
"cmdset":"\nCurrent Cmdset (including permission checks):\n %s",
"cmdset":"\nCurrent Cmdset(s):\n %s",
"cmdset_avail":"\nActual commands available to %s (incl. lock-checks, external cmds, etc):\n %s",
"scripts":"\nScripts:\n %s",
"exits":"\nExits: ",
"characters":"\nCharacters: ",
@ -1556,8 +1575,18 @@ class CmdExamine(ObjManipCommand):
string += headers["locks"] + utils.fill("; ".join([lock for lock in locks.split(';')]), indent=6)
if not (len(obj.cmdset.all()) == 1 and obj.cmdset.current.key == "Empty"):
cmdsetstr = "\n".join([utils.fill(cmdset, indent=2) for cmdset in str(obj.cmdset).split("\n")])
# list the current cmdsets
cmdsetstr = "\n".join([utils.fill(cmdset, indent=2) for cmdset in str(obj.cmdset).split("\n")])
string += headers["cmdset"] % cmdsetstr
# list the actually available commands
from src.commands.cmdhandler import get_and_merge_cmdsets
avail_cmdset = get_and_merge_cmdsets(obj)
avail_cmdset = sorted([cmd.key for cmd in avail_cmdset if cmd.access(obj, "cmd")])
cmdsetstr = utils.fill(", ".join(avail_cmdset), indent=2)
string += headers["cmdset_avail"] % (obj.key, cmdsetstr)
if hasattr(obj, "scripts") and hasattr(obj.scripts, "all") and obj.scripts.all():
string += headers["scripts"] % obj.scripts
# add the attributes

View file

@ -229,11 +229,11 @@ class CmdInventory(MuxCommand):
# format item list into nice collumns
cols = [[],[]]
for item in items:
cols[0].append(item.name)
desc = utils.crop(item.db.desc)
cols[0].append(item.name)
desc = item.db.desc
if not desc:
desc = ""
cols[1].append(desc)
cols[1].append(utils.crop(str(desc)))
# auto-format the columns to make them evenly wide
ftable = utils.format_table(cols)
string = "You are carrying:"

View file

@ -26,7 +26,6 @@ from src.utils import create
from src.commands.cmdhandler import CMD_NOINPUT
from src.commands.cmdhandler import CMD_NOMATCH
from src.commands.cmdhandler import CMD_MULTIMATCH
from src.commands.cmdhandler import CMD_NOPERM
from src.commands.cmdhandler import CMD_CHANNEL
from src.commands.default.muxcommand import MuxCommand
@ -124,26 +123,8 @@ class SystemMultimatch(MuxCommand):
"""
string = self.format_multimatches(self.caller, self.matches)
self.caller.msg(string)
class SystemNoPerm(MuxCommand):
"""
This is called when the user does not have the
correct permissions to use a particular command.
"""
key = CMD_NOPERM
locks = "cmd:all()"
def func(self):
"""
This receives the original raw
input string (the one whose command failed to validate)
as argument.
"""
self.caller.msg("You are not allowed to do that.")
# Command called when the comman given at the command line
# Command called when the command given at the command line
# was identified as a channel name, like there existing a
# channel named 'ooc' and the user wrote
# > ooc Hello!

View file

@ -124,6 +124,7 @@ class CmdScripts(MuxCommand):
Switches:
stop - stops an existing script
kill - kills a script - without running its cleanup hooks
validate - run a validation on the script(s)
If no switches are given, this command just views all active
@ -212,15 +213,19 @@ class CmdScripts(MuxCommand):
caller.msg(string)
return
if self.switches and self.switches[0] in ('stop', 'del', 'delete'):
if self.switches and self.switches[0] in ('stop', 'del', 'delete', 'kill'):
# we want to delete something
if not scripts:
string = "No scripts/objects matching '%s'. " % args
string += "Be more specific."
elif len(scripts) == 1:
# we have a unique match!
string = "Stopping script '%s'." % scripts[0].key
scripts[0].stop()
if 'kill' in self.switches:
string = "Killing script '%s'" % scripts[0].key
scripts[0].stop(kill=True)
else:
string = "Stopping script '%s'." % scripts[0].key
scripts[0].stop()
ScriptDB.objects.validate() #just to be sure all is synced
else:
# multiple matches.