From 61fdbcfa9febb3505407992f2f7e14e378112382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Domeradzki?= Date: Fri, 20 Dec 2024 15:08:17 +0100 Subject: [PATCH] Skip borrowed games from owned packages --- ArchiSteamFarm/Steam/Bot.cs | 5 ++--- ArchiSteamFarm/Steam/Cards/CardsFarmer.cs | 3 +-- ArchiSteamFarm/Steam/Data/LicenseData.cs | 1 - ArchiSteamFarm/Steam/Interaction/Commands.cs | 8 ++++---- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/ArchiSteamFarm/Steam/Bot.cs b/ArchiSteamFarm/Steam/Bot.cs index a35cffa704e1a..05b54ab624b24 100644 --- a/ArchiSteamFarm/Steam/Bot.cs +++ b/ArchiSteamFarm/Steam/Bot.cs @@ -3185,10 +3185,9 @@ private async void OnLicenseList(SteamApps.LicenseListCallback callback) { bool hasNewEntries = false; - // We want to record only the most relevant entry, therefore we apply ordering here so we end up preferably with the most recent non-borrowed entry - foreach (SteamApps.LicenseListCallback.License license in callback.LicenseList.OrderByDescending(static license => !license.LicenseFlags.HasFlag(ELicenseFlags.Borrowed)).ThenByDescending(static license => license.TimeCreated).Where(license => !ownedPackages.ContainsKey(license.PackageID))) { + // We want to record only the most relevant entry from non-borrowed games, therefore we also apply ordering here + foreach (SteamApps.LicenseListCallback.License license in callback.LicenseList.Where(static license => !license.LicenseFlags.HasFlag(ELicenseFlags.Borrowed)).OrderByDescending(static license => license.TimeCreated).Where(license => !ownedPackages.ContainsKey(license.PackageID))) { ownedPackages[license.PackageID] = new LicenseData { - LicenseFlags = license.LicenseFlags, PackageID = license.PackageID, PaymentMethod = license.PaymentMethod, TimeCreated = license.TimeCreated diff --git a/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs b/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs index 25a47e9ef1152..00a35bdc07a7b 100644 --- a/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs +++ b/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs @@ -45,7 +45,6 @@ using ArchiSteamFarm.Storage; using ArchiSteamFarm.Web; using JetBrains.Annotations; -using SteamKit2; namespace ArchiSteamFarm.Steam.Cards; @@ -1496,7 +1495,7 @@ private async Task SortGamesToFarm() { foreach (Game game in GamesToFarm) { DateTime redeemDate = DateTime.MinValue; - HashSet? packageIDs = ASF.GlobalDatabase?.GetPackageIDs(game.AppID, Bot.OwnedPackages.Values.Where(static package => !package.LicenseFlags.HasFlag(ELicenseFlags.Borrowed)).Select(static package => package.PackageID)); + HashSet? packageIDs = ASF.GlobalDatabase?.GetPackageIDs(game.AppID, Bot.OwnedPackages.Keys); if (packageIDs != null) { foreach (uint packageID in packageIDs) { diff --git a/ArchiSteamFarm/Steam/Data/LicenseData.cs b/ArchiSteamFarm/Steam/Data/LicenseData.cs index d2ff62164a0c1..f7a8a99bcf4e7 100644 --- a/ArchiSteamFarm/Steam/Data/LicenseData.cs +++ b/ArchiSteamFarm/Steam/Data/LicenseData.cs @@ -27,7 +27,6 @@ namespace ArchiSteamFarm.Steam.Data; public sealed record LicenseData { - public required ELicenseFlags LicenseFlags { get; init; } public required uint PackageID { get; init; } public required EPaymentMethod PaymentMethod { get; init; } public required DateTime TimeCreated { get; init; } diff --git a/ArchiSteamFarm/Steam/Interaction/Commands.cs b/ArchiSteamFarm/Steam/Interaction/Commands.cs index d9ae652172b51..6c521032326b2 100644 --- a/ArchiSteamFarm/Steam/Interaction/Commands.cs +++ b/ArchiSteamFarm/Steam/Interaction/Commands.cs @@ -666,7 +666,7 @@ internal void OnNewLicenseList() { switch (type.ToUpperInvariant()) { case "A" or "APP": { - HashSet? packageIDs = ASF.GlobalDatabase?.GetPackageIDs(gameID, Bot.OwnedPackages.Values.Where(static package => !package.LicenseFlags.HasFlag(ELicenseFlags.Borrowed)).Select(static package => package.PackageID), 1); + HashSet? packageIDs = ASF.GlobalDatabase?.GetPackageIDs(gameID, Bot.OwnedPackages.Keys, 1); if (packageIDs is { Count: > 0 }) { response.AppendLine(FormatBotResponse(Strings.FormatBotAddLicense($"app/{gameID}", $"{EResult.Fail}/{EPurchaseResultDetail.AlreadyPurchased}"))); @@ -690,7 +690,7 @@ internal void OnNewLicenseList() { break; } default: { - if (Bot.OwnedPackages.TryGetValue(gameID, out LicenseData? package) && !package.LicenseFlags.HasFlag(ELicenseFlags.Borrowed)) { + if (Bot.OwnedPackages.ContainsKey(gameID)) { response.AppendLine(FormatBotResponse(Strings.FormatBotAddLicense($"sub/{gameID}", $"{EResult.Fail}/{EPurchaseResultDetail.AlreadyPurchased}"))); break; @@ -2020,7 +2020,7 @@ internal void OnNewLicenseList() { switch (type.ToUpperInvariant()) { case "A" or "APP" when uint.TryParse(game, out uint appID) && (appID > 0): - HashSet? packageIDs = ASF.GlobalDatabase?.GetPackageIDs(appID, Bot.OwnedPackages.Values.Where(static package => !package.LicenseFlags.HasFlag(ELicenseFlags.Borrowed)).Select(static package => package.PackageID), 1); + HashSet? packageIDs = ASF.GlobalDatabase?.GetPackageIDs(appID, Bot.OwnedPackages.Keys, 1); if (packageIDs?.Count > 0) { if ((gamesOwned != null) && gamesOwned.TryGetValue(appID, out string? cachedGameName)) { @@ -2087,7 +2087,7 @@ internal void OnNewLicenseList() { continue; case "S" or "SUB" when uint.TryParse(game, out uint packageID) && (packageID > 0): - if (Bot.OwnedPackages.TryGetValue(packageID, out LicenseData? package) && !package.LicenseFlags.HasFlag(ELicenseFlags.Borrowed)) { + if (Bot.OwnedPackages.ContainsKey(packageID)) { result[$"sub/{packageID}"] = packageID.ToString(CultureInfo.InvariantCulture); response.AppendLine(FormatBotResponse(Strings.FormatBotOwnedAlready($"sub/{packageID}"))); } else {