Example #1
0
        public static CsgoLastMatches GetMatches(ulong id)
        {
            IEnumerable <CsgoLastMatches> result = from a in matches
                                                   where a.steamid == id
                                                   select a;
            CsgoLastMatches match = result.FirstOrDefault();

            return(match);
        }
Example #2
0
        public static void AddLastMatchesToStorage(CsgoLastMatches lastMatches)
        {
            bool accountActive = false;
            int  index         = 0;

            for (int i = 0; i < matches.Count; i++)
            {
                if (matches[i].discordid == lastMatches.discordid)
                {
                    accountActive = true;
                    index         = i;
                    break;
                }
            }
            if (accountActive)
            {
                bool isAvailable = true;
                if (matches[index].steamid == lastMatches.steamid)
                {
                    List <CsgoLastMatch> list = matches[index].lastmatches;
                    for (int i = 0; i < list.Count; i++)
                    {
                        if (list[i].id == lastMatches.lastmatches[0].id)
                        {
                            isAvailable = false;
                        }
                    }
                    if (isAvailable)
                    {
                        matches[index].lastmatches.Add(lastMatches.lastmatches[0]);
                    }
                }
            }
            else
            {
                matches.Add(lastMatches);
            }

            SaveData();
        }
Example #3
0
        public static CsgoLastMatch GetCSGOLastMatch(SocketUser user, ulong SteamID)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Global.csgoURL + SteamID);

            request.ContentType = "application/json; charset=utf-8";
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            string          data     = "";

            using (Stream responseStream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                data = reader.ReadToEnd();
            }

            Dictionary <string, PlayerStats> r = JsonConvert.DeserializeObject <Dictionary <string, PlayerStats> >(data);
            string      msg   = "";
            PlayerStats stats = r["playerstats"];

            string[] wantedStats = { "last_match_rounds",          "last_match_contribution_score", "last_match_wins",   "last_match_t_wins",      "last_match_ct_wins",     "last_match_kills",
                                     "last_match_deaths",          "last_match_mvps",               "last_match_damage", "last_match_money_spent", "last_match_dominations", "last_match_revenges","last_match_favweapon_id",
                                     "last_match_favweapon_shots", "last_match_favweapon_hits",     "last_match_favweapon_kills" };

            string[] formattedStats = { "Rounds",                "Contribution Score",   "Wins",   "Terrorist Wins", "Counter-Terrorist Wins", "Kills",
                                        "Deaths",                "MVPs",                 "Damage", "Money Spent",    "Dominations",            "Revenges","Favorite Weapon",
                                        "Favorite Weapon Shots", "Favorite Weapon Hits", "Favorite Weapon Kills" };

            int           max            = stats.stats.Count - 1;
            float         kills          = 0;
            float         deaths         = 0;
            float         KD             = 0;
            float         shots          = 0;
            float         hits           = 0;
            float         accuracy       = 0;
            float         rounds         = 0;
            SteamAccount  steamaccount   = GetAccount(user);
            CsgoLastMatch lastmatch      = new CsgoLastMatch();
            bool          createNewMatch = false;

            if (steamaccount != null)
            {
                if (steamaccount.SteamID == SteamID && steamaccount.DiscordID == user.Id)
                {
                    createNewMatch = true;
                }
            }

            for (int x = 0; x < wantedStats.Length; x++)
            {
                for (int i = 0; i < stats.stats.Count; i++)
                {
                    Stats curStat = stats.stats[i];
                    if (wantedStats[x] == curStat.name)
                    {
                        string value = curStat.value.ToString();
                        string name  = formattedStats[x];

                        if (name == "Revenges")
                        {
                            lastmatch.revenges = (uint)curStat.value;
                        }
                        if (name == "Dominations")
                        {
                            lastmatch.dominations = (uint)curStat.value;
                        }
                        if (name == "Damage")
                        {
                            lastmatch.damage = (uint)curStat.value;
                        }
                        if (name == "MVPs")
                        {
                            lastmatch.mvps = (uint)curStat.value;
                        }
                        if (name == "Contribution Score")
                        {
                            lastmatch.contribution_score = (uint)curStat.value;
                        }
                        if (name == "Terrorist Wins")
                        {
                            lastmatch.t_wins = (uint)curStat.value;
                        }
                        if (name == "Counter-Terrorist Wins")
                        {
                            lastmatch.ct_wins = (uint)curStat.value;
                        }

                        if (name == "Rounds")
                        {
                            rounds           = curStat.value;
                            lastmatch.rounds = (uint)curStat.value;
                        }

                        if (name == "Wins")
                        {
                            lastmatch.losses = uint.Parse((rounds - curStat.value) + "");
                            name             = "Game Outcome";
                            if (curStat.value > lastmatch.losses)
                            {
                                value = "Won";
                            }
                            else if (curStat.value == lastmatch.losses)
                            {
                                value = "Draw";
                            }
                            else
                            {
                                value = "Lost";
                            }

                            lastmatch.wins    = (uint)curStat.value;
                            lastmatch.outcome = value;
                            //Console.WriteLine("Rounds Won:" + curStat.value);
                        }
                        if (name == "Money Spent")
                        {
                            value = string.Format("${0:N2}", float.Parse(value));
                            lastmatch.money_spent = (uint)curStat.value;
                        }

                        if (name == "Kills")
                        {
                            kills           = float.Parse(value);
                            lastmatch.kills = (uint)curStat.value;
                        }

                        if (name == "Favorite Weapon Kills")
                        {
                            lastmatch.favweapon_kills = (uint)curStat.value;
                        }
                        if (name == "Favorite Weapon Shots")
                        {
                            shots = curStat.value;
                            lastmatch.favweapon_shots = (uint)curStat.value;
                        }
                        if (name == "Favorite Weapon")
                        {
                            value = getGunName(int.Parse(value));
                            lastmatch.favweapon_name = value;
                        }
                        msg += "**" + name + "**: " + value + "\n";
                        if (name == "Deaths")
                        {
                            deaths           = float.Parse(value);
                            KD               = kills / deaths;
                            msg             += "**K/D Ratio**: " + string.Format("{0:N2}", KD) + "\n";
                            lastmatch.deaths = (uint)curStat.value;
                            lastmatch.kd     = KD;
                        }
                        if (name == "Favorite Weapon Hits")
                        {
                            hits     = curStat.value;
                            accuracy = hits / shots * 100f;
                            msg     += string.Format("**Favorite Weapon Accuracy:** {0:N2}%\n", accuracy);
                            lastmatch.favweapon_hits = (uint)curStat.value;
                            lastmatch.accuracy       = accuracy;
                        }
                    }
                }
            }
            if (createNewMatch)
            {
                CsgoLastMatches matches = new CsgoLastMatches();
                matches.steamid   = SteamID;
                matches.discordid = user.Id;
                matches.username  = user.Username;
                if (matches.lastmatches == null)
                {
                    matches.lastmatches = new List <CsgoLastMatch>();
                }
                for (int i = 0; i < SteamData.matches.Count; i++)
                {
                    while (SteamData.matches[i].lastmatches.Count > 10)
                    {
                        SteamData.matches[i].lastmatches.RemoveAt(0);
                    }
                }
                lastmatch.createID();
                matches.lastmatches.Add(lastmatch);
                SteamData.AddLastMatchesToStorage(matches);
                Console.WriteLine("Created new match and Saved to User: " + user.Username);
            }
            //Console.WriteLine(msg);
            return(lastmatch);
        }