if input_data:
# keep only the first word and convert to lower-case
- user.proposed_name = string.split(input_data)[0].lower()
+ name = input_data.lower()
- # if we have a password hash, time to request a password
- if user.get_passhash():
+ # fail if there are non-alphanumeric characters
+ if name != filter(lambda x: x>="0" and x<="9" or x>="a" and x<="z", name):
+ user.error = "bad_name"
+
+ # if that account exists, time to request a password
+ elif name in muffuniv.universe.categories["account"]:
+ user.account = muffuniv.universe.categories["account"][name]
user.state = "checking_password"
# otherwise, this could be a brand new user
else:
- user.name = user.proposed_name
- user.proposed_name = None
- user.load()
- muffmisc.log("New user: " + user.name)
+ user.account = muffuniv.Element("account:" + name, muffuniv.universe)
+ user.account.set("name", name)
+ muffmisc.log("New user: " + name)
user.state = "checking_new_account_name"
# if the user entered nothing for a name, then buhbye
input_data = user.input_queue.pop(0)
# does the hashed input equal the stored hash?
- if md5.new(user.proposed_name + input_data).hexdigest() == user.passhash:
+ if md5.new(user.account.get("name") + input_data).hexdigest() == user.account.get("passhash"):
# if so, set the username and load from cold storage
- user.name = user.proposed_name
- del(user.proposed_name)
if not user.replace_old_connections():
- user.load()
user.authenticate()
user.state = "main_utility"
# if at first your hashes don't match, try, try again
- elif user.password_tries < muffconf.getint("general", "password_tries"):
+ elif user.password_tries < muffuniv.universe.categories["internal"]["general"].getint("password_tries"):
user.password_tries += 1
user.error = "incorrect"
# user selected to disconnect
if choice == "d":
+ user.account.delete()
user.state = "disconnecting"
# go back to the login screen
elif choice == "g":
+ user.account.delete()
user.state = "entering_account_name"
# new user, so ask for a password
if len(input_data) > 6 and len(filter(lambda x: x>="0" and x<="9", input_data)) and len(filter(lambda x: x>="A" and x<="Z", input_data)) and len(filter(lambda x: x>="a" and x<="z", input_data)):
# hash and store it, then move on to verification
- user.passhash = md5.new(user.name + input_data).hexdigest()
+ user.account.set("passhash", md5.new(user.account.get("name") + input_data).hexdigest())
user.state = "verifying_new_password"
# the password was weak, try again if you haven't tried too many times
- elif user.password_tries < muffconf.getint("general", "password_tries"):
+ elif user.password_tries < muffuniv.universe.categories["internal"]["general"].getint("password_tries"):
user.password_tries += 1
user.error = "weak"
# too many tries, so adios
else:
user.send("$(eol)$(red)Too many failed password attempts...$(nrm)$(eol)")
+ user.account.delete()
user.state = "disconnecting"
def handler_verifying_new_password(user):
input_data = user.input_queue.pop(0)
# hash the input and match it to storage
- if md5.new(user.name + input_data).hexdigest() == user.passhash:
+ if md5.new(user.account.get("name") + input_data).hexdigest() == user.account.get("passhash"):
user.authenticate()
- user.save()
# the hashes matched, so go active
if not user.replace_old_connections(): user.state = "main_utility"
# go back to entering the new password as long as you haven't tried
# too many times
- elif user.password_tries < muffconf.getint("general", "password_tries"):
+ elif user.password_tries < muffuniv.universe.categories["internal"]["general"].getint("password_tries"):
user.password_tries += 1
user.error = "differs"
user.state = "entering_new_password"
# otherwise, sayonara
else:
user.send("$(eol)$(red)Too many failed password attempts...$(nrm)$(eol)")
+ user.account.delete()
user.state = "disconnecting"
def handler_active(user):
input_data = user.input_queue.pop(0)
# split out the command (first word) and parameters (everything else)
- try:
- inputlist = string.split(input_data, None, 1)
- command = inputlist[0]
- except:
+ if input_data.find(" ") > 0:
+ command, parameters = input_data.split(" ", 1)
+ else:
command = input_data
- try:
- parameters = inputlist[1]
- except:
parameters = ""
- del(inputlist)
# lowercase the command
command = command.lower()
# the command matches a command word for which we have data
- if command in muffuniv.universe.commands.keys():
- exec(muffuniv.universe.commands[command].get("action"))
+ if command in muffuniv.universe.categories["command"]:
+ exec(muffuniv.universe.categories["command"][command].get("action"))
# no data matching the entered command word
elif command: command_error(user, command, parameters)
# see if there's a message or use a generic one
if parameters: message = "Halting: " + parameters
- else: message = "User " + user.name + " halted the world."
+ else: message = "User " + user.account.get("name") + " halted the world."
# let everyone know
muffmisc.broadcast(message)
# let the user know and log
user.send("Reloading all code modules, configs and data.")
- muffmisc.log("User " + user.name + " reloaded the world.")
+ muffmisc.log("User " + user.account.get("name") + " reloaded the world.")
# set a flag to reload
muffvars.reload_modules = True
"""Quit the world."""
user.state = "disconnecting"
-def command_time(user, command="", parameters=""):
- """Show the current world time in elapsed increments."""
- user.send(muffuniv.universe.internals["counters"].get("elapsed") + " increments elapsed since the world was created.")
-
def command_help(user, command="", parameters=""):
"""List available commands and provide help for commands."""
if parameters:
# is the command word one for which we have data?
- if parameters in muffuniv.universe.commands.keys():
+ if parameters in muffuniv.universe.categories["command"]:
# add a description if provided
- description = muffuniv.universe.commands[parameters].get("description")
+ description = muffuniv.universe.categories["command"][parameters].get("description")
if not description:
description = "(no short description provided)"
output = "$(grn)" + parameters + "$(nrm) - " + description + "$(eol)$(eol)"
# add the help text if provided
- help_text = muffuniv.universe.commands[parameters].get("help")
+ help_text = muffuniv.universe.categories["command"][parameters].get("help")
if not help_text:
help_text = "No help is provided for this command."
output += help_text
# give a sorted list of commands with descriptions if provided
output = "These are the commands available to you:$(eol)$(eol)"
- sorted_commands = muffuniv.universe.commands.keys()
+ sorted_commands = muffuniv.universe.categories["command"].keys()
sorted_commands.sort()
for item in sorted_commands:
- description = muffuniv.universe.commands[item].get("description")
+ description = muffuniv.universe.categories["command"][item].get("description")
if not description:
description = "(no short description provided)"
output += " $(grn)" + item + "$(nrm) - " + description + "$(eol)"
# a dictionary of punctuation:action pairs
actions = {}
- for option in muffconf.config_data.options("language"):
- if option.startswith("punctuation_"):
- action = option.split("_")[1]
- for mark in muffconf.config_data.get("language", option).split():
+ for facet in muffuniv.universe.categories["internal"]["language"].facets():
+ if facet.startswith("punctuation_"):
+ action = facet.split("_")[1]
+ for mark in muffuniv.universe.categories["internal"]["language"].get(facet).split():
actions[mark] = action
- # set the default action
- action = actions[muffconf.config_data.get("language", "default_punctuation")]
-
# match the punctuation used, if any, to an action
- default_punctuation = muffconf.config_data.get("language", "default_punctuation")
+ default_punctuation = muffuniv.universe.categories["internal"]["language"].get("default_punctuation")
+ action = actions[default_punctuation]
for mark in actions.keys():
if message.endswith(mark) and mark != default_punctuation:
action = actions[mark]
message += default_punctuation
# capitalize a list of words within the message
- capitalize = muffconf.get("language", "capitalize").split()
+ capitalize = muffuniv.universe.categories["internal"]["language"].get("capitalize").split()
for word in capitalize:
message = message.replace(" " + word + " ", " " + word.capitalize() + " ")
# tell the room
# TODO: we won't be using broadcast once there are actual rooms
- muffmisc.broadcast(user.name + " " + action + "s, \"" + message + "\"")
+ muffmisc.broadcast(user.account.get("name") + " " + action + "s, \"" + message + "\"")
# there was no message
else:
keys = muffuniv.universe.contents.keys()
keys.sort()
for key in keys: message += "$(eol) $(grn)" + key + "$(nrm)"
+ elif parameters == "time":
+ message = muffuniv.universe.categories["internal"]["counters"].get("elapsed") + " increments elapsed since the world was created."
elif parameters: message = "I don't know what \"" + parameters + "\" is."
else: message = "What do you want to show?"
user.send(message)