From 0374a529b9686fe9c754a72ea65a6aaa3e5bdafe Mon Sep 17 00:00:00 2001 From: azuisleet Date: Sat, 14 Apr 2012 17:49:21 -0600 Subject: [PATCH] Added support for Steam3 license list in AccountHasAccess. Ignore contenttype when depots are present. --- DepotDownloader/ContentDownloader.cs | 30 +++++++++++++---- DepotDownloader/Steam3Session.cs | 49 ++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 7 deletions(-) diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index 77943f56..7535d463 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -142,14 +142,28 @@ namespace DepotDownloader return false; } - static bool AccountHasAccess( int depotId ) + static bool AccountHasAccess( int depotId, bool appId=false ) { if ( steam3 == null || steam3.Licenses == null ) return CDRManager.SubHasDepot( 0, depotId ); foreach ( var license in steam3.Licenses ) { - // TODO: support PackageInfoRequest/Response, this is a steam2 dependency + steam3.RequestPackageInfo(license.PackageID); + + SteamApps.PackageInfoCallback.Package package; + if (steam3.PackageInfo.TryGetValue((uint)license.PackageID, out package) && package.Status == SteamApps.PackageInfoCallback.Package.PackageStatus.OK) + { + KeyValue root = package.Data[license.PackageID.ToString()]; + KeyValue subset = (appId == true ? root["appids"] : root["depotids"]); + + foreach (var child in subset.Children) + { + if (child.AsInteger() == depotId) + return true; + } + } + if ( CDRManager.SubHasDepot( ( int )license.PackageID, depotId ) ) return true; } @@ -210,10 +224,12 @@ namespace DepotDownloader int contenttype = config[appId.ToString()]["contenttype"].AsInteger(0); // EContentDownloadSourceType? - if (contenttype == 3) - return DownloadSource.Steam3; + if (contenttype != 3) + { + Console.WriteLine("Warning: App {0} does not advertise contenttype as steam3, but has steam3 depots", appId); + } - return DownloadSource.Steam2; + return DownloadSource.Steam3; } @@ -329,7 +345,7 @@ namespace DepotDownloader if(steam3 != null) steam3.RequestAppInfo((uint)appId); - if (!AccountHasAccess(appId)) + if (!AccountHasAccess(appId, true)) { string contentName = GetAppOrDepotName(-1, appId); Console.WriteLine("App {0} ({1}) is not available from this account.", appId, contentName); @@ -401,7 +417,7 @@ namespace DepotDownloader string contentName = GetAppOrDepotName(depotId, appId); - if (!AccountHasAccess(depotId)) + if (!AccountHasAccess(depotId, false)) { Console.WriteLine("Depot {0} ({1}) is not available from this account.", depotId, contentName); diff --git a/DepotDownloader/Steam3Session.cs b/DepotDownloader/Steam3Session.cs index 42cded70..701f209b 100644 --- a/DepotDownloader/Steam3Session.cs +++ b/DepotDownloader/Steam3Session.cs @@ -32,6 +32,7 @@ namespace DepotDownloader public Dictionary AppTickets { get; private set; } public Dictionary DepotKeys { get; private set; } public Dictionary AppInfo { get; private set; } + public Dictionary PackageInfo { get; private set; } public Dictionary AppInfoOverridesCDR { get; private set; } public SteamClient steamClient; @@ -51,6 +52,8 @@ namespace DepotDownloader // output Credentials credentials; + JobCallback packageInfoCallback; + static readonly TimeSpan STEAM3_TIMEOUT = TimeSpan.FromSeconds( 30 ); @@ -65,6 +68,7 @@ namespace DepotDownloader this.AppTickets = new Dictionary(); this.DepotKeys = new Dictionary(); this.AppInfo = new Dictionary(); + this.PackageInfo = new Dictionary(); this.AppInfoOverridesCDR = new Dictionary(); this.steamClient = new SteamClient(); @@ -117,6 +121,9 @@ namespace DepotDownloader Console.WriteLine("Got AppInfo for {0}: {1}", app.AppID, app.Status); AppInfo.Add(app.AppID, app); + if (app.Status == SteamApps.AppInfoCallback.App.AppInfoStatus.Unknown) + continue; + KeyValue depots; if (app.Sections.TryGetValue(EAppInfoSection.Depots, out depots)) { @@ -138,6 +145,33 @@ namespace DepotDownloader } } + public void RequestPackageInfo(uint packageId) + { + if (PackageInfo.ContainsKey(packageId)) + return; + + if (packageInfoCallback != null) + { + do + { + WaitForCallbacks(); + } + while (!packageInfoCallback.Completed && !bAborted); + + if (PackageInfo.ContainsKey(packageId)) + return; + } + + using (var singlePackageInfoCallback = new JobCallback(PackageInfoCallback, callbacks, steamApps.GetPackageInfo(packageId))) + { + do + { + WaitForCallbacks(); + } + while (!singlePackageInfoCallback.Completed && !bAborted); + } + } + public void RequestAppTicket(uint appId) { if (AppTickets.ContainsKey(appId) || bAborted) @@ -291,8 +325,23 @@ namespace DepotDownloader Console.WriteLine("Got {0} licenses for account!", licenseList.LicenseList.Count); Licenses = licenseList.LicenseList; + + List licenseQuery = new List(); + foreach (var license in Licenses) + { + licenseQuery.Add(license.PackageID); + } + + packageInfoCallback = new JobCallback(PackageInfoCallback, callbacks, steamApps.GetPackageInfo(licenseQuery)); } + private void PackageInfoCallback(SteamApps.PackageInfoCallback packageInfo, ulong jobid) + { + foreach (var package in packageInfo.Packages) + { + PackageInfo[package.PackageID] = package; + } + } private void UpdateMachineAuthCallback(SteamUser.UpdateMachineAuthCallback machineAuth, ulong jobId) {