Esempio n. 1
0
        public static void PerformLookup(string name)
        {
            WebClient           Getinfo = new WebClient();
            WebHeaderCollection WHC     = new WebHeaderCollection();

            Getinfo.Headers = WHC;
            WHC.Add("Accept-Language: en-US,en;q=0.8"); // Don't want any korean shit
            String source = Getinfo.DownloadString(Misc.getregionurl() + "summoner/ajax/spectator/userName="******"&force=true");

            // System.IO.File.WriteAllText(Path.Combine(LeagueSharp.Common.Config.AppDataDirectory, "webpage.txt"), Misc.RemoveSpaces(source)); // Testing purposes
            ParseIt(source);
        }
Esempio n. 2
0
        public OPGG()
        {
            Ranks = new List <Info>();

            foreach (var hero in ObjectManager.Get <Obj_AI_Hero>())
            {
                Info   info          = new Info();
                string playerNameEnc = HttpUtility.UrlEncode(hero.Name);
                if (Misc.getregionurl() != "Not Supported" && Misc.getregionurl().Contains("op.gg"))
                {
                    string htmlcode = "";
                    var    request  =
                        (HttpWebRequest)WebRequest.Create(Misc.getregionurl() + "summoner/userName="******"Response OK FOR: " + playerNameEnc);
                        //  System.IO.File.WriteAllText(@"C:\Users\Laptop\Desktop\" + hero.Name + ".txt", htmlcode);
                    }
                    else if (response.StatusCode != HttpStatusCode.OK)
                    {
                        Game.PrintChat("ERROR"); //Console.WriteLine("ERROR: " + playerNameEnc);
                        htmlcode = "ErrorHTTPSTATUS: " + playerNameEnc;
                    }
                    if (htmlcode.Contains("ErrorHTTPSTATUS"))
                    {
                        Console.WriteLine("Http Error: " + htmlcode);
                        info.Name       = hero.Name;
                        info.herohandle = hero;
                        info.Ranking    = "HTTPERROR";
                        info.lpamount   = "";
                        Ranks.Add(info);
                    }
                    if (htmlcode.Contains("tierRank") && htmlcode.Contains("leaguePoints"))
                    {
                        try
                        {
                            Match htmlmatchrank =
                                new Regex(@"\<span class=\""tierRank\"">(.*?)</span>").Matches(htmlcode)[0];
                            Match htmlmatchlp =
                                new Regex(@"\<span class=\""leaguePoints\"">(.*?)</span>").Matches(htmlcode)[0];
                            Match playerrank = new Regex(htmlmatchrank.Groups[1].ToString()).Matches(htmlcode)[0];
                            Match playerlp   = new Regex(htmlmatchlp.Groups[1].ToString()).Matches(htmlcode)[0];
                            rank = playerrank.ToString();
                            if (Misc.Config.Item("printranks").GetValue <bool>() && hero.IsAlly)
                            {
                                Game.PrintChat("<font color=\"#FF000\"><b>" + hero.ChampionName +
                                               "</font> <font color=\"#FFFFFF\">(" + hero.Name + ")" + " : " + rank);
                            }
                            if (Misc.Config.Item("printranks").GetValue <bool>() && hero.IsEnemy)
                            {
                                Game.PrintChat("<font color=\"#FF0000\"><b>" + hero.ChampionName +
                                               "</font> <font color=\"#FFFFFF\">(" + hero.Name + ")" + " : " + rank);
                            }
                            info.Name       = hero.Name;
                            info.herohandle = hero;
                            info.Ranking    = rank;
                            info.lpamount   = playerlp.ToString();
                            Ranks.Add(info);
                            Console.WriteLine("Added info" + hero.Name + info.Ranking);
                        }
                        catch (Exception)
                        {
                            info.Name       = hero.Name;
                            info.herohandle = hero;
                            info.Ranking    = "Exception";
                            info.lpamount   = "";
                            Ranks.Add(info);
                            Console.WriteLine("Exception in 1st");
                        }
                    }
                    if (!htmlcode.Contains("ChampionBox Unranked") &&
                        (htmlcode.Contains("tierRank")) && !htmlcode.Contains("leaguePoints"))
                    {
                        try
                        {
                            rank = "Unranked";
                            if (Misc.Config.Item("printranks").GetValue <bool>() && hero.IsAlly)
                            {
                                Game.PrintChat("<font color=\"#FF000\"><b>" + hero.ChampionName +
                                               "</font> <font color=\"#FFFFFF\">(" + hero.Name + ")" + " : " + rank);
                            }
                            if (Misc.Config.Item("printranks").GetValue <bool>() && hero.IsEnemy)
                            {
                                Game.PrintChat("<font color=\"#FF0000\"><b>" + hero.ChampionName +
                                               "</font> <font color=\"#FFFFFF\">(" + hero.Name + ")" + " : " + rank);
                            }

                            info.Name       = hero.Name;
                            info.herohandle = hero;
                            info.Ranking    = rank;
                            info.lpamount   = "";
                            Ranks.Add(info);
                            Console.WriteLine("Added info" + hero.Name + info.Ranking);
                        }
                        catch (Exception)
                        {
                            info.Name       = hero.Name;
                            info.herohandle = hero;
                            info.Ranking    = "Exception";
                            info.lpamount   = "";
                            Ranks.Add(info);
                            Console.WriteLine("Exception in 4th");
                        }
                    }
                    if (htmlcode.Contains("tierRank") && !htmlcode.Contains("leaguePoints") &&
                        (htmlcode.Contains("ChampionBox Unranked")))
                    {
                        try
                        {
                            Match htmlmatchrank =
                                new Regex(@"\<span class=\""tierRank\"">(.*?)</span>").Matches(htmlcode)[0];
                            Match playerrank = new Regex(htmlmatchrank.Groups[1].ToString()).Matches(htmlcode)[0];

                            rank = "Unranked (L-30)";
                            if (Misc.Config.Item("printranks").GetValue <bool>() && hero.IsAlly)
                            {
                                Game.PrintChat("<font color=\"#FF000\"><b>" + hero.ChampionName +
                                               "</font> <font color=\"#FFFFFF\">(" + hero.Name + ")" + " : " + rank);
                            }
                            if (Misc.Config.Item("printranks").GetValue <bool>() && hero.IsEnemy)
                            {
                                Game.PrintChat("<font color=\"#FF0000\"><b>" + hero.ChampionName +
                                               "</font> <font color=\"#FFFFFF\">(" + hero.Name + ")" + " : " + rank);
                            }
                            info.Name       = hero.Name;
                            info.herohandle = hero;
                            info.Ranking    = rank;
                            info.lpamount   = "";
                            Ranks.Add(info);
                            Console.WriteLine("Added info" + hero.Name + info.Ranking);
                        }
                        catch (Exception)
                        {
                            info.Name       = hero.Name;
                            info.herohandle = hero;
                            info.Ranking    = "Exception";
                            info.lpamount   = "";
                            Ranks.Add(info);
                            Console.WriteLine("Exception in 2nd");
                        }
                    }
                    if ((htmlcode.Contains("ChampionBox Unranked") &&
                         !htmlcode.Contains("leaguePoints") && (!htmlcode.Contains("tierRank"))))
                    {
                        try
                        {
                            rank = "Unranked";
                            if (Misc.Config.Item("printranks").GetValue <bool>() && hero.IsAlly)
                            {
                                Game.PrintChat("<font color=\"#FF000\"><b>" + hero.ChampionName +
                                               "</font> <font color=\"#FFFFFF\">(" + hero.Name + ")" + " : " + rank);
                            }
                            if (Misc.Config.Item("printranks").GetValue <bool>() && hero.IsEnemy)
                            {
                                Game.PrintChat("<font color=\"#FF0000\"><b>" + hero.ChampionName +
                                               "</font> <font color=\"#FFFFFF\">(" + hero.Name + ")" + " : " + rank);
                            }


                            info.Name       = hero.Name;
                            info.herohandle = hero;
                            info.Ranking    = "Unranked";
                            info.lpamount   = "";
                            Ranks.Add(info);
                            Console.WriteLine("Added info" + hero.Name + info.Ranking);
                        }
                        catch (Exception)
                        {
                            info.Name       = hero.Name;
                            info.herohandle = hero;
                            info.Ranking    = "Exception";
                            info.lpamount   = "";
                            Ranks.Add(info);
                            Console.WriteLine("Exception in 3rd");
                        }
                    }



                    if (!htmlcode.Contains("ChampionBox Unranked") &&
                        (!htmlcode.Contains("tierRank")))
                    {
                        try
                        {
                            rank = "Error";
                            if (Misc.Config.Item("printranks").GetValue <bool>() && hero.IsAlly)
                            {
                                Game.PrintChat("<font color=\"#FF000\"><b>" + hero.ChampionName +
                                               "</font> <font color=\"#FFFFFF\">(" + hero.Name + ")" + " : " + rank);
                            }
                            if (Misc.Config.Item("printranks").GetValue <bool>() && hero.IsEnemy)
                            {
                                Game.PrintChat("<font color=\"#FF0000\"><b>" + hero.ChampionName +
                                               "</font> <font color=\"#FFFFFF\">(" + hero.Name + ")" + " : " + rank);
                            }

                            info.Name       = hero.Name;
                            info.herohandle = hero;
                            info.Ranking    = rank;
                            info.lpamount   = "";
                            Ranks.Add(info);
                            Console.WriteLine("Added info" + hero.Name + info.Ranking);
                        }
                        catch (Exception)
                        {
                            info.Name       = hero.Name;
                            info.herohandle = hero;
                            info.Ranking    = "Exception";
                            info.lpamount   = "";
                            Ranks.Add(info);
                            Console.WriteLine("Exception in 4th");
                        }
                    }


                    if ((Misc.Config.Item("enablekdaratio").GetValue <bool>()) ||
                        (Misc.Config.Item("enablewinratio").GetValue <bool>()))
                    {
                        //Console.WriteLine("Starting Debug");
                        string data = "";
                        request =
                            (HttpWebRequest)
                            WebRequest.Create(Misc.getregionurl() + "summoner/champions/userName="******"summoner/champions/userName=Chief Raydere");
                        response = (HttpWebResponse)request.GetResponse();

                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            Stream       receiveStream = response.GetResponseStream();
                            StreamReader readStream    = null;

                            if (response.CharacterSet == null)
                            {
                                readStream = new StreamReader(receiveStream);
                            }
                            else
                            {
                                readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
                            }

                            data = readStream.ReadToEnd();

                            response.Close();
                            readStream.Close();
                        }


                        if (data.Contains("__spc24 __spc24-" + championid(hero) + "\""))
                        {
                            int    index     = data.IndexOf("__spc24 __spc24-" + championid(hero) + "\"");
                            String htmlstats = data.Remove(0, index);
                            index     = htmlstats.IndexOf("gold");
                            htmlstats = htmlstats.Substring(0, index);

                            Match htmlmatchwinRatio =
                                new Regex(@"\<span class=\""winRatio\"">(.*?)</span>").Matches(htmlstats)[0];
                            Match htmlmatchkill =
                                new Regex(@"\<span class=\""kill\"">(.*?)</span>").Matches(htmlstats)[0];
                            Match htmlmatchdeath =
                                new Regex(@"\<span class=\""death\"">(.*?)</span>").Matches(htmlstats)[0];
                            Match htmlmatchassist =
                                new Regex(@"\<span class=\""assist\"">(.*?)</span>").Matches(htmlstats)[0];
                            Match htmlmatchkdaratio =
                                new Regex(@"\<span class=\""kdaratio\"">(.*?)</span>").Matches(htmlstats)[0];

                            Match winRatio = new Regex(htmlmatchwinRatio.Groups[1].ToString()).Matches(htmlstats)[0];
                            Match kill     = new Regex(htmlmatchkill.Groups[1].ToString()).Matches(htmlstats)[0];
                            Match death    = new Regex(htmlmatchdeath.Groups[1].ToString()).Matches(htmlstats)[0];
                            Match assist   = new Regex(htmlmatchassist.Groups[1].ToString()).Matches(htmlstats)[0];
                            Match kdaratio = new Regex(htmlmatchkdaratio.Groups[1].ToString()).Matches(htmlstats)[0];

                            index     = htmlstats.IndexOf("wins");
                            htmlstats = htmlstats.Remove(0, (index + 6));
                            index     = htmlstats.IndexOf("</span>");
                            String wins = htmlstats.Substring(0, index);
                            wins = wins.Trim();
                            int Length = wins.Length;
                            wins = wins.Substring(0, Length - 1);

                            index     = htmlstats.IndexOf("losses");
                            htmlstats = htmlstats.Remove(0, (index + 8));
                            index     = htmlstats.IndexOf("</span>");
                            String losses = htmlstats.Substring(0, index);
                            losses = losses.Trim();
                            Length = losses.Length;
                            losses = losses.Substring(0, Length - 1);

                            String winratioString = ("Win Ratio (champ) = " + winRatio + " (" + wins + "/" + losses +
                                                     ")");

                            String kdaString = ("KDA = " + kdaratio + " (" + kill + "K + " + assist + "A / " + death +
                                                "D)");


                            if (kdaratio.ToString().Contains("."))
                            {
                                index = kdaratio.ToString().IndexOf(".");
                            }

                            else
                            {
                                index = kdaratio.ToString().IndexOf(":");
                            }
                            String kdaratio2     = kdaratio.ToString().Substring(0, index);
                            int    kdaratiocolor = 0;

                            if (Int32.TryParse(kdaratio2, out kdaratiocolor))
                            {
                                //Console.WriteLine(kdaratiocolor);
                                if (kdaratiocolor > 8)
                                {
                                    info.kdaratiocolor = Color.Orange; //Challenger
                                }
                                if (kdaratiocolor >= 6 && kdaratiocolor < 8)
                                {
                                    info.kdaratiocolor = Color.LimeGreen; //Master
                                }
                                if (kdaratiocolor >= 4 && kdaratiocolor < 6)
                                {
                                    info.kdaratiocolor = Color.Cyan; //Diamond
                                }
                                if (kdaratiocolor >= 3 && kdaratiocolor < 4)
                                {
                                    info.kdaratiocolor = Color.DeepSkyBlue; //Platinum
                                }
                                if (kdaratiocolor >= 2 && kdaratiocolor < 3)
                                {
                                    info.kdaratiocolor = Color.Gold; //Gold
                                }
                                if (kdaratiocolor >= 1 && kdaratiocolor < 2)
                                {
                                    info.kdaratiocolor = Color.Silver; //Silver
                                }
                                if (kdaratiocolor < 1)
                                {
                                    info.kdaratiocolor = Color.SandyBrown; //Bronze
                                }
                            }

                            string stringwinratio       = winRatio.ToString();
                            string winrateremovepercent = stringwinratio.Replace("%", "");
                            double winratio             = Convert.ToInt32(winrateremovepercent);
                            info.winratiocolor = colorwinratio(winratio);
                            info.winratio      = winratioString;
                            info.kdaratio      = kdaString;
                            Ranks.Add(info);
                        }
                        else
                        {
                            info.winratio      = "error";
                            info.kdaratio      = "error";
                            info.winratiocolor = Color.White;
                            Ranks.Add(info);
                        }
                    }
                }
            }
        }