Touched formatting and line endings. Tweaked login key handling.

pull/25/head
Ryan Kistner 9 years ago
parent dceed3a9a1
commit 58b5b6185e

@ -3,10 +3,7 @@ using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
namespace DepotDownloader namespace DepotDownloader
{ {

@ -1,15 +1,12 @@
using System; using SteamKit2;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Sockets;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using SteamKit2;
using System.Collections.Concurrent;
using System.Threading.Tasks;
namespace DepotDownloader namespace DepotDownloader
{ {
@ -334,13 +331,20 @@ namespace DepotDownloader
public static bool InitializeSteam3( string username, string password ) public static bool InitializeSteam3( string username, string password )
{ {
string loginKey = null;
if ( username != null && ContentDownloader.Config.RememberPassword && ConfigStore.TheConfig.LoginKeys.ContainsKey( username ) )
{
loginKey = ConfigStore.TheConfig.LoginKeys[ username ];
}
steam3 = new Steam3Session( steam3 = new Steam3Session(
new SteamUser.LogOnDetails() new SteamUser.LogOnDetails()
{ {
Username = username, Username = username,
Password = password, Password = loginKey == null ? password : null,
ShouldRememberPassword = Config.RememberPassword, ShouldRememberPassword = Config.RememberPassword,
LoginKey = username != null && ConfigStore.TheConfig.LoginKeys.ContainsKey(username) ? ConfigStore.TheConfig.LoginKeys[username] : null, LoginKey = loginKey,
} }
); );
@ -361,6 +365,7 @@ namespace DepotDownloader
if ( steam3 == null ) if ( steam3 == null )
return; return;
steam3.TryWaitForLoginKey();
steam3.Disconnect(); steam3.Disconnect();
} }
@ -584,7 +589,8 @@ namespace DepotDownloader
while ( depotManifest == null ) while ( depotManifest == null )
{ {
CDNClient client = null; CDNClient client = null;
try { try
{
client = cdnPool.GetConnectionForDepot( appId, depot.id, depot.depotKey, CancellationToken.None ); client = cdnPool.GetConnectionForDepot( appId, depot.id, depot.depotKey, CancellationToken.None );
depotManifest = client.DownloadManifest( depot.id, depot.manifestId ); depotManifest = client.DownloadManifest( depot.id, depot.manifestId );

@ -25,6 +25,7 @@ namespace DepotDownloader
public int MaxServers { get; set; } public int MaxServers { get; set; }
public int MaxDownloads { get; set; } public int MaxDownloads { get; set; }
public string SuppliedPassword { get; set; }
public bool RememberPassword { get; set; } public bool RememberPassword { get; set; }
} }
} }

@ -109,6 +109,9 @@ namespace DepotDownloader
Console.WriteLine( "No username given. Using anonymous account with dedicated server subscription." ); Console.WriteLine( "No username given. Using anonymous account with dedicated server subscription." );
} }
// capture the supplied password in case we need to re-use it after checking the login key
ContentDownloader.Config.SuppliedPassword = password;
if ( ContentDownloader.InitializeSteam3( username, password ) ) if ( ContentDownloader.InitializeSteam3( username, password ) )
{ {
ContentDownloader.DownloadApp( appId, depotId, branch, forceDepot ); ContentDownloader.DownloadApp( appId, depotId, branch, forceDepot );

@ -165,7 +165,8 @@ namespace DepotDownloader
} }
}; };
WaitUntilCallback(() => { WaitUntilCallback( () =>
{
callbacks.Subscribe( steamApps.PICSGetAccessTokens( new List<uint>() { appId }, new List<uint>() { } ), cbMethodTokens ); callbacks.Subscribe( steamApps.PICSGetAccessTokens( new List<uint>() { appId }, new List<uint>() { } ), cbMethodTokens );
}, () => { return completed; } ); }, () => { return completed; } );
@ -195,7 +196,8 @@ namespace DepotDownloader
request.Public = false; request.Public = false;
} }
WaitUntilCallback(() => { WaitUntilCallback( () =>
{
callbacks.Subscribe( steamApps.PICSGetProductInfo( new List<SteamApps.PICSRequest>() { request }, new List<SteamApps.PICSRequest>() { } ), cbMethod ); callbacks.Subscribe( steamApps.PICSGetProductInfo( new List<SteamApps.PICSRequest>() { request }, new List<SteamApps.PICSRequest>() { } ), cbMethod );
}, () => { return completed; } ); }, () => { return completed; } );
} }
@ -225,7 +227,8 @@ namespace DepotDownloader
} }
}; };
WaitUntilCallback(() => { WaitUntilCallback( () =>
{
callbacks.Subscribe( steamApps.PICSGetProductInfo( new List<uint>(), packages ), cbMethod ); callbacks.Subscribe( steamApps.PICSGetProductInfo( new List<uint>(), packages ), cbMethod );
}, () => { return completed; } ); }, () => { return completed; } );
} }
@ -240,7 +243,8 @@ namespace DepotDownloader
success = resultInfo.GrantedApps.Contains( appId ); success = resultInfo.GrantedApps.Contains( appId );
}; };
WaitUntilCallback(() => { WaitUntilCallback( () =>
{
callbacks.Subscribe( steamApps.RequestFreeLicense( appId ), cbMethod ); callbacks.Subscribe( steamApps.RequestFreeLicense( appId ), cbMethod );
}, () => { return completed; } ); }, () => { return completed; } );
@ -276,7 +280,8 @@ namespace DepotDownloader
} }
}; };
WaitUntilCallback(() => { WaitUntilCallback( () =>
{
callbacks.Subscribe( steamApps.GetAppOwnershipTicket( appId ), cbMethod ); callbacks.Subscribe( steamApps.GetAppOwnershipTicket( appId ), cbMethod );
}, () => { return completed; } ); }, () => { return completed; } );
} }
@ -392,6 +397,22 @@ namespace DepotDownloader
} }
} }
public void TryWaitForLoginKey()
{
if ( logonDetails.Username == null || !ContentDownloader.Config.RememberPassword ) return;
DateTime waitUntil = new DateTime().AddSeconds( 10 );
while ( true )
{
DateTime now = new DateTime();
if ( now >= waitUntil ) break;
if ( ConfigStore.TheConfig.LoginKeys.ContainsKey( logonDetails.Username ) ) break;
callbacks.RunWaitAllCallbacks( TimeSpan.FromMilliseconds( 100 ) );
}
}
private void WaitForCallbacks() private void WaitForCallbacks()
{ {
@ -443,7 +464,8 @@ namespace DepotDownloader
if ( bConnecting ) if ( bConnecting )
{ {
Console.WriteLine( "Connection to Steam failed. Trying again" ); Console.WriteLine( "Connection to Steam failed. Trying again" );
} else }
else
{ {
Console.WriteLine( "Lost connection to Steam. Reconnecting" ); Console.WriteLine( "Lost connection to Steam. Reconnecting" );
} }
@ -457,19 +479,41 @@ namespace DepotDownloader
{ {
bool isSteamGuard = loggedOn.Result == EResult.AccountLogonDenied; bool isSteamGuard = loggedOn.Result == EResult.AccountLogonDenied;
bool is2FA = loggedOn.Result == EResult.AccountLoginDeniedNeedTwoFactor; bool is2FA = loggedOn.Result == EResult.AccountLoginDeniedNeedTwoFactor;
bool isLoginKey = ContentDownloader.Config.RememberPassword && logonDetails.LoginKey != null && loggedOn.Result == EResult.InvalidPassword;
if (isSteamGuard || is2FA) if ( isSteamGuard || is2FA || isLoginKey )
{ {
bExpectingDisconnectRemote = true; bExpectingDisconnectRemote = true;
Abort( false ); Abort( false );
if ( !isLoginKey )
{
Console.WriteLine( "This account is protected by Steam Guard." ); Console.WriteLine( "This account is protected by Steam Guard." );
}
if ( is2FA ) if ( is2FA )
{ {
Console.Write( "Please enter your 2 factor auth code from your authenticator app: " ); Console.Write( "Please enter your 2 factor auth code from your authenticator app: " );
logonDetails.TwoFactorCode = Console.ReadLine(); logonDetails.TwoFactorCode = Console.ReadLine();
} }
else if ( isLoginKey )
{
ConfigStore.TheConfig.LoginKeys.Remove( logonDetails.Username );
ConfigStore.Save();
logonDetails.LoginKey = null;
if ( ContentDownloader.Config.SuppliedPassword != null )
{
Console.WriteLine( "Login key was expired. Connecting with supplied password." );
logonDetails.Password = ContentDownloader.Config.SuppliedPassword;
}
else
{
Console.WriteLine( "Login key was expired. Please enter your password: " );
logonDetails.Password = Util.ReadPassword();
}
}
else else
{ {
Console.Write( "Please enter the authentication code sent to your email address: " ); Console.Write( "Please enter the authentication code sent to your email address: " );
@ -566,6 +610,8 @@ namespace DepotDownloader
private void LoginKeyCallback( SteamUser.LoginKeyCallback loginKey ) private void LoginKeyCallback( SteamUser.LoginKeyCallback loginKey )
{ {
Console.WriteLine( "Accepted new login key for account {0}", logonDetails.Username );
ConfigStore.TheConfig.LoginKeys[ logonDetails.Username ] = loginKey.LoginKey; ConfigStore.TheConfig.LoginKeys[ logonDetails.Username ] = loginKey.LoginKey;
ConfigStore.Save(); ConfigStore.Save();

Loading…
Cancel
Save