예제 #1
0
def save_end_player_session(steam_id_64, timestamp):
    with enter_session() as sess:
        player = get_player(sess, steam_id_64)
        if not player:
            logger.error(
                "Can't record player session for %s, player not found", steam_id_64
            )
            return

        last_session = (
            sess.query(PlayerSession)
            .filter(PlayerSession.steamid == player)
            .order_by(PlayerSession.created.desc())
            .first()
        )

        if last_session.end:
            logger.warning(
                "Last session was already ended for %s. Creating a new one instead",
                steam_id_64,
            )
            last_session = PlayerSession(
                steamid=player,
            )
        last_session.end = datetime.datetime.fromtimestamp(timestamp)
        logger.info(
            "Recorded player %s session end at %s", steam_id_64, last_session.end
        )
        sess.commit()
예제 #2
0
def save_start_player_session(steam_id_64, timestamp):
    with enter_session() as sess:
        player = get_player(sess, steam_id_64)
        if not player:
            logger.error(
                "Can't record player session for %s, player not found",
                steam_id_64)
            return

        sess.add(
            PlayerSession(steamid=player,
                          start=datetime.datetime.fromtimestamp(timestamp)))
        logger.info("Recorded player %s session start at %s", steam_id_64,
                    datetime.datetime.fromtimestamp(timestamp))
        sess.commit()
예제 #3
0
def save_start_player_session(steam_id_64, timestamp, server_name=None):
    with enter_session() as sess:
        player = get_player(sess, steam_id_64)
        if not player:
            logger.error(
                "Can't record player session for %s, player not found", steam_id_64
            )
            return

        sess.add(
            PlayerSession(
                steamid=player, start=datetime.datetime.fromtimestamp(timestamp), server_number=os.getenv("SERVER_NUMBER", None), server_name=server_name
            )
        )
        logger.info(
            "Recorded player %s session start at %s",
            steam_id_64,
            datetime.datetime.fromtimestamp(timestamp),
        )
        sess.commit()