public ActionResult GetMatchDetails()
        {
            if (User.Identity.Name != "Steven")
            {
                return(View("AuthenticationError"));
            }

            var id           = HttpContext.Request.QueryString["matchId"];
            var confirmation = HttpContext.Request.QueryString["confirmation"] != null;

            var match = Mongo.Matches.FindOne(Query <Match> .Where(x => x.Id == ObjectId.Parse(id)));

            if (confirmation)
            {
                var key        = WebConfigurationManager.AppSettings["RiotTournamentApiKey"];
                var rateLimit1 = int.Parse(WebConfigurationManager.AppSettings["RateLimitPer10Seconds"]);
                var rateLimit2 = int.Parse(WebConfigurationManager.AppSettings["RateLimitPer10Minutes"]);

                var api = TournamentRiotApi.GetInstance(key, rateLimit1, rateLimit2);

                MatchScraper.GetMatchDetails(api, match, false);
                return(RedirectToAction("Matches", "Admin"));
            }

            return(View(match));
        }
Example #2
0
 /// <summary>
 ///     Create a tournament code for the tournament asynchronously.
 /// </summary>
 /// <param name="teamSize">The team size for the tournament code game.</param>
 /// <param name="allowedSummonerIds">participants</param>
 /// <param name="spectatorType">The spectator mode for the tournament code game.</param>
 /// <param name="pickType">The pick mode for tournament code game.</param>
 /// <param name="mapType">The game map for the tournament code game</param>
 /// <param name="metadata">The metadata for tournament code.</param>
 /// <returns>The tournament code.</returns>
 public async Task <string> CreateTournamentCodeAsync(int teamSize, List <long> allowedSummonerIds,
                                                      TournamentSpectatorType spectatorType, TournamentPickType pickType, TournamentMapType mapType,
                                                      string metadata)
 {
     return(await TournamentRiotApi.GetInstance()
            .CreateTournamentCodeAsync(Id, teamSize, allowedSummonerIds, spectatorType, pickType, mapType, metadata));
 }
Example #3
0
        public MatchController()
        {
            var tournamentKey = WebConfigurationManager.AppSettings["RiotTournamentApiKey"];
            var rateLimit1    = int.Parse(WebConfigurationManager.AppSettings["RateLimitPer10Seconds"]);
            var rateLimit2    = int.Parse(WebConfigurationManager.AppSettings["RateLimitPer10Minutes"]);

            _tournamentApi = TournamentRiotApi.GetInstance(tournamentKey, rateLimit1, rateLimit2);
        }
        static TournamentCodeFactory()
        {
            TournamentId = int.Parse(WebConfigurationManager.AppSettings["TournamentId"]);

            var tournamentKey = WebConfigurationManager.AppSettings["RiotTournamentApiKey"];
            var rateLimit1    = int.Parse(WebConfigurationManager.AppSettings["RateLimitPer10Seconds"]);
            var rateLimit2    = int.Parse(WebConfigurationManager.AppSettings["RateLimitPer10Minutes"]);

            TournamentApi = TournamentRiotApi.GetInstance(tournamentKey, rateLimit1, rateLimit2);
        }
 /// <summary>
 ///     Asynchronously creates a tournament for this provider.
 /// </summary>
 /// <param name="name">An optional tournament name.</param>
 /// <returns>A tournament instance.</returns>
 public async Task <Tournament> CreateTournamentAsync(string name)
 {
     return(await TournamentRiotApi.GetInstance().CreateTournamentAsync(Id, name));
 }
 /// <summary>
 ///     Creates a tournament for this provider.
 /// </summary>
 /// <param name="name">An optional tournament name.</param>
 /// <returns>A tournament instance.</returns>
 public Tournament CreateTournament(string name)
 {
     return(TournamentRiotApi.GetInstance().CreateTournament(Id, name));
 }
Example #7
0
 /// <summary>
 ///     Create multiple tournament codes for the tournament asynchronously.
 /// </summary>
 /// <param name="teamSize">The team size for the tournament code game.</param>
 /// <param name="spectatorType">The spectator mode for the tournament code game.</param>
 /// <param name="pickType">The pick mode for tournament code game.</param>
 /// <param name="mapType">The game map for the tournament code game</param>
 /// <param name="metadata">The metadata for tournament code.</param>
 /// <param name="count">The number of codes to be created</param>
 /// <returns>A list of the created tournament codes</returns>
 public async Task <List <string> > CreateTournamentCodesAsync(int teamSize, TournamentSpectatorType spectatorType,
                                                               TournamentPickType pickType, TournamentMapType mapType, string metadata, int count = 1)
 {
     return(await TournamentRiotApi.GetInstance()
            .CreateTournamentCodesAsync(Id, teamSize, spectatorType, pickType, mapType, metadata, count));
 }
 /// <summary>
 ///     Returns the tournament code object associated with a tournament code string asynchronously.
 /// </summary>
 /// <param name="tournamentCode">The tournament code.</param>
 /// <returns>the tournament code object associated with a tournament code string.</returns>
 public static async Task <TournamentCodeDetail> GetAsync(string tournamentCode)
 {
     return(await TournamentRiotApi.GetInstance().GetTournamentCodeDetailsAsync(tournamentCode));
 }
 /// <summary>
 ///     Returns the tournament code object associated with a tournament code string.
 /// </summary>
 /// <param name="tournamentCode">The tournament code.</param>
 /// <returns>the tournament code object associated with a tournament code string.</returns>
 public static TournamentCodeDetail Get(string tournamentCode)
 {
     return(TournamentRiotApi.GetInstance().GetTournamentCodeDetails(tournamentCode));
 }
 /// <summary>
 ///     Update the pick type, map, spectator type, or allowed summoners for a code asynchronously.
 /// </summary>
 /// <param name="allowedSummonerIds">Comma separated list of summoner Ids.</param>
 /// <param name="spectatorType">The spectator type.</param>
 /// <param name="pickType">The pick type.</param>
 /// <param name="mapType">The map type.</param>
 public async Task <bool> UpdateAsync(List <long> allowedSummonerIds, TournamentSpectatorType?spectatorType,
                                      TournamentPickType?pickType, TournamentMapType?mapType)
 {
     return(await TournamentRiotApi.GetInstance()
            .UpdateTournamentCodeAsync(Code, allowedSummonerIds, spectatorType, pickType, mapType));
 }
 /// <summary>
 ///     Update the pick type, map, spectator type, or allowed summoners for a code.
 /// </summary>
 /// <param name="allowedSummonerIds">Comma separated list of summoner Ids.</param>
 /// <param name="spectatorType">The spectator type.</param>
 /// <param name="pickType">The pick type.</param>
 /// <param name="mapType">The map type.</param>
 public bool Update(List <long> allowedSummonerIds, TournamentSpectatorType?spectatorType,
                    TournamentPickType?pickType, TournamentMapType?mapType)
 {
     return(TournamentRiotApi.GetInstance()
            .UpdateTournamentCode(Code, allowedSummonerIds, spectatorType, pickType, mapType));
 }
Example #12
0
        public static void GetMatchDetails(TournamentRiotApi api, Match match, bool callNewMatchHook)
        {
            MatchDetail matchDetails;

            // Get more match details
            try
            {
                if (match.RiotMatchId != 0)
                {
                    matchDetails = api.GetTournamentMatch(Region.euw, match.RiotMatchId, match.TournamentCode, false);
                }
                else
                {
                    var matchId = api.GetTournamentMatchId(Region.euw, match.TournamentCode);
                    matchDetails      = api.GetTournamentMatch(Region.euw, matchId, match.TournamentCode, false);
                    match.RiotMatchId = matchId;
                }
            }
            catch (Exception)
            {
                try
                {
                    if (match.RiotMatchId != 0)
                    {
                        matchDetails = api.GetTournamentMatch(Region.euw, match.RiotMatchId, match.TournamentCodeBlind, false);
                    }
                    else
                    {
                        var matchId = api.GetTournamentMatchId(Region.euw, match.TournamentCodeBlind);
                        matchDetails      = api.GetTournamentMatch(Region.euw, matchId, match.TournamentCodeBlind, false);
                        match.RiotMatchId = matchId;
                    }
                }
                catch (Exception)
                {
                    return;
                }
            }

            // Get the players that were supposed to be on blue side
            var supposedToBeBluePlayers = matchDetails.Participants.Where(matchDetailParticipant => match.BlueTeam.Participants.Select(localMatchParticipant => localMatchParticipant.Summoner.Name.ToLower()).Contains(matchDetails.ParticipantIdentities.Single(identity => identity.ParticipantId == matchDetailParticipant.ParticipantId).Player.SummonerName.ToLower())).ToList();

            if (supposedToBeBluePlayers.Count == 0)
            {
                // Teams did not have correct summoners playing the match. Match invalid.
                match.Invalid       = true;
                match.InvalidReason = "INCORRECT_SUMMONER_COUNT_BLUE_TEAM";

                // Save to database
                Mongo.Matches.Save(match);
            }

            // Set the team id to the side they actually played
            var blueTeamId = supposedToBeBluePlayers.First().TeamId;

            // Get the players that were supposed to be on red side
            var supposedToBeRedPlayers = matchDetails.Participants.Where(matchDetailParticipant => match.RedTeam.Participants.Select(localMatchParticipant => localMatchParticipant.Summoner.Name.ToLower()).Contains(matchDetails.ParticipantIdentities.Single(identity => identity.ParticipantId == matchDetailParticipant.ParticipantId).Player.SummonerName.ToLower())).ToList();

            if (supposedToBeRedPlayers.Count == 0)
            {
                // Teams did not have correct summoners playing the match. Match invalid.
                match.Invalid       = true;
                match.InvalidReason = "INCORRECT_SUMMONER_COUNT_RED_TEAM";

                // Save to database
                Mongo.Matches.Save(match);
            }

            // Set the team id to the side they actually played
            var redTeamId = supposedToBeRedPlayers.First().TeamId;

            // Set statistics
            match.Duration     = matchDetails.MatchDuration;
            match.CreationTime = matchDetails.MatchCreation;
            match.RiotMatchId  = matchDetails.MatchId;

            match.ChampionIds = matchDetails.Participants.Select(x => x.ChampionId).ToArray();

            // Exclude null bans for blind pick and for teams that forgot all their bans
            match.BanIds = matchDetails.Teams.Where(x => x.Bans != null).SelectMany(x => x.Bans).Select(x => x.ChampionId).ToArray();

            match.AssistsBlueTeam = matchDetails.Participants.Where(x => x.TeamId == blueTeamId).Sum(x => x.Stats.Assists);
            match.KillsBlueTeam   = matchDetails.Participants.Where(x => x.TeamId == blueTeamId).Sum(x => x.Stats.Kills);
            match.DeathsBlueTeam  = matchDetails.Participants.Where(x => x.TeamId == blueTeamId).Sum(x => x.Stats.Deaths);

            match.AssistsRedTeam = matchDetails.Participants.Where(x => x.TeamId == redTeamId).Sum(x => x.Stats.Assists);
            match.KillsRedTeam   = matchDetails.Participants.Where(x => x.TeamId == redTeamId).Sum(x => x.Stats.Kills);
            match.DeathsRedTeam  = matchDetails.Participants.Where(x => x.TeamId == redTeamId).Sum(x => x.Stats.Deaths);

            match.Invalid = false;

            if (blueTeamId == 200)
            {
                match.PlayedWrongSide = true;
            }

            // Save to database
            Mongo.Matches.Save(match);

            // Call the new match hook
            if (callNewMatchHook)
            {
                BracketHelper.NewMatch(match);
            }
        }