diff --git a/ArchiSteamFarm/Steam/Bot.cs b/ArchiSteamFarm/Steam/Bot.cs index 0bcfc01d5d01d..95b316c486536 100644 --- a/ArchiSteamFarm/Steam/Bot.cs +++ b/ArchiSteamFarm/Steam/Bot.cs @@ -263,7 +263,7 @@ private set { [JsonIgnore] [PublicAPI] - public FrozenDictionary OwnedPackages { get; private set; } = FrozenDictionary.Empty; + public FrozenDictionary OwnedPackages { get; private set; } = FrozenDictionary.Empty; [JsonInclude] [JsonRequired] @@ -1127,7 +1127,7 @@ internal static string FormatBotResponse(string response, string botName) { DateTime mostRecent = DateTime.MinValue; foreach (uint packageID in packageIDs) { - if (!OwnedPackages.TryGetValue(packageID, out SteamApps.LicenseListCallback.License? packageData)) { + if (!OwnedPackages.TryGetValue(packageID, out LicenseData? packageData)) { continue; } @@ -1152,7 +1152,7 @@ internal static string FormatBotResponse(string response, string botName) { DateTime safePlayableBefore = DateTime.UtcNow.AddMonths(-RegionRestrictionPlayableBlockMonths); foreach (uint packageID in packageIDs) { - if (!OwnedPackages.TryGetValue(packageID, out SteamApps.LicenseListCallback.License? ownedPackageData)) { + if (!OwnedPackages.TryGetValue(packageID, out LicenseData? ownedPackageData)) { // We don't own that packageID, keep checking continue; } @@ -2854,7 +2854,7 @@ private async void OnDisconnected(SteamClient.DisconnectedCallback callback) { Trading.OnDisconnected(); FirstTradeSent = false; - OwnedPackages = FrozenDictionary.Empty; + OwnedPackages = FrozenDictionary.Empty; EResult lastLogOnResult = LastLogOnResult; @@ -3178,7 +3178,7 @@ private async void OnLicenseList(SteamApps.LicenseListCallback callback) { Commands.OnNewLicenseList(); - Dictionary ownedPackages = new(); + Dictionary ownedPackages = new(); Dictionary packageAccessTokens = new(); Dictionary packagesToRefresh = new(); @@ -3187,7 +3187,12 @@ private async void OnLicenseList(SteamApps.LicenseListCallback callback) { // 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)).ThenBy(static license => license.TimeCreated)) { - ownedPackages[license.PackageID] = license; + ownedPackages[license.PackageID] = new LicenseData { + LicenseFlags = license.LicenseFlags, + PackageID = license.PackageID, + PaymentMethod = license.PaymentMethod, + TimeCreated = license.TimeCreated + }; if (!OwnedPackages.ContainsKey(license.PackageID)) { hasNewEntries = true; diff --git a/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs b/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs index a57099a5ac980..25a47e9ef1152 100644 --- a/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs +++ b/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs @@ -1500,7 +1500,7 @@ private async Task SortGamesToFarm() { if (packageIDs != null) { foreach (uint packageID in packageIDs) { - if (!Bot.OwnedPackages.TryGetValue(packageID, out SteamApps.LicenseListCallback.License? packageData)) { + if (!Bot.OwnedPackages.TryGetValue(packageID, out LicenseData? packageData)) { Bot.ArchiLogger.LogNullError(packageData); return; diff --git a/ArchiSteamFarm/Steam/Data/LicenseData.cs b/ArchiSteamFarm/Steam/Data/LicenseData.cs new file mode 100644 index 0000000000000..d2ff62164a0c1 --- /dev/null +++ b/ArchiSteamFarm/Steam/Data/LicenseData.cs @@ -0,0 +1,34 @@ +// ---------------------------------------------------------------------------------------------- +// _ _ _ ____ _ _____ +// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ +// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ +// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| +// ---------------------------------------------------------------------------------------------- +// | +// Copyright 2015-2024 Ɓukasz "JustArchi" Domeradzki +// Contact: JustArchi@JustArchi.net +// | +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// | +// http://www.apache.org/licenses/LICENSE-2.0 +// | +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using SteamKit2; + +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 47d2aa4d7fc67..d9ae652172b51 100644 --- a/ArchiSteamFarm/Steam/Interaction/Commands.cs +++ b/ArchiSteamFarm/Steam/Interaction/Commands.cs @@ -690,7 +690,7 @@ internal void OnNewLicenseList() { break; } default: { - if (Bot.OwnedPackages.TryGetValue(gameID, out SteamApps.LicenseListCallback.License? package) && !package.LicenseFlags.HasFlag(ELicenseFlags.Borrowed)) { + if (Bot.OwnedPackages.TryGetValue(gameID, out LicenseData? package) && !package.LicenseFlags.HasFlag(ELicenseFlags.Borrowed)) { response.AppendLine(FormatBotResponse(Strings.FormatBotAddLicense($"sub/{gameID}", $"{EResult.Fail}/{EPurchaseResultDetail.AlreadyPurchased}"))); break; @@ -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 SteamApps.LicenseListCallback.License? package) && !package.LicenseFlags.HasFlag(ELicenseFlags.Borrowed)) { + if (Bot.OwnedPackages.TryGetValue(packageID, out LicenseData? package) && !package.LicenseFlags.HasFlag(ELicenseFlags.Borrowed)) { result[$"sub/{packageID}"] = packageID.ToString(CultureInfo.InvariantCulture); response.AppendLine(FormatBotResponse(Strings.FormatBotOwnedAlready($"sub/{packageID}"))); } else {