diff --git a/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs b/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs index f5bfe1d6c8456..747ac0c1b58fd 100644 --- a/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs +++ b/ArchiSteamFarm/Steam/Integration/ArchiHandler.cs @@ -89,6 +89,47 @@ public async Task AddFriend(ulong steamID) { return response.Result == EResult.OK; } + [PublicAPI] + public async Task?> GetOwnedGames(ulong steamID) { + if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { + throw new ArgumentOutOfRangeException(nameof(steamID)); + } + + if (Client == null) { + throw new InvalidOperationException(nameof(Client)); + } + + if (!Client.IsConnected) { + return null; + } + + CPlayer_GetOwnedGames_Request request = new() { + steamid = steamID, + include_appinfo = true, + include_free_sub = true, + include_played_free_games = true, + skip_unvetted_apps = false + }; + + SteamUnifiedMessages.ServiceMethodResponse response; + + try { + response = await UnifiedPlayerService.SendMessage(x => x.GetOwnedGames(request)).ToLongRunningTask().ConfigureAwait(false); + } catch (Exception e) { + ArchiLogger.LogGenericWarningException(e); + + return null; + } + + if (response.Result != EResult.OK) { + return null; + } + + CPlayer_GetOwnedGames_Response body = response.GetDeserializedResponse(); + + return body.games.ToDictionary(game => (uint) game.appid, game => game.name); + } + public override void HandleMsg(IPacketMsg packetMsg) { if (packetMsg == null) { throw new ArgumentNullException(nameof(packetMsg)); diff --git a/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs b/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs index 1e41b6afb8b32..a57623a0ed451 100644 --- a/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs +++ b/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs @@ -254,8 +254,11 @@ public async IAsyncEnumerable GetInventoryAsync(ulong steamID = 0, uint a } } + [Obsolete("Use " + nameof(ArchiHandler) + "." + nameof(ArchiHandler.GetOwnedGames) + " instead")] [PublicAPI] public async Task?> GetMyOwnedGames() { + ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningDeprecated, nameof(GetMyOwnedGames), nameof(ArchiHandler) + "." + nameof(ArchiHandler.GetOwnedGames))); + Uri request = new(SteamCommunityURL, "/my/games?l=english&xml=1"); XmlDocumentResponse? response = await UrlGetToXmlDocumentWithSession(request, checkSessionPreemptively: false).ConfigureAwait(false); @@ -303,12 +306,15 @@ public async IAsyncEnumerable GetInventoryAsync(ulong steamID = 0, uint a return result; } + [Obsolete("Use " + nameof(ArchiHandler) + "." + nameof(ArchiHandler.GetOwnedGames) + " instead")] [PublicAPI] public async Task?> GetOwnedGames(ulong steamID) { if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) { throw new ArgumentOutOfRangeException(nameof(steamID)); } + ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningDeprecated, nameof(GetOwnedGames), nameof(ArchiHandler) + "." + nameof(ArchiHandler.GetOwnedGames))); + (bool success, string? steamApiKey) = await CachedApiKey.GetValue().ConfigureAwait(false); if (!success || string.IsNullOrEmpty(steamApiKey)) { diff --git a/ArchiSteamFarm/Steam/Interaction/Commands.cs b/ArchiSteamFarm/Steam/Interaction/Commands.cs index 695ba519b17fb..4acc97397b95a 100644 --- a/ArchiSteamFarm/Steam/Interaction/Commands.cs +++ b/ArchiSteamFarm/Steam/Interaction/Commands.cs @@ -481,9 +481,7 @@ internal void OnNewLicenseList() { return null; } - bool? hasValidApiKey = await Bot.ArchiWebHandler.HasValidApiKey().ConfigureAwait(false); - - Dictionary? gamesOwned = hasValidApiKey.GetValueOrDefault() ? await Bot.ArchiWebHandler.GetOwnedGames(Bot.SteamID).ConfigureAwait(false) : await Bot.ArchiWebHandler.GetMyOwnedGames().ConfigureAwait(false); + Dictionary? gamesOwned = await Bot.ArchiHandler.GetOwnedGames(Bot.SteamID).ConfigureAwait(false); if (gamesOwned?.Count > 0) { lock (CachedGamesOwned) { diff --git a/Directory.Packages.props b/Directory.Packages.props index 02d19fae5c5a4..7070b77bc9f2f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -13,7 +13,7 @@ - +