Exemplo n.º 1
0
def update_recent_matches():
    result = api_client.get_match_history(celery.settings)

    for match in result['matches']:
        with transaction.manager:
            if match['match_id'] is None:
                continue

            if DBSession.query(Match).get(match['match_id']):
                continue

            db_match = Match(
                id=match['match_id'],
                start_time=datetime.fromtimestamp(int(match['start_time']), tzutc()),
                lobby_type=match['lobby_type'],
            )

            log.info('Adding new match: id={}'.format(db_match.id))

            for player in match['players']:
                db_player = None

                if 'account_id' in player:
                    db_player = DBSession.query(Player).get(player['account_id'])

                    if not db_player:
                        db_player = Player(id=player['account_id'])
                        log.info('Adding new player: id={}'.format(db_player.id))

                slot = int(player['player_slot'])

                is_dire = slot & 0x80
                slot &= ~0x80

                db_player_match = PlayerMatch(
                        player=db_player,
                        match=db_match,
                        hero=DBSession.query(Hero).get(player['hero_id']),
                        is_dire=bool(is_dire),
                        slot=slot,
                    )

                log.info('Adding new player match: id={}'.format(db_player_match.id))

                DBSession.add(db_match)

                update_match_details.apply_async((db_match.id,))

    update_player_details.apply_async()
Exemplo n.º 2
0
def on_login_success(request):
    context = request.context

    steam_url = context.profile["accounts"][0]["username"]
    steam_id = convert_player_id_64_to_32(long(steam_url.rsplit("/", 1)[1]))

    player = DBSession.query(Player).get(steam_id)

    if player is not None:
        player.is_registerd = True
    else:
        player = Player(id=steam_id, is_registerd=True)
        DBSession.add(player)

    request.session["current_player_steamid"] = steam_id
    request.session["current_player"] = player

    return HTTPSeeOther(location="/")