X-Git-Url: https://mudpy.org/gitweb?p=mudpy.git;a=blobdiff_plain;f=lib%2Fmuff%2Fmuffmain.py;h=56a9e57360d9a3262b30af626f80160b88502123;hp=9e6c0b41830e3ade26de1b162efb9cebadd95515;hb=994d6e52ce3d5c719991e8f798642cdb8a24b7d1;hpb=0f39af78818acbbee0b99145ff5ff303553027c6 diff --git a/lib/muff/muffmain.py b/lib/muff/muffmain.py index 9e6c0b4..56a9e57 100644 --- a/lib/muff/muffmain.py +++ b/lib/muff/muffmain.py @@ -49,8 +49,7 @@ def main(): muffvars.userlist.append(user) # make a note of it - # TODO: need to log this crap - print len(muffvars.userlist),"connection(s)" + muffmisc.log(str(len(muffvars.userlist)) + " connection(s)") # iterate over the connected users for each_user in muffvars.userlist: @@ -58,45 +57,58 @@ def main(): # 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: + # disconnect users with the appropriate state + if each_user.state == "disconnecting": - # tack this on to any previous partial input - each_user.partial_input += input_data + # save to cold storage + each_user.save() - # the held input ends in a newline - if each_user.partial_input[-1] == "\n": + # close the connection + each_user.connection.close() - # filter out non-printable characters - each_user.partial_input = filter(lambda x: x>=' ' and x<='~', each_user.partial_input) + # remove from the list + each_user.remove() - # strip off leading/trailing whitespace - each_user.partial_input = string.strip(each_user.partial_input) + else: - # move it to the end of the input queue - each_user.input_queue.append(each_user.partial_input) + # 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: - # reset the held partial input - each_user.partial_input = "" + # tack this on to any previous partial + each_user.partial_input += input_data - # pass the first item in the input - # queue to the main handler - muffcmds.handle_user_input(each_user, each_user.input_queue[0]) + # the held input ends in a newline + if each_user.partial_input[-1] == "\n": - # remove the first item from the queue - each_user.input_queue.remove(each_user.input_queue[0]) + # 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]) # the loop has terminated, so tear down all sockets # TODO: move the save from command_halt() to here muffsock.destroy_all_sockets() # log a final message - # TODO: need a logging function for this kind of stuff - print "Shutting down now." + muffmisc.log("Shutting down now.")