P2: Multiplayer improvements

This commit is contained in:
LoveEevee
2018-11-13 07:36:15 +03:00
parent 1619622257
commit 25d705ffcf
10 changed files with 139 additions and 36 deletions

View File

@@ -145,15 +145,30 @@ async def connection(ws, path):
await ws.send(msgobj("gameend"))
elif action == "waiting" or action == "loading" or action == "loaded":
# Waiting for another user
if type == "leave" and not user["session"]:
if type == "leave":
# Stop waiting
del server_status["waiting"][user["gameid"]]
del user["gameid"]
user["action"] = "ready"
await asyncio.wait([
ws.send(msgobj("left")),
notify_status()
])
if user["session"]:
if "other_user" in user and "ws" in user["other_user"]:
user["action"] = "songsel"
await asyncio.wait([
ws.send(msgobj("left")),
user["other_user"]["ws"].send(msgobj("users", []))
])
else:
user["action"] = "ready"
user["session"] = False
await asyncio.wait([
ws.send(msgobj("gameend")),
ws.send(status_event())
])
else:
del server_status["waiting"][user["gameid"]]
del user["gameid"]
user["action"] = "ready"
await asyncio.wait([
ws.send(msgobj("left")),
notify_status()
])
if action == "loading":
if type == "gamestart":
user["action"] = "loaded"