X-Git-Url: https://mudpy.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=lib%2Fmuff%2Fmuffmain.py;h=89725bc27f668fd534de225f141d487c4a429e9b;hb=1ff00115321d800bec7313a3fdfc97a8b0b006fa;hp=0b6707ea7b9606f94a41fcf3952caaec3c6487ef;hpb=d49d19d943672b3cea1b2e43802f4b5eca6c81b5;p=mudpy.git diff --git a/lib/muff/muffmain.py b/lib/muff/muffmain.py index 0b6707e..89725bc 100644 --- a/lib/muff/muffmain.py +++ b/lib/muff/muffmain.py @@ -1,69 +1,48 @@ """Main loop for the MUFF Engine""" -# Copyright (c) 2005 mudpy, Jeremy Stanley -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# - Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# - Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following -# disclaimer in the documentation and/or other materials provided -# with the distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -# POSSIBILITY OF SUCH DAMAGE. +# Copyright (c) 2005 mudpy, Jeremy Stanley , all rights reserved. +# Licensed per terms in the LICENSE file distributed with this software. +# string.strip is used to clean up leading/trailing whitespace in user input import string + +# time.sleep is used in the loop to save cpu and provide crude pulse timing import time +# hack to load all modules in the muff package import muff for module in muff.__all__: exec("import " + module) def main(): - while not muffvars.terminate_world: - if not muffvars.newsocket: - muffsock.initialize_server_socket() - time.sleep(muffconf.config_data.getfloat("general", "increment")) + """The main loop.""" + + # 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: + + # reload the muff package reload(muff) + + # reload all modules listed in the muff package for module in muff.__all__: exec("reload(muff." + module + ")") - muffvars.reload_modules = 0 - user = muffsock.check_for_connection(muffvars.newsocket) - if user: - muffvars.userlist.append(user) - print len(muffvars.userlist),"connection(s)" - for each_user in muffvars.userlist: - each_user.show_menu() - input_data = "" - try: - input_data = each_user.connection.recv(1024) - except: - pass - if input_data: - each_user.partial_input += input_data - if each_user.partial_input and each_user.partial_input[-1] == "\n": - each_user.partial_input = filter(lambda x: x>=' ' and x<='~', each_user.partial_input) - each_user.partial_input = string.strip(each_user.partial_input) - each_user.input_queue.append(each_user.partial_input) - each_user.partial_input = "" - muffcmds.handle_user_input(each_user, each_user.input_queue[0]) - each_user.input_queue.remove(each_user.input_queue[0]) - muffsock.destroy_all_sockets() - print "Shutting down now." + + # move data into new persistent objects + muffmisc.reload_data() + + # reset the reload flag + muffvars.reload_modules = False + + # do what needs to be done on each pulse + muffmisc.on_pulse() + + # the loop has terminated, so save persistent variables + muffvars.save() + + # log a final message + muffmisc.log("Shutting down now.")