Use ArchiHandler to fetch owned games (#2370)

* Use ArchiHandler to fetch owned games

* Mark deprecated methods with Obsolete attribute
This commit is contained in:
Vitaliya 2021-07-10 18:31:48 +03:00 committed by GitHub
parent 1e30b843e0
commit fd4c1ef59b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 4 deletions

View file

@ -89,6 +89,47 @@ namespace ArchiSteamFarm.Steam.Integration {
return response.Result == EResult.OK;
}
[PublicAPI]
public async Task<Dictionary<uint, string>?> 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<CPlayer_GetOwnedGames_Response>();
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));

View file

@ -254,8 +254,11 @@ namespace ArchiSteamFarm.Steam.Integration {
}
}
[Obsolete("Use " + nameof(ArchiHandler) + "." + nameof(ArchiHandler.GetOwnedGames) + " instead")]
[PublicAPI]
public async Task<Dictionary<uint, string>?> 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 @@ namespace ArchiSteamFarm.Steam.Integration {
return result;
}
[Obsolete("Use " + nameof(ArchiHandler) + "." + nameof(ArchiHandler.GetOwnedGames) + " instead")]
[PublicAPI]
public async Task<Dictionary<uint, string>?> 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)) {

View file

@ -481,9 +481,7 @@ namespace ArchiSteamFarm.Steam.Interaction {
return null;
}
bool? hasValidApiKey = await Bot.ArchiWebHandler.HasValidApiKey().ConfigureAwait(false);
Dictionary<uint, string>? gamesOwned = hasValidApiKey.GetValueOrDefault() ? await Bot.ArchiWebHandler.GetOwnedGames(Bot.SteamID).ConfigureAwait(false) : await Bot.ArchiWebHandler.GetMyOwnedGames().ConfigureAwait(false);
Dictionary<uint, string>? gamesOwned = await Bot.ArchiHandler.GetOwnedGames(Bot.SteamID).ConfigureAwait(false);
if (gamesOwned?.Count > 0) {
lock (CachedGamesOwned) {

View file

@ -13,7 +13,7 @@
<PackageVersion Include="Nito.AsyncEx.Coordination" Version="5.1.0" />
<PackageVersion Include="NLog" Version="4.7.10" />
<PackageVersion Include="NLog.Web.AspNetCore" Version="4.12.0" />
<PackageVersion Include="SteamKit2" Version="2.3.0" />
<PackageVersion Include="SteamKit2" Version="2.4.0-Alpha.2" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.1.4" />
<PackageVersion Include="Swashbuckle.AspNetCore.Annotations" Version="6.1.4" />
<PackageVersion Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.1.4" />