@ -1,6 +1,4 @@
using SteamKit2 ;
using SteamKit2.Internal ;
using System ;
using System ;
using System.Collections.Concurrent ;
using System.Collections.Generic ;
using System.Collections.ObjectModel ;
@ -8,10 +6,11 @@ using System.IO;
using System.Linq ;
using System.Threading ;
using System.Threading.Tasks ;
using SteamKit2 ;
using SteamKit2.Internal ;
namespace DepotDownloader
{
class Steam3Session
{
public class Credentials
@ -41,13 +40,13 @@ namespace DepotDownloader
public SteamClient steamClient ;
public SteamUser steamUser ;
SteamApps steamApps ;
SteamCloud steamCloud ;
SteamUnifiedMessages . UnifiedService < IPublishedFile > steamPublishedFile ;
readonly SteamApps steamApps ;
readonly SteamCloud steamCloud ;
readonly SteamUnifiedMessages . UnifiedService < IPublishedFile > steamPublishedFile ;
CallbackManager callbacks ;
readonly CallbackManager callbacks ;
bool authenticatedUser ;
readonly bool authenticatedUser ;
bool bConnected ;
bool bConnecting ;
bool bAborted ;
@ -60,15 +59,15 @@ namespace DepotDownloader
DateTime connectTime ;
// input
SteamUser . LogOnDetails logonDetails ;
readonly SteamUser . LogOnDetails logonDetails ;
// output
Credentials credentials ;
readonly Credentials credentials ;
static readonly TimeSpan STEAM3_TIMEOUT = TimeSpan . FromSeconds ( 30 ) ;
static readonly TimeSpan STEAM3_TIMEOUT = TimeSpan . FromSeconds ( 30 ) ;
public Steam3Session ( SteamUser . LogOnDetails details )
public Steam3Session ( SteamUser . LogOnDetails details )
{
this . logonDetails = details ;
@ -103,30 +102,30 @@ namespace DepotDownloader
var steamUnifiedMessages = this . steamClient . GetHandler < SteamUnifiedMessages > ( ) ;
this . steamPublishedFile = steamUnifiedMessages . CreateService < IPublishedFile > ( ) ;
this . callbacks = new CallbackManager ( this . steamClient ) ;
this . callbacks = new CallbackManager ( this . steamClient ) ;
this . callbacks . Subscribe < SteamClient . ConnectedCallback > ( ConnectedCallback ) ;
this . callbacks . Subscribe < SteamClient . DisconnectedCallback > ( DisconnectedCallback ) ;
this . callbacks . Subscribe < SteamUser . LoggedOnCallback > ( LogOnCallback ) ;
this . callbacks . Subscribe < SteamUser . SessionTokenCallback > ( SessionTokenCallback ) ;
this . callbacks . Subscribe < SteamApps . LicenseListCallback > ( LicenseListCallback ) ;
this . callbacks . Subscribe < SteamUser . UpdateMachineAuthCallback > ( UpdateMachineAuthCallback ) ;
this . callbacks . Subscribe < SteamUser . LoginKeyCallback > ( LoginKeyCallback ) ;
this . callbacks . Subscribe < SteamClient . ConnectedCallback > ( ConnectedCallback ) ;
this . callbacks . Subscribe < SteamClient . DisconnectedCallback > ( DisconnectedCallback ) ;
this . callbacks . Subscribe < SteamUser . LoggedOnCallback > ( LogOnCallback ) ;
this . callbacks . Subscribe < SteamUser . SessionTokenCallback > ( SessionTokenCallback ) ;
this . callbacks . Subscribe < SteamApps . LicenseListCallback > ( LicenseListCallback ) ;
this . callbacks . Subscribe < SteamUser . UpdateMachineAuthCallback > ( UpdateMachineAuthCallback ) ;
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 ) ) ;
if ( AccountSettingsStore . Instance . SentryData ! = null & & AccountSettingsStore . Instance . SentryData . ContainsKey ( logonDetails . Username ) )
var fi = new FileInfo ( String . Format ( "{0}.sentryFile" , logonDetails . Username ) ) ;
if ( AccountSettingsStore . Instance . SentryData ! = null & & AccountSettingsStore . Instance . SentryData . ContainsKey ( logonDetails . Username ) )
{
logonDetails . SentryFileHash = Util . SHAHash ( AccountSettingsStore . Instance . SentryData [ logonDetails . Username ] ) ;
logonDetails . SentryFileHash = Util . SHAHash ( AccountSettingsStore . Instance . SentryData [ logonDetails . Username ] ) ;
}
else if ( fi . Exists & & fi . Length > 0 )
else if ( fi . Exists & & fi . Length > 0 )
{
var sentryData = File . ReadAllBytes ( fi . FullName ) ;
logonDetails . SentryFileHash = Util . SHAHash ( sentryData ) ;
AccountSettingsStore . Instance . SentryData [ logonDetails . Username ] = sentryData ;
var sentryData = File . ReadAllBytes ( fi . FullName ) ;
logonDetails . SentryFileHash = Util . SHAHash ( sentryData ) ;
AccountSettingsStore . Instance . SentryData [ logonDetails . Username ] = sentryData ;
AccountSettingsStore . Save ( ) ;
}
}
@ -135,26 +134,26 @@ namespace DepotDownloader
}
public delegate bool WaitCondition ( ) ;
private object steamLock = new object ( ) ;
public bool WaitUntilCallback ( Action submitter , WaitCondition waiter )
private readonly object steamLock = new object ( ) ;
public bool WaitUntilCallback ( Action submitter , WaitCondition waiter )
{
while ( ! bAborted & & ! waiter ( ) )
while ( ! bAborted & & ! waiter ( ) )
{
lock ( steamLock )
{
submitter ( ) ;
}
int seq = this . seq ;
var seq = this . seq ;
do
{
lock ( steamLock )
{
WaitForCallbacks ( ) ;
}
}
while ( ! bAborted & & this . seq = = seq & & ! waiter ( ) ) ;
} while ( ! bAborted & & this . seq = = seq & & ! waiter ( ) ) ;
}
return bAborted ;
@ -162,91 +161,91 @@ namespace DepotDownloader
public Credentials WaitForCredentials ( )
{
if ( credentials . IsValid | | bAborted )
if ( credentials . IsValid | | bAborted )
return credentials ;
WaitUntilCallback ( ( ) = > { } , ( ) = > { return credentials . IsValid ; } ) ;
WaitUntilCallback ( ( ) = > { } , ( ) = > { return credentials . IsValid ; } ) ;
return credentials ;
}
public void RequestAppInfo ( uint appId , bool bForce = false )
public void RequestAppInfo ( uint appId , bool bForce = false )
{
if ( ( AppInfo . ContainsKey ( appId ) & & ! bForce ) | | bAborted )
if ( ( AppInfo . ContainsKey ( appId ) & & ! bForce ) | | bAborted )
return ;
bool completed = false ;
Action < SteamApps . PICSTokensCallback > cbMethodTokens = ( appTokens ) = >
var completed = false ;
Action < SteamApps . PICSTokensCallback > cbMethodTokens = appTokens = >
{
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 [ token_dict . Key ] = token_dict . Value ;
this . AppTokens [ 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 ;
Action < SteamApps . PICSProductInfoCallback > cbMethod = ( appInfo ) = >
Action < SteamApps . PICSProductInfoCallback > cbMethod = appInfo = >
{
completed = ! appInfo . ResponsePending ;
foreach ( var app_value in appInfo . Apps )
foreach ( var app_value in appInfo . Apps )
{
var app = app_value . Value ;
Console . WriteLine ( "Got AppInfo for {0}" , app . ID ) ;
AppInfo [ app . ID ] = app ;
Console . WriteLine ( "Got AppInfo for {0}" , app . ID ) ;
AppInfo [ app . ID ] = app ;
}
foreach ( var app in appInfo . UnknownApps )
foreach ( var app in appInfo . UnknownApps )
{
AppInfo [ app ] = null ;
AppInfo [ app ] = null ;
}
} ;
SteamApps . PICSRequest request = new SteamApps . PICSRequest ( appId ) ;
if ( AppTokens . ContainsKey ( appId ) )
var request = new SteamApps . PICSRequest ( appId ) ;
if ( AppTokens . ContainsKey ( appId ) )
{
request . AccessToken = AppTokens [ appId ] ;
request . AccessToken = AppTokens [ appId ] ;
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 ( ) ;
packages . RemoveAll ( pid = > PackageInfo . ContainsKey ( pid ) ) ;
var packages = packageIds . ToList ( ) ;
packages . RemoveAll ( pid = > PackageInfo . ContainsKey ( pid ) ) ;
if ( packages . Count = = 0 | | bAborted )
if ( packages . Count = = 0 | | bAborted )
return ;
bool completed = false ;
Action < SteamApps . PICSProductInfoCallback > cbMethod = ( packageInfo ) = >
var completed = false ;
Action < SteamApps . PICSProductInfoCallback > cbMethod = packageInfo = >
{
completed = ! packageInfo . ResponsePending ;
foreach ( var package_value in packageInfo . Packages )
foreach ( var package_value in packageInfo . Packages )
{
var package = package_value . Value ;
PackageInfo [ package . ID ] = package ;
PackageInfo [ package . ID ] = package ;
}
foreach ( var package in packageInfo . UnknownPackages )
foreach ( var package in packageInfo . UnknownPackages )
{
PackageInfo [ package ] = null ;
}
@ -254,78 +253,79 @@ namespace DepotDownloader
var packageRequests = new List < SteamApps . PICSRequest > ( ) ;
foreach ( var package in packages )
foreach ( var package in packages )
{
var request = new SteamApps . PICSRequest ( package ) ;
var request = new SteamApps . PICSRequest ( package ) ;
if ( PackageTokens . TryGetValue ( package , out var token ) )
if ( PackageTokens . TryGetValue ( package , out var token ) )
{
request . AccessToken = token ;
request . Public = false ;
}
packageRequests . Add ( request ) ;
packageRequests . Add ( request ) ;
}
WaitUntilCallback ( ( ) = >
WaitUntilCallback ( ( ) = >
{
callbacks . Subscribe ( steamApps . PICSGetProductInfo ( new List < SteamApps . PICSRequest > ( ) , packageRequests ) , cbMethod ) ;
} , ( ) = > { return completed ; } ) ;
callbacks . Subscribe ( steamApps . PICSGetProductInfo ( new List < SteamApps . PICSRequest > ( ) , packageRequests ) , cbMethod ) ;
} , ( ) = > { return completed ; } ) ;
}
public bool RequestFreeAppLicense ( uint appId )
public bool RequestFreeAppLicense ( uint appId )
{
bool success = false ;
bool completed = false ;
Action < SteamApps . FreeLicenseCallback > cbMethod = ( resultInfo ) = >
var success = false ;
var completed = false ;
Action < SteamApps . FreeLicenseCallback > cbMethod = resultInfo = >
{
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 ;
}
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 ;
bool completed = false ;
var completed = false ;
Action < SteamApps . DepotKeyCallback > cbMethod = ( depotKey ) = >
Action < SteamApps . DepotKeyCallback > cbMethod = depotKey = >
{
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 ( ) ;
return ;
}
DepotKeys [ depotKey . DepotID ] = depotKey . DepotKey ;
DepotKeys [ depotKey . DepotID ] = depotKey . DepotKey ;
} ;
WaitUntilCallback ( ( ) = >
WaitUntilCallback ( ( ) = >
{
callbacks . Subscribe ( steamApps . GetDepotDecryptionKey ( depotId , appid ) , cbMethod ) ;
} , ( ) = > { return completed ; } ) ;
callbacks . Subscribe ( steamApps . GetDepotDecryptionKey ( depotId , appid ) , cbMethod ) ;
} , ( ) = > { return completed ; } ) ;
}
public string ResolveCDNTopLevelHost ( string host )
{
// SteamPipe CDN shares tokens with all hosts
if ( host . EndsWith ( ".steampipe.steamcontent.com" ) )
if ( host . EndsWith ( ".steampipe.steamcontent.com" ) )
{
return "steampipe.steamcontent.com" ;
}
else if ( host . EndsWith ( ".steamcontent.com" ) )
if ( host . EndsWith ( ".steamcontent.com" ) )
{
return "steamcontent.com" ;
}
@ -333,63 +333,63 @@ namespace DepotDownloader
return host ;
}
public void RequestCDNAuthToken ( uint appid , uint depotid , string host , string cdnKey )
public void RequestCDNAuthToken ( uint appid , uint depotid , string host , string cdnKey )
{
if ( CDNAuthTokens . ContainsKey ( cdnKey ) | | bAborted )
if ( CDNAuthTokens . ContainsKey ( cdnKey ) | | bAborted )
return ;
if ( ! CDNAuthTokens . TryAdd ( cdnKey , new TaskCompletionSource < SteamApps . CDNAuthTokenCallback > ( ) ) )
if ( ! CDNAuthTokens . TryAdd ( cdnKey , new TaskCompletionSource < SteamApps . CDNAuthTokenCallback > ( ) ) )
return ;
bool completed = false ;
var timeoutDate = DateTime . Now . AddSeconds ( 10 ) ;
Action < SteamApps . CDNAuthTokenCallback > cbMethod = ( cdnAuth ) = >
var completed = false ;
var timeoutDate = DateTime . Now . AddSeconds ( 10 ) ;
Action < SteamApps . CDNAuthTokenCallback > cbMethod = cdnAuth = >
{
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 ( ) ;
return ;
}
CDNAuthTokens [ cdnKey ] . TrySetResult ( cdnAuth ) ;
CDNAuthTokens [ cdnKey ] . TrySetResult ( cdnAuth ) ;
} ;
WaitUntilCallback ( ( ) = >
WaitUntilCallback ( ( ) = >
{
callbacks . Subscribe ( steamApps . GetCDNAuthToken ( appid , depotid , host ) , cbMethod ) ;
} , ( ) = > { return completed | | DateTime . Now > = timeoutDate ; } ) ;
callbacks . Subscribe ( steamApps . GetCDNAuthToken ( appid , depotid , host ) , cbMethod ) ;
} , ( ) = > { return completed | | DateTime . Now > = timeoutDate ; } ) ;
}
public void CheckAppBetaPassword ( uint appid , string password )
public void CheckAppBetaPassword ( uint appid , string password )
{
bool completed = false ;
Action < SteamApps . CheckAppBetaPasswordCallback > cbMethod = ( appPassword ) = >
var completed = false ;
Action < SteamApps . CheckAppBetaPasswordCallback > cbMethod = appPassword = >
{
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 ) ;
} , ( ) = > { return completed ; } ) ;
callbacks . Subscribe ( steamApps . CheckAppBetaPassword ( appid , password ) , cbMethod ) ;
} , ( ) = > { return completed ; } ) ;
}
public PublishedFileDetails GetPublishedFileDetails ( uint appId , PublishedFileID pubFile )
{
var pubFileRequest = new CPublishedFile_GetDetails_Request ( ) { appid = appId } ;
pubFileRequest . publishedfileids . Add ( pubFile ) ;
var pubFileRequest = new CPublishedFile_GetDetails_Request { appid = appId } ;
pubFileRequest . publishedfileids . Add ( pubFile ) ;
bool completed = false ;
var completed = false ;
PublishedFileDetails details = null ;
Action < SteamUnifiedMessages . ServiceMethodResponse > cbMethod = callback = >
@ -417,7 +417,7 @@ namespace DepotDownloader
public SteamCloud . UGCDetailsCallback GetUGCDetails ( UGCHandle ugcHandle )
{
bool completed = false ;
var completed = false ;
SteamCloud . UGCDetailsCallback details = null ;
Action < SteamCloud . UGCDetailsCallback > cbMethod = callback = >
@ -466,13 +466,14 @@ namespace DepotDownloader
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 ( ) ;
}
@ -484,9 +485,9 @@ namespace DepotDownloader
steamClient . Disconnect ( ) ;
// flush callbacks until our disconnected event
while ( ! bDidDisconnect )
while ( ! bDidDisconnect )
{
callbacks . RunWaitAllCallbacks ( TimeSpan . FromMilliseconds ( 100 ) ) ;
callbacks . RunWaitAllCallbacks ( TimeSpan . FromMilliseconds ( 100 ) ) ;
}
}
@ -498,82 +499,80 @@ namespace DepotDownloader
public void TryWaitForLoginKey ( )
{
if ( logonDetails . Username = = null | | ! credentials . LoggedOn | | ! ContentDownloader . Config . RememberPassword ) return ;
if ( logonDetails . Username = = null | | ! credentials . LoggedOn | | ! ContentDownloader . Config . RememberPassword ) return ;
var totalWaitPeriod = DateTime . Now . AddSeconds ( 3 ) ;
var totalWaitPeriod = DateTime . Now . AddSeconds ( 3 ) ;
while ( true )
while ( true )
{
DateTime now = DateTime . Now ;
if ( now > = totalWaitPeriod ) break ;
var now = DateTime . Now ;
if ( now > = totalWaitPeriod ) break ;
if ( bDidReceiveLoginKey ) break ;
if ( bDidReceiveLoginKey ) break ;
callbacks . RunWaitAllCallbacks ( TimeSpan . FromMilliseconds ( 100 ) ) ;
callbacks . RunWaitAllCallbacks ( TimeSpan . FromMilliseconds ( 100 ) ) ;
}
}
private void WaitForCallbacks ( )
{
callbacks . RunWaitCallbacks ( TimeSpan . FromSeconds ( 1 ) ) ;
callbacks . RunWaitCallbacks ( TimeSpan . FromSeconds ( 1 ) ) ;
TimeSpan diff = DateTime . Now - connectTime ;
var 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 ( ) ;
return ;
}
}
private void ConnectedCallback ( SteamClient . ConnectedCallback connected )
private void ConnectedCallback ( SteamClient . ConnectedCallback connected )
{
Console . WriteLine ( " Done!" ) ;
Console . WriteLine ( " Done!" ) ;
bConnecting = false ;
bConnected = true ;
if ( ! authenticatedUser )
if ( ! authenticatedUser )
{
Console . Write ( "Logging anonymously into Steam3..." ) ;
Console . Write ( "Logging anonymously into Steam3..." ) ;
steamUser . LogOnAnonymous ( ) ;
}
else
{
Console . Write ( "Logging '{0}' into Steam3..." , logonDetails . Username ) ;
steamUser . LogOn ( logonDetails ) ;
Console . Write ( "Logging '{0}' into Steam3..." , logonDetails . Username ) ;
steamUser . LogOn ( logonDetails ) ;
}
}
private void DisconnectedCallback ( SteamClient . DisconnectedCallback disconnected )
private void DisconnectedCallback ( SteamClient . DisconnectedCallback disconnected )
{
bDidDisconnect = true ;
// When recovering the connection, we want to reconnect even if the remote disconnects us
if ( ! bIsConnectionRecovery & & ( disconnected . UserInitiated | | bExpectingDisconnectRemote ) )
if ( ! bIsConnectionRecovery & & ( disconnected . UserInitiated | | bExpectingDisconnectRemote ) )
{
Console . WriteLine ( "Disconnected from Steam" ) ;
Console . WriteLine ( "Disconnected from Steam" ) ;
// Any operations outstanding need to be aborted
bAborted = true ;
}
else if ( connectionBackoff > = 10 )
else if ( connectionBackoff > = 10 )
{
Console . WriteLine ( "Could not connect to Steam after 10 tries" ) ;
Abort ( false ) ;
Console . WriteLine ( "Could not connect to Steam after 10 tries" ) ;
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
{
Console . WriteLine ( "Lost connection to Steam. Reconnecting" ) ;
Console . WriteLine ( "Lost connection to Steam. Reconnecting" ) ;
}
Thread . Sleep ( 1000 * + + connectionBackoff ) ;
Thread . Sleep ( 1000 * + + connectionBackoff ) ;
// Any connection related flags need to be reset here to match the state after Connect
ResetConnectionFlags ( ) ;
@ -581,125 +580,128 @@ namespace DepotDownloader
}
}
private void LogOnCallback ( SteamUser . LoggedOnCallback loggedOn )
private void LogOnCallback ( SteamUser . LoggedOnCallback loggedOn )
{
bool isSteamGuard = loggedOn . Result = = EResult . AccountLogonDenied ;
bool is2FA = loggedOn . Result = = EResult . AccountLoginDeniedNeedTwoFactor ;
bool isLoginKey = ContentDownloader . Config . RememberPassword & & logonDetails . LoginKey ! = null & & loggedOn . Result = = EResult . InvalidPassword ;
var isSteamGuard = loggedOn . Result = = EResult . AccountLogonDenied ;
var is2FA = loggedOn . Result = = EResult . AccountLoginDeniedNeedTwoFactor ;
var isLoginKey = ContentDownloader . Config . RememberPassword & & logonDetails . LoginKey ! = null & & loggedOn . Result = = EResult . InvalidPassword ;
if ( isSteamGuard | | is2FA | | isLoginKey )
if ( isSteamGuard | | is2FA | | isLoginKey )
{
bExpectingDisconnectRemote = true ;
Abort ( false ) ;
Abort ( false ) ;
if ( ! isLoginKey )
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 ( ) ;
}
else if ( isLoginKey )
else if ( isLoginKey )
{
AccountSettingsStore . Instance . LoginKeys . Remove ( logonDetails . Username ) ;
AccountSettingsStore . Instance . LoginKeys . Remove ( logonDetails . Username ) ;
AccountSettingsStore . Save ( ) ;
logonDetails . LoginKey = null ;
if ( ContentDownloader . Config . SuppliedPassword ! = null )
if ( ContentDownloader . Config . SuppliedPassword ! = null )
{
Console . WriteLine ( "Login key was expired. Connecting with supplied password." ) ;
Console . WriteLine ( "Login key was expired. Connecting with supplied password." ) ;
logonDetails . Password = ContentDownloader . Config . SuppliedPassword ;
}
else
{
Console . Write ( "Login key was expired. Please enter your password: " ) ;
Console . Write ( "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: " ) ;
Console . Write ( "Please enter the authentication code sent to your email address: " ) ;
logonDetails . AuthCode = Console . ReadLine ( ) ;
}
Console . Write ( "Retrying Steam3 connection..." ) ;
Console . Write ( "Retrying Steam3 connection..." ) ;
Connect ( ) ;
return ;
}
else if ( loggedOn . Result = = EResult . TryAnotherCM )
if ( loggedOn . Result = = EResult . TryAnotherCM )
{
Console . Write ( "Retrying Steam3 connection (TryAnotherCM)..." ) ;
Console . Write ( "Retrying Steam3 connection (TryAnotherCM)..." ) ;
Reconnect ( ) ;
return ;
}
else if ( loggedOn . Result = = EResult . ServiceUnavailable )
if ( loggedOn . Result = = EResult . ServiceUnavailable )
{
Console . WriteLine ( "Unable to login to Steam3: {0}" , loggedOn . Result ) ;
Abort ( false ) ;
Console . WriteLine ( "Unable to login to Steam3: {0}" , loggedOn . Result ) ;
Abort ( false ) ;
return ;
}
else if ( loggedOn . Result ! = EResult . OK )
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 ( ) ;
return ;
}
Console . WriteLine ( " Done!" ) ;
Console . WriteLine ( " Done!" ) ;
this . seq + + ;
credentials . LoggedOn = true ;
if ( ContentDownloader . Config . CellID = = 0 )
if ( ContentDownloader . Config . CellID = = 0 )
{
Console . WriteLine ( "Using Steam3 suggested CellID: " + loggedOn . CellID ) ;
ContentDownloader . Config . CellID = ( int ) loggedOn . CellID ;
Console . WriteLine ( "Using Steam3 suggested CellID: " + 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 ;
}
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 ( ) ;
return ;
}
Console . WriteLine ( "Got {0} licenses for account!" , licenseList . LicenseList . Count ) ;
Console . WriteLine ( "Got {0} licenses for account!" , licenseList . LicenseList . Count ) ;
Licenses = licenseList . LicenseList ;
foreach ( var license in licenseList . LicenseList )
foreach ( var license in licenseList . LicenseList )
{
if ( license . AccessToken > 0 )
if ( license . AccessToken > 0 )
{
PackageTokens . TryAdd ( license . PackageID , license . AccessToken ) ;
PackageTokens . TryAdd ( license . PackageID , license . AccessToken ) ;
}
}
}
private void UpdateMachineAuthCallback ( SteamUser . UpdateMachineAuthCallback machineAuth )
private void UpdateMachineAuthCallback ( SteamUser . UpdateMachineAuthCallback machineAuth )
{
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 ) ;
var hash = Util . SHAHash ( machineAuth . Data ) ;
Console . WriteLine ( "Got Machine Auth: {0} {1} {2} {3}" , machineAuth . FileName , machineAuth . Offset , machineAuth . BytesToWrite , machineAuth . Data . Length , hash ) ;
AccountSettingsStore . Instance . SentryData [ logonDetails . Username ] = machineAuth . Data ;
AccountSettingsStore . Instance . SentryData [ logonDetails . Username ] = machineAuth . Data ;
AccountSettingsStore . Save ( ) ;
var authResponse = new SteamUser . MachineAuthDetails
@ -720,21 +722,19 @@ namespace DepotDownloader
} ;
// send off our response
steamUser . SendMachineAuthResponse ( authResponse ) ;
steamUser . SendMachineAuthResponse ( authResponse ) ;
}
private void LoginKeyCallback ( SteamUser . LoginKeyCallback loginKey )
private void LoginKeyCallback ( SteamUser . LoginKeyCallback loginKey )
{
Console . WriteLine ( "Accepted new login key for account {0}" , logonDetails . Username ) ;
Console . WriteLine ( "Accepted new login key for account {0}" , logonDetails . Username ) ;
AccountSettingsStore . Instance . LoginKeys [ logonDetails . Username ] = loginKey . LoginKey ;
AccountSettingsStore . Instance . LoginKeys [ logonDetails . Username ] = loginKey . LoginKey ;
AccountSettingsStore . Save ( ) ;
steamUser . AcceptNewLoginKey ( loginKey ) ;
steamUser . AcceptNewLoginKey ( loginKey ) ;
bDidReceiveLoginKey = true ;
}
}
}