diff --git a/ArchiSteamFarm/ArchiSteamFarm.csproj b/ArchiSteamFarm/ArchiSteamFarm.csproj index b39155268..9355f6cd3 100644 --- a/ArchiSteamFarm/ArchiSteamFarm.csproj +++ b/ArchiSteamFarm/ArchiSteamFarm.csproj @@ -97,8 +97,12 @@ + + + + diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index a878b0ba4..1b447b93d 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -375,50 +375,59 @@ namespace ArchiSteamFarm { internal async Task> GetInventory() { List result = new List(); + try { - JObject jobj = await WebBrowser.UrlGetToJObject("http://steamcommunity.com/my/inventory/json/753/6", Cookie).ConfigureAwait(false); - IList results = jobj.SelectTokens("$.rgInventory.*").ToList(); - foreach (JToken res in results) { - result.Add(JsonConvert.DeserializeObject(res.ToString())); + JObject jObject = await WebBrowser.UrlGetToJObject("https://steamcommunity.com/my/inventory/json/753/6", Cookie).ConfigureAwait(false); + IEnumerable jTokens = jObject.SelectTokens("$.rgInventory.*"); + foreach (JToken jToken in jTokens) { + result.Add(JsonConvert.DeserializeObject(jToken.ToString())); } - } catch (Exception) { - //just return empty list on error + } catch (Exception e) { + Logging.LogGenericException(Bot.BotName, e); } + return result; } - internal async Task SendTradeOffer(List itemsSend, string masterid,string token=null) { + internal async Task SendTradeOffer(List items, ulong partnerID, string token = null) { + if (items == null || partnerID == 0) { + return false; + } + string sessionID; if (!Cookie.TryGetValue("sessionid", out sessionID)) { return false; } - SteamTradeItemList items = new SteamTradeItemList(); - foreach (var item in itemsSend) { - items.assets.Add(new SteamTradeItem(753, 6, Int32.Parse(item.amount), item.id)); + SteamTradeOfferRequest trade = new SteamTradeOfferRequest(); + + foreach (SteamInventoryItem item in items) { + trade.me.assets.Add(new SteamTradeItem() { + appid = 753, + contextid = 6, + amount = int.Parse(item.amount), + assetid = item.id + }); } - SteamTradeOfferRequest trade = new SteamTradeOfferRequest(true, 2, items, new SteamTradeItemList()); + string referer = "https://steamcommunity.com/tradeoffer/new"; + string request = referer + "/send"; - string referer = String.Format("https://steamcommunity.com/tradeoffer/new/?partner={0}", ((Int32)Int64.Parse(masterid)).ToString()); - - if (!string.IsNullOrEmpty(token)) { - referer += String.Format("&token={0}",token); - } - - Dictionary postData = new Dictionary() { + Dictionary postData = new Dictionary() { {"sessionid", sessionID}, - {"serverid","1" }, - {"partner",masterid }, - {"tradeoffermessage","sent by ASF" }, - {"json_tradeoffer",JsonConvert.SerializeObject(trade) }, - {"trade_offer_create_params",string.IsNullOrEmpty(token)?"":String.Format("{{ \"trade_offer_access_token\":\"{0}\" }}", token) } + {"serverid", "1"}, + {"partner", partnerID.ToString()}, + {"tradeoffermessage", "Sent by ASF"}, + {"json_tradeoffer", JsonConvert.SerializeObject(trade)}, + {"trade_offer_create_params", string.IsNullOrEmpty(token) ? "" : string.Format("{{ \"trade_offer_access_token\":\"{0}\" }}", token)} // TODO: This should be rewrote }; - HttpResponseMessage response = await WebBrowser.UrlPost("https://steamcommunity.com/tradeoffer/new/send", postData, Cookie, referer).ConfigureAwait(false); + + HttpResponseMessage response = await WebBrowser.UrlPost(request, postData, Cookie, referer).ConfigureAwait(false); if (response == null) { return false; } - return response.IsSuccessStatusCode; + + return true; } internal async Task GetBadgePage(int page) { diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 7910196c6..06fc9a3a3 100644 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -72,7 +72,7 @@ namespace ArchiSteamFarm { internal string SteamPassword { get; private set; } = "null"; internal string SteamNickname { get; private set; } = "null"; internal string SteamApiKey { get; private set; } = "null"; - internal string SteamTradeToken {get; private set; } = "null"; + internal string SteamTradeToken { get; private set; } = "null"; internal string SteamParentalPIN { get; private set; } = "0"; internal ulong SteamMasterID { get; private set; } = 0; internal ulong SteamMasterClanID { get; private set; } = 0; @@ -83,7 +83,7 @@ namespace ArchiSteamFarm { internal bool UseAsfAsMobileAuthenticator { get; private set; } = false; internal bool ShutdownOnFarmingFinished { get; private set; } = false; internal bool SendOnFarmingFinished { get; private set; } = false; - internal uint SendTradePeriod {get; private set; } = 0; + internal uint SendTradePeriod { get; private set; } = 0; internal HashSet Blacklist { get; private set; } = new HashSet(); internal bool Statistics { get; private set; } = true; @@ -485,32 +485,35 @@ namespace ArchiSteamFarm { } internal static async Task ResponseSendTrade(string botName) { - Bot bot; - string token=null; if (string.IsNullOrEmpty(botName)) { - return "Error, no name specified"; + return null; } + + Bot bot; if (!Bots.TryGetValue(botName, out bot)) { return "Couldn't find any bot named " + botName + "!"; } - if (bot.SendTradePeriod!=0) { - bot.Timer.Change(TimeSpan.FromHours(bot.SendTradePeriod),Timeout.InfiniteTimeSpan); + + if (bot.SteamMasterID == 0) { + return "Trade couldn't be send because SteamMasterID is not defined!"; } - if (bot.SteamMasterID==0) { - return "No master set"; + + string token = null; + if (!string.IsNullOrEmpty(bot.SteamTradeToken) && !bot.SteamTradeToken.Equals("null")) { + token = bot.SteamTradeToken; } - if ((!string.IsNullOrEmpty(bot.SteamTradeToken))&&(!bot.SteamTradeToken.Equals("null"))) { - token=bot.SteamTradeToken; + + List inventory = await bot.ArchiWebHandler.GetInventory().ConfigureAwait(false); + if (inventory.Count == 0) { + return "Nothing to send, inventory seems empty!"; } - List inv = await bot.ArchiWebHandler.GetInventory().ConfigureAwait(false); - if (inv.Count == 0) { - return "Nothing to send"; - } - if (await bot.ArchiWebHandler.SendTradeOffer(inv, bot.SteamMasterID.ToString(),token).ConfigureAwait(false)) { + + if (await bot.ArchiWebHandler.SendTradeOffer(inventory, bot.SteamMasterID, token).ConfigureAwait(false)) { await bot.AcceptAllConfirmations().ConfigureAwait(false); - return "Trade offer sent"; + return "Trade offer sent successfully!"; + } else { + return "Trade offer failed due to error!"; } - return "Error sending trade offer"; } internal static string Response2FA(string botName) { @@ -1042,7 +1045,7 @@ namespace ArchiSteamFarm { await CardsFarmer.StartFarming().ConfigureAwait(false); - if (SendTradePeriod!=0) { + if (SendTradePeriod != 0) { Timer = new Timer( async e => await ResponseSendTrade(BotName).ConfigureAwait(false), null, diff --git a/ArchiSteamFarm/SteamInventoryItem.cs b/ArchiSteamFarm/SteamInventoryItem.cs index 60158c527..e162ca586 100644 --- a/ArchiSteamFarm/SteamInventoryItem.cs +++ b/ArchiSteamFarm/SteamInventoryItem.cs @@ -1,12 +1,44 @@ - -namespace ArchiSteamFarm -{ - public class SteamInventoryItem - { - public string id { get; set; } - public string classid { get; set; } - public string instanceid { get; set; } - public string amount { get; set; } - public int pos { get; set; } - } +/* + _ _ _ ____ _ _____ + / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ + / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ + / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| + + Copyright 2015 Łukasz "JustArchi" Domeradzki + Contact: JustArchi@JustArchi.net + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +using Newtonsoft.Json; + +namespace ArchiSteamFarm { + internal class SteamInventoryItem { + [JsonProperty] + internal string id { get; set; } + + [JsonProperty] + internal string classid { get; set; } + + [JsonProperty] + internal string instanceid { get; set; } + + [JsonProperty] + internal string amount { get; set; } + + [JsonProperty] + internal int pos { get; set; } + } } diff --git a/ArchiSteamFarm/SteamItem.cs b/ArchiSteamFarm/SteamItem.cs index 420b0e0d9..5e3e7c734 100644 --- a/ArchiSteamFarm/SteamItem.cs +++ b/ArchiSteamFarm/SteamItem.cs @@ -22,16 +22,34 @@ */ +using Newtonsoft.Json; + namespace ArchiSteamFarm { internal sealed class SteamItem { // REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_Asset + + [JsonProperty] internal string appid { get; set; } + + [JsonProperty] internal string contextid { get; set; } + + [JsonProperty] internal string assetid { get; set; } + + [JsonProperty] internal string currencyid { get; set; } + + [JsonProperty] internal string classid { get; set; } + + [JsonProperty] internal string instanceid { get; set; } + + [JsonProperty] internal string amount { get; set; } + + [JsonProperty] internal bool missing { get; set; } } } diff --git a/ArchiSteamFarm/SteamTradeItem.cs b/ArchiSteamFarm/SteamTradeItem.cs index f2090d792..429a5629b 100644 --- a/ArchiSteamFarm/SteamTradeItem.cs +++ b/ArchiSteamFarm/SteamTradeItem.cs @@ -1,15 +1,41 @@ - +/* + _ _ _ ____ _ _____ + / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ + / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ + / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| + + Copyright 2015 Łukasz "JustArchi" Domeradzki + Contact: JustArchi@JustArchi.net + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +using Newtonsoft.Json; + namespace ArchiSteamFarm { - public class SteamTradeItem { - public int appid { get; set; } - public int contextid { get; set; } - public int amount { get; set; } - public string assetid { get; set; } - public SteamTradeItem (int aid, int cid, int am, string asset) { - appid = aid; - contextid = cid; - amount = am; - assetid = asset; - } + internal class SteamTradeItem { + [JsonProperty] + internal int appid { get; set; } + + [JsonProperty] + internal int contextid { get; set; } + + [JsonProperty] + internal int amount { get; set; } + + [JsonProperty] + internal string assetid { get; set; } } } diff --git a/ArchiSteamFarm/SteamTradeItemList.cs b/ArchiSteamFarm/SteamTradeItemList.cs index 2173a32e2..a410b44e0 100644 --- a/ArchiSteamFarm/SteamTradeItemList.cs +++ b/ArchiSteamFarm/SteamTradeItemList.cs @@ -1,14 +1,39 @@ -using System.Collections.Generic; +/* + _ _ _ ____ _ _____ + / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ + / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ + / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| + + Copyright 2015 Łukasz "JustArchi" Domeradzki + Contact: JustArchi@JustArchi.net + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +using Newtonsoft.Json; +using System.Collections.Generic; namespace ArchiSteamFarm { - public class SteamTradeItemList { - public List assets { get; set; } - public List currency { get; set; } - public bool ready { get; set; } - public SteamTradeItemList() { - assets = new List(); - currency = new List(); - ready = false; - } + internal class SteamTradeItemList { + [JsonProperty] + internal List assets { get; set; } = new List(); + + [JsonProperty] + internal List currency { get; set; } = new List(); + + [JsonProperty] + internal bool ready { get; set; } = false; } } diff --git a/ArchiSteamFarm/SteamTradeOffer.cs b/ArchiSteamFarm/SteamTradeOffer.cs index 75a0eaa4d..d772a55fd 100644 --- a/ArchiSteamFarm/SteamTradeOffer.cs +++ b/ArchiSteamFarm/SteamTradeOffer.cs @@ -22,6 +22,7 @@ */ +using Newtonsoft.Json; using SteamKit2; using System.Collections.Generic; @@ -49,18 +50,43 @@ namespace ArchiSteamFarm { MobileApp } + [JsonProperty] internal string tradeofferid { get; set; } + + [JsonProperty] internal int accountid_other { get; set; } + + [JsonProperty] internal string message { get; set; } + + [JsonProperty] internal int expiration_time { get; set; } + + [JsonProperty] internal ETradeOfferState trade_offer_state { get; set; } - internal List items_to_give { get; set; } - internal List items_to_receive { get; set; } + + [JsonProperty] + internal List items_to_give { get; set; } = new List(); + + [JsonProperty] + internal List items_to_receive { get; set; } = new List(); + + [JsonProperty] internal bool is_our_offer { get; set; } + + [JsonProperty] internal int time_created { get; set; } + + [JsonProperty] internal int time_updated { get; set; } + + [JsonProperty] internal bool from_real_time_trade { get; set; } + + [JsonProperty] internal int escrow_end_date { get; set; } + + [JsonProperty] internal ETradeOfferConfirmationMethod confirmation_method { get; set; } // Extra diff --git a/ArchiSteamFarm/SteamTradeOfferRequest.cs b/ArchiSteamFarm/SteamTradeOfferRequest.cs index 5540c1194..0a5fad9a3 100644 --- a/ArchiSteamFarm/SteamTradeOfferRequest.cs +++ b/ArchiSteamFarm/SteamTradeOfferRequest.cs @@ -1,15 +1,41 @@ - +/* + _ _ _ ____ _ _____ + / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ + / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ + / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| + + Copyright 2015 Łukasz "JustArchi" Domeradzki + Contact: JustArchi@JustArchi.net + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +*/ + +using Newtonsoft.Json; + namespace ArchiSteamFarm { - public class SteamTradeOfferRequest { - public bool newversion { get; set; } - public int version { get; set; } - public SteamTradeItemList me { get; set; } - public SteamTradeItemList them { get; set; } - public SteamTradeOfferRequest (bool nv, int v, SteamTradeItemList m, SteamTradeItemList t) { - newversion = nv; - version = v; - me = m; - them = t; - } - } + internal class SteamTradeOfferRequest { + [JsonProperty] + internal bool newversion { get; set; } = true; + + [JsonProperty] + internal int version { get; set; } = 2; + + [JsonProperty] + internal SteamTradeItemList me { get; set; } = new SteamTradeItemList(); + + [JsonProperty] + internal SteamTradeItemList them { get; set; } = new SteamTradeItemList(); + } } diff --git a/ArchiSteamFarm/config/example.xml b/ArchiSteamFarm/config/example.xml index a73bbc747..8ab58c015 100644 --- a/ArchiSteamFarm/config/example.xml +++ b/ArchiSteamFarm/config/example.xml @@ -1,7 +1,7 @@ - + @@ -104,7 +104,6 @@ -