コード例 #1
0
ファイル: OfferSession.cs プロジェクト: Cimera42/SteamBot
        public bool Accept(string tradeOfferId, out string tradeId)
        {
            tradeId = "";
            var data = new NameValueCollection();

            data.Add("sessionid", steamWeb.SessionId);
            data.Add("serverid", "1");
            data.Add("tradeofferid", tradeOfferId);

            string url     = string.Format("https://steamcommunity.com/tradeoffer/{0}/accept", tradeOfferId);
            string referer = string.Format("https://steamcommunity.com/tradeoffer/{0}/", tradeOfferId);

            string resp = steamWeb.Fetch(url, "POST", data, false, referer);

            if (!String.IsNullOrEmpty(resp))
            {
                try
                {
                    var result = JsonConvert.DeserializeObject <TradeOfferAcceptResponse>(resp);
                    if (!String.IsNullOrEmpty(result.TradeId))
                    {
                        tradeId = result.TradeId;
                        return(true);
                    }
                    //todo: log the error
                    Debug.WriteLine(result.TradeError);
                }
                catch (JsonException jsex)
                {
                    Debug.WriteLine(jsex);
                }
            }
            else
            {
                var state = webApi.GetOfferState(tradeOfferId);
                if (state == TradeOfferState.TradeOfferStateAccepted)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
ファイル: OfferSession.cs プロジェクト: kgns/ASteambotOld
        public TradeOfferAcceptResponse Accept(string tradeOfferId)
        {
            var data = new NameValueCollection();

            data.Add("sessionid", steamWeb.SessionId);
            data.Add("serverid", "1");
            data.Add("tradeofferid", tradeOfferId);

            string url     = string.Format("https://steamcommunity.com/tradeoffer/{0}/accept", tradeOfferId);
            string referer = string.Format("https://steamcommunity.com/tradeoffer/{0}/", tradeOfferId);

            string resp = steamWeb.Fetch(url, "POST", data, false, referer, true);

            if (!String.IsNullOrEmpty(resp))
            {
                try
                {
                    var res = JsonConvert.DeserializeObject <TradeOfferAcceptResponse>(resp);
                    //steam can return 'null' response
                    if (res != null)
                    {
                        res.Accepted = string.IsNullOrEmpty(res.TradeError);
                        return(res);
                    }
                }
                catch (JsonException)
                {
                    return(new TradeOfferAcceptResponse {
                        TradeError = "Error parsing server response: " + resp
                    });
                }
            }
            //if it didn't work as expected, check the state, maybe it was accepted after all
            var state = webApi.GetOfferState(tradeOfferId);

            return(new TradeOfferAcceptResponse {
                Accepted = state == TradeOfferState.TradeOfferStateAccepted
            });
        }
コード例 #3
0
ファイル: OfferSession.cs プロジェクト: Noobgam/MarketBot
        public bool Decline(string tradeOfferId)
        {
            var data = new NameValueCollection();

            data.Add("sessionid", steamWeb.SessionId);
            data.Add("serverid", "1");
            data.Add("tradeofferid", tradeOfferId);

            string url = string.Format("https://steamcommunity.com/tradeoffer/{0}/decline", tradeOfferId);
            //should be https://steamcommunity.com/{0}/{1}/tradeoffers - id/profile persona/id64 ideally
            string referer = string.Format("https://steamcommunity.com/tradeoffer/{0}/", tradeOfferId);

            var resp = steamWeb.Fetch(url, "POST", data, false, referer);

            if (!String.IsNullOrEmpty(resp))
            {
                try
                {
                    var json = JsonConvert.DeserializeObject <NewTradeOfferResponse>(resp);
                    if (json.TradeOfferId != null && json.TradeOfferId == tradeOfferId)
                    {
                        return(true);
                    }
                }
                catch (JsonException jsex)
                {
                    Debug.WriteLine(jsex);
                }
            }
            else
            {
                var state = webApi.GetOfferState(tradeOfferId);
                if (state == TradeOfferState.TradeOfferStateDeclined)
                {
                    return(true);
                }
            }
            return(false);
        }