X-Git-Url: https://mudpy.org/gitweb?a=blobdiff_plain;f=mudpy%2Fmisc.py;h=62f531eb43fd5b0287296a750a969c2401d1186b;hb=5c4f77cf2f28dedbb24280005ea7db9421ed197f;hp=e76b4dd3b65d9083f8be8c68862b439498015eac;hpb=1ebcab5d26b7e3b482edf97ca0c1134323d858c9;p=mudpy.git diff --git a/mudpy/misc.py b/mudpy/misc.py index e76b4dd..62f531e 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -406,7 +406,7 @@ class Universe: """Create a new, empty Universe (the Big Bang).""" new_universe = Universe() for attribute in vars(self).keys(): - exec("new_universe." + attribute + " = self." + attribute) + setattr(new_universe, attribute, getattr(self, attribute)) new_universe.reload_flag = False del self return new_universe @@ -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.""" @@ -1584,8 +1581,8 @@ def get_menu_prompt(state): def get_menu_choices(user): """Return a dict of choice:meaning.""" - menu = universe.groups["menu"][user.state] - create_choices = menu.get("create") + state = universe.groups["menu"][user.state] + create_choices = state.get("create") if create_choices: choices = eval(create_choices) else: @@ -1593,7 +1590,7 @@ def get_menu_choices(user): ignores = [] options = {} creates = {} - for facet in menu.facets(): + for facet in state.facets(): if facet.startswith("demand_") and not eval( universe.groups["menu"][user.state].get(facet) ): @@ -1604,10 +1601,10 @@ def get_menu_choices(user): options[facet] = facet.split("_", 2)[1] for facet in creates.keys(): if not creates[facet] in ignores: - choices[creates[facet]] = eval(menu.get(facet)) + choices[creates[facet]] = eval(state.get(facet)) for facet in options.keys(): if not options[facet] in ignores: - choices[options[facet]] = menu.get(facet) + choices[options[facet]] = state.get(facet) return choices @@ -1688,9 +1685,9 @@ def handle_user_input(user): user.send("", add_prompt=False, prepend_padding=False) # check to make sure the state is expected, then call that handler - if "handler_" + user.state in globals(): - exec("handler_" + user.state + "(user)") - else: + try: + globals()["handler_" + user.state](user) + except KeyError: generic_menu_handler(user) # since we got input, flag that the menu/prompt needs to be redisplayed @@ -1893,12 +1890,14 @@ def handler_active(user): if actor.can_run(command): # dereference the relative object path for the requested function action = mudpy - for component in command.get("action", command.key).split("."): + 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 for command "%s"') + log('Could not find action function "%s" for command "%s"' + % (action_fname, command_name)) action = None break if action: @@ -1909,6 +1908,7 @@ def handler_active(user): '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: @@ -2077,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