Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ArchiHandler to fetch owned games #2370

Merged
merged 2 commits into from
Jul 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions ArchiSteamFarm/Steam/Integration/ArchiHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,47 @@ public async Task<bool> AddFriend(ulong steamID) {
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));
Expand Down
6 changes: 6 additions & 0 deletions ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,11 @@ public async IAsyncEnumerable<Asset> GetInventoryAsync(ulong steamID = 0, uint a
}
}

[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)));
ezhevita marked this conversation as resolved.
Show resolved Hide resolved

Uri request = new(SteamCommunityURL, "/my/games?l=english&xml=1");

XmlDocumentResponse? response = await UrlGetToXmlDocumentWithSession(request, checkSessionPreemptively: false).ConfigureAwait(false);
Expand Down Expand Up @@ -303,12 +306,15 @@ public async IAsyncEnumerable<Asset> GetInventoryAsync(ulong steamID = 0, uint a
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)));
ezhevita marked this conversation as resolved.
Show resolved Hide resolved

(bool success, string? steamApiKey) = await CachedApiKey.GetValue().ConfigureAwait(false);

if (!success || string.IsNullOrEmpty(steamApiKey)) {
Expand Down
4 changes: 1 addition & 3 deletions ArchiSteamFarm/Steam/Interaction/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,7 @@ internal void OnNewLicenseList() {
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) {
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down