"""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
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."""
self.address = ""
self.authenticated = False
self.avatar = None
+ self.choice = ""
self.columns = 79
self.connection = None
self.error = ""
"""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."""
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:
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)
):
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
return universe.groups["menu"][state].get("branch")
-def get_choice_branch(user, choice):
+def get_choice_branch(user):
"""Returns the new state matching the given choice."""
branches = get_menu_branches(user.state)
- if choice in branches.keys():
- return branches[choice]
- elif choice in user.menu_choices.keys():
+ if user.choice in branches.keys():
+ return branches[user.choice]
+ elif user.choice in user.menu_choices.keys():
return get_default_branch(user.state)
else:
return ""
return universe.groups["menu"][state].get("action")
-def get_choice_action(user, choice):
+def get_choice_action(user):
"""Run any indicated script for the given choice."""
actions = get_menu_actions(user.state)
- if choice in actions.keys():
- return actions[choice]
- elif choice in user.menu_choices.keys():
+ if user.choice in actions.keys():
+ return actions[user.choice]
+ elif user.choice in user.menu_choices.keys():
return get_default_action(user.state)
else:
return ""
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
# get a lower-case representation of the next line of input
if user.input_queue:
- choice = user.input_queue.pop(0)
- if choice:
- choice = choice.lower()
+ user.choice = user.input_queue.pop(0)
+ if user.choice:
+ user.choice = user.choice.lower()
else:
- choice = ""
- if not choice:
- choice = get_default_menu_choice(user.state)
- if choice in user.menu_choices:
- exec(get_choice_action(user, choice))
- new_state = get_choice_branch(user, choice)
+ user.choice = ""
+ if not user.choice:
+ user.choice = get_default_menu_choice(user.state)
+ if user.choice in user.menu_choices:
+ exec(get_choice_action(user))
+ new_state = get_choice_branch(user)
if new_state:
user.state = new_state
else:
if actor.can_run(command):
# dereference the relative object path for the requested function
action = mudpy
- for component in command.get("action").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:
'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:
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