Esempio n. 1
0
        private async Task <int> SaveMatchResult(bool result, Match match, SummonerProfile summoner)
        {
            GameOutcome outcome;

            if (match.BluePlayer.SummonerId == summoner.SummonerId)
            {
                if (result)
                {
                    outcome = GameOutcome.BluePlayer;
                }
                else
                {
                    outcome = GameOutcome.RedPlayer;
                }
            }
            else
            {
                if (result)
                {
                    outcome = GameOutcome.RedPlayer;
                }
                else
                {
                    outcome = GameOutcome.BluePlayer;
                }
            }
            var uri          = API.EloConnection.SaveMatch;
            var http         = new HttpClient();
            var matchOutcome = new MatchResult
            {
                MatchId     = match.MatchId,
                BluePlayer  = match.BluePlayer.SummonerId,
                RedPlayer   = match.RedPlayer.SummonerId,
                Winner      = outcome,
                RequestUser = summoner.SummonerId,
                RedChamp    = RedChamp,
                BlueChamp   = BlueChamp
            };
            var content  = new StringContent(JsonConvert.SerializeObject(matchOutcome), Encoding.UTF8, "application/json");
            var response = await http.PostAsync(uri, content);

            var newElo = JsonConvert.DeserializeObject <int>(await response.Content.ReadAsStringAsync());

            return(newElo);
        }
Esempio n. 2
0
        private async Task <bool> MatchParser(Match match, SummonerProfile summoner)
        {
            while (IsInGame)
            {
                using (var httpClientHandler = new HttpClientHandler())
                {
                    httpClientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, sslPolicyErrors) =>
                    {
                        if (sslPolicyErrors == SslPolicyErrors.None)
                        {
                            return(true);   //Is valid
                        }
                        return(true);
                    };
                    http = new HttpClient(httpClientHandler);
                    try
                    {
                        var gamedata = await http.GetStringAsync("https://localhost:2999/liveclientdata/allgamedata");

                        var jsonmodel = JsonConvert.DeserializeObject <MatchOneVOneModel>(gamedata);

                        if (string.IsNullOrWhiteSpace(RedChamp) || string.IsNullOrWhiteSpace(BlueChamp))
                        {
                            var currentPlayer = jsonmodel.AllPlayers.FirstOrDefault(x => x.SummonerName == summoner.DisplayName);
                            var opponent      = jsonmodel.AllPlayers.FirstOrDefault(x => x.SummonerName != summoner.DisplayName);
                            if (match.BluePlayer.SummonerId == summoner.SummonerId)
                            {
                                BlueChamp = currentPlayer.ChampionName;
                                RedChamp  = opponent.ChampionName;
                            }
                            else
                            {
                                RedChamp  = currentPlayer.ChampionName;
                                BlueChamp = opponent.ChampionName;
                            }
                        }

                        foreach (var item in jsonmodel.Events.EventsEvents)
                        {
                            if (item.EventName == "FirstBlood")
                            {
                                IsInGame = false;
                                KillLeague();
                                if (summoner.DisplayName == item.Recipient)
                                {
                                    return(true);
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                            else if (item.EventName == "FirstBrick")
                            {
                                IsInGame = false;
                                KillLeague();
                                if (item.KillerName == summoner.DisplayName ||
                                    (item.KillerName.Contains("T100") && match.BluePlayer.SummonerId == summoner.SummonerId) ||
                                    (item.KillerName.Contains("T200") && match.RedPlayer.SummonerId == summoner.SummonerId))
                                {
                                    return(true);
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                        }
                        foreach (var item in jsonmodel.AllPlayers)
                        {
                            if (item.Scores.CreepScore == 100)
                            {
                                IsInGame = false;
                                KillLeague();
                                if (summoner.DisplayName == item.SummonerName)
                                {
                                    return(true);
                                }
                                else
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                    catch
                    {
                        Thread.Sleep(8000);
                    }
                    Thread.Sleep(50);
                }
            }
            return(false);
        }