X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=lib%2Fmuff%2Fmuffmain.py;h=89725bc27f668fd534de225f141d487c4a429e9b;hp=56a9e57360d9a3262b30af626f80160b88502123;hb=1ff00115321d800bec7313a3fdfc97a8b0b006fa;hpb=994d6e52ce3d5c719991e8f798642cdb8a24b7d1 diff --git a/lib/muff/muffmain.py b/lib/muff/muffmain.py index 56a9e57..89725bc 100644 --- a/lib/muff/muffmain.py +++ b/lib/muff/muffmain.py @@ -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,78 +31,17 @@ 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 - muffmisc.log(str(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() - - # disconnect users with the appropriate state - if each_user.state == "disconnecting": - - # save to cold storage - each_user.save() - - # close the connection - each_user.connection.close() - - # remove from the list - each_user.remove() - - else: - - # 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 - each_user.partial_input += input_data - - # the held input ends in a newline - if each_user.partial_input[-1] == "\n": - - # filter out non-printables - each_user.partial_input = filter(lambda x: x>=' ' and x<='~', each_user.partial_input) - - # strip off extra whitespace - each_user.partial_input = string.strip(each_user.partial_input) - - # put on the end of the queue - each_user.input_queue.append(each_user.partial_input) - - # reset the held partial input - each_user.partial_input = "" - - # pass first item in the input - # queue to the main handler - muffcmds.handle_user_input(each_user, each_user.input_queue[0]) - - # then remove it 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 variables + muffvars.save() # log a final message muffmisc.log("Shutting down now.")