mirror of
https://github.com/JustArchiNET/ArchiSteamFarm
synced 2024-11-10 07:04:27 +00:00
Use ArchiHandler to fetch owned games (#2370)
* Use ArchiHandler to fetch owned games * Mark deprecated methods with Obsolete attribute
This commit is contained in:
parent
1e30b843e0
commit
fd4c1ef59b
4 changed files with 49 additions and 4 deletions
|
@ -89,6 +89,47 @@ namespace ArchiSteamFarm.Steam.Integration {
|
||||||
return response.Result == EResult.OK;
|
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) {
|
public override void HandleMsg(IPacketMsg packetMsg) {
|
||||||
if (packetMsg == null) {
|
if (packetMsg == null) {
|
||||||
throw new ArgumentNullException(nameof(packetMsg));
|
throw new ArgumentNullException(nameof(packetMsg));
|
||||||
|
|
|
@ -254,8 +254,11 @@ namespace ArchiSteamFarm.Steam.Integration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Obsolete("Use " + nameof(ArchiHandler) + "." + nameof(ArchiHandler.GetOwnedGames) + " instead")]
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public async Task<Dictionary<uint, string>?> GetMyOwnedGames() {
|
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");
|
Uri request = new(SteamCommunityURL, "/my/games?l=english&xml=1");
|
||||||
|
|
||||||
XmlDocumentResponse? response = await UrlGetToXmlDocumentWithSession(request, checkSessionPreemptively: false).ConfigureAwait(false);
|
XmlDocumentResponse? response = await UrlGetToXmlDocumentWithSession(request, checkSessionPreemptively: false).ConfigureAwait(false);
|
||||||
|
@ -303,12 +306,15 @@ namespace ArchiSteamFarm.Steam.Integration {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Obsolete("Use " + nameof(ArchiHandler) + "." + nameof(ArchiHandler.GetOwnedGames) + " instead")]
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public async Task<Dictionary<uint, string>?> GetOwnedGames(ulong steamID) {
|
public async Task<Dictionary<uint, string>?> GetOwnedGames(ulong steamID) {
|
||||||
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) {
|
if ((steamID == 0) || !new SteamID(steamID).IsIndividualAccount) {
|
||||||
throw new ArgumentOutOfRangeException(nameof(steamID));
|
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);
|
(bool success, string? steamApiKey) = await CachedApiKey.GetValue().ConfigureAwait(false);
|
||||||
|
|
||||||
if (!success || string.IsNullOrEmpty(steamApiKey)) {
|
if (!success || string.IsNullOrEmpty(steamApiKey)) {
|
||||||
|
|
|
@ -481,9 +481,7 @@ namespace ArchiSteamFarm.Steam.Interaction {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool? hasValidApiKey = await Bot.ArchiWebHandler.HasValidApiKey().ConfigureAwait(false);
|
Dictionary<uint, string>? gamesOwned = await Bot.ArchiHandler.GetOwnedGames(Bot.SteamID).ConfigureAwait(false);
|
||||||
|
|
||||||
Dictionary<uint, string>? gamesOwned = hasValidApiKey.GetValueOrDefault() ? await Bot.ArchiWebHandler.GetOwnedGames(Bot.SteamID).ConfigureAwait(false) : await Bot.ArchiWebHandler.GetMyOwnedGames().ConfigureAwait(false);
|
|
||||||
|
|
||||||
if (gamesOwned?.Count > 0) {
|
if (gamesOwned?.Count > 0) {
|
||||||
lock (CachedGamesOwned) {
|
lock (CachedGamesOwned) {
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
<PackageVersion Include="Nito.AsyncEx.Coordination" Version="5.1.0" />
|
<PackageVersion Include="Nito.AsyncEx.Coordination" Version="5.1.0" />
|
||||||
<PackageVersion Include="NLog" Version="4.7.10" />
|
<PackageVersion Include="NLog" Version="4.7.10" />
|
||||||
<PackageVersion Include="NLog.Web.AspNetCore" Version="4.12.0" />
|
<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" Version="6.1.4" />
|
||||||
<PackageVersion Include="Swashbuckle.AspNetCore.Annotations" Version="6.1.4" />
|
<PackageVersion Include="Swashbuckle.AspNetCore.Annotations" Version="6.1.4" />
|
||||||
<PackageVersion Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.1.4" />
|
<PackageVersion Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.1.4" />
|
||||||
|
|
Loading…
Reference in a new issue