コード例 #1
0
ファイル: vips.py プロジェクト: timraay/hll_rcon_tool
def get_prunable_vips(days_of_inactivity=30):
    rcon = RecordedRcon(SERVER_INFO)

    age_limit = datetime.datetime.now() - datetime.timedelta(days=days_of_inactivity)
    vips = rcon.get_vip_ids()
    vips_by_steam_id = {vip["steam_id_64"]: vip["name"] for vip in vips}
    profiles = get_profiles(list(vips_by_steam_id.keys()), 1)

    for player in profiles:
        try:
            last_session = player["sessions"][0]
        except IndexError:
            print(f"""
                VIP Name: {vips_by_steam_id[player["steam_id_64"]]}
                Last seen: N/A
                AKAs: {'  ||  '.join(n["name"] for n in player["names"])}
            """)
            continue
        last_session = last_session["start"] or last_session["end"] or last_session["created"]
        # TODO: Handle no sessions
        if  last_session < age_limit:
            print(f"""
                VIP Name: {vips_by_steam_id[player["steam_id_64"]]}
                Last seen: {last_session.isoformat()}
                AKAs: {'  ||  '.join(n["name"] for n in player["names"])}
            """)
コード例 #2
0
    def get_players(self):
        players = super().get_players()

        steam_ids = [p.get(STEAMID) for p in players if p.get(STEAMID)]
        profiles = {p['steam_id_64']: p for p in get_profiles(steam_ids)}

        for p in players:
            p.update({'profile': profiles.get(p.get(STEAMID))})

        return players
コード例 #3
0
    def get_players(self):
        players = super().get_players()

        vips = set(v['steam_id_64'] for v in super().get_vip_ids())
        steam_ids = [p.get(STEAMID) for p in players if p.get(STEAMID)]
        profiles = {p['steam_id_64']: p for p in get_profiles(steam_ids)}

        for p in players:
            p.update({
                'profile': profiles.get(p.get(STEAMID)),
                'is_vip': p.get(STEAMID) in vips
            })

        return players
コード例 #4
0
    def get_current_players_stats(self):
        players = self.rcon.get_players()
        if not players:
            logger.debug("No players")
            return {}

        profiles_by_id = {
            profile["steam_id_64"]: profile
            for profile in get_profiles([p["steam_id_64"] for p in players],
                                        nb_sessions=0)
        }
        logger.info("%s players, %s profiles loaded", len(players),
                    len(profiles_by_id))
        oldest_session_seconds = self._get_player_session_time(
            max(players, key=self._get_player_session_time))
        logger.debug("Oldest session: %s", oldest_session_seconds)
        now = datetime.datetime.now()
        min_timestamp = (
            now -
            datetime.timedelta(seconds=oldest_session_seconds)).timestamp()
        logger.debug("Min timestamp: %s", min_timestamp)
        logs = get_recent_logs(min_timestamp=min_timestamp)
        logger.info("%s log lines to process", len(logs["logs"]))

        indexed_players = {p["name"]: p for p in players}
        indexed_logs = self._get_indexed_logs_by_player_for_session(
            now, indexed_players, logs["logs"])
        stats_by_player = {}

        actions_processors = {
            "KILL": self._add_kill,
            "TEAM KILL": self._add_tk,
            "VOTE STARTED": self._add_vote_started,
            "VOTE": self._add_vote,
        }
        for p in players:
            logger.debug("Crunching stats for %s", p)
            player_logs = indexed_logs.get(p["name"], [])
            stats = {
                "player":
                p["name"],
                "steam_id_64":
                p.get("steam_id_64"),
                "steaminfo":
                profiles_by_id.get(p.get("steam_id_64"), {}).get("steaminfo"),
                "kills":
                0,
                "kills_streak":
                0,
                "deaths":
                0,
                "deaths_without_kill_streak":
                0,
                "teamkills":
                0,
                "teamkills_streak":
                0,
                "deaths_by_tk":
                0,
                "deaths_by_tk_streak":
                0,
                "nb_vote_started":
                0,
                "nb_voted_yes":
                0,
                "nb_voted_no":
                0,
                "time_seconds":
                self._get_player_session_time(p),
            }

            streaks = Streaks()

            for l in player_logs:
                action = l["action"]
                processor = actions_processors.get(action,
                                                   lambda **kargs: None)
                processor(stats=stats, player=p, log=l)
                self._streaks_accumulator(p, l, stats, streaks)

            # stats = self._compute_stats(stats)
            stats_by_player[p["name"]] = self._compute_stats(stats)

        return stats_by_player