diff --git a/Samples/9.AsyncJobs/Program.cs b/Samples/9.AsyncJobs/Program.cs index 8d0023d63..a6996222d 100644 --- a/Samples/9.AsyncJobs/Program.cs +++ b/Samples/9.AsyncJobs/Program.cs @@ -122,10 +122,13 @@ static async void OnLoggedOn( SteamUser.LoggedOnCallback callback ) return; } - // in this sample, we'll simply do a few async requests to acquire information about appid 440 (Team Fortress 2) + // in this sample, we'll simply do a few async requests to acquire information about Counter-Strike: Global Offensive - // first, we'll request a depot decryption key for TF2's client/server shared depot (441) - var depotJob = steamApps.GetDepotDecryptionKey( depotid: 441, appid: 440 ); + uint appid = 730; + uint depotid = 731; + + // first, we'll request a depot decryption key for CSGO's common files depot (731) + var depotJob = steamApps.GetDepotDecryptionKey( depotid, appid ); // at this point, this request is now in-flight to the steam server, so we'll use te async/await pattern to wait for a response // the await pattern allows this code to resume once the Steam servers have replied to the request. @@ -144,8 +147,20 @@ static async void OnLoggedOn( SteamUser.LoggedOnCallback callback ) Console.WriteLine( "Unable to request depot key!" ); } - // now request some product info for TF2 - var productJob = steamApps.PICSGetProductInfo( 440, package: null ); + // now request the access token + var accessTokenJob = steamApps.PICSGetAccessTokens( appid, package: null ); + var accessTokenResult = await accessTokenJob; + ulong accessToken = 0; + + // Get the access token, if the app is owned it may be a long value, or 0 if it is public. + // If the request was denied, the appid will be listed in AppTokensDenied. + accessTokenResult.AppTokens.TryGetValue( appid, out accessToken ); + + // create a request product info request struct + var request = new SteamApps.PICSRequest( appid, accessToken ); + + // now request some product info + var productJob = steamApps.PICSGetProductInfo( app: request, package: null, metaDataOnly: false ); // note that with some requests, Steam can return multiple results, so these jobs don't return the callback object directly, but rather // a result set that could contain multiple callback objects if Steam gives us multiple results @@ -168,7 +183,7 @@ static async void OnLoggedOn( SteamUser.LoggedOnCallback callback ) // AsyncJobFailedException or TaskCanceledException will be thrown // the result set might not have our data, so we need to test to see if we have results for our request - SteamApps.PICSProductInfoCallback productInfo = resultSet.Results.FirstOrDefault( prodCallback => prodCallback.Apps.ContainsKey( 440 ) ); + SteamApps.PICSProductInfoCallback productInfo = resultSet.Results.FirstOrDefault( prodCallback => prodCallback.Apps.ContainsKey( appid ) ); if ( productInfo != null ) { @@ -184,7 +199,7 @@ static async void OnLoggedOn( SteamUser.LoggedOnCallback callback ) // the request partially completed, but then we timed out. essentially the same as the previous case, but Steam didn't explicitly fail. // we still need to check our result set to see if we have our data - SteamApps.PICSProductInfoCallback productInfo = resultSet.Results.FirstOrDefault( prodCallback => prodCallback.Apps.ContainsKey( 440 ) ); + SteamApps.PICSProductInfoCallback productInfo = resultSet.Results.FirstOrDefault( prodCallback => prodCallback.Apps.ContainsKey( appid ) ); if ( productInfo != null ) { @@ -198,7 +213,7 @@ static async void OnLoggedOn( SteamUser.LoggedOnCallback callback ) // lastly, if you're unable to use the async/await pattern (older VS/compiler, etc) you can still directly access the TPL Task associated // with the async job by calling `ToTask()` - var depotTask = steamApps.GetDepotDecryptionKey( depotid: 441, appid: 440 ).ToTask(); + var depotTask = steamApps.GetDepotDecryptionKey( depotid, appid ).ToTask(); // set up a continuation for when this task completes var ignored = depotTask.ContinueWith( task => @@ -212,7 +227,6 @@ static async void OnLoggedOn( SteamUser.LoggedOnCallback callback ) }, TaskContinuationOptions.OnlyOnRanToCompletion ); } - static void OnLoggedOff( SteamUser.LoggedOffCallback callback ) { diff --git a/SteamKit2/SteamKit2/Steam/Handlers/SteamApps/SteamApps.cs b/SteamKit2/SteamKit2/Steam/Handlers/SteamApps/SteamApps.cs index 98ffd3c93..e3e348b55 100644 --- a/SteamKit2/SteamKit2/Steam/Handlers/SteamApps/SteamApps.cs +++ b/SteamKit2/SteamKit2/Steam/Handlers/SteamApps/SteamApps.cs @@ -16,16 +16,10 @@ namespace SteamKit2 /// public sealed partial class SteamApps : ClientMsgHandler { - - // Ambiguous reference in cref attribute: 'SteamApps.PICSGetProductInfo'. Assuming 'SteamKit2.SteamApps.PICSGetProductInfo(uint?, uint?, bool, bool)', - // but could have also matched other overloads including 'SteamKit2.SteamApps.PICSGetProductInfo(System.Collections.Generic.IEnumerable, System.Collections.Generic.IEnumerable, bool)'. -#pragma warning disable 0419 - /// - /// Represents a PICS request used for + /// Represents a PICS request used for /// public struct PICSRequest -#pragma warning restore 0419 { /// /// Gets or sets the ID of the app or package being requested @@ -181,14 +175,14 @@ public AsyncJob PICSGetChangesSince( uint lastChangeNumber /// Results are returned in a callback. /// The returned can also be awaited to retrieve the callback result. /// - /// App id requested. - /// Package id requested. + /// request for an app. + /// request for a package. /// Whether to send only meta data. /// The Job ID of the request. This can be used to find the appropriate . - public AsyncJobMultiple PICSGetProductInfo(uint? app, uint? package, bool metaDataOnly = false) + public AsyncJobMultiple PICSGetProductInfo( PICSRequest? app, PICSRequest? package, bool metaDataOnly = false ) { - List apps = new List(); - List packages = new List(); + var apps = new List(); + var packages = new List(); if ( app.HasValue ) apps.Add( app.Value ); if ( package.HasValue ) packages.Add( package.Value ); @@ -196,20 +190,6 @@ public AsyncJobMultiple PICSGetProductInfo(uint? app, u return PICSGetProductInfo( apps, packages, metaDataOnly ); } - /// - /// Request product information for a list of apps or packages - /// Results are returned in a callback. - /// The returned can also be awaited to retrieve the callback result. - /// - /// List of app ids requested. - /// List of package ids requested. - /// Whether to send only meta data. - /// The Job ID of the request. This can be used to find the appropriate . - public AsyncJobMultiple PICSGetProductInfo( IEnumerable apps, IEnumerable packages, bool metaDataOnly = false ) - { - return PICSGetProductInfo( apps.Select( app => new PICSRequest( app ) ), packages.Select( package => new PICSRequest( package ) ), metaDataOnly ); - } - /// /// Request product information for a list of apps or packages /// Results are returned in a callback.