From 028e9ce8c829fffe96ceb24b221ae40c15f96302 Mon Sep 17 00:00:00 2001 From: Ryan Kistner Date: Tue, 19 Feb 2013 19:58:23 -0700 Subject: [PATCH] Added PICS token support. Cleaned up reconnect logic. --HG-- extra : rebase_source : 7fac8df8fba76a3dd084341154822ae3745eb879 --- DepotDownloader/Steam3Session.cs | 36 ++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/DepotDownloader/Steam3Session.cs b/DepotDownloader/Steam3Session.cs index af8fb2b6..63ab45fa 100644 --- a/DepotDownloader/Steam3Session.cs +++ b/DepotDownloader/Steam3Session.cs @@ -31,6 +31,7 @@ namespace DepotDownloader } public Dictionary AppTickets { get; private set; } + public Dictionary AppTokens { get; private set; } public Dictionary DepotKeys { get; private set; } public Dictionary AppInfo { get; private set; } public Dictionary PackageInfo { get; private set; } @@ -66,6 +67,7 @@ namespace DepotDownloader this.bAborted = false; this.AppTickets = new Dictionary(); + this.AppTokens = new Dictionary(); this.DepotKeys = new Dictionary(); this.AppInfo = new Dictionary(); this.PackageInfo = new Dictionary(); @@ -118,6 +120,28 @@ namespace DepotDownloader if (AppInfo.ContainsKey(appId) || bAborted) return; + Action cbMethodTokens = (appTokens, jobId) => + { + if (appTokens.AppTokensDenied.Contains(appId)) + { + Console.WriteLine("Insufficient privileges to get access token for app {0}", appId); + } + + foreach (var token_dict in appTokens.AppTokens) + { + this.AppTokens.Add(token_dict.Key, token_dict.Value); + } + }; + + using (JobCallback appTokensCallback = new JobCallback(cbMethodTokens, callbacks, steamApps.PICSGetAccessTokens(new List() { appId }, new List() { }))) + { + do + { + WaitForCallbacks(); + } + while (!appTokensCallback.Completed && !bAborted); + } + Action cbMethod = (appInfo, jobId) => { Debug.Assert( appInfo.ResponsePending == false ); @@ -145,7 +169,11 @@ namespace DepotDownloader } }; - using (JobCallback appInfoCallback = new JobCallback(cbMethod, callbacks, steamApps.PICSGetProductInfo(appId, null, false))) + SteamApps.PICSRequest request = new SteamApps.PICSRequest(appId); + if (AppTokens.ContainsKey(appId)) + request.AccessToken = AppTokens[appId]; + + using (JobCallback appInfoCallback = new JobCallback(cbMethod, callbacks, steamApps.PICSGetProductInfo(new List() { request }, new List() { }))) { do { @@ -255,6 +283,8 @@ namespace DepotDownloader void Connect() { + bAborted = false; + bConnected = false; this.connectTime = DateTime.Now; this.steamClient.Connect(); } @@ -311,7 +341,7 @@ namespace DepotDownloader private void DisconnectedCallback(SteamClient.DisconnectedCallback disconnected) { - if (bAborted) + if (!bConnected || bAborted) return; Console.WriteLine("Reconnecting"); @@ -338,6 +368,8 @@ namespace DepotDownloader Console.WriteLine("This account is protected by Steam Guard. Please enter the authentication code sent to your email address."); Console.Write("Auth Code: "); + Abort(false); + logonDetails.AuthCode = Console.ReadLine(); Console.Write("Retrying Steam3 connection...");