From 8aad8b6bcf3c1ad09f8f2da2d9a9cd997a78ded4 Mon Sep 17 00:00:00 2001 From: Archi Date: Wed, 18 Jan 2023 23:11:17 +0100 Subject: [PATCH] Misc --- .../RemoteCommunication.cs | 29 ++++--------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs index 19f161540..5f552f561 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs @@ -66,7 +66,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { private readonly SemaphoreSlim MatchActivelySemaphore = new(1, 1); private readonly Timer? MatchActivelyTimer; private readonly SemaphoreSlim RequestsSemaphore = new(1, 1); - private readonly WebBrowser? WebBrowser; + private readonly WebBrowser WebBrowser; private DateTime LastAnnouncement; private DateTime LastHeartBeat; @@ -79,14 +79,9 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { ArgumentNullException.ThrowIfNull(bot); Bot = bot; - - if (!Bot.BotConfig.RemoteCommunication.HasFlag(BotConfig.ERemoteCommunication.PublicListing) && !Bot.BotConfig.TradingPreferences.HasFlag(BotConfig.ETradingPreferences.MatchActively)) { - return; - } - WebBrowser = new WebBrowser(bot.ArchiLogger, ASF.GlobalConfig?.WebProxy, true); - if (Bot.BotConfig.RemoteCommunication.HasFlag(BotConfig.ERemoteCommunication.PublicListing)) { + if (Bot.BotConfig.TradingPreferences.HasFlag(BotConfig.ETradingPreferences.SteamTradeMatcher) && Bot.BotConfig.RemoteCommunication.HasFlag(BotConfig.ERemoteCommunication.PublicListing)) { HeartBeatTimer = new Timer( HeartBeat, null, @@ -113,6 +108,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { // Those are objects that are always being created if constructor doesn't throw exception MatchActivelySemaphore.Dispose(); RequestsSemaphore.Dispose(); + WebBrowser.Dispose(); // Those are objects that might be null and the check should be in-place HeartBeatTimer?.Dispose(); @@ -123,14 +119,13 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { MatchActivelyTimer.Dispose(); } } - - WebBrowser?.Dispose(); } public async ValueTask DisposeAsync() { // Those are objects that are always being created if constructor doesn't throw exception MatchActivelySemaphore.Dispose(); RequestsSemaphore.Dispose(); + WebBrowser.Dispose(); // Those are objects that might be null and the check should be in-place if (HeartBeatTimer != null) { @@ -143,8 +138,6 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { MatchActivelyTimer.Dispose(); } } - - WebBrowser?.Dispose(); } internal void OnNewItemsNotification() => ShouldSendAnnouncementEarlier = true; @@ -154,10 +147,6 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { return; } - if (WebBrowser == null) { - throw new InvalidOperationException(nameof(WebBrowser)); - } - if ((DateTime.UtcNow < LastAnnouncement.AddMinutes(ShouldSendAnnouncementEarlier ? MinAnnouncementTTL : MaxAnnouncementTTL)) && ShouldSendHeartBeats) { return; } @@ -421,16 +410,12 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { } private async void HeartBeat(object? state = null) { - if (WebBrowser == null) { - throw new InvalidOperationException(nameof(WebBrowser)); - } - if (!Bot.IsConnectedAndLoggedOn || (Bot.HeartBeatFailures > 0)) { return; } // Request persona update if needed - if (Bot.BotConfig.RemoteCommunication.HasFlag(BotConfig.ERemoteCommunication.PublicListing) && Bot.BotConfig.TradingPreferences.HasFlag(BotConfig.ETradingPreferences.SteamTradeMatcher) && (DateTime.UtcNow > LastPersonaStateRequest.AddMinutes(MinPersonaStateTTL)) && (DateTime.UtcNow > LastAnnouncement.AddMinutes(ShouldSendAnnouncementEarlier ? MinAnnouncementTTL : MaxAnnouncementTTL))) { + if ((DateTime.UtcNow > LastPersonaStateRequest.AddMinutes(MinPersonaStateTTL)) && (DateTime.UtcNow > LastAnnouncement.AddMinutes(ShouldSendAnnouncementEarlier ? MinAnnouncementTTL : MaxAnnouncementTTL))) { LastPersonaStateRequest = DateTime.UtcNow; Bot.RequestPersonaStateUpdate(); } @@ -530,10 +515,6 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { } private async void MatchActively(object? state = null) { - if (WebBrowser == null) { - throw new InvalidOperationException(nameof(WebBrowser)); - } - if (ASF.GlobalConfig == null) { throw new InvalidOperationException(nameof(ASF.GlobalConfig)); }