Exemplo n.º 1
0
 def update_db_play_aCard(self, userId, cardId):
     update_rows(
         **{
             "table_name": "gameStatus",
             "columns": {
                 "starter": self.get_nextPlayer(userId),
                 f'player{self.reversePlayerMappings[userId]}': cardId,
             },
             "filters": {
                 "roomId": self.roomId,
             }
         })
     cards = self.cards.get(userId)
     cards.remove(cardId)
     if not cards:
         cards = None
     else:
         cards = [str(card) for card in cards]
         cards = ",".join(cards)
     update_rows(
         **{
             "table_name": "roomStatus",
             "columns": {
                 "cards": cards,
             },
             "filters": {
                 "roomId": self.roomId,
                 "userId": userId,
             }
         })
Exemplo n.º 2
0
    def give_PlayerAPoint(self, userId):
        cursor = select_query(
            **{
                "columns": ["points"],
                "filters": {
                    "roomId": self.roomId,
                    "userId": userId,
                },
                "table_name": "roomStatus",
            })
        point = cursor.fetchone()
        if not point:
            point = 0
        else:
            point = point[0]
            try:
                point = int(point)
            except:
                point = 0
        point += 1

        update_rows(
            **{
                "table_name": "roomStatus",
                "columns": {
                    "points": point,
                },
                "filters": {
                    "userId": userId,
                    "roomId": self.roomId,
                }
            })
Exemplo n.º 3
0
 def add_playersToGame(self, playerChosen):
     #team-mate as 3
     update_rows(
         **{
             "table_name": "roomStatus",
             "columns": {
                 "roomUserId": 3,
             },
             "filters": {
                 "userId": playerChosen,
                 "roomId": self.roomId,
             }
         })
     players = self.players
     players.remove(playerChosen)
     players.remove(self.host)
     for i, userId in enumerate(players):
         update_rows(
             **{
                 "table_name": "roomStatus",
                 "columns": {
                     "roomUserId": 2 * i + 2,
                 },
                 "filters": {
                     "userId": userId,
                     "roomId": self.roomId,
                 }
             })
Exemplo n.º 4
0
 def update_teamScore(self, teamName, updatedScore):
     update_rows(
         **{
             "table_name": "roomInfo",
             "columns": {
                 teamName: updatedScore,
             },
             "filters": {
                 "roomId": self.roomId,
             }
         })
Exemplo n.º 5
0
 def update_gameSelector(self, userId):
     update_rows(
         **{
             "table_name": "gameStatus",
             "columns": {
                 "starter": userId,
             },
             "filters": {
                 "roomId": self.roomId,
             }
         })
Exemplo n.º 6
0
 def update_firstPlayer(self, userId):
     update_rows(
         **{
             "table_name": "roomInfo",
             "columns": {
                 "starter": userId,
             },
             "filters": {
                 "roomId": self.roomId,
             }
         })
Exemplo n.º 7
0
 def set_gameRoundEnded(self):
     update_rows(
         **{
             "table_name": "roomInfo",
             "columns": {
                 "roomState": "E",
             },
             "filters": {
                 "roomId": self.roomId,
             }
         })
Exemplo n.º 8
0
 def reset_PlayerPoint(self, userId):
     update_rows(
         **{
             "table_name": "roomStatus",
             "columns": {
                 "points": 0,
             },
             "filters": {
                 "userId": userId,
                 "roomId": self.roomId,
             }
         })
Exemplo n.º 9
0
 def clear_gameType(self):
     """ clear gameType"""
     update_rows(
         **{
             "table_name": "roomInfo",
             "columns": {
                 "gameType": None,
             },
             "filters": {
                 "roomId": self.roomId,
             }
         })
Exemplo n.º 10
0
 def set_gameType(self, gameType):
     update_rows(
         **{
             "table_name": "roomInfo",
             "columns": {
                 "gameType": gameType,
             },
             "filters": {
                 "roomId": self.roomId,
             }
         })
     self.gameType = gameType
Exemplo n.º 11
0
 def drop_game(self):
     update_rows(
         **{
             "table_name": "roomInfo",
             "columns": {
                 "roomState": "C",
                 "gameType": None,
             },
             "filters": {
                 "roomId": self.roomId,
             }
         })
     self.update_gameSelector(self.get_previousPlayer(self.currentPlayer))
     self.update_firstPlayer(self.get_previousPlayer(self.currentPlayer))
Exemplo n.º 12
0
 def clear_db_play_aCard(self, userId):
     """round is finished and winner is added, and other columns are cleared"""
     update_rows(
         **{
             "table_name": "gameStatus",
             "columns": {
                 "starter": userId,
                 "player1": None,
                 "player2": None,
                 "player3": None,
                 "player4": None,
             },
             "filters": {
                 "roomId": self.roomId,
             }
         })
Exemplo n.º 13
0
 def distribute_cards(self):
     card = Card()
     card.shuffle_allCards()
     cardsForPlayers = card.distribute_cards()
     for i, cards in enumerate(cardsForPlayers):
         cards = [str(card) for card in cards]
         update_rows(
             **{
                 "table_name": "roomStatus",
                 "columns": {
                     "cards": ",".join(cards),
                 },
                 "filters": {
                     "roomUserId": i + 1,
                     "roomId": self.roomId,
                 }
             })
Exemplo n.º 14
0
def send_otp(user_info):
    current_app.logger.info(f'sending OTP to {user_info["emailId"]}')
    otp = generate_otp()
    body = f"""access code: {otp}
    """
    title = "verify account"
    state, message = send_text_email(user_info["emailId"], title, body)
    if state:
        if not update_rows(
                **{
                    "table_name": "tempUsers",
                    "userId": user_info["userId"],
                    "columns": {
                        "otp": otp,
                    },
                    "filters": {
                        "emailId": user_info["emailId"],
                    }
                }):
            raise Exception("failed to store OTP")
    else:
        raise Exception("failed to send OTP through email")