X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=mudpy%2Fmisc.py;h=f99fac357cc79cbf196fa341581d4edd19401290;hp=501d5b40498ccc3e2bd0dab25a4a1ffb92352de7;hb=f38d6c0f396d2ff3da597b0fbac2cee2891df934;hpb=de65a162dc402df0e052c9a6e79a533a00036902 diff --git a/mudpy/misc.py b/mudpy/misc.py index 501d5b4..f99fac3 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -1486,8 +1486,10 @@ def find_command(command_name): command = universe.groups["command"][command_name] else: for candidate in sorted(universe.groups["command"]): - if candidate.startswith(command_name): - # the command matches the start of a command word + if candidate.startswith(command_name) and not universe.groups[ + "command"][candidate].get("administrative"): + # the command matches the start of a command word and is not + # restricted to administrators command = universe.groups["command"][candidate] break return command @@ -1887,11 +1889,31 @@ def handler_active(user): command = find_command(command_name) # if it's allowed, do it + ran = False if actor.can_run(command): - exec(command.get("action")) - - # otherwise, give an error - elif command_name: + # dereference the relative object path for the requested function + action = mudpy + action_fname = command.get("action", command.key) + for component in action_fname.split("."): + try: + action = getattr(action, component) + ran = True + except AttributeError: + log('Could not find action function "%s" for command "%s"' + % (action_fname, command_name)) + action = None + break + if action: + try: + action(actor, parameters) + except Exception: + log('Command string "%s" from user %s raised an ' + 'exception...\n%s' % ( + input_data, actor.owner.account.get("name"), + traceback.format_exc())) + + # if the command was not run, give an error + if not ran: mudpy.command.error(actor, input_data) # if no input, just idle back with a prompt