コード例 #1
0
        /// <summary>
        ///     Creates a new trade offer with a token
        /// </summary>
        /// <param name="message">A message to include with the trade offer</param>
        /// <param name="otherSteamId">The SteamID of the partner we are trading with</param>
        /// <param name="status">The list of items we and they are going to trade</param>
        /// <param name="token">The token of the partner we are trading with</param>
        /// <returns>True if successfully returns a newTradeOfferId, else false</returns>
        public string SendTradeOfferWithToken(string message, SteamID otherSteamId, TradeStatus status, string token)
        {
            if (string.IsNullOrEmpty(token))
            {
                throw new ArgumentNullException(nameof(token), @"Partner trade offer token is missing");
            }

            var offerToken = new OfferAccessToken {
                TradeOfferAccessToken = token
            };

            var data = new NameValueCollection
            {
                { "sessionid", this._sessionId },
                { "captcha", string.Empty },
                { "serverid", "1" },
                { "partner", otherSteamId.ConvertToUInt64().ToString() },
                { "tradeoffermessage", message },
                { "json_tradeoffer", JsonConvert.SerializeObject(status, this.JsonSerializerSettings) },
                {
                    "trade_offer_create_params",
                    JsonConvert.SerializeObject(offerToken, this.JsonSerializerSettings)
                }
            };

            var referer = $"https://steamcommunity.com/tradeoffer/new/?partner={otherSteamId.AccountID}&token={token}";

            return(this.Request(SendUrl, data, referer));
        }
コード例 #2
0
        /// <summary>
        ///     Creates a new counter offer
        /// </summary>
        /// <param name="message">A message to include with the trade offer</param>
        /// <param name="otherSteamId">The SteamID of the partner we are trading with</param>
        /// <param name="status">The list of items we and they are going to trade</param>
        /// <param name="newTradeOfferId">The trade offer Id that will be created if successful</param>
        /// <param name="tradeOfferId">The trade offer Id of the offer being countered</param>
        /// <returns></returns>
        public bool CounterOffer(string message, SteamID otherSteamId, TradeStatus status,
                                 out string newTradeOfferId, string tradeOfferId)
        {
            if (string.IsNullOrEmpty(tradeOfferId))
            {
                throw new ArgumentNullException("tradeOfferId", @"Trade Offer Id must be set for counter offers.");
            }

            var data = new NameValueCollection
            {
                { "sessionid", _sessionId },
                { "serverid", "1" },
                { "partner", otherSteamId.ConvertToUInt64().ToString() },
                { "tradeoffermessage", message },
                { "json_tradeoffer", JsonConvert.SerializeObject(status, JsonSerializerSettings) },
                { "tradeofferid_countered", tradeOfferId },
                { "trade_offer_create_params", "{}" }
            };

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

            if (!Request(SendUrl, data, referer, tradeOfferId, out newTradeOfferId))
            {
                var state = _webApi.GetOfferState(tradeOfferId);
                if (state == TradeOfferState.TradeOfferStateCountered)
                {
                    return(true);
                }
                return(false);
            }

            return(true);
        }
コード例 #3
0
 public TradeOffer(OfferSession session, SteamID partnerSteamdId)
 {
     Items          = new TradeStatus();
     IsOurOffer     = true;
     OfferState     = TradeOfferState.TradeOfferStateUnknown;
     Session        = session;
     PartnerSteamId = partnerSteamdId;
 }
コード例 #4
0
        public TradeOffer(OfferSession session, Offer offer)
        {
            var myAssets           = new List <TradeAsset>();
            var myMissingAssets    = new List <TradeAsset>();
            var theirAssets        = new List <TradeAsset>();
            var theirMissingAssets = new List <TradeAsset>();

            if (offer.ItemsToGive != null)
            {
                foreach (var asset in offer.ItemsToGive)
                {
                    var tradeAsset = new TradeAsset();
                    //todo: for currency items we need to check descriptions for currency bool and use the appropriate method
                    tradeAsset.CreateItemAsset(Convert.ToInt64(asset.AppId), Convert.ToInt64(asset.ContextId),
                                               Convert.ToInt64(asset.AssetId), Convert.ToInt64(asset.Amount));
                    //todo: for missing assets we should store them somewhere else? if offer state is active we shouldn't be here though
                    if (!asset.IsMissing)
                    {
                        myAssets.Add(tradeAsset);
                    }
                    else
                    {
                        myMissingAssets.Add(tradeAsset);
                    }
                }
            }

            if (offer.ItemsToReceive != null)
            {
                foreach (var asset in offer.ItemsToReceive)
                {
                    var tradeAsset = new TradeAsset();
                    tradeAsset.CreateItemAsset(Convert.ToInt64(asset.AppId), Convert.ToInt64(asset.ContextId),
                                               Convert.ToInt64(asset.AssetId), Convert.ToInt64(asset.Amount));
                    if (!asset.IsMissing)
                    {
                        theirAssets.Add(tradeAsset);
                    }
                    else
                    {
                        theirMissingAssets.Add(tradeAsset);
                    }
                }
            }

            Session = session;
            //assume public individual
            PartnerSteamId = new SteamID(Convert.ToUInt32(offer.AccountIdOther), EUniverse.Public,
                                         EAccountType.Individual);
            TradeOfferId   = offer.TradeOfferId;
            OfferState     = offer.TradeOfferState;
            IsOurOffer     = offer.IsOurOffer;
            ExpirationTime = offer.ExpirationTime;
            TimeCreated    = offer.TimeCreated;
            TimeUpdated    = offer.TimeUpdated;
            Message        = offer.Message;
            Items          = new TradeStatus(myAssets, theirAssets);
        }
コード例 #5
0
        /// <summary>
        ///     Creates a new trade offer
        /// </summary>
        /// <param name="message">A message to include with the trade offer</param>
        /// <param name="otherSteamId">The SteamID of the partner we are trading with</param>
        /// <param name="status">The list of items we and they are going to trade</param>
        /// <returns>True if successfully returns a newTradeOfferId, else false</returns>
        public string SendTradeOffer(string message, SteamID otherSteamId, TradeStatus status)
        {
            var data = new NameValueCollection
            {
                { "sessionid", this._sessionId },
                { "serverid", "1" },
                { "partner", otherSteamId.ConvertToUInt64().ToString() },
                { "tradeoffermessage", message },
                { "json_tradeoffer", JsonConvert.SerializeObject(status, this.JsonSerializerSettings) },
                { "trade_offer_create_params", "{}" }
            };

            var referer = string.Format(
                "https://steamcommunity.com/tradeoffer/new/?partner={0}",
                otherSteamId.AccountID);

            return(this.Request(SendUrl, data, referer));
        }