Beispiel #1
0
        public static SteamAccount GetAccount(SocketUser user)
        {
            IEnumerable <SteamAccount> result = from a in accounts
                                                where a.DiscordID == user.Id
                                                select a;

            SteamAccount account = result.FirstOrDefault();

            //return account
            return(account);
        }
Beispiel #2
0
        private static SteamAccount CreateAccount(ulong steamID, ulong discordID, string discordUsername)
        {
            SteamAccount newAcct = new SteamAccount()
            {
                SteamID         = steamID,
                DiscordID       = discordID,
                DiscordUsername = discordUsername,
                SteamUsername   = GetAccountObject(steamID).personaname
            };

            accounts.Add(newAcct);
            SaveAccounts();
            return(newAcct);
        }
Beispiel #3
0
        private static SteamAccount GetOrCreateAcount(ulong steamID, ulong discordID, string discordName)
        {
            IEnumerable <SteamAccount> result = from a in accounts
                                                where a.SteamID == steamID
                                                select a;

            SteamAccount account = result.FirstOrDefault();

            if (account == null)
            {
                account = CreateAccount(steamID, discordID, discordName);
            }

            //return account
            return(account);
        }
Beispiel #4
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);
        }