diff --git a/network/multiuser_server.py b/network/multiuser_server.py index 52badb2..0890584 100644 --- a/network/multiuser_server.py +++ b/network/multiuser_server.py @@ -162,6 +162,8 @@ def main(): # to the user } + + # And now let's call a thread for this user threads[userid] = threading.Thread(target=user, args=(userid, )) threads[userid].setDaemon(True) # So I could close the program @@ -206,6 +208,8 @@ def user(userid): # litteral sense of those 2 words. From now own user will be able # to request a bunch of stuff. So... + request_all([0,"users"]) + def get_story(client): global story insure.send(client, "story") @@ -250,23 +254,13 @@ def user(userid): insure.send(client, "yours") - # Here when the connection is established. I would like to tell all the - # already connected users that the connection is established. It's going - # to be a 2 way process. - # 1. We send a notice to all the threads saying to send the corrisponding - # users the data about the new user. - request_all([0,"users"]) - # 2. We execute this request. Which is not going to happen in this thread - # but in the instances of this thread for all the other users. So the - # code is in this function. while True: try: - # Recieving users request request = insure.recv(client) @@ -310,7 +304,15 @@ def user(userid): # Clearing the request. users[userid]["request"] = [] - + + ########################################################### + # AUTOMATIC REQUESTING # + ########################################################### + + if not assets: + request_all([0,"assets"]) + print("assets requested") + # If there is nothing we want to tell the user that it's # their turn to request. else: @@ -335,7 +337,7 @@ def user(userid): elif request[0] == "at": output(userid+" | at | "+request[1]+" | time | "+request[2]) request_all([userid, "at", request[1], request[2]]) - + elif request == "users": insure.send(client, users_list()) @@ -369,9 +371,11 @@ def user(userid): # The other thread will unpause this thread when the # folder is downloaded. - except: + except Exception as e: # Sometimes there is no user to get it from. - print("USER GET ERROR") + output(userid+" | get | error | "+str(e)) + globals()["assets"] = {} + # Finishing the request and giving the user it's turn insure.send(client, "yours") @@ -389,7 +393,8 @@ def user(userid): # We want to clear the data of the assets if this happens globals()["assets"] = {} - request_all([0,"assets"]) + + return @@ -411,8 +416,8 @@ def request_all(request): for user in users: if user != request[0]: - while users[user]["request"]: - time.sleep(0.001) + #while users[user]["request"]: + # time.sleep(0.001) users[user]["request"] = request