Exemplo n.º 1
0
        public TradeOfferAcceptResponse Accept(string tradeOfferId, string partnerId = "")
        {
            var data = new NameValueCollection();

            data.Add("sessionid", steamWeb.SessionId);
            data.Add("serverid", "1");
            data.Add("tradeofferid", tradeOfferId);
            if (partnerId != "")
            {
                data.Add("partner", partnerId);
            }

            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 tradeOffer = webApi.GetTradeOffer(tradeOfferId);
            var state      = TradeOfferState.TradeOfferStateUnknown;

            if (tradeOffer != null && tradeOffer.Offer != null)
            {
                state = tradeOffer.Offer.TradeOfferState;
            }
            if (state != TradeOfferState.TradeOfferStateAccepted)
            {
                File.AppendAllText("failedtrades", "+++++++++++++++++++++++++++++\n");
                File.AppendAllText("failedtrades", JObject.FromObject(tradeOffer).ToString(Formatting.Indented));
                File.AppendAllText("failedtrades", "\n----------------------------\n");
            }
            return(new TradeOfferAcceptResponse {
                Accepted = state == TradeOfferState.TradeOfferStateAccepted
            });
        }
Exemplo n.º 2
0
        public OfferResponse GetTradeOffer(string tradeofferid)
        {
            string options = string.Format("?key={0}&tradeofferid={1}&language={2}", _apiKey, tradeofferid, "en_us");
            string url     = String.Format(BaseUrl, "GetTradeOffer", "v1", options);

            try
            {
                string response = _steamWeb.Fetch(url, "GET", null, false);
                var    result   = JsonConvert.DeserializeObject <ApiResponse <OfferResponse> >(response);
                return(result.Response);
            }
            catch (Exception ex)
            {
                //todo log
                Debug.WriteLine(ex);
            }
            return(new OfferResponse());
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        private SteamID GetSelfId()
        {
            var html  = web.Fetch(@"https://steamcommunity.com/", "get");
            var temp  = html.Split(new[] { "data-miniprofile" }, StringSplitOptions.None)[0];
            var temp2 = temp.Split(new[] { "href=" }, StringSplitOptions.None);
            var id    = temp2[temp2.Length - 1].Replace("\"", "");

            if (id.Contains("/id/"))
            {
                string profileVanity = id.Split(new[] { "id/" }, StringSplitOptions.None)[1].Split('/')[0];
                var    xml           = web.Fetch($@"http://steamcommunity.com/id/{profileVanity}/?xml=1", "get");

                string profile64 = xml.Split(new[] { "<steamID64>" }, StringSplitOptions.None)[1].Split(new[] { "</steamID64>" }, StringSplitOptions.None)[0];
                return(new SteamID(ulong.Parse(profile64)));
            }
            else
            {
                string profile64 = id.Split(new[] { "profiles/" }, StringSplitOptions.None)[1].Split('/')[0];
                return(new SteamID(ulong.Parse(profile64)));
            }
        }
Exemplo n.º 5
0
        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
            });
        }
Exemplo n.º 6
0
        private bool CancelTradeOffer(ulong tradeofferid)
        {
            string options = string.Format("?key={0}&tradeofferid={1}", ApiKey, tradeofferid);
            string url     = String.Format(BaseUrl, "CancelTradeOffer", "v1", options);

            Debug.WriteLine(url);
            string  response = SteamWeb.Fetch(url, "POST", null, null, false);
            dynamic json     = JsonConvert.DeserializeObject(response);

            if (json == null || json.success != "1")
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 7
0
        public static void SendUsageStats(ulong steamId)
        {
            string systemName = string.Empty;

            System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem");
            foreach (System.Management.ManagementObject os in searcher.Get())
            {
                systemName = os["Caption"].ToString();
                break;
            }
            var data = new System.Collections.Specialized.NameValueCollection();

            data.Add("steamId", steamId.ToString());
            data.Add("os", systemName);
            SteamWeb.Fetch("http://jzhang.net/mist/stats.php", "POST", data);
        }
Exemplo n.º 8
0
        public TradeOffersSummary GetTradeOffersSummary(UInt32 timeLastVisit)
        {
            string options = string.Format("?key={0}&time_last_visit={1}", ApiKey, timeLastVisit);
            string url     = String.Format(BaseUrl, "GetTradeOffersSummary", "v1", options);

            try
            {
                string response = SteamWeb.Fetch(url, "GET", null, null, false);
                var    resp     = JsonConvert.DeserializeObject <ApiResponse <TradeOffersSummary> >(response);

                return(resp.Response);
            }
            catch (Exception ex)
            {
                //todo log
                Debug.WriteLine(ex);
            }
            return(new TradeOffersSummary());
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
        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 http://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);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Fetches the inventory for the given Steam ID using the Steam API.
        /// </summary>
        /// <returns>The give users inventory.</returns>
        /// <param name='steamId'>Steam identifier.</param>
        /// <param name='apiKey'>The needed Steam API key.</param>
        public static CsgoInventory FetchInventory(ulong steamId, string apiKey, SteamWeb steamWeb)
        {
            //TODO: Add a while loop here to try to fetch multiple times because according the
            //original authors the steam API is not reliable.
            //var url = "http://api.steampowered.com/IEconItems_730/GetPlayerItems/v0001/?key=" + apiKey + "&steamid=" + steamId;
            var url = string.Format("http://steamcommunity.com/profiles/{0}/inventory/json/{1}/{2}", steamId, 730, 2);
            var response = steamWeb.Fetch(url, "GET", null, false);

            dynamic obj = JsonConvert.DeserializeObject<dynamic>(response);
            bool success = obj["success"];
            bool more = obj["more"];
            bool moreStart = obj["more_start"];
            var items = new List<Item>();
            foreach (var variable in obj["rgDescriptions"].Children())
            {
                string str = variable.Value.ToString();
                var desc = JsonConvert.DeserializeObject<Item>(str);
                items.Add(desc);
            }

            //var result = JsonConvert.DeserializeObject<InventoryResponse>(response);
            return new CsgoInventory(items, success, more, moreStart);
        }
Exemplo n.º 12
0
        public OffersResponse GetTradeOffers(bool getSentOffers, bool getReceivedOffers, bool getDescriptions, bool activeOnly, bool historicalOnly, string timeHistoricalCutoff = "1389106496", string language = "en_us")
        {
            if (!getSentOffers && !getReceivedOffers)
            {
                throw new ArgumentException("getSentOffers and getReceivedOffers can't be both false");
            }

            string options = string.Format("?key={0}&get_sent_offers={1}&get_received_offers={2}&get_descriptions={3}&language={4}&active_only={5}&historical_only={6}&time_historical_cutoff={7}",
                                           ApiKey, BoolConverter(getSentOffers), BoolConverter(getReceivedOffers), BoolConverter(getDescriptions), language, BoolConverter(activeOnly), BoolConverter(historicalOnly), timeHistoricalCutoff);
            string url      = String.Format(BaseUrl, "GetTradeOffers", "v1", options);
            string response = SteamWeb.Fetch(url, "GET", null, null, false);

            try
            {
                var result = JsonConvert.DeserializeObject <ApiResponse <OffersResponse> >(response);
                return(result.Response);
            }
            catch (Exception ex)
            {
                //todo log
                Debug.WriteLine(ex);
            }
            return(new OffersResponse());
        }
Exemplo n.º 13
0
        private bool ScanMarket(Games game, int startIndex = 0)
        {
            try
            {
                RootObject ro = null;
                do
                {
                    int    timeout = (int)TimeSpan.FromMinutes(3).TotalMilliseconds;
                    string target  = "http://arkarrsourceservers.ddns.net:27019/steammarketitems?apikey=" + APIkey + "&start=" + startIndex + "&appid=" + (int)game;
                    string json    = fetcher.Fetch(target, "GET", null, true, "", true, timeout);
                    ro = JsonConvert.DeserializeObject <RootObject>(json);

                    /*if (ro == null)
                     * {
                     *  Console.WriteLine("Error fetching : " + target + " !");
                     *  Console.WriteLine("Trying again.");
                     * }*/
                }while (ro == null && !stop);

                if (stop)
                {
                    return(false);
                }

                List <Item> items = ro.items;
                if (ro.success && stop == false)
                {
                    List <Item> itemToAdd = new List <Item>();
                    foreach (Item item in items)
                    {
                        Item i = null;
                        if (game == Games.TF2)
                        {
                            i = steamMarketItemsTF2.FirstOrDefault(x => x.Name == item.Name);
                        }
                        else if (game == Games.CSGO)
                        {
                            i = steamMarketItemsCSGO.FirstOrDefault(x => x.Name == item.Name);
                        }
                        else if (game == Games.Dota2)
                        {
                            i = steamMarketItemsDOTA2.FirstOrDefault(x => x.Name == item.Name);
                        }

                        if (i != null && i.Value != item.Value)
                        {
                            i.Value       = item.Value;
                            i.LastUpdated = item.LastUpdated;
                        }
                        else if (i == null)
                        {
                            itemToAdd.Add(item);
                        }
                    }

                    if (itemToAdd.Count != 0)
                    {
                        if (game == Games.TF2)
                        {
                            steamMarketItemsTF2.AddRange(itemToAdd);
                        }
                        else if (game == Games.CSGO)
                        {
                            steamMarketItemsCSGO.AddRange(itemToAdd);
                        }
                        else if (game == Games.Dota2)
                        {
                            steamMarketItemsDOTA2.AddRange(itemToAdd);
                        }

                        itemToAdd.Clear();
                    }

                    if (ro.nbritems > startIndex + 500)
                    {
                        return(ScanMarket(game, startIndex + 500));
                    }

                    return(true);
                }
                else
                {
                    Console.WriteLine("Error while fetching " + game.ToString() + "'s market : ");
                    Console.WriteLine(ro.message);

                    return(false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error while fetching " + game.ToString() + "'s market : ");
                Console.WriteLine(e.Message);

                return(false);
            }
        }
Exemplo n.º 14
0
 string Fetch(string url, string method, NameValueCollection data = null)
 {
     return(SteamWeb.Fetch(url, method, data));
 }
Exemplo n.º 15
0
        private bool ScanItem(Games game, string itemName, int startIndex = 0)
        {
            try
            {
                RootObject ro = null;
                do
                {
                    int    timeout = (int)TimeSpan.FromMinutes(3).TotalMilliseconds;
                    string target  = "http://arkarrsourceservers.ddns.net:27019/steammarketitems?apikey=" + APIkey + "&appid=" + (int)game + "&market_hash_name=" + itemName + "&version=2";
                    string json    = fetcher.Fetch(target, "GET", null, true, "", true, timeout);
                    ro = JsonConvert.DeserializeObject <RootObject>(json);

                    if (ro == null)
                    {
                        Console.WriteLine("Error fetching : " + target + " !");
                        Console.WriteLine("Trying again.");
                    }
                }while (ro == null && !stop);

                if (stop)
                {
                    return(false);
                }

                if (ro.success && stop == false && ro.items.Count > 0)
                {
                    Item item = ro.items.First();

                    Item i = null;
                    if (game == Games.TF2)
                    {
                        i = steamMarketItemsTF2.FirstOrDefault(x => x.Name == item.Name);
                    }
                    else if (game == Games.CSGO)
                    {
                        i = steamMarketItemsCSGO.FirstOrDefault(x => x.Name == item.Name);
                    }
                    else if (game == Games.Dota2)
                    {
                        i = steamMarketItemsDOTA2.FirstOrDefault(x => x.Name == item.Name);
                    }

                    if (i != null && i.Value != item.Value)
                    {
                        i.Value       = item.Value;
                        i.LastUpdated = item.LastUpdated;
                    }
                    else if (i == null)
                    {
                        if (game == Games.TF2)
                        {
                            steamMarketItemsTF2.Add(item);
                        }
                        else if (game == Games.CSGO)
                        {
                            steamMarketItemsCSGO.Add(item);
                        }
                        else if (game == Games.Dota2)
                        {
                            steamMarketItemsDOTA2.Add(item);
                        }
                    }

                    return(true);
                }
                else if (ro.items.Count == 0)
                {
                    Console.WriteLine("Error while fetching " + game.ToString() + "'s market : ");
                    Console.WriteLine("No item with that name (" + itemName + ") in API");

                    return(false);
                }
                else
                {
                    Console.WriteLine("Error while fetching " + game.ToString() + "'s market : ");
                    Console.WriteLine(ro.message);

                    return(false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error while fetching " + game.ToString() + "'s market : ");
                Console.WriteLine(e.Message);

                return(false);
            }
        }
Exemplo n.º 16
0
        private bool ScanMarket(Games game, int startIndex = 0)
        {
            try
            {
                int timeout = (int)TimeSpan.FromMinutes(3).TotalMilliseconds;
                string json = fetcher.Fetch("http://arkarrsourceservers.ddns.net:27019/steammarketitems?apikey=" + APIkey + "&start="+startIndex+"&appid=" + (int)game, "GET");
                RootObject ro = JsonConvert.DeserializeObject<RootObject>(json);
                List<Item> items = ro.items;
                if (ro.success && stop == false)
                {
                    List<Item> itemToAdd = new List<Item>();
                    foreach (Item item in items)
                    {
                        Item i = null;
                        if (game == Games.TF2)
                            i = steamMarketItemsTF2.FirstOrDefault(x => x.Name == item.Name);
                        else if (game == Games.CSGO)
                            i = steamMarketItemsCSGO.FirstOrDefault(x => x.Name == item.Name);
                        else if (game == Games.Dota2)
                            i = steamMarketItemsDOTA2.FirstOrDefault(x => x.Name == item.Name);

                        if (i != null && i.Value != item.Value)
                        {
                            i.Value = item.Value;
                            i.LastUpdated = item.LastUpdated;
                        }
                        else if (i == null)
                        {
                            itemToAdd.Add(item);
                        }
                    }

                    if (itemToAdd.Count != 0)
                    {
                        if (game == Games.TF2)
                            steamMarketItemsTF2.AddRange(itemToAdd);
                        else if (game == Games.CSGO)
                            steamMarketItemsCSGO.AddRange(itemToAdd);
                        else if (game == Games.Dota2)
                            steamMarketItemsDOTA2.AddRange(itemToAdd);

                        itemToAdd.Clear();
                    }

                    if (ro.nbritems <= startIndex + 500)
                        Console.WriteLine("Price for game " + game.ToString() + " updated !");
                    else
                        return ScanMarket(game, startIndex + 500);

                    return true;
                }
                else
                {
                    Console.WriteLine("Error while fetching " + game.ToString() + "'s market : ");
                    Console.WriteLine(ro.message);

                    return false;
                }
            }
            catch(Exception e)
            {
                Console.WriteLine("Error while fetching " + game.ToString() + "'s market : ");
                Console.WriteLine(e.Message);

                return false;
            }
        }