示例#1
0
        /// <summary>
        /// Sends a trade offer to the specified recipient.
        /// </summary>
        /// <param name="partnerSid">The SteamId64 (ulong) of the person to send the offer to.</param>
        /// <param name="tradeoffermessage">An optional message to be sent with the offer. Can be null.</param>
        /// <param name="serverid">Almost always 1, not quite sure what other numbers do.</param>
        /// <param name="offer">A TradeOffer object containing the trade parameters.</param>
        /// <param name="container">Auth Cookies MUST be passed here, the function will fail if not.</param>
        /// <returns>A SendOfferResponse object.</returns>
        public SendOfferResponse SendTradeOffer(ulong partnerSid, string tradeoffermessage,
                                                string serverid, TradeOffer offer, CookieContainer container)
        {
            const string url = "https://steamcommunity.com/tradeoffer/new/send";

            container.Add(new Cookie("bCompletedTradeOfferTutorial", "true")
            {
                Domain = "steamcommunity.com"
            });
            string sessionid = (from Cookie cookie in container.GetCookies(new Uri("https://steamcommunity.com"))
                                where cookie.Name == "sessionid"
                                select cookie.Value).FirstOrDefault();

            var data = new Dictionary <string, string>
            {
                { "sessionid", sessionid },
                { "serverid", serverid },
                { "partner", partnerSid.ToString() },
                { "tradeoffermessage", tradeoffermessage },
                { "json_tradeoffer", JsonConvert.SerializeObject(offer) },
                { "captcha", string.Empty },
                { "trade_offer_create_params", "{}" }
            };

            return(_web.RetryFetch(TimeSpan.FromSeconds(10), 20, url, "POST", data, container, false,
                                   "https://steamcommunity.com/tradeoffer/new/?partner=" +
                                   IdConversions.UlongToAccountId(partnerSid))
                   .DeserializeJson <SendOfferResponse>());
        }
示例#2
0
        /// <summary>
        /// Requests group information as well as all pages of users.
        /// </summary>
        /// <param name="groupId">The SteamId64 of the group to request information about.</param>
        /// <param name="retryWait">The number of miliseconds to wait between each retry.</param>
        /// <param name="retryCount">The number of times to retry before inserting a null MemberList object.</param>
        /// <returns>A List of the MemberList object.</returns>
        public List <MemberList> RequestAllMemberLists(ulong groupId, TimeSpan retryWait, int retryCount = 10)
        {
            var          membersList = new List <MemberList>();
            const string url         = "http://steamcommunity.com/gid/{0}/memberslistxml/?xml=1&p={1}";

            int  count        = 1;
            int  totalPages   = 1;
            bool firstRequest = false;

            do
            {
                string requestUrl = string.Format(url, groupId, count);

                try
                {
                    IResponse fetched = _web.RetryFetch(retryWait, retryCount,
                                                        requestUrl, "GET");

                    var populatedList = fetched.DeserializeXml <MemberList>();

                    membersList.Add(populatedList);

                    if (!firstRequest)
                    {
                        firstRequest = true;
                        totalPages   = populatedList.TotalPages;
                    }
                }
                catch (WebException)
                {
                    membersList.Add(null);
                }
                catch (NullReferenceException)
                {
                    membersList.Add(null);
                }
                Thread.Sleep(1000);

                count++;
            } while (totalPages >= count);

            return(membersList);
        }