X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=lib%2Fmudpy%2Fmisc.py;h=6c720d53f7af78a2d0235f20358046d0c04f762d;hp=b3f2e25d2454c44fcd3ce46905447dc6e2c00769;hb=4708e5ad2215bce4806578c9417a09ceccef0292;hpb=381d70d0d1d4b80e89acc46435031ed9c9547374 diff --git a/lib/mudpy/misc.py b/lib/mudpy/misc.py index b3f2e25..6c720d5 100644 --- a/lib/mudpy/misc.py +++ b/lib/mudpy/misc.py @@ -252,48 +252,17 @@ class Element: def move_direction(self, direction): """Relocate the element in a specified direction.""" - self.echo_to_location( - self.get( - "name" - ) + " exits " + self.universe.categories[ - "internal" - ][ - "directions" - ].get( - direction - )[ - "exit" - ] + "." - ) - self.send( - "You exit " + self.universe.categories[ - "internal" - ][ - "directions" - ].get( - direction - )[ - "exit" - ] + ".", - add_prompt=False - ) + motion = self.universe.contents["mudpy.movement.%s" % direction] + enter_term = motion.get("enter_term") + exit_term = motion.get("exit_term") + self.echo_to_location("%s exits %s." % (self.get("name"), exit_term)) + self.send("You exit %s." % exit_term, add_prompt=False) self.go_to( self.universe.contents[ self.get("location")].link_neighbor(direction) ) - self.echo_to_location( - self.get( - "name" - ) + " arrives from " + self.universe.categories[ - "internal" - ][ - "directions" - ].get( - direction - )[ - "enter" - ] + "." - ) + self.echo_to_location("%s arrives from %s." % ( + self.get("name"), enter_term)) def look_at(self, key): """Show an element to another element.""" @@ -331,14 +300,9 @@ class Element: if re.match("""^area:-?\d+,-?\d+,-?\d+$""", self.key): coordinates = [(int(x)) for x in self.key.split(":")[1].split(",")] - directions = self.universe.categories["internal"]["directions"] - offsets = dict( - [ - ( - x, directions.get(x)["vector"] - ) for x in directions.facets() - ] - ) + 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]) @@ -379,6 +343,7 @@ class Universe: self.categories = {} self.contents = {} self.default_origins = {} + self.directions = set() self.loglines = [] self.private_files = [] self.reload_flag = False @@ -477,8 +442,8 @@ class Universe: """Create and open the listening socket.""" # need to know the local address and port number for the listener - host = self.categories["internal"]["network"].get("host") - port = self.categories["internal"]["network"].get("port") + host = self.contents["mudpy.network"].get("host") + port = self.contents["mudpy.network"].get("port") # if no host was specified, bind to all local addresses (preferring # ipv6) @@ -685,13 +650,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.categories[ - "internal" - ][ - "limits" - ].get( - "default_admins" - ): + if self.account.subkey in universe.contents["mudpy.limit"].get( + "admins"): self.account.set("administrator", "True") def show_menu(self): @@ -1013,11 +973,9 @@ def log(message, level=0): """Log a message.""" # a couple references we need - file_name = universe.categories["internal"]["logging"].get("file") - max_log_lines = universe.categories["internal"]["logging"].get( - "max_log_lines" - ) - syslog_name = universe.categories["internal"]["logging"].get("syslog") + 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") timestamp = time.asctime()[4:19] # turn the message into a list of nonempty lines @@ -1034,7 +992,7 @@ def log(message, level=0): file_descriptor.close() # send the timestamp and line to standard output - if universe.categories["internal"]["logging"].get("stdout"): + if universe.contents["mudpy.log"].get("stdout"): for line in lines: print(timestamp + " " + line) @@ -1760,13 +1718,8 @@ 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.categories[ - "internal" - ][ - "limits" - ].get( - "password_tries" - ) - 1: + elif user.password_tries < universe.contents["mudpy.limit"].get( + "password_tries") - 1: user.password_tries += 1 user.error = "incorrect" @@ -1799,13 +1752,8 @@ 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.categories[ - "internal" - ][ - "limits" - ].get( - "password_tries" - ) - 1: + elif user.password_tries < universe.contents["mudpy.limit"].get( + "password_tries") - 1: user.password_tries += 1 user.error = "weak" @@ -1834,13 +1782,8 @@ 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.categories[ - "internal" - ][ - "limits" - ].get( - "password_tries" - ) - 1: + elif user.password_tries < universe.contents["mudpy.limit"].get( + "password_tries") - 1: user.password_tries += 1 user.error = "differs" user.state = "entering_new_password" @@ -2183,8 +2126,8 @@ def command_show(actor, parameters): elif arguments[0] == "element": if len(arguments) != 2: message = "You must specify one element." - elif arguments[1] in universe.contents: - element = universe.contents[arguments[1]] + elif arguments[1].strip(".") in universe.contents: + element = universe.contents[arguments[1].strip(".")] message = ("These are the properties of the \"" + arguments[1] + "\" element (in \"" + element.origin.filename + "\"):$(eol)") @@ -2369,7 +2312,7 @@ def daemonize(universe): """Fork and disassociate from everything.""" # only if this is what we're configured to do - if universe.contents["internal:process"].get("daemon"): + if universe.contents["mudpy.process"].get("daemon"): # log before we start forking around, so the terminal gets the message log("Disassociating from the controlling terminal.") @@ -2406,7 +2349,7 @@ def create_pidfile(universe): """Write a file containing the current process ID.""" pid = str(os.getpid()) log("Process ID: " + pid) - file_name = universe.contents["internal:process"].get("pidfile") + file_name = universe.contents["mudpy.process"].get("pidfile") if file_name: if not os.path.isabs(file_name): file_name = os.path.join(universe.startdir, file_name) @@ -2418,7 +2361,7 @@ def create_pidfile(universe): def remove_pidfile(universe): """Remove the file containing the current process ID.""" - file_name = universe.contents["internal:process"].get("pidfile") + file_name = universe.contents["mudpy.process"].get("pidfile") if file_name: if not os.path.isabs(file_name): file_name = os.path.join(universe.startdir, file_name)