示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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
示例#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]
示例#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