fix(disconnect): Await, also remove metadata

parent cf9cbaf9
...@@ -36,7 +36,7 @@ async def hello_world(): ...@@ -36,7 +36,7 @@ async def hello_world():
@router.get("/reset") @router.get("/reset")
async def reset( async def reset(
): ):
return lobby.reset() return await lobby.reset()
app.include_router(router) app.include_router(router)
......
...@@ -58,6 +58,7 @@ class LobbyManager(ClientManager): ...@@ -58,6 +58,7 @@ class LobbyManager(ClientManager):
for p in self.players: for p in self.players:
await self.send(p, MessageToPlayer.Disconnected, extras={"justLeft": name}) await self.send(p, MessageToPlayer.Disconnected, extras={"justLeft": name})
self.metadata.pop(name)
return return
print(f"No player for sid {sid}...", file=stderr) print(f"No player for sid {sid}...", file=stderr)
...@@ -96,15 +97,15 @@ class LobbyManager(ClientManager): ...@@ -96,15 +97,15 @@ class LobbyManager(ClientManager):
print(f"Game started : {' vs '.join([p.name for p in players])}") print(f"Game started : {' vs '.join([p.name for p in players])}")
await game.new_game() await game.new_game()
def reset(self): async def reset(self):
players = len(self.players) players = len(self.players)
games = len(self.games) games = len(self.games)
msg = f"Resetting! sorry for the {players} players / {games} games..." msg = f"Resetting! sorry for the {players} players / {games} games..."
print(msg) print(msg)
for p in self.players: for p in self.players:
m = self.metadata[p.name] m = self.metadata[p.name]
self.send(p, MessageToPlayer.Reset) await self.send(p, MessageToPlayer.Reset)
self.sio.disconnect(m.sid) await self.sio.disconnect(m.sid)
self.lobby.clear() self.lobby.clear()
self.players.clear() self.players.clear()
self.metadata.clear() self.metadata.clear()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment