Skip to content

Commit

Permalink
Verify lack of ownership before activation attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
Citrinate committed Dec 19, 2024
1 parent 69521a3 commit cca469a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
16 changes: 16 additions & 0 deletions FreePackages/PackageFilter/PackageFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
17 changes: 16 additions & 1 deletion FreePackages/PackageQueue/PackageQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -135,6 +136,13 @@ private async Task<EResult> ClaimPackage(Package package) {
}

private async Task<EResult> 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);
Expand Down Expand Up @@ -171,6 +179,13 @@ private async Task<EResult> ClaimFreeApp(uint appID) {
}

private async Task<EResult> 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 {
Expand Down

0 comments on commit cca469a

Please sign in to comment.