Exemple #1
0
def player_elo_info_data(request):
    """
    Provides elo information on a specific player. Raw data is returned.
    """
    (idfp, status) = verify_request(request)
    log.debug("d0_blind_id verification: idfp={0} status={1}\n".format(idfp, status))

    log.debug("\n----- BEGIN REQUEST BODY -----\n" + request.body +
            "----- END REQUEST BODY -----\n\n")

    hashkey = request.matchdict['hashkey']

    # the incoming hashkey is double quoted, and WSGI unquotes once...
    hashkey = unquote(hashkey)

    try:
        player = DBSession.query(Player).\
                filter(Player.player_id == Hashkey.player_id).\
                filter(Player.active_ind == True).\
                filter(Hashkey.hashkey == hashkey).one()

        elos = get_elos(player.player_id)

    except Exception as e:
        log.debug(e)
        raise pyramid.httpexceptions.HTTPNotFound

    return {
        'hashkey':hashkey,
        'player':player,
        'elos':elos,
    }
Exemple #2
0
def player_hashkey_info_data(request):
    # hashkey = request.matchdict['hashkey']

    # the incoming hashkey is double quoted, and WSGI unquotes once...
    # hashkey = unquote(hashkey)

    # if using request verification to obtain the hashkey
    (idfp, status) = verify_request(request)
    log.debug("d0_blind_id verification: idfp={0} status={1}\n".format(idfp, status))

    log.debug("\n----- BEGIN REQUEST BODY -----\n" + request.body + "----- END REQUEST BODY -----\n\n")

    # if config is to *not* verify requests and we get nothing back, this
    # query will return nothing and we'll 404.
    try:
        player = (
            DBSession.query(Player)
            .filter(Player.player_id == Hashkey.player_id)
            .filter(Player.active_ind == True)
            .filter(Hashkey.hashkey == idfp)
            .one()
        )

        games_played = get_games_played(player.player_id)
        overall_stats = get_overall_stats(player.player_id)
        fav_maps = get_fav_maps(player.player_id)
        elos = get_elos(player.player_id)
        ranks = get_ranks(player.player_id)
        most_recent_game = get_recent_games(player.player_id, 1)[0]

    except Exception as e:
        raise pyramid.httpexceptions.HTTPNotFound

    return {
        "player": player,
        "hashkey": idfp,
        "games_played": games_played,
        "overall_stats": overall_stats,
        "fav_maps": fav_maps,
        "elos": elos,
        "ranks": ranks,
        "most_recent_game": most_recent_game,
    }
Exemple #3
0
def submit_stats(request):
    """
    Entry handler for POST stats submissions.
    """
    try:
        # placeholder for the actual session
        session = None

        log.debug("\n----- BEGIN REQUEST BODY -----\n" + request.body +
                "----- END REQUEST BODY -----\n\n")

        (idfp, status) = verify_request(request)
        (game_meta, raw_players, raw_teams) = parse_stats_submission(request.body)
        revision = game_meta.get('R', 'unknown')
        duration = game_meta.get('D', None)

        # only players present at the end of the match are eligible for stats
        raw_players = filter(played_in_game, raw_players)

        do_precondition_checks(request, game_meta, raw_players)

        # the "duel" gametype is fake
        if len(raw_players) == 2 \
            and num_real_players(raw_players) == 2 \
            and game_meta['G'] == 'dm':
            game_meta['G'] = 'duel'

        #----------------------------------------------------------------------
        # Actual setup (inserts/updates) below here
        #----------------------------------------------------------------------
        session = DBSession()

        game_type_cd = game_meta['G']

        # All game types create Game, Server, Map, and Player records
        # the same way.
        server = get_or_create_server(
                session      = session,
                hashkey      = idfp,
                name         = game_meta['S'],
                revision     = revision,
                ip_addr      = get_remote_addr(request),
                port         = game_meta.get('U', None),
                impure_cvars = game_meta.get('C', 0))

        gmap = get_or_create_map(
                session = session,
                name    = game_meta['M'])

        game = create_game(
                session      = session,
                start_dt     = datetime.datetime.utcnow(),
                server_id    = server.server_id,
                game_type_cd = game_type_cd,
                map_id       = gmap.map_id,
                match_id     = game_meta['I'],
                duration     = duration,
                mod          = game_meta.get('O', None))

        # keep track of the players we've seen
        player_ids = []
        pgstats = []
        hashkeys = {}
        for events in raw_players:
            player = get_or_create_player(
                session = session,
                hashkey = events['P'],
                nick    = events.get('n', None))

            pgstat = create_game_stat(session, game_meta, game, server,
                    gmap, player, events)
            pgstats.append(pgstat)

            if player.player_id > 1:
                anticheats = create_anticheats(session, pgstat, game, player, events)

            if player.player_id > 2:
                player_ids.append(player.player_id)
                hashkeys[player.player_id] = events['P']

            if should_do_weapon_stats(game_type_cd) and player.player_id > 1:
                pwstats = create_weapon_stats(session, game_meta, game, player,
                        pgstat, events)

        # store them on games for easy access
        game.players = player_ids

        for events in raw_teams:
            try:
                teamstat = create_team_stat(session, game, events)
            except Exception as e:
                raise e

        if server.elo_ind and gametype_elo_eligible(game_type_cd):
            ep = EloProcessor(session, game, pgstats)
            ep.save(session)

        session.commit()
        log.debug('Success! Stats recorded.')

        # ranks are fetched after we've done the "real" processing
        ranks = get_ranks(session, player_ids, game_type_cd)

        # plain text response
        request.response.content_type = 'text/plain'

        return {
                "now"        : calendar.timegm(datetime.datetime.utcnow().timetuple()),
                "server"     : server,
                "game"       : game,
                "gmap"       : gmap,
                "player_ids" : player_ids,
                "hashkeys"   : hashkeys,
                "elos"       : ep.wip,
                "ranks"      : ranks,
        }

    except Exception as e:
        if session:
            session.rollback()
        raise e
Exemple #4
0
def submit_stats(request):
    """
    Entry handler for POST stats submissions.
    """
    try:
        # placeholder for the actual session
        session = None

        log.debug("\n----- BEGIN REQUEST BODY -----\n" + request.body +
                "----- END REQUEST BODY -----\n\n")

        (idfp, status) = verify_request(request)
        (game_meta, raw_players, raw_teams) = parse_stats_submission(request.body)
        revision = game_meta.get('R', 'unknown')
        duration = game_meta.get('D', None)

        # only players present at the end of the match are eligible for stats
        raw_players = filter(played_in_game, raw_players)

        do_precondition_checks(request, game_meta, raw_players)

        # the "duel" gametype is fake
        if len(raw_players) == 2 \
            and num_real_players(raw_players) == 2 \
            and game_meta['G'] == 'dm':
            game_meta['G'] = 'duel'

        #----------------------------------------------------------------------
        # Actual setup (inserts/updates) below here
        #----------------------------------------------------------------------
        session = DBSession()

        game_type_cd = game_meta['G']

        # All game types create Game, Server, Map, and Player records
        # the same way.
        server = get_or_create_server(
                session  = session,
                hashkey  = idfp,
                name     = game_meta['S'],
                revision = revision,
                ip_addr  = get_remote_addr(request),
                port     = game_meta.get('U', None))

        gmap = get_or_create_map(
                session = session,
                name    = game_meta['M'])

        game = create_game(
                session      = session,
                start_dt     = datetime.datetime.utcnow(),
                server_id    = server.server_id,
                game_type_cd = game_type_cd,
                map_id       = gmap.map_id,
                match_id     = game_meta['I'],
                duration     = duration,
                mod          = game_meta.get('O', None))

        for events in raw_players:
            player = get_or_create_player(
                session = session,
                hashkey = events['P'],
                nick    = events.get('n', None))

            pgstat = create_game_stat(session, game_meta, game, server,
                    gmap, player, events)

            if player.player_id > 1:
                anticheats = create_anticheats(session, pgstat, game, player,
                    events)

            if should_do_weapon_stats(game_type_cd) and player.player_id > 1:
                pwstats = create_weapon_stats(session, game_meta, game, player,
                        pgstat, events)

        for events in raw_teams:
            try:
                teamstat = create_team_stat(session, game, events)
            except Exception as e:
                raise e

        if should_do_elos(game_type_cd):
            create_elos(session, game)

        session.commit()
        log.debug('Success! Stats recorded.')
        return Response('200 OK')
    except Exception as e:
        if session:
            session.rollback()
        raise e