X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=mudpy%2Fmisc.py;h=6cb780434799e65267f747a392c3c086f2556f11;hp=6c720d53f7af78a2d0235f20358046d0c04f762d;hb=9d7268dbda760522aaef21b6f40c9b3358a20ffb;hpb=91f6b37e5fc36953cc1f3150695382d0822b0672 diff --git a/mudpy/misc.py b/mudpy/misc.py index 6c720d5..6cb7804 100644 --- a/mudpy/misc.py +++ b/mudpy/misc.py @@ -154,6 +154,8 @@ class Element: def set(self, facet, value): """Set values.""" + if facet in ["loglevel"]: + value = int(value) if not self.has_facet(facet) or not self.get(facet) == value: if self.old_style: if self.key not in self.origin.data: @@ -300,9 +302,10 @@ class Element: if re.match("""^area:-?\d+,-?\d+,-?\d+$""", self.key): coordinates = [(int(x)) for x in self.key.split(":")[1].split(",")] - offsets = dict((x, - self.universe.contents["mudpy.movement.%s" % x].get("vector") - ) for x in self.universe.directions) + offsets = dict( + (x, + self.universe.contents["mudpy.movement.%s" % x].get("vector") + ) for x in self.universe.directions) for portal in self.get("gridlinks"): adjacent = map(lambda c, o: c + o, coordinates, offsets[portal]) @@ -650,8 +653,8 @@ class User: if self.state is not "authenticated": log("User " + self.account.get("name") + " logged in.", 2) self.authenticated = True - if self.account.subkey in universe.contents["mudpy.limit"].get( - "admins"): + if ("mudpy.limit" in universe.contents and self.account.subkey in + universe.contents["mudpy.limit"].get("admins")): self.account.set("administrator", "True") def show_menu(self): @@ -973,9 +976,14 @@ def log(message, level=0): """Log a message.""" # a couple references we need - file_name = universe.contents["mudpy.log"].get("file") - max_log_lines = universe.contents["mudpy.log"].get("lines") - syslog_name = universe.contents["mudpy.log"].get("syslog") + if "mudpy.log" in universe.contents: + file_name = universe.contents["mudpy.log"].get("file", "") + max_log_lines = universe.contents["mudpy.log"].get("lines", 0) + syslog_name = universe.contents["mudpy.log"].get("syslog", "") + else: + file_name = "" + max_log_lines = 0 + syslog_name = "" timestamp = time.asctime()[4:19] # turn the message into a list of nonempty lines @@ -992,7 +1000,8 @@ def log(message, level=0): file_descriptor.close() # send the timestamp and line to standard output - if universe.contents["mudpy.log"].get("stdout"): + if ("mudpy.log" in universe.contents and + universe.contents["mudpy.log"].get("stdout")): for line in lines: print(timestamp + " " + line) @@ -1709,6 +1718,12 @@ def handler_checking_password(user): # get the next waiting line of input input_data = user.input_queue.pop(0) + if "mudpy.limit" in universe.contents: + max_password_tries = universe.contents["mudpy.limit"].get( + "password_tries", 3) + else: + max_password_tries = 3 + # does the hashed input equal the stored hash? if mudpy.password.verify(input_data, user.account.get("passhash")): @@ -1718,8 +1733,7 @@ def handler_checking_password(user): user.state = "main_utility" # if at first your hashes don't match, try, try again - elif user.password_tries < universe.contents["mudpy.limit"].get( - "password_tries") - 1: + elif user.password_tries < max_password_tries - 1: user.password_tries += 1 user.error = "incorrect" @@ -1737,6 +1751,12 @@ def handler_entering_new_password(user): # get the next waiting line of input input_data = user.input_queue.pop(0) + if "mudpy.limit" in universe.contents: + max_password_tries = universe.contents["mudpy.limit"].get( + "password_tries", 3) + else: + max_password_tries = 3 + # make sure the password is strong--at least one upper, one lower and # one digit, seven or more characters in length if len(input_data) > 6 and len( @@ -1752,8 +1772,7 @@ def handler_entering_new_password(user): user.state = "verifying_new_password" # the password was weak, try again if you haven't tried too many times - elif user.password_tries < universe.contents["mudpy.limit"].get( - "password_tries") - 1: + elif user.password_tries < max_password_tries - 1: user.password_tries += 1 user.error = "weak" @@ -1772,6 +1791,12 @@ def handler_verifying_new_password(user): # get the next waiting line of input input_data = user.input_queue.pop(0) + if "mudpy.limit" in universe.contents: + max_password_tries = universe.contents["mudpy.limit"].get( + "password_tries", 3) + else: + max_password_tries = 3 + # hash the input and match it to storage if mudpy.password.verify(input_data, user.account.get("passhash")): user.authenticate() @@ -1782,8 +1807,7 @@ def handler_verifying_new_password(user): # go back to entering the new password as long as you haven't tried # too many times - elif user.password_tries < universe.contents["mudpy.limit"].get( - "password_tries") - 1: + elif user.password_tries < max_password_tries - 1: user.password_tries += 1 user.error = "differs" user.state = "entering_new_password" @@ -1997,12 +2021,13 @@ def command_say(actor, parameters): if message: # match the punctuation used, if any, to an action - actions = universe.contents["mudpy.linguistic"].get( - "actions" - ) - default_punctuation = ( - universe.contents["mudpy.linguistic"].get( - "default_punctuation")) + if "mudpy.linguistic" in universe.contents: + actions = universe.contents["mudpy.linguistic"].get("actions", {}) + default_punctuation = (universe.contents["mudpy.linguistic"].get( + "default_punctuation", ".")) + else: + actions = {} + default_punctuation = "." action = "" # reverse sort punctuation options so the longest match wins @@ -2026,9 +2051,10 @@ def command_say(actor, parameters): message = message[0].lower() + message[1:] # iterate over all words in message, replacing typos - typos = universe.contents["mudpy.linguistic"].get( - "typos" - ) + if "mudpy.linguistic" in universe.contents: + typos = universe.contents["mudpy.linguistic"].get("typos", {}) + else: + typos = {} words = message.split() for index in range(len(words)): word = words[index] @@ -2312,7 +2338,8 @@ def daemonize(universe): """Fork and disassociate from everything.""" # only if this is what we're configured to do - if universe.contents["mudpy.process"].get("daemon"): + if "mudpy.process" in universe.contents and universe.contents[ + "mudpy.process"].get("daemon"): # log before we start forking around, so the terminal gets the message log("Disassociating from the controlling terminal.") @@ -2349,7 +2376,10 @@ def create_pidfile(universe): """Write a file containing the current process ID.""" pid = str(os.getpid()) log("Process ID: " + pid) - file_name = universe.contents["mudpy.process"].get("pidfile") + if "mudpy.process" in universe.contents: + file_name = universe.contents["mudpy.process"].get("pidfile", "") + else: + file_name = "" if file_name: if not os.path.isabs(file_name): file_name = os.path.join(universe.startdir, file_name) @@ -2361,7 +2391,10 @@ def create_pidfile(universe): def remove_pidfile(universe): """Remove the file containing the current process ID.""" - file_name = universe.contents["mudpy.process"].get("pidfile") + if "mudpy.process" in universe.contents: + file_name = universe.contents["mudpy.process"].get("pidfile", "") + else: + file_name = "" if file_name: if not os.path.isabs(file_name): file_name = os.path.join(universe.startdir, file_name)