Imported from archive.
[mudpy.git] / mudpy
diff --git a/mudpy b/mudpy
index 5130834..8e115bd 100755 (executable)
--- a/mudpy
+++ b/mudpy
@@ -1,36 +1,55 @@
 #!/usr/bin/python
-"""Skeletal executable for the MUFF Engine"""
+"""Skeletal executable for the mudpy engine."""
 
-# Copyright (c) 2005 mudpy, Jeremy Stanley <fungi@yuggoth.org>, all rights reserved.
-# Licensed per terms in the LICENSE file distributed with this software.
+# Copyright (c) 2004-2008 Jeremy Stanley <fungi@yuggoth.org>. Permission
+# to use, copy, modify, and distribute this software is granted under
+# terms provided in the LICENSE file distributed with this software.
 
-# muff uses the ini-style configs supported by the ConfigParser module
-import ConfigParser
+# core objects for the mudpy engine
+import mudpy
 
-# need the sys module to alter the import path appropriately
-import sys
+# a consistent list so we can reimport these on reload
+importlist = [
+       "argv",
+       "create_pidfile",
+       "daemonize",
+       "log",
+       "on_pulse",
+       "reload_data",
+       "remove_pidfile",
+       "universe"
+       ]
+for item in importlist: exec("from mudpy import " + item)
 
-def get_main_loop():
-       """Find and return the main loop function"""
+# log an initial message
+log("Started mudpy with command line: " + " ".join(argv))
 
-       # figure out where to find our main configuration file
-       config_data = ConfigParser.SafeConfigParser()
-       config_dirs = [".", "./etc", "/usr/local/muff", "/usr/local/muff/etc", "/etc/muff", "/etc" ]
-       config_name = "mudpy.conf"
-       config_files = []
-       for each_dir in config_dirs:
-               config_files.append(each_dir + "/" + config_name)
+# fork and disassociate
+daemonize()
 
-       # load the config file, get the module path and add it to sys.path
-       config_data.read(config_files)
-       module_path = config_data.get("files", "modules")
-       sys.path.append(module_path)
+# make the pidfile
+create_pidfile(universe)
 
-       # import the main loop function
-       from muff.muffmain import main
-       return main
+# loop indefinitely while the world is not flagged for termination or
+# there are connected users
+while not universe.terminate_flag or universe.userlist:
 
-# load the main loop and run it
-main = get_main_loop()
-main()
+       # the world was flagged for a reload of all code/data
+       if universe.reload_flag:
+
+               # reload the mudpy module
+               reload(mudpy)
+               for item in importlist: exec("from mudpy import " + item)
+
+       # do what needs to be done on each pulse
+       on_pulse()
+
+# the loop has terminated, so save persistent data
+universe.save()
+
+# log a final message
+log("Shutting down now.")
+
+# get rid of the pidfile
+remove_pidfile(universe)