From 80c362d5edb2122f1083743c773dbf63cd93f9d8 Mon Sep 17 00:00:00 2001 From: Archi Date: Wed, 29 Nov 2023 19:52:43 +0100 Subject: [PATCH] Fix regression in trades received now Also improve that code while I'm at it --- .../Steam/Data/InventoryResponse.cs | 48 +++++++++++++------ .../Steam/Integration/ArchiWebHandler.cs | 24 ++++++---- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/ArchiSteamFarm/Steam/Data/InventoryResponse.cs b/ArchiSteamFarm/Steam/Data/InventoryResponse.cs index 1bb80a589..40534e281 100644 --- a/ArchiSteamFarm/Steam/Data/InventoryResponse.cs +++ b/ArchiSteamFarm/Steam/Data/InventoryResponse.cs @@ -19,6 +19,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; @@ -91,6 +92,15 @@ internal sealed class InventoryResponse : OptionalResultResponse { private InventoryResponse() { } internal sealed class Description { + [JsonProperty("appid", Required = Required.Always)] + internal readonly uint AppID; + + [JsonProperty("market_fee_app", Required = Required.Always)] + internal readonly uint RealAppID; + + [JsonProperty("tags", Required = Required.DisallowNull)] + internal readonly ImmutableHashSet Tags = ImmutableHashSet.Empty; + internal Asset.ERarity Rarity { get { foreach (Tag tag in Tags) { @@ -190,20 +200,10 @@ internal sealed class InventoryResponse : OptionalResultResponse { set; } - [JsonProperty("appid", Required = Required.Always)] - internal uint AppID { get; set; } - - internal ulong ClassID { get; set; } - internal ulong InstanceID { get; set; } - internal bool Marketable { get; set; } - - [JsonProperty("market_fee_app", Required = Required.Always)] - internal uint RealAppID { get; set; } - - [JsonProperty("tags", Required = Required.DisallowNull)] - internal ImmutableHashSet Tags { get; set; } = ImmutableHashSet.Empty; - - internal bool Tradable { get; set; } + internal ulong ClassID { get; private set; } + internal ulong InstanceID { get; private set; } + internal bool Marketable { get; private set; } + internal bool Tradable { get; private set; } [JsonProperty("classid", Required = Required.Always)] private string ClassIDText { @@ -251,7 +251,25 @@ internal sealed class InventoryResponse : OptionalResultResponse { set => Tradable = value > 0; } + // Constructed from trades being received/sent + internal Description(uint appID, ulong classID, ulong instanceID, bool marketable, uint realAppID, ICollection? tags = null) { + ArgumentOutOfRangeException.ThrowIfZero(appID); + ArgumentOutOfRangeException.ThrowIfZero(classID); + ArgumentOutOfRangeException.ThrowIfZero(realAppID); + + AppID = appID; + ClassID = classID; + InstanceID = instanceID; + Marketable = marketable; + RealAppID = realAppID; + Tradable = true; + + if (tags?.Count > 0) { + Tags = tags.ToImmutableHashSet(); + } + } + [JsonConstructor] - internal Description() { } + private Description() { } } } diff --git a/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs b/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs index 9250d048e..fd8e915fb 100644 --- a/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs +++ b/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs @@ -558,18 +558,22 @@ public sealed class ArchiWebHandler : IDisposable { continue; } - InventoryResponse.Description parsedDescription = new() { - AppID = appID, - ClassID = classID, - InstanceID = instanceID, - Marketable = description["marketable"].AsBoolean(), - Tradable = true // We're parsing active trade offers, we can assume as much - }; + uint realAppID = description["market_fee_app"].AsUnsignedInteger(); + + if (realAppID == 0) { + Bot.ArchiLogger.LogNullError(realAppID); + + return null; + } + + bool marketable = description["marketable"].AsBoolean(); List tags = description["tags"].Children; + HashSet? parsedTags = null; + if (tags.Count > 0) { - HashSet parsedTags = new(tags.Count); + parsedTags = new HashSet(tags.Count); foreach (KeyValue tag in tags) { string? identifier = tag["category"].AsString(); @@ -591,10 +595,10 @@ public sealed class ArchiWebHandler : IDisposable { parsedTags.Add(new Tag(identifier, value)); } - - parsedDescription.Tags = parsedTags.ToImmutableHashSet(); } + InventoryResponse.Description parsedDescription = new(appID, classID, instanceID, marketable, realAppID, parsedTags); + descriptions[key] = parsedDescription; }