From 8ab6137ab10345ab7f507a01ed7e39ee1051ceb6 Mon Sep 17 00:00:00 2001 From: Archi Date: Sat, 21 Jan 2023 23:23:08 +0100 Subject: [PATCH] Ensure we don't skip announcement if our trade token has changed We don't care about nickname or avatar hash, even total amount of items is not that important, but trade token is crucial for matching --- .../RemoteCommunication.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs index e8a173314..b5057b2f7 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs @@ -58,16 +58,18 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { Asset.EType.TradingCard ); - // We access this collection only within a semaphore, therefore there is no need for concurrent access - private readonly Dictionary AnnouncedItems = new(); - private readonly Bot Bot; private readonly Timer? HeartBeatTimer; + + // We access this collection only within a semaphore, therefore there is no need for concurrent access + private readonly Dictionary LastAnnouncedItems = new(); + private readonly SemaphoreSlim MatchActivelySemaphore = new(1, 1); private readonly Timer? MatchActivelyTimer; private readonly SemaphoreSlim RequestsSemaphore = new(1, 1); private readonly WebBrowser WebBrowser; + private string? LastAnnouncedTradeToken; private DateTime LastAnnouncement; private DateTime LastHeartBeat; private DateTime LastPersonaStateRequest; @@ -289,7 +291,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { } } - if (ShouldSendHeartBeats && (assetsForListing.Count == AnnouncedItems.Count) && assetsForListing.All(item => AnnouncedItems.TryGetValue(item.AssetID, out uint amount) && (item.Amount == amount))) { + 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; ShouldSendAnnouncementEarlier = false; @@ -383,13 +385,14 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { ShouldSendAnnouncementEarlier = false; ShouldSendHeartBeats = true; - AnnouncedItems.Clear(); + LastAnnouncedTradeToken = tradeToken; + LastAnnouncedItems.Clear(); foreach (AssetForListing item in assetsForListing) { - AnnouncedItems[item.AssetID] = item.Amount; + LastAnnouncedItems[item.AssetID] = item.Amount; } - AnnouncedItems.TrimExcess(); + LastAnnouncedItems.TrimExcess(); } finally { RequestsSemaphore.Release(); }