Skip to content

Commit

Permalink
Skip borrowed games from owned packages
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Dec 20, 2024
1 parent f7f7dbd commit 61fdbcf
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
5 changes: 2 additions & 3 deletions ArchiSteamFarm/Steam/Bot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions ArchiSteamFarm/Steam/Cards/CardsFarmer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
using ArchiSteamFarm.Storage;
using ArchiSteamFarm.Web;
using JetBrains.Annotations;
using SteamKit2;

namespace ArchiSteamFarm.Steam.Cards;

Expand Down Expand Up @@ -1496,7 +1495,7 @@ private async Task SortGamesToFarm() {

foreach (Game game in GamesToFarm) {
DateTime redeemDate = DateTime.MinValue;
HashSet<uint>? packageIDs = ASF.GlobalDatabase?.GetPackageIDs(game.AppID, Bot.OwnedPackages.Values.Where(static package => !package.LicenseFlags.HasFlag(ELicenseFlags.Borrowed)).Select(static package => package.PackageID));
HashSet<uint>? packageIDs = ASF.GlobalDatabase?.GetPackageIDs(game.AppID, Bot.OwnedPackages.Keys);

if (packageIDs != null) {
foreach (uint packageID in packageIDs) {
Expand Down
1 change: 0 additions & 1 deletion ArchiSteamFarm/Steam/Data/LicenseData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
namespace ArchiSteamFarm.Steam.Data;

public sealed record LicenseData {

Check warning on line 29 in ArchiSteamFarm/Steam/Data/LicenseData.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

RoslynAnalyzers Consider making public types internal

Because an application's API isn't typically referenced from outside the assembly, types can be made internal

Check warning on line 29 in ArchiSteamFarm/Steam/Data/LicenseData.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

RoslynAnalyzers Consider making public types internal

Because an application's API isn't typically referenced from outside the assembly, types can be made internal
public required ELicenseFlags LicenseFlags { get; init; }
public required uint PackageID { get; init; }
public required EPaymentMethod PaymentMethod { get; init; }
public required DateTime TimeCreated { get; init; }
Expand Down
8 changes: 4 additions & 4 deletions ArchiSteamFarm/Steam/Interaction/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ internal void OnNewLicenseList() {

switch (type.ToUpperInvariant()) {
case "A" or "APP": {
HashSet<uint>? packageIDs = ASF.GlobalDatabase?.GetPackageIDs(gameID, Bot.OwnedPackages.Values.Where(static package => !package.LicenseFlags.HasFlag(ELicenseFlags.Borrowed)).Select(static package => package.PackageID), 1);
HashSet<uint>? 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}")));
Expand All @@ -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;
Expand Down Expand Up @@ -2020,7 +2020,7 @@ internal void OnNewLicenseList() {

switch (type.ToUpperInvariant()) {
case "A" or "APP" when uint.TryParse(game, out uint appID) && (appID > 0):
HashSet<uint>? packageIDs = ASF.GlobalDatabase?.GetPackageIDs(appID, Bot.OwnedPackages.Values.Where(static package => !package.LicenseFlags.HasFlag(ELicenseFlags.Borrowed)).Select(static package => package.PackageID), 1);
HashSet<uint>? packageIDs = ASF.GlobalDatabase?.GetPackageIDs(appID, Bot.OwnedPackages.Keys, 1);

if (packageIDs?.Count > 0) {
if ((gamesOwned != null) && gamesOwned.TryGetValue(appID, out string? cachedGameName)) {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 61fdbcf

Please sign in to comment.