Log User object ID even when account is an admin
[mudpy.git] / mudpy / misc.py
index 501d5b4..eea2f00 100644 (file)
@@ -457,10 +457,8 @@ class Universe:
         self.listening_socket.listen(1)
 
         # note that we're now ready for user connections
-        log(
-            "Listening for Telnet connections on: " +
-            host + ":" + str(port)
-        )
+        log("Listening for Telnet connections on %s port %s" % (
+                host, str(port)))
 
     def get_time(self):
         """Convenience method to get the elapsed time counter."""
@@ -639,14 +637,13 @@ class User:
         """Flag the user as authenticated and disconnect duplicates."""
         if self.state != "authenticated":
             self.authenticated = True
+            log("User %s authenticated for account %s." % (
+                    self, self.account.subkey), 2)
             if ("mudpy.limit" in universe.contents and self.account.subkey in
                     universe.contents["mudpy.limit"].get("admins")):
                 self.account.set("administrator", True)
-                log("Administrator %s authenticated." %
-                    self.account.get("name"), 2)
-            else:
-                log("User %s authenticated for account %s." % (
-                        self, self.account.subkey), 2)
+                log("Account %s is an administrator." % (
+                        self.account.subkey), 2)
 
     def show_menu(self):
         """Send the user their current menu."""
@@ -1486,8 +1483,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 +1886,32 @@ 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()))
+                    mudpy.command.error(actor, input_data)
+
+        # 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
@@ -2057,8 +2077,9 @@ def setup():
     log("Import path: %s" % ", ".join(sys.path), 1)
     log("Installed dependencies: %s" % universe.versions.dependencies_text, 1)
     log("Other python packages: %s" % universe.versions.environment_text, 1)
-    log("Started %s with command line: %s" % (
-        universe.versions.version, " ".join(sys.argv)), 1)
+    log("Running version: %s" % universe.versions.version, 1)
+    log("Initial directory: %s" % universe.startdir, 1)
+    log("Command line: %s" % " ".join(sys.argv), 1)
 
     # pass the initialized universe back
     return universe