Multiuser StartUp Polish
There was a sync problem at the startup of the server It seems to be gone now that I fixed it. Please test.
This commit is contained in:
parent
b21473b35e
commit
dabea36fc4
|
@ -162,6 +162,8 @@ def main():
|
||||||
# to the user
|
# to the user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# And now let's call a thread for this user
|
# And now let's call a thread for this user
|
||||||
threads[userid] = threading.Thread(target=user, args=(userid, ))
|
threads[userid] = threading.Thread(target=user, args=(userid, ))
|
||||||
threads[userid].setDaemon(True) # So I could close the program
|
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
|
# litteral sense of those 2 words. From now own user will be able
|
||||||
# to request a bunch of stuff. So...
|
# to request a bunch of stuff. So...
|
||||||
|
|
||||||
|
request_all([0,"users"])
|
||||||
|
|
||||||
def get_story(client):
|
def get_story(client):
|
||||||
global story
|
global story
|
||||||
insure.send(client, "story")
|
insure.send(client, "story")
|
||||||
|
@ -250,23 +254,13 @@ def user(userid):
|
||||||
|
|
||||||
insure.send(client, "yours")
|
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:
|
while True:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Recieving users request
|
# Recieving users request
|
||||||
request = insure.recv(client)
|
request = insure.recv(client)
|
||||||
|
|
||||||
|
@ -310,7 +304,15 @@ def user(userid):
|
||||||
|
|
||||||
# Clearing the request.
|
# Clearing the request.
|
||||||
users[userid]["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
|
# If there is nothing we want to tell the user that it's
|
||||||
# their turn to request.
|
# their turn to request.
|
||||||
else:
|
else:
|
||||||
|
@ -335,7 +337,7 @@ def user(userid):
|
||||||
elif request[0] == "at":
|
elif request[0] == "at":
|
||||||
output(userid+" | at | "+request[1]+" | time | "+request[2])
|
output(userid+" | at | "+request[1]+" | time | "+request[2])
|
||||||
request_all([userid, "at", request[1], request[2]])
|
request_all([userid, "at", request[1], request[2]])
|
||||||
|
|
||||||
elif request == "users":
|
elif request == "users":
|
||||||
insure.send(client, users_list())
|
insure.send(client, users_list())
|
||||||
|
|
||||||
|
@ -369,9 +371,11 @@ def user(userid):
|
||||||
|
|
||||||
# The other thread will unpause this thread when the
|
# The other thread will unpause this thread when the
|
||||||
# folder is downloaded.
|
# folder is downloaded.
|
||||||
except:
|
except Exception as e:
|
||||||
# Sometimes there is no user to get it from.
|
# 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
|
# Finishing the request and giving the user it's turn
|
||||||
insure.send(client, "yours")
|
insure.send(client, "yours")
|
||||||
|
@ -389,7 +393,8 @@ def user(userid):
|
||||||
# We want to clear the data of the assets if this happens
|
# We want to clear the data of the assets if this happens
|
||||||
|
|
||||||
globals()["assets"] = {}
|
globals()["assets"] = {}
|
||||||
request_all([0,"assets"])
|
|
||||||
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -411,8 +416,8 @@ def request_all(request):
|
||||||
|
|
||||||
for user in users:
|
for user in users:
|
||||||
if user != request[0]:
|
if user != request[0]:
|
||||||
while users[user]["request"]:
|
#while users[user]["request"]:
|
||||||
time.sleep(0.001)
|
# time.sleep(0.001)
|
||||||
users[user]["request"] = request
|
users[user]["request"] = request
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue