diff --git a/cmdhandler.py b/cmdhandler.py index 1cfb3e641e..5238e35da0 100755 --- a/cmdhandler.py +++ b/cmdhandler.py @@ -159,11 +159,16 @@ def handle(cdat): pobject = session.get_pobject() exit_matches = match_exits(pobject, ' '.join(parsed_input['splitted'])) if exit_matches: - exit = exit_matches[0] - if exit.get_home(): + targ_exit = exit_matches[0] + if targ_exit.get_home(): cdat['uinput'] = parsed_input - pobject.move_to(exit.get_home()) - session.execute_cmd("look") + + # SCRIPT: See if the player can traverse the exit + if not targ_exit.get_scriptlink().default_lock(pobject): + session.msg("You can't traverse that exit.") + else: + pobject.move_to(targ_exit.get_home()) + session.execute_cmd("look") else: session.msg("That exit leads to nowhere.") return diff --git a/scripthandler.py b/scripthandler.py index 4e83fd5c22..e6b80b42ce 100644 --- a/scripthandler.py +++ b/scripthandler.py @@ -1,6 +1,7 @@ import os from traceback import format_exc +import settings import functions_general """ This module is responsible for managing scripts and their connection to the @@ -31,9 +32,6 @@ def scriptlink(source_obj, scriptname): if retval: return retval.class_factory(source_obj) - # Store the original working directory so we can revert. - orig_path = os.getcwd() - # Split the script name up by periods to give us the directory we need # to change to. I really wish we didn't have to do this, but there's some # strange issue with __import__ and more than two directories worth of @@ -45,22 +43,22 @@ def scriptlink(source_obj, scriptname): try: # Change the working directory to the location of the script and import. - os.chdir('scripts/%s/' % (newpath_str)) + os.chdir('%s/%s/' % (settings.SCRIPT_ROOT, newpath_str)) functions_general.log_infomsg("SCRIPT: Caching and importing %s." % (modname)) modreference = __import__(modname) # Store the module reference for later fast retrieval. cached_scripts[scriptname] = modreference except ImportError: functions_general.log_infomsg('Error importing %s: %s' % (modname, format_exc())) - os.chdir(orig_path) + os.chdir(settings.BASE_PATH) return except OSError: functions_general.log_infomsg('Invalid module path: %s' % (format_exc())) - os.chdir(orig_path) + os.chdir(settings.BASE_PATH) return # Change back to the original working directory. - os.chdir(orig_path) + os.chdir(settings.BASE_PATH) # The new script module has been cached, return the reference. return modreference.class_factory(source_obj) \ No newline at end of file diff --git a/scripts/basicobject.py b/scripts/basicobject.py index 7cb03ad23f..f3fcaf8119 100644 --- a/scripts/basicobject.py +++ b/scripts/basicobject.py @@ -41,6 +41,39 @@ class BasicObject: # Un-comment the line below for an example #print "SCRIPT TEST: %s got %s." % (actor, self.source_obj) pass + + def default_lock(self, actor): + """ + This method returns a True or False boolean value to determine whether + the actor passes the lock. This is generally used for picking up + objects or traversing exits. + + actor: (Object) Reference to the person attempting an action + """ + # Assume everyone passes the default lock by default. + return True + + def use_lock(self, actor): + """ + This method returns a True or False boolean value to determine whether + the actor passes the lock. This is generally used for seeing whether + a player can use an object or any of its commands. + + actor: (Object) Reference to the person attempting an action + """ + # Assume everyone passes the use lock by default. + return True + + def enter_lock(self, actor): + """ + This method returns a True or False boolean value to determine whether + the actor passes the lock. This is generally used for seeing whether + a player can enter another object. + + actor: (Object) Reference to the person attempting an action + """ + # Assume everyone passes the enter lock by default. + return True def class_factory(source_obj): """ diff --git a/settings.py.dist b/settings.py.dist index 1a97997052..a2bdbce4d3 100755 --- a/settings.py.dist +++ b/settings.py.dist @@ -14,7 +14,7 @@ ADMINS = ( MANAGERS = ADMINS -# The path that contains this settings.py file. +# The path that contains this settings.py file (no trailing slash). BASE_PATH = '/home/evennia/evennia' # 'postgresql', 'mysql', 'mysql_old', 'sqlite3' or 'ado_mssql'. @@ -52,10 +52,14 @@ USE_I18N = False # lighttpd). SERVE_MEDIA = False -# Absolute path to the directory that holds media. -# Example: "/home/media/media.lawrence.com/" +# Absolute path to the directory that holds media (no trailing slash). +# Example: "/home/media/media.lawrence.com" MEDIA_ROOT = '%s/media' % (BASE_PATH) +# Absolute path to the directory that has the script tree in it. (no trailing slash) +# Example: "/home/evennia/scripts" +SCRIPT_ROOT = '%s/scripts' % (BASE_PATH) + # URL that handles the media served from MEDIA_ROOT. # Example: "http://media.lawrence.com" MEDIA_URL = '/media/'