Imported from archive.
[mudpy.git] / lib / muff / muffmain.py
index 9e6c0b4..4ddab12 100644 (file)
@@ -17,14 +17,9 @@ for module in muff.__all__:
 def main():
        """The main loop."""
 
-       # loop indefinitely while the world is not flagged for termination
-       while not muffvars.terminate_world:
-
-               # open the listening socket if it hasn't been already
-               if not muffvars.newsocket: muffsock.initialize_server_socket()
-
-               # pause for a configurable amount of time (decimal seconds)
-               time.sleep(muffconf.config_data.getfloat("general", "increment"))
+       # loop indefinitely while the world is not flagged for termination or
+       # there are connected users
+       while not muffvars.terminate_world or muffvars.userlist:
 
                # the world was flagged for a reload of all code/data
                if muffvars.reload_modules:
@@ -36,67 +31,19 @@ def main():
                        for module in muff.__all__:
                                exec("reload(muff." + module + ")")
 
+                       # move data into new persistent objects
+                       muffmisc.reload_data()
+
                        # reset the reload flag
                        muffvars.reload_modules = False
 
-               # assign a user if a new connection is waiting
-               user = muffsock.check_for_connection(muffvars.newsocket)
-
-               # there was a new connection
-               if user:
-
-                       # welcome to the user list
-                       muffvars.userlist.append(user)
-
-                       # make a note of it
-                       # TODO: need to log this crap
-                       print len(muffvars.userlist),"connection(s)"
-
-               # iterate over the connected users
-               for each_user in muffvars.userlist:
-
-                       # show the user a menu as needed
-                       each_user.show_menu()
-
-                       # check for some input
-                       # TODO: make a separate function for this
-                       try:
-                               input_data = each_user.connection.recv(1024)
-                       except:
-                               input_data = ""
-                       # we got something
-                       if input_data:
-
-                               # tack this on to any previous partial input
-                               each_user.partial_input += input_data
-
-                               # the held input ends in a newline
-                               if each_user.partial_input[-1] == "\n":
-
-                                       # filter out non-printable characters
-                                       each_user.partial_input = filter(lambda x: x>=' ' and x<='~', each_user.partial_input)
-
-                                       # strip off leading/trailing whitespace
-                                       each_user.partial_input = string.strip(each_user.partial_input)
-
-                                       # move it to the end of the input queue
-                                       each_user.input_queue.append(each_user.partial_input)
-
-                                       # reset the held partial input
-                                       each_user.partial_input = ""
-
-                                       # pass the first item in the input
-                                       # queue to the main handler
-                                       muffcmds.handle_user_input(each_user, each_user.input_queue[0])
-
-                                       # remove the first item from the queue
-                                       each_user.input_queue.remove(each_user.input_queue[0])
+               # do what needs to be done on each pulse
+               muffmisc.on_pulse()
 
-       # the loop has terminated, so tear down all sockets
-       # TODO: move the save from command_halt() to here
-       muffsock.destroy_all_sockets()
+       # the loop has terminated, so save persistent data
+       muffvars.save()
+       muffuniv.universe.save()
 
        # log a final message
-       # TODO: need a logging function for this kind of stuff
-       print "Shutting down now."
+       muffmisc.log("Shutting down now.")