Пример #1
0
    def get(self, match_id, team_id):
        query = g.db.query(MatchTeam)
        query = query.filter(MatchTeam.match_id == match_id,
                             MatchTeam.team_id == team_id)
        row = query.first()
        if not row:
            abort(httplib.NOT_FOUND)

        ret = row.as_dict()
        ret["url"] = url_for("matches.team", match_id=match_id, team_id=row.team_id, _external=True)

        query = g.db.query(MatchPlayer)
        query = query.filter(MatchPlayer.match_id == match_id,
                             MatchPlayer.team_id == team_id)
        rows = query.all()
        players = []
        for r in rows:
            player = r.as_dict()
            player["matchplayer_url"] = url_for("matches.player",
                                                match_id=match_id,
                                                player_id=r.player_id,
                                                _external=True)
            player["player_url"] = url_player(r.player_id)
            players.append(player)
        ret["players"] = players
        return ret
Пример #2
0
def make_matchqueueplayer_response(player, matchqueue_entry, server=None):
    player_id = player.player_id
    ret = {
        "player_id":
        player_id,
        "player_url":
        url_player(player_id),
        "player_name":
        player.player_name,
        "match_id":
        matchqueue_entry.match_id,
        "match_url":
        None,
        "ue4_connection_url":
        None,
        "status":
        matchqueue_entry.status,
        "matchqueueplayer_url":
        url_for("matchqueue.player", player_id=player_id, _external=True),
        "create_date":
        matchqueue_entry.create_date,
        "criteria":
        matchqueue_entry.criteria,
    }
    if matchqueue_entry.match_id:
        ret["match_url"] = url_for("matches.entry",
                                   match_id=matchqueue_entry.match_id,
                                   _external=True)
    if server:
        ret["ue4_connection_url"] = "%s:%s?player_id=%s?token=%s" % (
            server.public_ip, server.port, player_id, server.token)
    return ret
Пример #3
0
    def get(self, user_id):
        """

        """
        user = g.db.query(User).filter(User.user_id == user_id).first()
        if not user:
            abort(httplib.NOT_FOUND)

        data = user.as_dict()
        data["client_url"] = None
        if user.client_id:
            data["client_url"] = url_for("clients.client",
                                         client_id=user.client_id,
                                         _external=True)
        players = g.db.query(CorePlayer).filter(CorePlayer.user_id == user_id)
        data["players"] = []
        for player in players:
            data["players"].append({
                "player_id": player.player_id,
                "player_name": player.player_name,
                "player_url": url_player(player.player_id)
            })
        identities = g.db.query(UserIdentity).filter(
            UserIdentity.user_id == user_id)
        data["identities"] = []
        for identity in identities:
            data["identities"].append({
                "identity_id": identity.identity_id,
                "name": identity.name,
                "type": identity.identity_type,
                "logon_date": identity.logon_date,
                "num_logons": identity.num_logons,
            })

        return data
Пример #4
0
    def get(self, match_id):
        """
        Get information about a single battle. Dumps out the DB row as json
        URL's are provided for additional information about the battle for
        drilldown. Machine and matcheserver url's are also written out.
        """
        match = g.db.query(Match).get(match_id)
        if not match:
            abort(httplib.NOT_FOUND)

        ret = match.as_dict()
        ret["url"] = url_for("matches.entry", match_id=match_id, _external=True)

        server = g.db.query(Server).get(match.server_id)
        ret["server"] = None
        ret["server_url"] = None
        ret["machine_url"] = None
        if server:
            ret["server"] = server.as_dict()
            ret["server_url"] = url_for("servers.entry", server_id=server.server_id, _external=True)

            machine = g.db.query(Machine).get(server.machine_id)
            ret["machine"] = None
            if server:
                ret["machine_url"] = url_for("machines.entry",
                                             machine_id=machine.machine_id, _external=True)

        teams = []
        rows = g.db.query(MatchTeam).filter(MatchTeam.match_id == match_id).all()
        for r in rows:
            team = r.as_dict()
            team["url"] = url_for("matches.team", match_id=match_id, team_id=r.team_id,
                                  _external=True)
            teams.append(team)
        ret["teams"] = teams

        ret["matchplayers_url"] = url_for("matches.players", match_id=match_id, _external=True)
        ret["teams_url"] = url_for("matches.teams", match_id=match_id, _external=True)

        players = []
        rows = g.db.query(MatchPlayer).filter(MatchPlayer.match_id == match_id).all()
        for r in rows:
            player = r.as_dict()
            player["matchplayer_url"] = url_for("matches.player", match_id=match_id,
                                                player_id=r.player_id, _external=True)
            player["player_url"] = url_player(r.player_id)
            players.append(player)
        ret["players"] = players
        ret["num_players"] = len(players)

        log.debug("Returning info for match %s", match_id)

        return ret
Пример #5
0
def get_player_entry(recordset, columns=None):
    player = recordset[0]
    user = recordset[1]
    client = recordset[2]
    entry = player.as_dict()
    entry["player_url"] = url_player(player.player_id)
    entry["user_url"] = url_user(player.user_id)
    entry["counter_url"] = url_for("playercounters.list",
                                   player_id=player.player_id,
                                   _external=True)
    entry["countertotals_url"] = url_for("playercounters.totals",
                                         player_id=player.player_id,
                                         _external=True)
    entry["gamestates_url"] = url_for("gamestate.gamestates",
                                      player_id=player.player_id,
                                      _external=True)
    entry["journal_url"] = url_for("journal.list",
                                   player_id=player.player_id,
                                   _external=True)
    entry["messages_url"] = url_for("messages.exchange",
                                    exchange="players",
                                    exchange_id=player.player_id,
                                    _external=True)
    entry["messagequeue_url"] = url_for("messages.exchange",
                                        exchange="players",
                                        exchange_id=player.player_id,
                                        _external=True) + "/{queue}"
    entry["summary_url"] = url_for("summary.summary",
                                   player_id=player.player_id,
                                   _external=True)
    entry["tickets_url"] = url_for("tickets.list",
                                   player_id=player.player_id,
                                   _external=True)
    is_online = False
    if client:
        is_online = client.is_online
    entry["is_online"] = is_online

    if columns:
        columns = set(columns)
        # player_id should always be returned
        columns.add("player_id")
        ret = {}
        for c in columns:
            ret[c] = entry.get(c, None)
    else:
        ret = entry
    return ret
Пример #6
0
    def get(self, match_id, player_id):
        """
        Get a specific player from a battle
        """
        player = g.db.query(MatchPlayer) \
                     .filter(MatchPlayer.match_id == match_id, MatchPlayer.player_id == player_id) \
                     .first()
        if not player:
            abort(httplib.NOT_FOUND)

        ret = player.as_dict()
        ret["team_url"] = None
        if player.team_id:
            ret["team_url"] = url_for("matches.team", match_id=match_id,
                                      team_id=player.team_id, _external=True)
        ret["player_url"] = url_player(player_id)
        return ret
Пример #7
0
    def get(self, client_id):
        """
        Get information about a single client. Just dumps out the DB row as json
        """
        ret = self.validate_call(client_id)
        if ret:
            return ret

        client = g.db.query(Client).get(client_id)
        if not client or client.status == "deleted":
            abort(httplib.NOT_FOUND)
        ret = client.as_dict()
        ret["url"] = url_client(client_id)
        ret["player_url"] = url_player(client.player_id)
        ret["user_url"] = url_user(client.user_id)

        log.debug("Returning info for client %s", client_id)
        return ret
Пример #8
0
    def get(self, match_id):
        """
        Get players from a match
        """
        rows = g.db.query(MatchPlayer) \
                   .filter(MatchPlayer.match_id == match_id) \
                   .all()
        ret = []
        for r in rows:
            player = r.as_dict()
            player["matchplayer_url"] = url_for("matches.player",
                                                match_id=match_id,
                                                player_id=r.player_id,
                                                _external=True)
            player["player_url"] = url_player(r.player_id)
            ret.append(player)

        return ret
Пример #9
0
    def get(self):
        """
        Retrieves all active clients. If a client has not heartbeat
        for 5 minutes it is considered disconnected and is not returned by
        this endpoint
        """
        args = self.get_args.parse_args()

        ret = []
        heartbeat_timeout = current_app.config.get("heartbeat_timeout", DEFAULT_HEARTBEAT_TIMEOUT)
        min_heartbeat_time = utcnow() - datetime.timedelta(seconds=heartbeat_timeout)
        filters = [Client.heartbeat >= min_heartbeat_time]
        if args["player_id"]:
            filters.append(Client.player_id == args["player_id"])
        rows = g.db.query(Client).filter(*filters)
        for row in rows:
            data = row.as_dict()
            data["client_url"] = url_client(row.client_id)
            data["player_url"] = url_player(row.player_id)
            ret.append(data)
        return ret
Пример #10
0
def endpoint_info(current_user):
    ret = {"players": url_for("players.players", _external=True)}
    ret["my_player"] = None
    if current_user:
        ret["my_player"] = url_player(current_user["player_id"])
    return ret
Пример #11
0
    def get(self):
        """This endpoint used by clients to fetch a list of matches available
        for joining
        """
        args = self.get_args.parse_args()
        num_rows = args.get("rows") or 100

        query = g.db.query(Match, Server, Machine)
        query = query.filter(Server.machine_id == Machine.machine_id,
                             Match.server_id == Server.server_id,
                             Match.status.notin_(["ended", "completed"]),
                             Server.status.in_(["started", "running", "active", "ready"]),
                             Server.heartbeat_date >= utcnow() - datetime.timedelta(seconds=60)
                             )
        if args.get("ref"):
            query = query.filter(Server.ref == args.get("ref"))
        if args.get("version"):
            query = query.filter(Server.version == args.get("version"))
        if args.get("placement"):
            query = query.filter(Machine.placement == args.get("placement"))
        if args.get("realm"):
            query = query.filter(Machine.realm == args.get("realm"))
        player_ids = []
        if args.get("player_id"):
            player_ids = args.get("player_id")

        query = query.order_by(-Match.num_players, -Match.server_id)
        query = query.limit(num_rows)
        rows = query.all()

        ret = []
        for row in rows:
            include = True
            if player_ids:
                include = False

            match = row[0]
            server = row[1]
            machine = row[2]
            record = {}
            record["create_date"] = match.create_date
            record["game_mode"] = match.game_mode
            record["map_name"] = match.map_name
            record["max_players"] = match.max_players
            record["match_status"] = match.status
            record["server_status"] = server.status
            record["public_ip"] = server.public_ip
            record["port"] = server.port
            record["version"] = server.version
            record["match_id"] = match.match_id
            record["server_id"] = match.server_id
            record["machine_id"] = server.machine_id
            record["heartbeat_date"] = server.heartbeat_date
            record["realm"] = machine.realm
            record["placement"] = machine.placement
            record["ref"] = server.ref
            record["match_url"] = url_for("matches.entry",
                                          match_id=match.match_id,
                                          _external=True)
            record["server_url"] = url_for("servers.entry",
                                           server_id=server.server_id,
                                           _external=True)
            record["machine_url"] = url_for("machines.entry",
                                            machine_id=server.machine_id,
                                            _external=True)
            conn_url = "%s:%s?player_id=%s?token=%s"
            record["ue4_connection_url"] = conn_url % (server.public_ip,
                                                       server.port,
                                                       current_user["player_id"],
                                                       server.token)
            player_array = []
            players = g.db.query(MatchPlayer) \
                          .filter(MatchPlayer.match_id == match.match_id,
                                  MatchPlayer.status.in_(["active"])) \
                          .all()
            for player in players:
                player_array.append({
                    "player_id": player.player_id,
                    "player_url": url_player(player.player_id),
                })
                if player.player_id in player_ids:
                    include = True
            record["players"] = player_array
            record["num_players"] = len(player_array)

            if include:
                ret.append(record)

        return ret