def sendChat(self, msg): sender = next(p for p in self.players if p["sid"] == request.sid)["name"] print(sender, "> ", msg) sio.emit("chat", json.dumps({"sender": sender, "message": msg}), room=self.room) if msg == "!next": self.nextGame()
def dispatchLobbyState(self): msg = [[u["name"], u["ready"], False] for u in self.lobby] for i in range(0, len(self.lobby)): try: msg[i][2] = True sio.emit("getUsers", msg, room=self.lobby[i]["sid"]) msg[i][2] = False except IndexError: pass
def dispatchGameLobbyState(self): msg = [[u["name"], u["ready"], False] for u in self.players] for i in range(0, len(self.players)): msg[i][2] = True try: sio.emit("getUsers", msg, room=self.players[i]["sid"]) except IndexError: print("Handled disconnect gracefully") msg[i][2] = False
def handleAllReady(self): if len(self.lobby) in [3, 4]: print("ALL READY") sio.emit("allReady", room=self.room) # Start game self.game.initGame(self.lobby) else: if len(self.lobby) < 3: self.game.info("waiting for " + str(3 - len(self.lobby)) + " more players to join") else: self.game.info("waiting for " + str(len(self.lobby) - 4) + " players to leave")
def info(self, msg): print("INFO>", msg) sio.emit("INFO", msg, room=self.room)
def error(self, msg): print("ERROR>", msg) sio.emit("ERROR", msg, room=self.room)
def dispatchPublicState(self, event): for player in self.players: playerState = self.getPublicState(player["sid"]) sio.emit(event, json.dumps(playerState), room=player["sid"])
def getCards(self): playerState = self.getPublicState(request.sid) sio.emit("getState", json.dumps(playerState), room=request.sid)
def broadcastLobbyChange(self): sio.emit("getLobbies", json.dumps(self.getLobbies()), room="watchingLobbies")