From e5ff2e9f02f6a706c2b9815a93d5ca4bee061dcd Mon Sep 17 00:00:00 2001 From: Archi Date: Sun, 15 Jan 2023 00:16:53 +0100 Subject: [PATCH] Include TotalInventoryCount for the backend --- ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Backend.cs | 8 ++++++-- .../Data/AnnouncementRequest.cs | 10 +++++++++- .../RemoteCommunication.cs | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Backend.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Backend.cs index 18e86c4a8..f6dc91351 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Backend.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Backend.cs @@ -38,7 +38,7 @@ using SteamKit2; namespace ArchiSteamFarm.OfficialPlugins.ItemsMatcher; internal static class Backend { - internal static async Task AnnounceForListing(ulong steamID, WebBrowser webBrowser, IReadOnlyCollection inventory, IReadOnlyCollection acceptedMatchableTypes, bool matchEverything, string tradeToken, string? nickname = null, string? avatarHash = null) { + internal static async Task AnnounceForListing(ulong steamID, WebBrowser webBrowser, IReadOnlyCollection inventory, IReadOnlyCollection acceptedMatchableTypes, uint totalInventoryCount, bool matchEverything, string tradeToken, string? nickname = null, string? avatarHash = null) { if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { throw new ArgumentOutOfRangeException(nameof(steamID)); } @@ -53,6 +53,10 @@ internal static class Backend { throw new ArgumentNullException(nameof(acceptedMatchableTypes)); } + if (totalInventoryCount == 0) { + throw new ArgumentOutOfRangeException(nameof(totalInventoryCount)); + } + if (string.IsNullOrEmpty(tradeToken)) { throw new ArgumentNullException(nameof(tradeToken)); } @@ -63,7 +67,7 @@ internal static class Backend { Uri request = new(ArchiNet.URL, "/Api/Listing/Announce/v2"); - AnnouncementRequest data = new(ASF.GlobalDatabase?.Identifier ?? Guid.NewGuid(), steamID, tradeToken, inventory, acceptedMatchableTypes, matchEverything, ASF.GlobalConfig?.MaxTradeHoldDuration ?? GlobalConfig.DefaultMaxTradeHoldDuration, nickname, avatarHash); + AnnouncementRequest data = new(ASF.GlobalDatabase?.Identifier ?? Guid.NewGuid(), steamID, tradeToken, inventory, acceptedMatchableTypes, totalInventoryCount, matchEverything, ASF.GlobalConfig?.MaxTradeHoldDuration ?? GlobalConfig.DefaultMaxTradeHoldDuration, nickname, avatarHash); return await webBrowser.UrlPost(request, data: data, requestOptions: WebBrowser.ERequestOptions.ReturnRedirections | WebBrowser.ERequestOptions.ReturnClientErrors).ConfigureAwait(false); } diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Data/AnnouncementRequest.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Data/AnnouncementRequest.cs index b9440b730..b18df966c 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Data/AnnouncementRequest.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Data/AnnouncementRequest.cs @@ -55,10 +55,13 @@ internal sealed class AnnouncementRequest { [JsonProperty(Required = Required.Always)] private readonly ulong SteamID; + [JsonProperty(Required = Required.Always)] + private readonly uint TotalInventoryCount; + [JsonProperty(Required = Required.Always)] private readonly string TradeToken; - internal AnnouncementRequest(Guid guid, ulong steamID, string tradeToken, IReadOnlyCollection inventory, IReadOnlyCollection matchableTypes, bool matchEverything, byte maxTradeHoldDuration, string? nickname = null, string? avatarHash = null) { + internal AnnouncementRequest(Guid guid, ulong steamID, string tradeToken, IReadOnlyCollection inventory, IReadOnlyCollection matchableTypes, uint totalInventoryCount, bool matchEverything, byte maxTradeHoldDuration, string? nickname = null, string? avatarHash = null) { if (guid == Guid.Empty) { throw new ArgumentOutOfRangeException(nameof(guid)); } @@ -83,6 +86,10 @@ internal sealed class AnnouncementRequest { throw new ArgumentNullException(nameof(matchableTypes)); } + if (totalInventoryCount == 0) { + throw new ArgumentOutOfRangeException(nameof(totalInventoryCount)); + } + Guid = guid; SteamID = steamID; TradeToken = tradeToken; @@ -90,6 +97,7 @@ internal sealed class AnnouncementRequest { MatchableTypes = matchableTypes.ToImmutableHashSet(); MatchEverything = matchEverything; MaxTradeHoldDuration = maxTradeHoldDuration; + TotalInventoryCount = totalInventoryCount; Nickname = nickname; AvatarHash = avatarHash; diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs index 5bb01a381..6cdfc9107 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs @@ -322,7 +322,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { Bot.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Localization.Strings.ListingAnnouncing, Bot.SteamID, nickname, assetsForListing.Count)); // ReSharper disable once RedundantSuppressNullableWarningExpression - required for .NET Framework - BasicResponse? response = await Backend.AnnounceForListing(Bot.SteamID, WebBrowser, assetsForListing, acceptedMatchableTypes, matchEverything, tradeToken!, nickname, avatarHash).ConfigureAwait(false); + BasicResponse? response = await Backend.AnnounceForListing(Bot.SteamID, WebBrowser, assetsForListing, acceptedMatchableTypes, (uint) inventory.Count, matchEverything, tradeToken!, nickname, avatarHash).ConfigureAwait(false); if (response == null) { // This is actually a network failure, so we'll stop sending heartbeats but not record it as valid check