From cca469a1de989603878d8399ba8154c9e1ba2a01 Mon Sep 17 00:00:00 2001 From: Citrinate Date: Thu, 19 Dec 2024 18:11:18 -0500 Subject: [PATCH] Verify lack of ownership before activation attempts --- FreePackages/PackageFilter/PackageFilter.cs | 16 ++++++++++++++++ FreePackages/PackageQueue/PackageQueue.cs | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/FreePackages/PackageFilter/PackageFilter.cs b/FreePackages/PackageFilter/PackageFilter.cs index 42fa3b5..b3157e6 100644 --- a/FreePackages/PackageFilter/PackageFilter.cs +++ b/FreePackages/PackageFilter/PackageFilter.cs @@ -370,5 +370,21 @@ internal bool IsWantedPlaytest(FilterableApp app) { return FilterConfigs.Any(filter => !FilterOnlyAllowsPackages(filter) && IsPlaytestWantedByFilter(app, filter) && !IsAppIgnoredByFilter(app, filter)); } + + internal bool OwnsApp(uint appID) { + if (OwnedAppIDs == null) { + throw new InvalidOperationException(nameof(OwnedAppIDs)); + } + + return OwnedAppIDs.Contains(appID); + } + + internal bool OwnsSub(uint subID) { + if (UserData == null) { + throw new InvalidOperationException(nameof(UserData)); + } + + return UserData.OwnedPackages.Contains(subID); + } } } diff --git a/FreePackages/PackageQueue/PackageQueue.cs b/FreePackages/PackageQueue/PackageQueue.cs index d6ad6c1..58743af 100644 --- a/FreePackages/PackageQueue/PackageQueue.cs +++ b/FreePackages/PackageQueue/PackageQueue.cs @@ -12,6 +12,7 @@ namespace FreePackages { internal sealed class PackageQueue : IDisposable { private readonly Bot Bot; private readonly BotCache BotCache; + private PackageFilter PackageFilter => PackageHandler.Handlers[Bot.BotName].PackageFilter; private Timer Timer; private const int DelayBetweenActivationsSeconds = 5; private readonly uint ActivationsPerPeriod = 25; @@ -101,7 +102,7 @@ private async Task ProcessQueue() { return; } - if (result == EResult.OK || result == EResult.Invalid) { + if (result == EResult.OK || result == EResult.Invalid || result == EResult.AlreadyOwned) { BotCache.RemovePackage(package); } else if (result == EResult.Timeout) { UpdateTimer(DateTime.Now.AddMinutes(5)); @@ -135,6 +136,13 @@ private async Task ClaimPackage(Package package) { } private async Task ClaimFreeApp(uint appID) { + // One final check before claiming to make sure we still don't own this app + if (PackageFilter.OwnsApp(appID)) { + Bot.ArchiLogger.LogGenericDebug(String.Format(ArchiSteamFarm.Localization.Strings.BotAddLicense, String.Format("app/{0}", appID), EResult.AlreadyOwned)); + + return EResult.AlreadyOwned; + } + SteamApps.FreeLicenseCallback response; try { response = await Bot.SteamApps.RequestFreeLicense(appID).ToLongRunningTask().ConfigureAwait(false); @@ -171,6 +179,13 @@ private async Task ClaimFreeApp(uint appID) { } private async Task ClaimFreeSub(uint subID) { + // One final check before claiming to make sure we still don't own this package + if (PackageFilter.OwnsSub(subID)) { + Bot.ArchiLogger.LogGenericDebug(String.Format(ArchiSteamFarm.Localization.Strings.BotAddLicense, String.Format("sub/{0}", subID), EResult.AlreadyOwned)); + + return EResult.AlreadyOwned; + } + EResult result; EPurchaseResultDetail purchaseResult; try {