Exemplo n.º 1
0
        public async Task <List <Match> > ProtobufToMatches(List <MatchInfo> protobuf)
        {
            Log.Information($"Converting {protobuf.Count} protobuf matches into MatchModels.");
            var matchModels = new List <Match>();

            foreach (var match in protobuf)
            {
                var lastRound = match.Roundstatsall.Last();

                var baseDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

                var playerIds      = lastRound.Reservation.AccountIds.Select(x => x + STEAM64_BASE).ToArray();
                var playerProfiles = await _steamApi.GetPlayerProfilesAsync(playerIds);

                var team1 = CreateTeamLeaderboard(playerProfiles, lastRound, 0);
                var team2 = CreateTeamLeaderboard(playerProfiles, lastRound, 5);

                matchModels.Add(new Match
                {
                    Date = baseDate.AddSeconds(match.Matchtime).ToLocalTime(),

                    MatchId = match.Matchid,
                    // ReservationId still needs to check the legacy version since once in a while it will encounter a match that contains the legacy format
                    ReservationId = match.RoundstatsLegacy?.Reservationid ?? lastRound.Reservationid,
                    TvPort        = match.Watchablematchinfo.TvPort,

                    Map = match.Watchablematchinfo.GameMap,

                    Team1 = team1,
                    Team2 = team2,

                    Victory = lastRound.MatchResult == 2,
                    Scores  = lastRound.TeamScores.ToList()
                });
            }

            return(matchModels);
        }