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
{ {

File diff suppressed because it is too large Load Diff

@ -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; }
} }
} }

@ -19,7 +19,7 @@ namespace DepotDownloader
DebugLog.Enabled = false; DebugLog.Enabled = false;
ConfigStore.LoadFromFile(Path.Combine(Environment.CurrentDirectory, "DepotDownloader.config")); ConfigStore.LoadFromFile( Path.Combine( Environment.CurrentDirectory, "DepotDownloader.config" ) );
bool bDumpManifest = HasParameter( args, "-manifest-only" ); bool bDumpManifest = HasParameter( args, "-manifest-only" );
uint appId = GetParameter<uint>( args, "-app", ContentDownloader.INVALID_APP_ID ); uint appId = GetParameter<uint>( args, "-app", ContentDownloader.INVALID_APP_ID );
@ -32,24 +32,24 @@ namespace DepotDownloader
return; return;
} }
if (depotId == ContentDownloader.INVALID_DEPOT_ID && ContentDownloader.Config.ManifestId != ContentDownloader.INVALID_MANIFEST_ID) if ( depotId == ContentDownloader.INVALID_DEPOT_ID && ContentDownloader.Config.ManifestId != ContentDownloader.INVALID_MANIFEST_ID )
{ {
Console.WriteLine("Error: -manifest requires -depot to be specified"); Console.WriteLine( "Error: -manifest requires -depot to be specified" );
return; return;
} }
ContentDownloader.Config.DownloadManifestOnly = bDumpManifest; ContentDownloader.Config.DownloadManifestOnly = bDumpManifest;
int cellId = GetParameter<int>(args, "-cellid", -1); int cellId = GetParameter<int>( args, "-cellid", -1 );
if (cellId == -1) if ( cellId == -1 )
{ {
cellId = 0; cellId = 0;
} }
ContentDownloader.Config.CellID = cellId; ContentDownloader.Config.CellID = cellId;
ContentDownloader.Config.BetaPassword = GetParameter<string>(args, "-betapassword"); ContentDownloader.Config.BetaPassword = GetParameter<string>( args, "-betapassword" );
string fileList = GetParameter<string>(args, "-filelist"); string fileList = GetParameter<string>( args, "-filelist" );
string[] files = null; string[] files = null;
if ( fileList != null ) if ( fileList != null )
@ -63,16 +63,16 @@ namespace DepotDownloader
ContentDownloader.Config.FilesToDownload = new List<string>(); ContentDownloader.Config.FilesToDownload = new List<string>();
ContentDownloader.Config.FilesToDownloadRegex = new List<Regex>(); ContentDownloader.Config.FilesToDownloadRegex = new List<Regex>();
foreach (var fileEntry in files) foreach ( var fileEntry in files )
{ {
try try
{ {
Regex rgx = new Regex(fileEntry, RegexOptions.Compiled | RegexOptions.IgnoreCase); Regex rgx = new Regex( fileEntry, RegexOptions.Compiled | RegexOptions.IgnoreCase );
ContentDownloader.Config.FilesToDownloadRegex.Add(rgx); ContentDownloader.Config.FilesToDownloadRegex.Add( rgx );
} }
catch catch
{ {
ContentDownloader.Config.FilesToDownload.Add(fileEntry); ContentDownloader.Config.FilesToDownload.Add( fileEntry );
continue; continue;
} }
} }
@ -85,40 +85,43 @@ namespace DepotDownloader
} }
} }
string username = GetParameter<string>(args, "-username") ?? GetParameter<string>(args, "-user"); string username = GetParameter<string>( args, "-username" ) ?? GetParameter<string>( args, "-user" );
string password = GetParameter<string>(args, "-password") ?? GetParameter<string>(args, "-pass"); string password = GetParameter<string>( args, "-password" ) ?? GetParameter<string>( args, "-pass" );
ContentDownloader.Config.RememberPassword = HasParameter(args, "-remember-password"); ContentDownloader.Config.RememberPassword = HasParameter( args, "-remember-password" );
ContentDownloader.Config.InstallDirectory = GetParameter<string>(args, "-dir"); ContentDownloader.Config.InstallDirectory = GetParameter<string>( args, "-dir" );
ContentDownloader.Config.DownloadAllPlatforms = HasParameter(args, "-all-platforms"); ContentDownloader.Config.DownloadAllPlatforms = HasParameter( args, "-all-platforms" );
ContentDownloader.Config.VerifyAll = HasParameter(args, "-verify-all") || HasParameter(args, "-verify_all") || HasParameter(args, "-validate"); ContentDownloader.Config.VerifyAll = HasParameter( args, "-verify-all" ) || HasParameter( args, "-verify_all" ) || HasParameter( args, "-validate" );
ContentDownloader.Config.MaxServers = GetParameter<int>(args, "-max-servers", 20); ContentDownloader.Config.MaxServers = GetParameter<int>( args, "-max-servers", 20 );
ContentDownloader.Config.MaxDownloads = GetParameter<int>(args, "-max-downloads", 4); ContentDownloader.Config.MaxDownloads = GetParameter<int>( args, "-max-downloads", 4 );
string branch = GetParameter<string>(args, "-branch") ?? GetParameter<string>(args, "-beta") ?? "Public"; string branch = GetParameter<string>( args, "-branch" ) ?? GetParameter<string>( args, "-beta" ) ?? "Public";
var forceDepot = HasParameter(args, "-force-depot"); var forceDepot = HasParameter( args, "-force-depot" );
ContentDownloader.Config.MaxServers = Math.Max(ContentDownloader.Config.MaxServers, ContentDownloader.Config.MaxDownloads); ContentDownloader.Config.MaxServers = Math.Max( ContentDownloader.Config.MaxServers, ContentDownloader.Config.MaxDownloads );
if (username != null && password == null && !ConfigStore.TheConfig.LoginKeys.ContainsKey(username)) if ( username != null && password == null && !ConfigStore.TheConfig.LoginKeys.ContainsKey( username ) )
{ {
Console.Write("Enter account password for \"{0}\": ", username); Console.Write( "Enter account password for \"{0}\": ", username );
password = Util.ReadPassword(); password = Util.ReadPassword();
Console.WriteLine(); Console.WriteLine();
} }
else if (username == null) else if ( username == null )
{ {
Console.WriteLine("No username given. Using anonymous account with dedicated server subscription."); Console.WriteLine( "No username given. Using anonymous account with dedicated server subscription." );
} }
if (ContentDownloader.InitializeSteam3(username, password)) // 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 ) )
{ {
ContentDownloader.DownloadApp(appId, depotId, branch, forceDepot); ContentDownloader.DownloadApp( appId, depotId, branch, forceDepot );
ContentDownloader.ShutdownSteam3(); ContentDownloader.ShutdownSteam3();
} }
} }
static int IndexOfParam( string[] args, string param ) static int IndexOfParam( string[] args, string param )
{ {
for ( int x = 0 ; x < args.Length ; ++x ) for ( int x = 0; x < args.Length; ++x )
{ {
if ( args[ x ].Equals( param, StringComparison.OrdinalIgnoreCase ) ) if ( args[ x ].Equals( param, StringComparison.OrdinalIgnoreCase ) )
return x; return x;
@ -130,22 +133,22 @@ namespace DepotDownloader
return IndexOfParam( args, param ) > -1; return IndexOfParam( args, param ) > -1;
} }
static T GetParameter<T>(string[] args, string param, T defaultValue = default(T)) static T GetParameter<T>( string[] args, string param, T defaultValue = default( T ) )
{ {
int index = IndexOfParam(args, param); int index = IndexOfParam( args, param );
if (index == -1 || index == (args.Length - 1)) if ( index == -1 || index == ( args.Length - 1 ) )
return defaultValue; return defaultValue;
string strParam = args[index + 1]; string strParam = args[ index + 1 ];
var converter = TypeDescriptor.GetConverter(typeof(T)); var converter = TypeDescriptor.GetConverter( typeof( T ) );
if( converter != null ) if ( converter != null )
{ {
return (T)converter.ConvertFromString(strParam); return ( T )converter.ConvertFromString( strParam );
} }
return default(T); return default( T );
} }
static void PrintUsage() static void PrintUsage()
@ -153,7 +156,7 @@ namespace DepotDownloader
Console.WriteLine( "\nUsage: depotdownloader <parameters> [optional parameters]\n" ); Console.WriteLine( "\nUsage: depotdownloader <parameters> [optional parameters]\n" );
Console.WriteLine( "Parameters:" ); Console.WriteLine( "Parameters:" );
Console.WriteLine("\t-app <#>\t\t\t\t- the AppID to download."); Console.WriteLine( "\t-app <#>\t\t\t\t- the AppID to download." );
Console.WriteLine(); Console.WriteLine();
Console.WriteLine( "Optional Parameters:" ); Console.WriteLine( "Optional Parameters:" );

@ -86,30 +86,30 @@ namespace DepotDownloader
this.steamUser = this.steamClient.GetHandler<SteamUser>(); this.steamUser = this.steamClient.GetHandler<SteamUser>();
this.steamApps = this.steamClient.GetHandler<SteamApps>(); this.steamApps = this.steamClient.GetHandler<SteamApps>();
this.callbacks = new CallbackManager(this.steamClient); this.callbacks = new CallbackManager( this.steamClient );
this.callbacks.Subscribe<SteamClient.ConnectedCallback>(ConnectedCallback); this.callbacks.Subscribe<SteamClient.ConnectedCallback>( ConnectedCallback );
this.callbacks.Subscribe<SteamClient.DisconnectedCallback>(DisconnectedCallback); this.callbacks.Subscribe<SteamClient.DisconnectedCallback>( DisconnectedCallback );
this.callbacks.Subscribe<SteamUser.LoggedOnCallback>(LogOnCallback); this.callbacks.Subscribe<SteamUser.LoggedOnCallback>( LogOnCallback );
this.callbacks.Subscribe<SteamUser.SessionTokenCallback>(SessionTokenCallback); this.callbacks.Subscribe<SteamUser.SessionTokenCallback>( SessionTokenCallback );
this.callbacks.Subscribe<SteamApps.LicenseListCallback>(LicenseListCallback); this.callbacks.Subscribe<SteamApps.LicenseListCallback>( LicenseListCallback );
this.callbacks.Subscribe<SteamUser.UpdateMachineAuthCallback>(UpdateMachineAuthCallback); this.callbacks.Subscribe<SteamUser.UpdateMachineAuthCallback>( UpdateMachineAuthCallback );
this.callbacks.Subscribe<SteamUser.LoginKeyCallback>(LoginKeyCallback); this.callbacks.Subscribe<SteamUser.LoginKeyCallback>( LoginKeyCallback );
Console.Write( "Connecting to Steam3..." ); Console.Write( "Connecting to Steam3..." );
if ( authenticatedUser ) if ( authenticatedUser )
{ {
FileInfo fi = new FileInfo(String.Format("{0}.sentryFile", logonDetails.Username)); FileInfo fi = new FileInfo( String.Format( "{0}.sentryFile", logonDetails.Username ) );
if (ConfigStore.TheConfig.SentryData != null && ConfigStore.TheConfig.SentryData.ContainsKey(logonDetails.Username)) if ( ConfigStore.TheConfig.SentryData != null && ConfigStore.TheConfig.SentryData.ContainsKey( logonDetails.Username ) )
{ {
logonDetails.SentryFileHash = Util.SHAHash(ConfigStore.TheConfig.SentryData[logonDetails.Username]); logonDetails.SentryFileHash = Util.SHAHash( ConfigStore.TheConfig.SentryData[ logonDetails.Username ] );
} }
else if (fi.Exists && fi.Length > 0) else if ( fi.Exists && fi.Length > 0 )
{ {
var sentryData = File.ReadAllBytes(fi.FullName); var sentryData = File.ReadAllBytes( fi.FullName );
logonDetails.SentryFileHash = Util.SHAHash(sentryData); logonDetails.SentryFileHash = Util.SHAHash( sentryData );
ConfigStore.TheConfig.SentryData[logonDetails.Username] = sentryData; ConfigStore.TheConfig.SentryData[ logonDetails.Username ] = sentryData;
ConfigStore.Save(); ConfigStore.Save();
} }
} }
@ -118,9 +118,9 @@ namespace DepotDownloader
} }
public delegate bool WaitCondition(); public delegate bool WaitCondition();
public bool WaitUntilCallback(Action submitter, WaitCondition waiter) public bool WaitUntilCallback( Action submitter, WaitCondition waiter )
{ {
while (!bAborted && !waiter()) while ( !bAborted && !waiter() )
{ {
submitter(); submitter();
@ -129,7 +129,7 @@ namespace DepotDownloader
{ {
WaitForCallbacks(); WaitForCallbacks();
} }
while (!bAborted && this.seq == seq && !waiter()); while ( !bAborted && this.seq == seq && !waiter() );
} }
return bAborted; return bAborted;
@ -137,224 +137,229 @@ namespace DepotDownloader
public Credentials WaitForCredentials() public Credentials WaitForCredentials()
{ {
if (credentials.IsValid || bAborted) if ( credentials.IsValid || bAborted )
return credentials; return credentials;
WaitUntilCallback(() => { }, () => { return credentials.IsValid; }); WaitUntilCallback( () => { }, () => { return credentials.IsValid; } );
return credentials; return credentials;
} }
public void RequestAppInfo(uint appId) public void RequestAppInfo( uint appId )
{ {
if (AppInfo.ContainsKey(appId) || bAborted) if ( AppInfo.ContainsKey( appId ) || bAborted )
return; return;
bool completed = false; bool completed = false;
Action<SteamApps.PICSTokensCallback> cbMethodTokens = (appTokens) => Action<SteamApps.PICSTokensCallback> cbMethodTokens = ( appTokens ) =>
{ {
completed = true; completed = true;
if (appTokens.AppTokensDenied.Contains(appId)) if ( appTokens.AppTokensDenied.Contains( appId ) )
{ {
Console.WriteLine("Insufficient privileges to get access token for app {0}", appId); Console.WriteLine( "Insufficient privileges to get access token for app {0}", appId );
} }
foreach (var token_dict in appTokens.AppTokens) foreach ( var token_dict in appTokens.AppTokens )
{ {
this.AppTokens.Add(token_dict.Key, token_dict.Value); this.AppTokens.Add( token_dict.Key, token_dict.Value );
} }
}; };
WaitUntilCallback(() => { WaitUntilCallback( () =>
callbacks.Subscribe(steamApps.PICSGetAccessTokens(new List<uint>() { appId }, new List<uint>() { }), cbMethodTokens); {
}, () => { return completed; }); callbacks.Subscribe( steamApps.PICSGetAccessTokens( new List<uint>() { appId }, new List<uint>() { } ), cbMethodTokens );
}, () => { return completed; } );
completed = false; completed = false;
Action<SteamApps.PICSProductInfoCallback> cbMethod = (appInfo) => Action<SteamApps.PICSProductInfoCallback> cbMethod = ( appInfo ) =>
{ {
completed = !appInfo.ResponsePending; completed = !appInfo.ResponsePending;
foreach (var app_value in appInfo.Apps) foreach ( var app_value in appInfo.Apps )
{ {
var app = app_value.Value; var app = app_value.Value;
Console.WriteLine("Got AppInfo for {0}", app.ID); Console.WriteLine( "Got AppInfo for {0}", app.ID );
AppInfo.Add(app.ID, app); AppInfo.Add( app.ID, app );
} }
foreach (var app in appInfo.UnknownApps) foreach ( var app in appInfo.UnknownApps )
{ {
AppInfo.Add(app, null); AppInfo.Add( app, null );
} }
}; };
SteamApps.PICSRequest request = new SteamApps.PICSRequest(appId); SteamApps.PICSRequest request = new SteamApps.PICSRequest( appId );
if (AppTokens.ContainsKey(appId)) if ( AppTokens.ContainsKey( appId ) )
{ {
request.AccessToken = AppTokens[appId]; request.AccessToken = AppTokens[ appId ];
request.Public = false; request.Public = false;
} }
WaitUntilCallback(() => { WaitUntilCallback( () =>
callbacks.Subscribe(steamApps.PICSGetProductInfo(new List<SteamApps.PICSRequest>() { request }, new List<SteamApps.PICSRequest>() { }), cbMethod); {
}, () => { return completed; }); callbacks.Subscribe( steamApps.PICSGetProductInfo( new List<SteamApps.PICSRequest>() { request }, new List<SteamApps.PICSRequest>() { } ), cbMethod );
}, () => { return completed; } );
} }
public void RequestPackageInfo(IEnumerable<uint> packageIds) public void RequestPackageInfo( IEnumerable<uint> packageIds )
{ {
List<uint> packages = packageIds.ToList(); List<uint> packages = packageIds.ToList();
packages.RemoveAll(pid => PackageInfo.ContainsKey(pid)); packages.RemoveAll( pid => PackageInfo.ContainsKey( pid ) );
if (packages.Count == 0 || bAborted) if ( packages.Count == 0 || bAborted )
return; return;
bool completed = false; bool completed = false;
Action<SteamApps.PICSProductInfoCallback> cbMethod = (packageInfo) => Action<SteamApps.PICSProductInfoCallback> cbMethod = ( packageInfo ) =>
{ {
completed = !packageInfo.ResponsePending; completed = !packageInfo.ResponsePending;
foreach (var package_value in packageInfo.Packages) foreach ( var package_value in packageInfo.Packages )
{ {
var package = package_value.Value; var package = package_value.Value;
PackageInfo.Add(package.ID, package); PackageInfo.Add( package.ID, package );
} }
foreach (var package in packageInfo.UnknownPackages) foreach ( var package in packageInfo.UnknownPackages )
{ {
PackageInfo.Add(package, null); PackageInfo.Add( package, null );
} }
}; };
WaitUntilCallback(() => { WaitUntilCallback( () =>
callbacks.Subscribe(steamApps.PICSGetProductInfo(new List<uint>(), packages), cbMethod); {
}, () => { return completed; }); callbacks.Subscribe( steamApps.PICSGetProductInfo( new List<uint>(), packages ), cbMethod );
}, () => { return completed; } );
} }
public bool RequestFreeAppLicense(uint appId) public bool RequestFreeAppLicense( uint appId )
{ {
bool success = false; bool success = false;
bool completed = false; bool completed = false;
Action<SteamApps.FreeLicenseCallback> cbMethod = (resultInfo) => Action<SteamApps.FreeLicenseCallback> cbMethod = ( resultInfo ) =>
{ {
completed = true; completed = true;
success = resultInfo.GrantedApps.Contains(appId); success = resultInfo.GrantedApps.Contains( appId );
}; };
WaitUntilCallback(() => { WaitUntilCallback( () =>
callbacks.Subscribe(steamApps.RequestFreeLicense(appId), cbMethod); {
}, () => { return completed; }); callbacks.Subscribe( steamApps.RequestFreeLicense( appId ), cbMethod );
}, () => { return completed; } );
return success; return success;
} }
public void RequestAppTicket(uint appId) public void RequestAppTicket( uint appId )
{ {
if (AppTickets.ContainsKey(appId) || bAborted) if ( AppTickets.ContainsKey( appId ) || bAborted )
return; return;
if ( !authenticatedUser ) if ( !authenticatedUser )
{ {
AppTickets[appId] = null; AppTickets[ appId ] = null;
return; return;
} }
bool completed = false; bool completed = false;
Action<SteamApps.AppOwnershipTicketCallback> cbMethod = (appTicket) => Action<SteamApps.AppOwnershipTicketCallback> cbMethod = ( appTicket ) =>
{ {
completed = true; completed = true;
if (appTicket.Result != EResult.OK) if ( appTicket.Result != EResult.OK )
{ {
Console.WriteLine("Unable to get appticket for {0}: {1}", appTicket.AppID, appTicket.Result); Console.WriteLine( "Unable to get appticket for {0}: {1}", appTicket.AppID, appTicket.Result );
Abort(); Abort();
} }
else else
{ {
Console.WriteLine("Got appticket for {0}!", appTicket.AppID); Console.WriteLine( "Got appticket for {0}!", appTicket.AppID );
AppTickets[appTicket.AppID] = appTicket.Ticket; AppTickets[ appTicket.AppID ] = appTicket.Ticket;
} }
}; };
WaitUntilCallback(() => { WaitUntilCallback( () =>
callbacks.Subscribe(steamApps.GetAppOwnershipTicket(appId), cbMethod); {
}, () => { return completed; }); callbacks.Subscribe( steamApps.GetAppOwnershipTicket( appId ), cbMethod );
}, () => { return completed; } );
} }
public void RequestDepotKey(uint depotId, uint appid = 0) public void RequestDepotKey( uint depotId, uint appid = 0 )
{ {
if (DepotKeys.ContainsKey(depotId) || bAborted) if ( DepotKeys.ContainsKey( depotId ) || bAborted )
return; return;
bool completed = false; bool completed = false;
Action<SteamApps.DepotKeyCallback> cbMethod = (depotKey) => Action<SteamApps.DepotKeyCallback> cbMethod = ( depotKey ) =>
{ {
completed = true; completed = true;
Console.WriteLine("Got depot key for {0} result: {1}", depotKey.DepotID, depotKey.Result); Console.WriteLine( "Got depot key for {0} result: {1}", depotKey.DepotID, depotKey.Result );
if (depotKey.Result != EResult.OK) if ( depotKey.Result != EResult.OK )
{ {
Abort(); Abort();
return; return;
} }
DepotKeys[depotKey.DepotID] = depotKey.DepotKey; DepotKeys[ depotKey.DepotID ] = depotKey.DepotKey;
}; };
WaitUntilCallback(() => WaitUntilCallback( () =>
{ {
callbacks.Subscribe(steamApps.GetDepotDecryptionKey(depotId, appid), cbMethod); callbacks.Subscribe( steamApps.GetDepotDecryptionKey( depotId, appid ), cbMethod );
}, () => { return completed; }); }, () => { return completed; } );
} }
public void RequestCDNAuthToken(uint appid, uint depotid, string host) public void RequestCDNAuthToken( uint appid, uint depotid, string host )
{ {
var cdnKey = string.Format("{0:D}:{1}", depotid, host); var cdnKey = string.Format( "{0:D}:{1}", depotid, host );
if (CDNAuthTokens.ContainsKey(cdnKey) || bAborted) if ( CDNAuthTokens.ContainsKey( cdnKey ) || bAborted )
return; return;
bool completed = false; bool completed = false;
Action<SteamApps.CDNAuthTokenCallback> cbMethod = (cdnAuth) => Action<SteamApps.CDNAuthTokenCallback> cbMethod = ( cdnAuth ) =>
{ {
completed = true; completed = true;
Console.WriteLine("Got CDN auth token for {0} result: {1} (expires {2})", host, cdnAuth.Result, cdnAuth.Expiration); Console.WriteLine( "Got CDN auth token for {0} result: {1} (expires {2})", host, cdnAuth.Result, cdnAuth.Expiration );
if (cdnAuth.Result != EResult.OK) if ( cdnAuth.Result != EResult.OK )
{ {
Abort(); Abort();
return; return;
} }
CDNAuthTokens.TryAdd(cdnKey, cdnAuth); CDNAuthTokens.TryAdd( cdnKey, cdnAuth );
}; };
WaitUntilCallback(() => WaitUntilCallback( () =>
{ {
callbacks.Subscribe(steamApps.GetCDNAuthToken(appid, depotid, host), cbMethod); callbacks.Subscribe( steamApps.GetCDNAuthToken( appid, depotid, host ), cbMethod );
}, () => { return completed; }); }, () => { return completed; } );
} }
public void CheckAppBetaPassword(uint appid, string password) public void CheckAppBetaPassword( uint appid, string password )
{ {
bool completed = false; bool completed = false;
Action<SteamApps.CheckAppBetaPasswordCallback> cbMethod = (appPassword) => Action<SteamApps.CheckAppBetaPasswordCallback> cbMethod = ( appPassword ) =>
{ {
completed = true; completed = true;
Console.WriteLine("Retrieved {0} beta keys with result: {1}", appPassword.BetaPasswords.Count, appPassword.Result); Console.WriteLine( "Retrieved {0} beta keys with result: {1}", appPassword.BetaPasswords.Count, appPassword.Result );
foreach (var entry in appPassword.BetaPasswords) foreach ( var entry in appPassword.BetaPasswords )
{ {
AppBetaPasswords[entry.Key] = entry.Value; AppBetaPasswords[ entry.Key ] = entry.Value;
} }
}; };
WaitUntilCallback(() => WaitUntilCallback( () =>
{ {
callbacks.Subscribe(steamApps.CheckAppBetaPassword(appid, password), cbMethod); callbacks.Subscribe( steamApps.CheckAppBetaPassword( appid, password ), cbMethod );
}, () => { return completed; }); }, () => { return completed; } );
} }
void Connect() void Connect()
@ -369,13 +374,13 @@ namespace DepotDownloader
this.steamClient.Connect(); this.steamClient.Connect();
} }
private void Abort(bool sendLogOff=true) private void Abort( bool sendLogOff = true )
{ {
Disconnect(sendLogOff); Disconnect( sendLogOff );
} }
public void Disconnect(bool sendLogOff=true) public void Disconnect( bool sendLogOff = true )
{ {
if (sendLogOff) if ( sendLogOff )
{ {
steamUser.LogOff(); steamUser.LogOff();
} }
@ -386,31 +391,47 @@ namespace DepotDownloader
bAborted = true; bAborted = true;
// flush callbacks until our disconnected event // flush callbacks until our disconnected event
while (!bDidDisconnect) while ( !bDidDisconnect )
{ {
callbacks.RunWaitAllCallbacks(TimeSpan.FromMilliseconds(100)); callbacks.RunWaitAllCallbacks( TimeSpan.FromMilliseconds( 100 ) );
} }
} }
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()
{ {
callbacks.RunWaitCallbacks( TimeSpan.FromSeconds(1) ); callbacks.RunWaitCallbacks( TimeSpan.FromSeconds( 1 ) );
TimeSpan diff = DateTime.Now - connectTime; TimeSpan diff = DateTime.Now - connectTime;
if (diff > STEAM3_TIMEOUT && !bConnected) if ( diff > STEAM3_TIMEOUT && !bConnected )
{ {
Console.WriteLine("Timeout connecting to Steam3."); Console.WriteLine( "Timeout connecting to Steam3." );
Abort(); Abort();
return; return;
} }
} }
private void ConnectedCallback(SteamClient.ConnectedCallback connected) private void ConnectedCallback( SteamClient.ConnectedCallback connected )
{ {
Console.WriteLine(" Done!"); Console.WriteLine( " Done!" );
bConnecting = false; bConnecting = false;
bConnected = true; bConnected = true;
if ( !authenticatedUser ) if ( !authenticatedUser )
@ -425,122 +446,145 @@ namespace DepotDownloader
} }
} }
private void DisconnectedCallback(SteamClient.DisconnectedCallback disconnected) private void DisconnectedCallback( SteamClient.DisconnectedCallback disconnected )
{ {
bDidDisconnect = true; bDidDisconnect = true;
if (disconnected.UserInitiated || bExpectingDisconnectRemote) if ( disconnected.UserInitiated || bExpectingDisconnectRemote )
{ {
Console.WriteLine("Disconnected from Steam"); Console.WriteLine( "Disconnected from Steam" );
} }
else if (connectionBackoff >= 10) else if ( connectionBackoff >= 10 )
{ {
Console.WriteLine("Could not connect to Steam after 10 tries"); Console.WriteLine( "Could not connect to Steam after 10 tries" );
Abort(false); Abort( false );
} }
else if (!bAborted) else if ( !bAborted )
{ {
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" );
} }
Thread.Sleep(1000 * ++connectionBackoff); Thread.Sleep( 1000 * ++connectionBackoff );
steamClient.Connect(); steamClient.Connect();
} }
} }
private void LogOnCallback(SteamUser.LoggedOnCallback loggedOn) private void LogOnCallback( SteamUser.LoggedOnCallback loggedOn )
{ {
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 );
Console.WriteLine("This account is protected by Steam Guard."); if ( !isLoginKey )
{
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 else
{ {
Console.Write("Please enter the authentication code sent to your email address: "); Console.WriteLine( "Login key was expired. Please enter your password: " );
logonDetails.Password = Util.ReadPassword();
}
}
else
{
Console.Write( "Please enter the authentication code sent to your email address: " );
logonDetails.AuthCode = Console.ReadLine(); logonDetails.AuthCode = Console.ReadLine();
} }
Console.Write("Retrying Steam3 connection..."); Console.Write( "Retrying Steam3 connection..." );
Connect(); Connect();
return; return;
} }
else if (loggedOn.Result == EResult.ServiceUnavailable) else if ( loggedOn.Result == EResult.ServiceUnavailable )
{ {
Console.WriteLine("Unable to login to Steam3: {0}", loggedOn.Result); Console.WriteLine( "Unable to login to Steam3: {0}", loggedOn.Result );
Abort(false); Abort( false );
return; return;
} }
else if (loggedOn.Result != EResult.OK) else if ( loggedOn.Result != EResult.OK )
{ {
Console.WriteLine("Unable to login to Steam3: {0}", loggedOn.Result); Console.WriteLine( "Unable to login to Steam3: {0}", loggedOn.Result );
Abort(); Abort();
return; return;
} }
Console.WriteLine(" Done!"); Console.WriteLine( " Done!" );
this.seq++; this.seq++;
credentials.LoggedOn = true; credentials.LoggedOn = true;
if (ContentDownloader.Config.CellID == 0) if ( ContentDownloader.Config.CellID == 0 )
{ {
Console.WriteLine("Using Steam3 suggested CellID: " + loggedOn.CellID); Console.WriteLine( "Using Steam3 suggested CellID: " + loggedOn.CellID );
ContentDownloader.Config.CellID = (int)loggedOn.CellID; ContentDownloader.Config.CellID = ( int )loggedOn.CellID;
} }
} }
private void SessionTokenCallback(SteamUser.SessionTokenCallback sessionToken) private void SessionTokenCallback( SteamUser.SessionTokenCallback sessionToken )
{ {
Console.WriteLine("Got session token!"); Console.WriteLine( "Got session token!" );
credentials.SessionToken = sessionToken.SessionToken; credentials.SessionToken = sessionToken.SessionToken;
} }
private void LicenseListCallback(SteamApps.LicenseListCallback licenseList) private void LicenseListCallback( SteamApps.LicenseListCallback licenseList )
{ {
if (licenseList.Result != EResult.OK) if ( licenseList.Result != EResult.OK )
{ {
Console.WriteLine("Unable to get license list: {0} ", licenseList.Result); Console.WriteLine( "Unable to get license list: {0} ", licenseList.Result );
Abort(); Abort();
return; return;
} }
Console.WriteLine("Got {0} licenses for account!", licenseList.LicenseList.Count); Console.WriteLine( "Got {0} licenses for account!", licenseList.LicenseList.Count );
Licenses = licenseList.LicenseList; Licenses = licenseList.LicenseList;
IEnumerable<uint> licenseQuery = Licenses.Select(lic => IEnumerable<uint> licenseQuery = Licenses.Select( lic =>
{ {
return lic.PackageID; return lic.PackageID;
}); } );
Console.WriteLine("Licenses: {0}", string.Join(", ", licenseQuery)); Console.WriteLine( "Licenses: {0}", string.Join( ", ", licenseQuery ) );
} }
private void UpdateMachineAuthCallback(SteamUser.UpdateMachineAuthCallback machineAuth) private void UpdateMachineAuthCallback( SteamUser.UpdateMachineAuthCallback machineAuth )
{ {
byte[] hash = Util.SHAHash(machineAuth.Data); byte[] hash = Util.SHAHash( machineAuth.Data );
Console.WriteLine("Got Machine Auth: {0} {1} {2} {3}", machineAuth.FileName, machineAuth.Offset, machineAuth.BytesToWrite, machineAuth.Data.Length, hash); Console.WriteLine( "Got Machine Auth: {0} {1} {2} {3}", machineAuth.FileName, machineAuth.Offset, machineAuth.BytesToWrite, machineAuth.Data.Length, hash );
ConfigStore.TheConfig.SentryData[logonDetails.Username] = machineAuth.Data; ConfigStore.TheConfig.SentryData[ logonDetails.Username ] = machineAuth.Data;
ConfigStore.Save(); ConfigStore.Save();
var authResponse = new SteamUser.MachineAuthDetails var authResponse = new SteamUser.MachineAuthDetails
@ -564,12 +608,14 @@ namespace DepotDownloader
steamUser.SendMachineAuthResponse( authResponse ); steamUser.SendMachineAuthResponse( authResponse );
} }
private void LoginKeyCallback(SteamUser.LoginKeyCallback loginKey) private void LoginKeyCallback( SteamUser.LoginKeyCallback loginKey )
{ {
ConfigStore.TheConfig.LoginKeys[logonDetails.Username] = loginKey.LoginKey; Console.WriteLine( "Accepted new login key for account {0}", logonDetails.Username );
ConfigStore.TheConfig.LoginKeys[ logonDetails.Username ] = loginKey.LoginKey;
ConfigStore.Save(); ConfigStore.Save();
steamUser.AcceptNewLoginKey(loginKey); steamUser.AcceptNewLoginKey( loginKey );
} }

Loading…
Cancel
Save