diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index 68288df8..21a0ab39 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -14,6 +14,8 @@ namespace DepotDownloader { const string DOWNLOAD_DIR = "depots"; + static Steam3Session steam3; + public static void Download( int depotId, int depotVersion, int cellId, string username, string password ) { Directory.CreateDirectory( DOWNLOAD_DIR ); @@ -55,6 +57,10 @@ namespace DepotDownloader if ( storageId == uint.MaxValue ) { Console.WriteLine( "This depot requires valid user credentials and a license for this app" ); + + if ( steam3 != null ) + steam3.Disconnect(); + return; } @@ -126,6 +132,9 @@ namespace DepotDownloader csClient.Disconnect(); + if ( steam3 != null ) + steam3.Disconnect(); + } static ContentServerClient.Credentials GetCredentials( uint depotId, string username, string password ) @@ -144,7 +153,7 @@ namespace DepotDownloader byte[] serverTgt; Blob accountRecord; - Console.Write( "Logging in '{0}'... ", username ); + Console.Write( "Logging '{0}' into Steam2... ", username ); AuthServerClient.LoginResult result = asClient.Login( username, password, out clientTgt, out serverTgt, out accountRecord ); if ( result != AuthServerClient.LoginResult.LoggedIn ) @@ -153,7 +162,9 @@ namespace DepotDownloader return null; } - Steam3Session steam3 = new Steam3Session( + Console.WriteLine( " Done!" ); + + steam3 = new Steam3Session( new SteamUser.LogOnDetails() { Username = username, diff --git a/DepotDownloader/Steam3Session.cs b/DepotDownloader/Steam3Session.cs index bcfb025d..37a46756 100644 --- a/DepotDownloader/Steam3Session.cs +++ b/DepotDownloader/Steam3Session.cs @@ -24,6 +24,8 @@ namespace DepotDownloader SteamApps steamApps; Thread callbackThread; + ManualResetEvent credentialHandle; + bool bConnected; DateTime connectTime; @@ -43,7 +45,8 @@ namespace DepotDownloader this.logonDetails = details; this.credentials = new Credentials(); - + this.credentialHandle = new ManualResetEvent( false ); + this.bConnected = false; this.steamClient = new SteamClient(); @@ -53,16 +56,22 @@ namespace DepotDownloader this.callbackThread = new Thread( HandleCallbacks ); this.callbackThread.Start(); + Console.Write( "Connecting to Steam3..." ); + this.connectTime = DateTime.Now; this.steamClient.Connect(); } public Credentials WaitForCredentials() { - this.callbackThread.Join(); // no timespan as the thread will terminate itself + this.credentialHandle.WaitOne(); return credentials; } + public void Disconnect() + { + steamClient.Disconnect(); + } void HandleCallbacks() { @@ -72,7 +81,10 @@ namespace DepotDownloader TimeSpan diff = DateTime.Now - connectTime; - if ( diff > STEAM3_TIMEOUT || ( credentials.HasSessionToken && credentials.AppTicket != null ) ) + if ( diff > STEAM3_TIMEOUT && !bConnected ) + break; + + if ( credentials.HasSessionToken && credentials.AppTicket != null ) break; if ( callback == null ) @@ -80,7 +92,14 @@ namespace DepotDownloader if ( callback.IsType() ) { + Console.WriteLine( " Done!" ); + bConnected = true; steamUser.LogOn( logonDetails ); + + SteamID steamId = new SteamID(); + steamId.SetFromSteam2( logonDetails.ClientTGT.UserID, steamClient.ConnectedUniverse ); + + Console.Write( "Logging '{0}' into Steam3...", steamId.Render() ); } if ( callback.IsType() ) @@ -94,6 +113,8 @@ namespace DepotDownloader break; } + Console.WriteLine( " Done!" ); + steamApps.GetAppOwnershipTicket( depotId ); } @@ -111,6 +132,7 @@ namespace DepotDownloader break; } + Console.WriteLine( "Got appticket for {0}!", depotId ); credentials.AppTicket = msg.Ticket; } @@ -119,12 +141,15 @@ namespace DepotDownloader { var msg = callback as SteamUser.SessionTokenCallback; + Console.WriteLine( "Got session token!" ); credentials.SessionToken = msg.SessionToken; credentials.HasSessionToken = true; } } - steamClient.Disconnect(); + credentialHandle.Set(); + } + } }