- # 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])