diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 45e095ffb..e3fa28343 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -289,6 +289,46 @@ namespace ArchiSteamFarm { return result; } + internal Dictionary GetOwnedGames(ulong steamID) { + if (steamID == 0 || string.IsNullOrEmpty(Bot.BotConfig.SteamApiKey)) { + return null; + } + + KeyValue response = null; + using (dynamic iPlayerService = WebAPI.GetInterface("IPlayerService", Bot.BotConfig.SteamApiKey)) { + iPlayerService.Timeout = Timeout; + + for (byte i = 0; i < WebBrowser.MaxRetries && response == null; i++) { + try { + response = iPlayerService.GetOwnedGames( + steamid: steamID, + include_appinfo: 1, + secure: !Program.GlobalConfig.ForceHttp + ); + } catch (Exception e) { + Logging.LogGenericException(e); + } + } + } + + if (response == null) { + Logging.LogGenericWTF("Request failed even after " + WebBrowser.MaxRetries + " tries"); + return null; + } + + Dictionary result = new Dictionary(response["games"].Children.Count); + foreach (KeyValue game in response["games"].Children) { + uint appID = (uint) game["appid"].AsUnsignedLong(); + if (appID == 0) { + continue; + } + + result.Add(appID, game["name"].Value); + } + + return result; + } + internal HashSet GetTradeOffers() { if (string.IsNullOrEmpty(Bot.BotConfig.SteamApiKey)) { return null; diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 1c4c0e89a..ef5c8b9f1 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -998,7 +998,13 @@ namespace ArchiSteamFarm { return null; } - Dictionary ownedGames = await ArchiWebHandler.GetOwnedGames().ConfigureAwait(false); + Dictionary ownedGames; + if (!string.IsNullOrEmpty(BotConfig.SteamApiKey)) { + ownedGames = ArchiWebHandler.GetOwnedGames(SteamClient.SteamID); + } else { + ownedGames = await ArchiWebHandler.GetOwnedGames().ConfigureAwait(false); + } + if (ownedGames == null || ownedGames.Count == 0) { return "List of owned games is empty!"; }