Beispiel #1
0
 public static double GetSteamMarketPrice(SteamBot.Bot bot, GenericInventory.Inventory.Item item, bool withFee = true)
 {
     var url = string.Format("http://steamcommunity.com/market/listings/{0}/{1}/render?currency=1", item.AppId, item.MarketHashName);
     var response = SteamWeb.Fetch(url, "GET", null, bot.botCookies, false);
     try
     {
         var json = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(response);
         List<double> prices = new List<double>();
         int count = 0;
         var listings = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, dynamic>>(Convert.ToString(json.listinginfo));
         foreach (var listingItem in listings.Values)
         {
             if (listingItem.price == 0) continue;
             if (count == 3) break;
             var basePrice = (double)listingItem.converted_price;
             var fee = withFee ? (double)listingItem.converted_fee : 0;
             var price = (double)((basePrice + fee) / 100);
             prices.Add(price);
             count++;
         }
         var totalPrices = 0.0;
         foreach (var price in prices)
         {
             totalPrices += price;
         }
         var averagePrice = prices.Count > 0 ? Math.Round(totalPrices / prices.Count, 2) : 0;
         return averagePrice;
     }
     catch
     {
         return 0;
     }
 }
 public UserHandler (Bot bot, SteamID sid)
 {
     Bot = bot;
     OtherSID = sid;
     MySID = bot.SteamUser.SteamID;
     if (MySID != OtherSID)
     {
         MyInventory = new GenericInventory(MySID, MySID);
         OtherInventory = new GenericInventory(OtherSID, MySID);
     }            
 }
Beispiel #3
0
        /// <summary>
        /// Gets an item from a TradeEvent, and passes it into the UserHandler's implemented OnUserAddItem([...]) routine.
        /// Passes in null items if something went wrong.
        /// </summary>
        /// <param name="tradeEvent">TradeEvent to get item from</param>
        /// <returns></returns>
        private void FireOnUserAddItem(TradeEvent tradeEvent, SteamID botId)
        {
            bool isCurrency = tradeEvent.currencyid != 0;
            var  item       = OtherInventory.GetItem(tradeEvent.appid, tradeEvent.contextid, isCurrency ? tradeEvent.currencyid : tradeEvent.assetid, isCurrency);

            if (item == null)
            {
                if (GenericInventory.ShouldFetchInventory(tradeEvent.appid, MySteamId))
                {
                    OtherInventory.AddForeignInventory(new SteamID(Convert.ToUInt64(tradeEvent.steamid)), botId, tradeEvent.appid, tradeEvent.contextid);
                    item = OtherInventory.GetItem(tradeEvent.appid, tradeEvent.contextid, isCurrency ? tradeEvent.currencyid : tradeEvent.assetid, isCurrency);
                }
            }
            else
            {
                item.Amount = tradeEvent.amount;
            }
            OnUserAddItem(item);
        }
Beispiel #4
0
        internal Trade(SteamID me, SteamID other, string sessionId, string token, GenericInventory myInventory, GenericInventory otherInventory)
        {
            TradeStarted = false;
            OtherIsReady = false;
            MeIsReady    = false;
            mySteamId    = me;
            OtherSID     = other;

            session = new TradeSession(sessionId, token, other);

            this.eventList = new List <TradeEvent>();

            OtherOfferedItems   = new List <GenericInventory.GenericItem>();
            MyOfferedItems      = new List <GenericInventory.GenericItem>();
            steamMyOfferedItems = new Dictionary <int, GenericInventory.GenericItem>();

            MyInventory    = myInventory;
            OtherInventory = otherInventory;
        }
 // ----------------------------------------------------------------------
 public SteamTradeDemoHandler(Bot bot, SteamID sid)
     : base(bot, sid)
 {
     mySteamInventory = new GenericInventory(SteamWeb);
     OtherSteamInventory = new GenericInventory(SteamWeb);
 }
 public override void OnTradeRemoveItem(GenericInventory.Inventory.Item inventoryItem) { }
Beispiel #7
0
        /// <summary>
        /// Fetchs the inventories of both the bot and the other user as well as the TF2 item schema.
        /// </summary>
        /// <param name='me'>
        /// The <see cref="SteamID"/> of the bot.
        /// </param>
        /// <param name='other'>
        /// The <see cref="SteamID"/> of the other trade partner.
        /// </param>
        /// <remarks>
        /// This should be done anytime a new user is traded with or the inventories are out of date. It should
        /// be done sometime before calling <see cref="CreateTrade"/>.
        /// </remarks>
        public void InitializeTrade(SteamID me, SteamID other)
        {
            // fetch our inventory from the Steam API.
            myInventory = new GenericInventory(me, me, true);

            // fetch other player's inventory from the Steam API.
            otherInventory = new GenericInventory(other, me, true);            
        }
Beispiel #8
0
        /// <summary>
        /// Stops the trade thread.
        /// </summary>
        /// <remarks>
        /// Also, nulls out the inventory objects so they have to be fetched
        /// again if a new trade is started.
        /// </remarks>            
        public void StopTrade()
        {
            // TODO: something to check that trade was the Trade returned from CreateTrade
            otherInventory = null;
            myInventory = null;

            IsTradeThreadRunning = false;
        }
 public override void OnTradeRemoveItem(GenericInventory.Inventory.Item inventoryItem)
 {
     Bot.main.Invoke((Action)(() =>
     {
         ChatTab.AppendLog(OtherSID, "[Trade Chat] " + Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " removed: " + inventoryItem.Name + "\r\n");
     }));
 }
Beispiel #10
0
 private void PutOnSellingItems(Object source, ElapsedEventArgs e)
 {
     if (Monitor.TryEnter(putOnSaleLocker))
     {
         try
         {
             SQLHelper sqlHelper = SQLHelper.getInstance();
             GenericInventory myInventory = new GenericInventory(SteamWeb);
             List<long> contexts = new List<long>();
             List<ItemOnCsgotm> itemsOnCsgotm = CsgotmAPI.GetTrades();
             contexts.Add(2);
             myInventory.load(730, contexts, Bot.SteamUser.SteamID);
             //TODO test what's faster this
             List<ItemOnCsgotm> itemsSelling = ItemsByStatus(itemsOnCsgotm, ItemOnCsgotmStatus.Selling);
             List<ItemOnCsgotm> itemsToSend = ItemsByStatus(itemsOnCsgotm, ItemOnCsgotmStatus.SendToCsgotmbot);
             List<ItemOnCsgotm> sellingAndSendingItems = itemsSelling.Concat(itemsToSend).ToList();
             /*
     items in my inventory that we're able to sell on csgo.tm
         */
             /*items in bot's inventory
     for which we have a record in sql. If in inventory we find class_instance, for which we don't have a record
     in sql - we skip this item.
     */
             //TODO I think I can create on request to SQL to retreive all items from it.
             foreach (var description in myInventory.descriptions)
             {
                 if (description.Value.tradable)
                 {
                     ItemInSQL itemInSql = sqlHelper.Select(description.Key); 
                     if (itemInSql != null)
                     {
                         var itemsInInventory =
                             myInventory.items.Where(item => item.Value.descriptionid == description.Key);
                         var csgotmItems =
                             sellingAndSendingItems.Where(
                                 item => (item.ClassId + "_" + item.InstanceId) == description.Key);
                         if (!csgotmItems.Any())
                         {
                             //probably we've got a weapon with instance_id !=0, so trying to find items only by class
                             csgotmItems = sellingAndSendingItems.Where(
                                 item => (item.ClassId  == description.Value.classid));
                         }
                         if (itemsInInventory.Count() > csgotmItems.Count())
                         {
                             int numberOfItemsToSell = itemsInInventory.Count() - csgotmItems.Count();
                             for (int i = 0; i < numberOfItemsToSell; i++)
                             {
                                 CsgotmAPI.SellItem(itemInSql);
                             }
                         }
                         if (itemsInInventory.Count() < csgotmItems.Count())
                         {
                             int numberOfItemsToDelete = csgotmItems.Count() - itemsInInventory.Count();
                             var numerator = csgotmItems.GetEnumerator();
                             for (int i = 0; i < numberOfItemsToDelete; i++)
                             {
                                 numerator.MoveNext();
                                 CsgotmAPI.StopSellingItem(numerator.Current);
                             }
                         }
                         //Update price for items
                         foreach (var item in csgotmItems)
                         {
                             CsgotmAPI.RenewPriceOnSellingItem(item);
                         }
                     }
                 }
             }
         }
         finally
         {
             Monitor.Exit(putOnSaleLocker);
         }
     }
 }
        public override void OnMessage(string message, EChatEntryType type)
        {
            //var inventory = OtherInventory;
            //var jsonIventory = JsonConvert.SerializeObject(inventory);
            //var inventory2 = JsonConvert.DeserializeObject<TF2Inventory>(jsonIventory);
            //Log.Info(jsonIventory);
            //Console.WriteLine("test");
            //SendChatMessage(Bot.ChatResponse);
            /**                         **/
            //var rand = new Random();
            //Bot.GetInventory();
            //var inventory = Bot.MyInventory.Items;
            //var randomItem = inventory[rand.Next(inventory.Length)];
            //var tradeOffer = Bot.NewTradeOffer(OtherSID);
            //tradeOffer.Items.AddMyItem(randomItem.AppId, randomItem.ContextId, (long) randomItem.Id);

            //string tradeId;
            //tradeOffer.Send(out tradeId);

            var rand = new Random();

            List<long> contextId = new List<long>();
            //contextId.Add(6);
            contextId.Add(2);

            var genericInv = new GenericInventory(Bot.SteamWeb);
            genericInv.load(730, contextId, OtherSID);

            var inventory = genericInv.items;
            foreach (var item in genericInv.items)
            {
                Log.Info(genericInv.getDescription(item.Key).name);

            }

            //var randomItem = inventory[rand.Next(inventory.Length)];
            //var tradeOffer = Bot.NewTradeOffer(OtherSID);
            //tradeOffer.Items.AddMyItem(randomItem.AppId, randomItem.ContextId, (long)randomItem.Id);

            //string tradeId;
            //tradeOffer.Send(out tradeId);
        }
 /// <summary>
 /// Wrapper for GenericInventory's AddInventoriesToFetch function.
 /// </summary>
 /// <param name="type">Type of inventory to fetch</param>
 public virtual void AddInventoriesToFetch(GenericInventory.InventoryTypes type)
 {
     GenericInventory.AddInventoriesToFetch(type, MySID);
 }
 public abstract void OnTradeRemoveItem(GenericInventory.Inventory.Item inventoryItem);