Exemplo n.º 1
0
    def increaseCommonPlays(self, interaction, userId, token, friendId):
        interaction.execute("select token from accounts where id = ?", (userId, ))
        realToken = interaction.fetchone()
        if realToken is None or not Utility.checkToken(token, realToken[0]):
            return False
        interaction.execute("update friends set commonPlays = commonPlays + 1 where userId1=? and userId2=?",(userId, friendId))

        return True
Exemplo n.º 2
0
    def deleteInvite(self, interaction, id, token, inviteId):
        interaction.execute("select token from accounts where id = ?", (id, ))
        realToken = interaction.fetchone()
        if realToken is None or not Utility.checkToken(token, realToken[0]):
            return False

        interaction.execute("delete from invites where id=? and inviteeId=?",(inviteId, id))

        return True
Exemplo n.º 3
0
    def deleteFriend(self, interaction, id, token, friend):
        interaction.execute("select token from accounts where id = ?", (id, ))
        realToken = interaction.fetchone()
        if realToken is None or not Utility.checkToken(token, realToken[0]):
            return False

        interaction.execute("delete from friends where (userId1=? and userId2=?) or (userId1=? and userId2=?)",(id, friend, friend, id))

        return True
Exemplo n.º 4
0
    def addInvite(self, interaction, id, token, friends, gameId):
        interaction.execute("select token from accounts where id = ?", (id, ))
        realToken = interaction.fetchone()
        if realToken is None or not Utility.checkToken(token, realToken[0]):
            return False

        for friend in friends:
            interaction.execute("insert or ignore into invites (inviterId, inviteeId, gameId) values (?,?,?)",(id, friend, gameId))

        return True
Exemplo n.º 5
0
    def acceptFriend(self, interaction, id, token, friend):
        interaction.execute("select token from accounts where id = ?", (id, ))
        realToken = interaction.fetchone()
        if realToken is None or not Utility.checkToken(token, realToken[0]):
            return False

        interaction.execute("update friends set pending = 0 where userId1=? and userId2=?",(friend, id))
        # Only the other player (userId2) can accept the pending friend request

        return True
Exemplo n.º 6
0
    def addFriends(self, interaction, id, token, friends, pending):
        interaction.execute("select token from accounts where id = ?", (id, ))
        realToken = interaction.fetchone()
        if realToken is None or not Utility.checkToken(token, realToken[0]):
            return False

        for friend in friends:
            interaction.execute("insert or ignore into friends (userId1, userId2, pending) values (?,?,?)",(id, friend, pending))

        return True
Exemplo n.º 7
0
    def showInvites(self, interaction, id, token):
        interaction.execute("select token from accounts where id = ?", (id, ))
        realToken = interaction.fetchone()
        if realToken is None or not Utility.checkToken(token, realToken[0]):
            return False

        interaction.execute("select id, inviterId, gameId from invites where inviteeId=?",(id,))
        invites = interaction.fetchall()
        result = []
        for invite in invites:
            result.append(json.dumps({"inviteId" : invite[0], "inviterId" : invite[1], "gameId" : invite[2]}))
        return result
Exemplo n.º 8
0
    def updateAccount(self, interaction, id, token, newName, newPictureUrl):
        interaction.execute("select token from accounts where id = ?", (id, ))
        result = interaction.fetchone()
        if result is None or not Utility.checkToken(token, result[0]):
            return False

        if newName is not None:
            interaction.execute("update accounts set name=? where id=?",(newName,id))
        if newPictureUrl is not None:
            interaction.execute("update accounts set pictureUrl=? where id=?",(newPictureUrl,id))

        return True
Exemplo n.º 9
0
    def leaveGame(self, interaction, playerId, token):
        interaction.execute("select token from accounts where id = ?", (playerId, ))
        realToken = interaction.fetchone()
        if realToken is None or not Utility.checkToken(token, realToken[0]):
            return False

        interaction.execute(
            """
            update or ignore accounts set currentGame = 0 where id = ?
            """,
            (playerId, )
        )
        return True
Exemplo n.º 10
0
    def insertGame(self, interaction, name, owner, maxPlayers, token, playerToken,
        wallbreaker, timeLimit, maxDist):

        interaction.execute("select token from accounts where id = ?", (owner, ))
        realToken = interaction.fetchone()
        if realToken is None or not Utility.checkToken(playerToken, realToken[0]):
            return None

        interaction.execute(
            """
            insert or ignore into games (
                name, owner, maxPlayers, ping, token, wallbreaker, timeLimit, maxDist
            )
            values (?, ?, ?, 0, ?, ?, ?, ?)
            """,
            (name, owner, maxPlayers, Utility.hashToken(token), wallbreaker, timeLimit, maxDist)
        )
        interaction.execute("select max(id) from games")
        return interaction.fetchone()[0]
Exemplo n.º 11
0
    def endGame(self, interaction, gameId, token, winnerId):
        interaction.execute("select token from games where id = ?", (gameId, ))
        realToken = interaction.fetchone()
        if realToken is None or not Utility.checkToken(token, realToken[0]):
            return False

        # Increase the wins of the winner
        interaction.execute(
            "update accounts set wins = wins + 1, currentGame = 0 where id = ?",
            (winnerId, )
        )
        # Increase the losses of all other players in the game
        interaction.execute(
            """
            update accounts set losses = losses + 1, currentGame = 0 where id = 
            (select id from accounts where currentGame = ?) and id != ? 
            """,
            (gameId, winnerId)
        )

        # TODO: do we want to permanently remove the game?
        # interaction.execute("delete from games where id = ?", (gameId,))
        return True