Exemple #1
0
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()
Exemple #2
0
 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
Exemple #3
0
 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
Exemple #4
0
 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")
Exemple #5
0
 def info(self, msg):
     print("INFO>", msg)
     sio.emit("INFO", msg, room=self.room)
Exemple #6
0
 def error(self, msg):
     print("ERROR>", msg)
     sio.emit("ERROR", msg, room=self.room)
Exemple #7
0
 def dispatchPublicState(self, event):
     for player in self.players:
         playerState = self.getPublicState(player["sid"])
         sio.emit(event, json.dumps(playerState), room=player["sid"])
Exemple #8
0
 def getCards(self):
     playerState = self.getPublicState(request.sid)
     sio.emit("getState", json.dumps(playerState), room=request.sid)
Exemple #9
0
 def broadcastLobbyChange(self):
     sio.emit("getLobbies", json.dumps(self.getLobbies()), room="watchingLobbies")