diff --git a/ArchiSteamFarm/ArchiSteamFarm.csproj b/ArchiSteamFarm/ArchiSteamFarm.csproj index 3c69c965a..e835bd94b 100644 --- a/ArchiSteamFarm/ArchiSteamFarm.csproj +++ b/ArchiSteamFarm/ArchiSteamFarm.csproj @@ -105,17 +105,14 @@ - + + - - - - diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 2a0279f3b..1c03d2833 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -145,7 +145,7 @@ namespace ArchiSteamFarm { return false; } - internal List GetTradeOffers() { + internal List GetTradeOffers() { if (string.IsNullOrEmpty(Bot.BotConfig.SteamApiKey)) { return null; } @@ -172,15 +172,15 @@ namespace ArchiSteamFarm { return null; } - List result = new List(); + List result = new List(); foreach (KeyValue trade in response["trade_offers_received"].Children) { - SteamTradeOffer tradeOffer = new SteamTradeOffer { + Steam.TradeOffer tradeOffer = new Steam.TradeOffer { tradeofferid = trade["tradeofferid"].AsString(), accountid_other = trade["accountid_other"].AsInteger(), - trade_offer_state = trade["trade_offer_state"].AsEnum() + trade_offer_state = trade["trade_offer_state"].AsEnum() }; foreach (KeyValue item in trade["items_to_give"].Children) { - tradeOffer.items_to_give.Add(new SteamItem { + tradeOffer.items_to_give.Add(new Steam.Item { appid = item["appid"].AsString(), contextid = item["contextid"].AsString(), assetid = item["assetid"].AsString(), @@ -190,7 +190,7 @@ namespace ArchiSteamFarm { }); } foreach (KeyValue item in trade["items_to_receive"].Children) { - tradeOffer.items_to_receive.Add(new SteamItem { + tradeOffer.items_to_receive.Add(new Steam.Item { appid = item["appid"].AsString(), contextid = item["contextid"].AsString(), assetid = item["assetid"].AsString(), @@ -297,7 +297,7 @@ namespace ArchiSteamFarm { return true; } - internal async Task> GetMyTradableInventory() { + internal async Task> GetMyTradableInventory() { JObject jObject = null; for (byte i = 0; i < WebBrowser.MaxRetries && jObject == null; i++) { jObject = await WebBrowser.UrlGetToJObject("https://steamcommunity.com/my/inventory/json/753/6?trading=1", Cookie).ConfigureAwait(false); @@ -314,10 +314,10 @@ namespace ArchiSteamFarm { return null; } - List result = new List(); + List result = new List(); foreach (JToken jToken in jTokens) { try { - result.Add(JsonConvert.DeserializeObject(jToken.ToString())); + result.Add(JsonConvert.DeserializeObject(jToken.ToString())); } catch (Exception e) { Logging.LogGenericException(e, Bot.BotName); } @@ -326,7 +326,7 @@ namespace ArchiSteamFarm { return result; } - internal async Task SendTradeOffer(List inventory, ulong partnerID, string token = null) { + internal async Task SendTradeOffer(List inventory, ulong partnerID, string token = null) { if (inventory == null || inventory.Count == 0 || partnerID == 0) { return false; } @@ -336,21 +336,21 @@ namespace ArchiSteamFarm { return false; } - List trades = new List(1 + inventory.Count / Trading.MaxItemsPerTrade); + List trades = new List(1 + inventory.Count / Trading.MaxItemsPerTrade); - SteamTradeOfferRequest singleTrade = null; + Steam.TradeOfferRequest singleTrade = null; for (ushort i = 0; i < inventory.Count; i++) { if (i % Trading.MaxItemsPerTrade == 0) { if (trades.Count >= Trading.MaxTradesPerAccount) { break; } - singleTrade = new SteamTradeOfferRequest(); + singleTrade = new Steam.TradeOfferRequest(); trades.Add(singleTrade); } - SteamItem item = inventory[i]; - singleTrade.me.assets.Add(new SteamItem() { + Steam.Item item = inventory[i]; + singleTrade.me.assets.Add(new Steam.Item() { appid = "753", contextid = "6", amount = item.amount, @@ -361,7 +361,7 @@ namespace ArchiSteamFarm { string referer = "https://steamcommunity.com/tradeoffer/new"; string request = referer + "/send"; - foreach (SteamTradeOfferRequest trade in trades) { + foreach (Steam.TradeOfferRequest trade in trades) { Dictionary data = new Dictionary(6) { {"sessionid", sessionID}, {"serverid", "1"}, diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index c7f80122e..e18651d32 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -456,7 +456,7 @@ namespace ArchiSteamFarm { } await Trading.LimitInventoryRequestsAsync().ConfigureAwait(false); - List inventory = await ArchiWebHandler.GetMyTradableInventory().ConfigureAwait(false); + List inventory = await ArchiWebHandler.GetMyTradableInventory().ConfigureAwait(false); if (inventory == null || inventory.Count == 0) { return "Nothing to send, inventory seems empty!"; diff --git a/ArchiSteamFarm/CMsgClientClanInviteAction.cs b/ArchiSteamFarm/CMsgs/CMsgClientClanInviteAction.cs similarity index 100% rename from ArchiSteamFarm/CMsgClientClanInviteAction.cs rename to ArchiSteamFarm/CMsgs/CMsgClientClanInviteAction.cs diff --git a/ArchiSteamFarm/JSON/Steam.cs b/ArchiSteamFarm/JSON/Steam.cs new file mode 100644 index 000000000..5fb4e09f5 --- /dev/null +++ b/ArchiSteamFarm/JSON/Steam.cs @@ -0,0 +1,122 @@ +/* + _ _ _ ____ _ _____ + / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ + / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ + / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| + + Copyright 2015-2016 Ł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 SteamKit2; +using System.Collections.Generic; + +namespace ArchiSteamFarm { + internal static class Steam { + internal sealed class Item { + // REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_Asset + [JsonProperty(Required = Required.DisallowNull)] + internal string appid { get; set; } + + [JsonProperty(Required = Required.DisallowNull)] + internal string contextid { get; set; } + + [JsonProperty(Required = Required.DisallowNull)] + internal string assetid { get; set; } + + [JsonProperty(Required = Required.DisallowNull)] + internal string id { + get { return assetid; } + set { assetid = value; } + } + + [JsonProperty(Required = Required.AllowNull)] + internal string classid { get; set; } + + [JsonProperty(Required = Required.AllowNull)] + internal string instanceid { get; set; } + + [JsonProperty(Required = Required.Always)] + internal string amount { get; set; } + } + + internal sealed class ItemList { + [JsonProperty(Required = Required.Always)] + internal List assets { get; } = new List(); + } + + internal sealed class TradeOffer { + // REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_TradeOffer + internal enum ETradeOfferState : byte { + Unknown, + Invalid, + Active, + Accepted, + Countered, + Expired, + Canceled, + Declined, + InvalidItems, + EmailPending, + EmailCanceled, + OnHold + } + + [JsonProperty(Required = Required.Always)] + internal string tradeofferid { get; set; } + + [JsonProperty(Required = Required.Always)] + internal int accountid_other { get; set; } + + [JsonProperty(Required = Required.Always)] + internal ETradeOfferState trade_offer_state { get; set; } + + [JsonProperty(Required = Required.Always)] + internal List items_to_give { get; } = new List(); + + [JsonProperty(Required = Required.Always)] + internal List items_to_receive { get; } = new List(); + + // Extra + private ulong _OtherSteamID64 = 0; + internal ulong OtherSteamID64 { + get { + if (_OtherSteamID64 == 0 && accountid_other != 0) { + _OtherSteamID64 = new SteamID((uint) accountid_other, EUniverse.Public, EAccountType.Individual).ConvertToUInt64(); + } + + return _OtherSteamID64; + } + } + } + + internal sealed class TradeOfferRequest { + [JsonProperty(Required = Required.Always)] + internal bool newversion { get; } = true; + + [JsonProperty(Required = Required.Always)] + internal int version { get; } = 2; + + [JsonProperty(Required = Required.Always)] + internal Steam.ItemList me { get; } = new Steam.ItemList(); + + [JsonProperty(Required = Required.Always)] + internal Steam.ItemList them { get; } = new Steam.ItemList(); + } + } +} diff --git a/ArchiSteamFarm/SteamItem.cs b/ArchiSteamFarm/SteamItem.cs deleted file mode 100644 index 6e3aa56e6..000000000 --- a/ArchiSteamFarm/SteamItem.cs +++ /dev/null @@ -1,54 +0,0 @@ -/* - _ _ _ ____ _ _____ - / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ - / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ - / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | -/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| - - Copyright 2015-2016 Ł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 sealed class SteamItem { - // REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_Asset - [JsonProperty(Required = Required.DisallowNull)] - internal string appid { get; set; } - - [JsonProperty(Required = Required.DisallowNull)] - internal string contextid { get; set; } - - [JsonProperty(Required = Required.DisallowNull)] - internal string assetid { get; set; } - - [JsonProperty(Required = Required.DisallowNull)] - internal string id { - get { return assetid; } - set { assetid = value; } - } - - [JsonProperty(Required = Required.AllowNull)] - internal string classid { get; set; } - - [JsonProperty(Required = Required.AllowNull)] - internal string instanceid { get; set; } - - [JsonProperty(Required = Required.Always)] - internal string amount { get; set; } - } -} diff --git a/ArchiSteamFarm/SteamItemList.cs b/ArchiSteamFarm/SteamItemList.cs deleted file mode 100644 index 44ce15c03..000000000 --- a/ArchiSteamFarm/SteamItemList.cs +++ /dev/null @@ -1,33 +0,0 @@ -/* - _ _ _ ____ _ _____ - / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ - / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ - / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | -/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| - - Copyright 2015-2016 Ł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 { - internal sealed class SteamItemList { - [JsonProperty(Required = Required.Always)] - internal List assets { get; } = new List(); - } -} diff --git a/ArchiSteamFarm/SteamTradeOffer.cs b/ArchiSteamFarm/SteamTradeOffer.cs deleted file mode 100644 index 9e29ca64d..000000000 --- a/ArchiSteamFarm/SteamTradeOffer.cs +++ /dev/null @@ -1,74 +0,0 @@ -/* - _ _ _ ____ _ _____ - / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ - / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ - / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | -/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| - - Copyright 2015-2016 Ł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 SteamKit2; -using System.Collections.Generic; - -namespace ArchiSteamFarm { - internal sealed class SteamTradeOffer { - // REF: https://developer.valvesoftware.com/wiki/Steam_Web_API/IEconService#CEcon_TradeOffer - internal enum ETradeOfferState : byte { - Unknown, - Invalid, - Active, - Accepted, - Countered, - Expired, - Canceled, - Declined, - InvalidItems, - EmailPending, - EmailCanceled, - OnHold - } - - [JsonProperty(Required = Required.Always)] - internal string tradeofferid { get; set; } - - [JsonProperty(Required = Required.Always)] - internal int accountid_other { get; set; } - - [JsonProperty(Required = Required.Always)] - internal ETradeOfferState trade_offer_state { get; set; } - - [JsonProperty(Required = Required.Always)] - internal List items_to_give { get; } = new List(); - - [JsonProperty(Required = Required.Always)] - internal List items_to_receive { get; } = new List(); - - // Extra - private ulong _OtherSteamID64 = 0; - internal ulong OtherSteamID64 { - get { - if (_OtherSteamID64 == 0 && accountid_other != 0) { - _OtherSteamID64 = new SteamID((uint) accountid_other, EUniverse.Public, EAccountType.Individual).ConvertToUInt64(); - } - - return _OtherSteamID64; - } - } - } -} diff --git a/ArchiSteamFarm/SteamTradeOfferRequest.cs b/ArchiSteamFarm/SteamTradeOfferRequest.cs deleted file mode 100644 index 15188ebc2..000000000 --- a/ArchiSteamFarm/SteamTradeOfferRequest.cs +++ /dev/null @@ -1,41 +0,0 @@ -/* - _ _ _ ____ _ _____ - / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ - / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ - / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | -/_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| - - Copyright 2015-2016 Ł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 sealed class SteamTradeOfferRequest { - [JsonProperty(Required = Required.Always)] - internal bool newversion { get; } = true; - - [JsonProperty(Required = Required.Always)] - internal int version { get; } = 2; - - [JsonProperty(Required = Required.Always)] - internal SteamItemList me { get; } = new SteamItemList(); - - [JsonProperty(Required = Required.Always)] - internal SteamItemList them { get; } = new SteamItemList(); - } -} diff --git a/ArchiSteamFarm/Trading.cs b/ArchiSteamFarm/Trading.cs index 2fcdce43a..93e824d27 100644 --- a/ArchiSteamFarm/Trading.cs +++ b/ArchiSteamFarm/Trading.cs @@ -64,14 +64,14 @@ namespace ArchiSteamFarm { } private async Task ParseActiveTrades() { - List tradeOffers = Bot.ArchiWebHandler.GetTradeOffers(); + List tradeOffers = Bot.ArchiWebHandler.GetTradeOffers(); if (tradeOffers == null) { return; } List tasks = new List(); - foreach (SteamTradeOffer tradeOffer in tradeOffers) { - if (tradeOffer.trade_offer_state == SteamTradeOffer.ETradeOfferState.Active) { + foreach (Steam.TradeOffer tradeOffer in tradeOffers) { + if (tradeOffer.trade_offer_state == Steam.TradeOffer.ETradeOfferState.Active) { tasks.Add(Task.Run(async () => await ParseTrade(tradeOffer).ConfigureAwait(false))); } } @@ -80,7 +80,7 @@ namespace ArchiSteamFarm { await Bot.AcceptAllConfirmations().ConfigureAwait(false); } - private async Task ParseTrade(SteamTradeOffer tradeOffer) { + private async Task ParseTrade(Steam.TradeOffer tradeOffer) { if (tradeOffer == null) { return; }