From b39b64e11f8eac36f0aff0ad9c38afe5807f0d09 Mon Sep 17 00:00:00 2001 From: Archi Date: Wed, 31 May 2023 15:32:56 +0200 Subject: [PATCH] Add server-side limit of items also to client side --- .../RemoteCommunication.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs index 52dd3ce9f..5849349bd 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs @@ -51,6 +51,7 @@ namespace ArchiSteamFarm.OfficialPlugins.ItemsMatcher; internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { private const string MatchActivelyTradeOfferIDsStorageKey = $"{nameof(ItemsMatcher)}-{nameof(MatchActively)}-TradeOfferIDs"; private const byte MaxAnnouncementTTL = 60; // Maximum amount of minutes we can wait if the next announcement doesn't happen naturally + private const uint MaxItemsCount = 400000; // Server is unwilling to accept more items than this private const byte MaxTradeOffersActive = 5; // The actual upper limit is 30, but we should use lower amount to allow some bots to react before we hit the maximum allowed private const byte MinAnnouncementTTL = 5; // Minimum amount of minutes we must wait before the next Announcement private const byte MinHeartBeatTTL = 10; // Minimum amount of minutes we must wait before sending next HeartBeat @@ -300,6 +301,16 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { } } + if (assetsForListing.Count > MaxItemsCount) { + // We're not eligible, record this as a valid check + LastAnnouncement = DateTime.UtcNow; + ShouldSendAnnouncementEarlier = ShouldSendHeartBeats = false; + + Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, $"{nameof(assetsForListing)} > {MaxItemsCount}")); + + return; + } + if (ShouldSendHeartBeats && (tradeToken == LastAnnouncedTradeToken) && (assetsForListing.Count == LastAnnouncedItems.Count) && assetsForListing.All(item => LastAnnouncedItems.TryGetValue(item.AssetID, out uint amount) && (item.Amount == amount))) { // There is nothing new to announce, this is fine, skip the request LastAnnouncement = DateTime.UtcNow; @@ -650,6 +661,12 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { return; } + if (ourInventory.Count > MaxItemsCount) { + Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, $"{nameof(ourInventory)} > {MaxItemsCount}")); + + return; + } + // ReSharper disable once RedundantSuppressNullableWarningExpression - required for .NET Framework (HttpStatusCode StatusCode, ImmutableHashSet Users)? response = await Backend.GetListedUsersForMatching(ASF.GlobalConfig.LicenseID.Value, Bot, WebBrowser, ourInventory.Values, acceptedMatchableTypes).ConfigureAwait(false);