Esempio n. 1
0
        public bool RemoveTheirItem(int appId, long contextId, long assetId, long amount = 1)
        {
            var asset = new TradeAsset();

            asset.CreateItemAsset(appId, contextId, assetId, amount);
            return(ShouldUpdate(TheirOfferedItems.RemoveItem(asset)));
        }
Esempio n. 2
0
        public bool AddTheirCurrencyItem(int appId, long contextId, long currencyId, long amount)
        {
            var asset = new TradeAsset();

            asset.CreateCurrencyAsset(appId, contextId, currencyId, amount);
            return(ShouldUpdate(TheirOfferedItems.AddCurrencyItem(asset)));
        }
Esempio n. 3
0
        public bool AddMyItem(int appId, long contextId, long assetId, long amount = 1)
        {
            var asset = new TradeAsset();

            asset.CreateItemAsset(appId, contextId, assetId, amount);
            return(ShouldUpdate(MyOfferedItems.AddItem(asset)));
        }
Esempio n. 4
0
 public bool Equals(TradeAsset other)
 {
     return((this.appid == other.appid) &&
            (this.contextid == other.contextid) &&
            (this.amount == other.amount) &&
            (this.assetid == other.assetid));
 }
Esempio n. 5
0
        public bool RemoveMyCurrencyItem(int appId, string contextId, long currencyId, long amount)
        {
            var asset = new TradeAsset();

            asset.CreateCurrencyAsset(appId, contextId, currencyId, amount);
            return(this.ShouldUpdate(this.MyOfferedItems.RemoveCurrencyItem(asset)));
        }
Esempio n. 6
0
        public bool AddTheirItem(int appId, string contextId, string assetId, long amount = 1)
        {
            var asset = new TradeAsset();

            asset.CreateItemAsset(appId, contextId, assetId, amount);
            return(this.ShouldUpdate(this.TheirOfferedItems.AddItem(asset)));
        }
Esempio n. 7
0
        public TradeOffer(OfferSession session, Offer offer)
        {
            var myAssets    = new List <TradeAsset>();
            var theirAssets = 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),
                        asset.ContextId,
                        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);
                    }
                }
            }

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

            this.Session = session;

            // assume public individual
            this.PartnerSteamId = new SteamID(
                Convert.ToUInt32(offer.AccountIdOther),
                EUniverse.Public,
                EAccountType.Individual);
            this.TradeOfferId   = offer.TradeOfferId;
            this.OfferState     = offer.TradeOfferState;
            this.IsOurOffer     = offer.IsOurOffer;
            this.ExpirationTime = offer.ExpirationTime;
            this.TimeCreated    = offer.TimeCreated;
            this.TimeUpdated    = offer.TimeUpdated;
            this.Message        = offer.Message;
            this.Items          = new TradeStatus(myAssets, theirAssets);
        }
Esempio n. 8
0
 internal bool AddCurrencyItem(TradeAsset asset)
 {
     if (!Currency.Contains(asset))
     {
         Currency.Add(asset);
         return(true);
     }
     return(false);
 }
Esempio n. 9
0
 internal bool AddItem(TradeAsset asset)
 {
     if (!Assets.Contains(asset))
     {
         Assets.Add(asset);
         return(true);
     }
     return(false);
 }
Esempio n. 10
0
 public bool AddItem(TradeAsset asset)
 {
     if (!assets.Contains(asset))
     {
         tradeStatus.version++;
         assets.Add(asset);
         return(true);
     }
     return(false);
 }
Esempio n. 11
0
                public override bool Equals(object obj)
                {
                    if (obj == null)
                    {
                        return(false);
                    }

                    TradeAsset other = obj as TradeAsset;

                    if ((Object)other == null)
                    {
                        return(false);
                    }

                    return(Equals(other));
                }
Esempio n. 12
0
        public bool TryGetTheirItem(int appId, string contextId, string assetId, long amount, out TradeAsset asset)
        {
            var tradeAsset = new TradeAsset
            {
                AppId = appId, Amount = amount, AssetId = assetId, ContextId = contextId
            };

            asset = new TradeAsset();
            foreach (var item in this.TheirOfferedItems.Assets)
            {
                if (item.Equals(tradeAsset))
                {
                    asset = item;
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 13
0
        public bool TryGetTheirCurrencyItem(int appId, long contextId, long currencyId, long amount,
                                            out TradeAsset asset)
        {
            var tradeAsset = new TradeAsset
            {
                AppId      = appId,
                Amount     = amount,
                CurrencyId = currencyId,
                ContextId  = contextId
            };

            asset = new TradeAsset();
            foreach (var item in TheirOfferedItems.Currency)
            {
                if (item.Equals(tradeAsset))
                {
                    asset = item;
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 14
0
 internal bool RemoveItem(TradeAsset asset)
 {
     return(Assets.Contains(asset) && Assets.Remove(asset));
 }
Esempio n. 15
0
 /// <summary>
 /// Add a bot's item to the trade offer.
 /// </summary>
 /// <param name="asset">TradeAsset object</param>
 /// <returns>True if item hasn't been added already, false if it has.</returns>
 public bool AddMyItem(TradeAsset asset)
 {
     return(tradeStatus.me.AddItem(asset));
 }
Esempio n. 16
0
 /// <summary>
 /// Add a user's item to the trade offer.
 /// </summary>
 /// <param name="asset">TradeAsset object</param>
 /// <returns>True if item hasn't been added already, false if it has.</returns>
 public bool AddOtherItem(TradeAsset asset)
 {
     return tradeStatus.them.AddItem(asset);
 }
Esempio n. 17
0
            /// <summary>
            /// Send the current trade offer.
            /// </summary>
            /// <param name="message">Message to send with trade offer.</param>
            /// <param name="token">Optional trade offer token.</param>
            /// <returns>-1 if response fails to deserialize (general error), 0 if no tradeofferid exists (Steam error), or the Trade Offer ID of the newly created trade offer.</returns>
            public ulong SendTrade(string message, string token = "")
            {
                var url     = "https://steamcommunity.com/tradeoffer/new/send";
                var referer = "http://steamcommunity.com/tradeoffer/new/?partner=" + partnerId.AccountID;
                var data    = new NameValueCollection();

                data.Add("sessionid", sessionId);
                data.Add("partner", partnerId.ConvertToUInt64().ToString());
                data.Add("tradeoffermessage", message);
                data.Add("json_tradeoffer", JsonConvert.SerializeObject(this.tradeStatus));
                data.Add("trade_offer_create_params", token == "" ? "{}" : "{\"trade_offer_access_token\":\"" + token + "\"}");
                try
                {
                    string result = "";
                    for (int i = 0; i < 10; i++)
                    {
                        try
                        {
                            var response = SteamWeb.Request(url, "POST", data, cookies, true, referer);
                            using (System.IO.Stream responseStream = response.GetResponseStream())
                            {
                                using (var reader = new System.IO.StreamReader(responseStream))
                                {
                                    result = reader.ReadToEnd();
                                    if (string.IsNullOrEmpty(result))
                                    {
                                        Console.WriteLine("Web request failed (status: {0}). Retrying...", response.StatusCode);
                                        System.Threading.Thread.Sleep(1000);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        catch (WebException ex)
                        {
                            try
                            {
                                int statusCode = 0;
                                if (ex.Status == WebExceptionStatus.ProtocolError)
                                {
                                    statusCode = (int)((HttpWebResponse)ex.Response).StatusCode;
                                    Console.WriteLine("Status Code: {0}, {1}", statusCode, ((HttpWebResponse)ex.Response).StatusDescription);
                                }
                                string errorMessage = new System.IO.StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
                                Console.WriteLine("Error: {0}", errorMessage);
                                if (statusCode == 500 && errorMessage.Contains("There was an error sending your trade offer."))
                                {
                                    var errorJson = JsonConvert.DeserializeObject <dynamic>(errorMessage);
                                    if (errorJson.strError != null)
                                    {
                                        string errorString = errorJson.strError;
                                        int    errorCode   = Convert.ToInt32(errorString.Split(new char[] { '(', ')' })[1]);
                                        if (errorCode == 16 || errorCode == 11)
                                        {
                                            Console.WriteLine("Encountered Steam error code {0}, manually checking for completion...", errorCode);
                                            var tradeOfferList = tradeOffers.GetTradeOffers();
                                            foreach (var tradeOffer in tradeOfferList)
                                            {
                                                if (tradeStatus.me.assets.Count == tradeOffer.ItemsToGive.Length && tradeStatus.them.assets.Count == tradeOffer.ItemsToReceive.Length)
                                                {
                                                    foreach (var item in tradeOffer.ItemsToGive)
                                                    {
                                                        var asset = new TradeAsset(item.AppId, Convert.ToInt64(item.ContextId), item.AssetId.ToString(), item.Amount);
                                                        if (!tradeStatus.me.assets.Contains(asset))
                                                        {
                                                            Console.WriteLine("Could not validate that this trade offer was sent successfully. (1)");
                                                            return(0);
                                                        }
                                                    }
                                                    foreach (var item in tradeOffer.ItemsToReceive)
                                                    {
                                                        var asset = new TradeAsset(item.AppId, Convert.ToInt64(item.ContextId), item.AssetId.ToString(), item.Amount);
                                                        if (!tradeStatus.them.assets.Contains(asset))
                                                        {
                                                            Console.WriteLine("Could not validate that this trade offer was sent successfully. (2)");
                                                            return(0);
                                                        }
                                                    }
                                                    Console.WriteLine("Successfully validated!");
                                                    return(tradeOffer.Id);
                                                }
                                            }
                                        }
                                        else if (errorCode == 15)
                                        {
                                            throw new TradeOfferException(errorString, errorCode);
                                        }
                                    }
                                }
                            }
                            catch
                            {
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }
                    var jsonResponse = JsonConvert.DeserializeObject <dynamic>(result);
                    try
                    {
                        return(Convert.ToUInt64(jsonResponse.tradeofferid));
                    }
                    catch
                    {
                        return(0);
                    }
                }
                catch
                {
                    return(0);
                }
            }
Esempio n. 18
0
 public bool AddItem(int appId, ulong contextId, ulong assetId, int amount = 1)
 {
     var asset = new TradeAsset(appId, contextId, assetId, amount);
     return AddItem(asset);
 }
Esempio n. 19
0
 public bool AddItem(TradeAsset asset)
 {
     if (!assets.Contains(asset))
     {
         tradeStatus.version++;
         assets.Add(asset);
         return true;
     }
     return false;
 }
Esempio n. 20
0
 public bool Equals(TradeAsset other)
 {
     return (this.appid == other.appid) &&
             (this.contextid == other.contextid) &&
             (this.amount == other.amount) &&
             (this.assetid == other.assetid);
 }
Esempio n. 21
0
 /// <summary>
 /// Add a user's item to the trade offer.
 /// </summary>
 /// <param name="appId">App ID of item</param>
 /// <param name="contextId">Context ID of item</param>
 /// <param name="assetId">Asset (unique) ID of item</param>
 /// <param name="amount">Amount to add (default = 1)</param>
 /// <returns>True if item hasn't been added already, false if it has.</returns>
 public bool AddOtherItem(int appId, ulong contextId, ulong assetId, int amount = 1)
 {
     var asset = new TradeAsset(appId, contextId, assetId, amount);
     return tradeStatus.them.AddItem(asset);
 }
Esempio n. 22
0
 internal bool RemoveCurrencyItem(TradeAsset asset)
 {
     return(Currency.Contains(asset) && Currency.Remove(asset));
 }
Esempio n. 23
0
 public bool ContainsItem(TradeAsset asset)
 {
     return(Assets.Contains(asset));
 }
Esempio n. 24
0
            public bool AddItem(int appId, ulong contextId, ulong assetId, int amount = 1)
            {
                var asset = new TradeAsset(appId, contextId, assetId, amount);

                return(AddItem(asset));
            }
Esempio n. 25
0
 /// <summary>
 /// Add a user's item to the trade offer.
 /// </summary>
 /// <param name="asset">TradeAsset object</param>
 /// <returns>True if item hasn't been added already, false if it has.</returns>
 public bool AddOtherItem(TradeAsset asset)
 {
     return(tradeStatus.them.AddItem(asset));
 }
Esempio n. 26
0
 /// <summary>
 /// Add a bot's item to the trade offer.
 /// </summary>
 /// <param name="asset">TradeAsset object</param>
 /// <returns>True if item hasn't been added already, false if it has.</returns>
 public bool AddMyItem(TradeAsset asset)
 {
     return tradeStatus.me.AddItem(asset);
 }
Esempio n. 27
0
        /// <summary>
        /// Add a user's item to the trade offer.
        /// </summary>
        /// <param name="appId">App ID of item</param>
        /// <param name="contextId">Context ID of item</param>
        /// <param name="assetId">Asset (unique) ID of item</param>
        /// <param name="amount">Amount to add (default = 1)</param>
        /// <returns>True if item hasn't been added already, false if it has.</returns>
        public bool AddOtherItem(int appId, ulong contextId, ulong assetId, int amount = 1)
        {
            var asset = new TradeAsset(appId, contextId, assetId, amount);

            return(tradeStatus.them.AddItem(asset));
        }
Esempio n. 28
0
            /// <summary>
            /// Add a bot's item to the trade offer.
            /// </summary>
            /// <param name="appId">App ID of item</param>
            /// <param name="contextId">Context ID of item</param>
            /// <param name="assetId">Asset (unique) ID of item</param>
            /// <param name="amount">Amount to add (default = 1)</param>
            /// <returns>True if item hasn't been added already, false if it has.</returns>
            public bool AddMyItem(int appId, long contextId, ulong assetId, int amount = 1)
            {
                var asset = new TradeAsset(appId, contextId, assetId.ToString(), amount);

                return(tradeStatus.me.AddItem(asset));
            }