Beispiel #1
0
    def processHost(self, qmsg):
        """
        original_message = [
            "HOST", "taboo",
            {"numTeams": <int>,         # 1..4
             "turnDurationSec": <int>,  # 30..180
             "wordSets": ["name1", "name2", ...]}]

        qmsg.jmsg = original_message[2:]
        """
        try:
            hostParameters = HostParameters.fromJmsg(qmsg.jmsg)
        except InvalidDataException as exc:
            self.txQueue.put_nowait(
                ClientTxMsg([MTYPE_HOST_BAD] + exc.toJmsg(),
                            {qmsg.initiatorWs},
                            initiatorWs=qmsg.initiatorWs))
            return True

        self.gameIdx += 1

        newRoom = TabooRoom("taboo:{}".format(self.gameIdx),
                            "Taboo Room #{}".format(self.gameIdx),
                            hostParameters)
        self.rooms[self.gameIdx] = newRoom
        self.txQueue.put_nowait(
            InternalRegisterGi(newRoom, initiatorWs=qmsg.initiatorWs))

        return True
Beispiel #2
0
    def testEnoughTurnsPlayed(self):
        txq = asyncio.Queue()
        wordset = SupportedWordSets["test"]

        allConns = Connections(txq)
        team1 = mockPlyrTeam(txq, allConns, 1, {"sb": [101]}, {"sb": 2})
        team2 = mockPlyrTeam(txq, allConns, 2, {"jg": [102]}, {"jg": 2})

        teams = {1: team1, 2: team2}
        hostParameters = HostParameters(numTeams=2,
                                        turnDurationSec=30,
                                        wordSets=["test"],
                                        numTurns=2)

        for team in teams.values():
            for ws in team.conns._wss:
                allConns.addConn(ws)

        turnMgr = TurnManager("taboo:1", txq, wordset, teams, hostParameters, allConns, None)

        self.assertFalse(turnMgr.startNewTurn())
        self.assertGiTxQueueMsgs(txq, [
            ClientTxMsg(['PLAYER-STATUS', 'jg', {'numConns': 1, 'ready': False, 'turnsPlayed': 0}],
                        {101}),
            ClientTxMsg(['PLAYER-STATUS', 'sb', {'numConns': 1, 'ready': False, 'turnsPlayed': 0}],
                        {101}),
            ClientTxMsg(['PLAYER-STATUS', 'jg', {'numConns': 1, 'ready': False, 'turnsPlayed': 0}],
                        {102}),
            ClientTxMsg(['PLAYER-STATUS', 'sb', {'numConns': 1, 'ready': False, 'turnsPlayed': 0}],
                        {102}),
            ClientTxMsg(["SCORE", {1: 0, 2: 0}],
                        {101, 102}),
        ], anyOrder=True)
Beispiel #3
0
    def setUpTabooRoom(self):
        rxq = asyncio.Queue()
        txq = asyncio.Queue()

        hostParameters = HostParameters(numTeams=2,
                                        turnDurationSec=30,
                                        wordSets=["test"],
                                        numTurns=1)
        room = TabooRoom.TabooRoom("taboo:1", "Taboo Room #1", hostParameters)
        room.setRxTxQueues(rxq, txq)

        return Map(rxq=rxq,
                   txq=txq,
                   hostParameters=hostParameters,
                   room=room)
Beispiel #4
0
    def testBasic(self):
        txq = asyncio.Queue()
        wordset = SupportedWordSets["test"]
        with stub(wordset, "nextWord", self.mockNextWord):
            allConns = Connections(txq)
            team1 = mockPlyrTeam(txq, allConns, 1, {"sb1": [101], "sb2": [102]}, {})
            team2 = mockPlyrTeam(txq, allConns, 2, {"jg1": [201], "jg2": [202]}, {})

            teams = {1: team1, 2: team2}
            hostParameters = HostParameters(numTeams=2,
                                            turnDurationSec=30,
                                            wordSets=["test"],
                                            numTurns=2)

            for team in teams.values():
                for ws in team.conns._wss:
                    allConns.addConn(ws)
            self.drainGiTxQueue(txq)

            turnMgr = TurnManager("taboo:1", txq, wordset, teams, hostParameters, allConns, None)
            def mockFindNextPlayer():
                return team2.members["jg1"]
            stub1 = stub(turnMgr, "_findNextPlayer", mockFindNextPlayer)
            stub1.__enter__() # pylint: disable=no-member

            self.assertGiTxQueueMsgs(txq, [
                ClientTxMsg(["SCORE", {1: 0, 2: 0}],
                            {101, 102, 201, 202}),
            ], anyOrder=True)

            self.assertTrue(turnMgr.startNewTurn())
            self.assertGiTxQueueMsgs(txq, [
                ClientTxMsg(["WAIT-FOR-KICKOFF", 1, "jg1"], {101, 102, 201, 202}, None),
            ])

            self.assertTrue(turnMgr.startNextWord())
            secretMsg = ['TURN', 1, 1, {'team': 2, 'player': 'jg1', 'state': 'IN_PLAY',
                                        'utcTimeout': None,  # We didn't send KICKOFF explicitly
                                        'secret': 'c', 'disallowed': ['c1', 'c2']}]
            publicMsg = ['TURN', 1, 1, {'team': 2, 'player': 'jg1', 'state': 'IN_PLAY',
                                        'utcTimeout': None}]
            self.assertGiTxQueueMsgs(txq, [
                ClientTxMsg(publicMsg, {101, 102, 201, 202}),
                ClientTxMsg(secretMsg, {101, 102}),
                ClientTxMsg(secretMsg, {201}),
            ], anyOrder=True)
Beispiel #5
0
    def testNoClients(self):
        txq = asyncio.Queue()
        wordset = SupportedWordSets["test"]
        allConns = Connections(txq)

        team1 = mockPlyrTeam(txq, allConns, 1, {"sb": []})
        team2 = mockPlyrTeam(txq, allConns, 2, {"jg": []})

        teams = {1: team1, 2: team2}
        hostParameters = HostParameters(numTeams=2,
                                        turnDurationSec=30,
                                        wordSets=["test"],
                                        numTurns=1)

        for team in teams.values():
            for ws in team.conns._wss:
                allConns.addConn(ws)

        turnMgr = TurnManager("taboo:1", txq, wordset, teams, hostParameters, allConns, None)

        self.assertFalse(turnMgr.startNewTurn())
        self.assertGiTxQueueMsgs(txq, [])