private async Task <bool> UnlockParentalAccount(string parentalPin)
        {
            if (string.IsNullOrEmpty(parentalPin) || parentalPin.Equals("0"))
            {
                return(true);
            }

            Logging.LogGenericInfo("Unlocking parental account...", Bot.BotName);
            Dictionary <string, string> data = new Dictionary <string, string>(1)
            {
                { "pin", parentalPin }
            };

            string referer = SteamCommunityURL;
            string request = referer + "/parental/ajaxunlock";

            HttpResponseMessage response = null;

            for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++)
            {
                response = await WebBrowser.UrlPost(request, data, Cookie, referer).ConfigureAwait(false);
            }

            if (response == null)
            {
                Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
                return(false);
            }

            IEnumerable <string> setCookieValues;

            if (!response.Headers.TryGetValues("Set-Cookie", out setCookieValues))
            {
                Logging.LogNullError("setCookieValues", Bot.BotName);
                return(false);
            }

            foreach (string setCookieValue in setCookieValues)
            {
                if (!setCookieValue.Contains("steamparental="))
                {
                    continue;
                }

                string setCookie = setCookieValue.Substring(setCookieValue.IndexOf("steamparental=", StringComparison.Ordinal) + 14);

                int index = setCookie.IndexOf(';');
                if (index > 0)
                {
                    setCookie = setCookie.Substring(0, index);
                }

                Cookie["steamparental"] = setCookie;
                Logging.LogGenericInfo("Success!", Bot.BotName);
                return(true);
            }

            Logging.LogGenericWarning("Failed to unlock parental account!", Bot.BotName);
            return(false);
        }
        internal async Task <bool> AcceptGift(ulong gid)
        {
            if (gid == 0)
            {
                return(false);
            }

            if (!await RefreshSessionIfNeeded().ConfigureAwait(false))
            {
                return(false);
            }

            string sessionID = WebBrowser.CookieContainer.GetCookieValue(SteamCommunityURL, "sessionid");

            if (string.IsNullOrEmpty(sessionID))
            {
                Logging.LogNullError("sessionID");
                return(false);
            }

            string request = SteamCommunityURL + "/gifts/" + gid + "/acceptunpack";
            Dictionary <string, string> data = new Dictionary <string, string>(1)
            {
                { "sessionid", sessionID }
            };

            bool result = false;

            for (byte i = 0; (i < WebBrowser.MaxRetries) && !result; i++)
            {
                result = await WebBrowser.UrlPost(request, data).ConfigureAwait(false);
            }

            if (result)
            {
                return(true);
            }

            Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
            return(false);
        }
Example #3
0
        private async Task UnlockParentalAccount(string parentalPin)
        {
            if (string.IsNullOrEmpty(parentalPin) || parentalPin.Equals("0"))
            {
                return;
            }

            Logging.LogGenericInfo("Unlocking parental account...", Bot.BotName);
            Dictionary <string, string> data = new Dictionary <string, string>(1)
            {
                { "pin", parentalPin }
            };

            HttpResponseMessage response = null;

            for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++)
            {
                response = await WebBrowser.UrlPost("https://steamcommunity.com/parental/ajaxunlock", data, Cookie, "https://steamcommunity.com/").ConfigureAwait(false);
            }

            if (response == null)
            {
                Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
                return;
            }

            IEnumerable <string> setCookieValues;

            if (!response.Headers.TryGetValues("Set-Cookie", out setCookieValues))
            {
                Logging.LogNullError("setCookieValues", Bot.BotName);
                return;
            }

            foreach (string setCookieValue in setCookieValues)
            {
                if (setCookieValue.Contains("steamparental="))
                {
                    string setCookie = setCookieValue.Substring(setCookieValue.IndexOf("steamparental=") + 14);
                    setCookie = setCookie.Substring(0, setCookie.IndexOf(';'));
                    Cookie["steamparental"] = setCookie;
                    Logging.LogGenericInfo("Success!", Bot.BotName);
                    return;
                }
            }

            Logging.LogGenericWarning("Failed to unlock parental account!", Bot.BotName);
        }
        internal async Task <bool> AcceptTradeOffer(ulong tradeID)
        {
            if (tradeID == 0)
            {
                return(false);
            }

            if (!await RefreshSessionIfNeeded().ConfigureAwait(false))
            {
                return(false);
            }

            string sessionID;

            if (!Cookie.TryGetValue("sessionid", out sessionID))
            {
                return(false);
            }

            string referer = SteamCommunityURL + "/tradeoffer/" + tradeID;
            string request = referer + "/accept";

            Dictionary <string, string> data = new Dictionary <string, string>(3)
            {
                { "sessionid", sessionID },
                { "serverid", "1" },
                { "tradeofferid", tradeID.ToString() }
            };

            HttpResponseMessage response = null;

            for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++)
            {
                response = await WebBrowser.UrlPost(request, data, Cookie, referer).ConfigureAwait(false);
            }

            if (response == null)
            {
                Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
                return(false);
            }

            return(true);
        }
        internal async Task <bool> JoinClan(ulong clanID)
        {
            if (clanID == 0)
            {
                return(false);
            }

            if (!await RefreshSessionIfNeeded().ConfigureAwait(false))
            {
                return(false);
            }

            string sessionID;

            if (!Cookie.TryGetValue("sessionid", out sessionID))
            {
                return(false);
            }

            string request = SteamCommunityURL + "/gid/" + clanID;

            Dictionary <string, string> data = new Dictionary <string, string>(2)
            {
                { "sessionID", sessionID },
                { "action", "join" }
            };

            HttpResponseMessage response = null;

            for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++)
            {
                response = await WebBrowser.UrlPost(request, data, Cookie).ConfigureAwait(false);
            }

            if (response == null)
            {
                Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
                return(false);
            }

            return(true);
        }
Example #6
0
        internal async Task <bool> SendTradeOffer(List <Steam.Item> inventory, ulong partnerID, string token = null)
        {
            if (inventory == null || inventory.Count == 0 || partnerID == 0)
            {
                return(false);
            }

            string sessionID;

            if (!Cookie.TryGetValue("sessionid", out sessionID))
            {
                return(false);
            }

            List <Steam.TradeOfferRequest> trades = new List <Steam.TradeOfferRequest>(1 + inventory.Count / Trading.MaxItemsPerTrade);

            Steam.TradeOfferRequest singleTrade = null;
            for (ushort i = 0; i < inventory.Count; i++)
            {
                if (i % Trading.MaxItemsPerTrade == 0)
                {
                    if (trades.Count >= Trading.MaxTradesPerAccount)
                    {
                        break;
                    }

                    singleTrade = new Steam.TradeOfferRequest();
                    trades.Add(singleTrade);
                }

                Steam.Item item = inventory[i];
                singleTrade.me.assets.Add(new Steam.Item()
                {
                    appid     = "753",
                    contextid = "6",
                    amount    = item.amount,
                    assetid   = item.id
                });
            }

            string referer = SteamCommunityURL + "/tradeoffer/new";
            string request = referer + "/send";

            foreach (Steam.TradeOfferRequest trade in trades)
            {
                Dictionary <string, string> data = new Dictionary <string, string>(6)
                {
                    { "sessionid", sessionID },
                    { "serverid", "1" },
                    { "partner", partnerID.ToString() },
                    { "tradeoffermessage", "Sent by ASF" },
                    { "json_tradeoffer", JsonConvert.SerializeObject(trade) },
                    { "trade_offer_create_params", string.IsNullOrEmpty(token) ? "" : $"{{\"trade_offer_access_token\":\"{token}\"}}" }
                };

                HttpResponseMessage response = null;
                for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++)
                {
                    response = await WebBrowser.UrlPost(request, data, Cookie, referer).ConfigureAwait(false);
                }

                if (response == null)
                {
                    Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries", Bot.BotName);
                    return(false);
                }
            }

            return(true);
        }