Connection state flag fixes to ensure we actually recover when TryAnotherCM is returned

pull/233/head
Ryan Kistner 4 years ago
parent 22b4b5fe3c
commit 913c85a4dd

@ -54,6 +54,7 @@ namespace DepotDownloader
bool bExpectingDisconnectRemote; bool bExpectingDisconnectRemote;
bool bDidDisconnect; bool bDidDisconnect;
bool bDidReceiveLoginKey; bool bDidReceiveLoginKey;
bool bIsConnectionRecovery;
int connectionBackoff; int connectionBackoff;
int seq; // more hack fixes int seq; // more hack fixes
DateTime connectTime; DateTime connectTime;
@ -444,15 +445,23 @@ namespace DepotDownloader
return details; return details;
} }
private void ResetConnectionFlags()
{
bExpectingDisconnectRemote = false;
bDidDisconnect = false;
bIsConnectionRecovery = false;
bDidReceiveLoginKey = false;
}
void Connect() void Connect()
{ {
bAborted = false; bAborted = false;
bConnected = false; bConnected = false;
bConnecting = true; bConnecting = true;
connectionBackoff = 0; connectionBackoff = 0;
bExpectingDisconnectRemote = false;
bDidDisconnect = false; ResetConnectionFlags();
bDidReceiveLoginKey = false;
this.connectTime = DateTime.Now; this.connectTime = DateTime.Now;
this.steamClient.Connect(); this.steamClient.Connect();
} }
@ -467,12 +476,13 @@ namespace DepotDownloader
{ {
steamUser.LogOff(); steamUser.LogOff();
} }
steamClient.Disconnect(); bAborted = true;
bConnected = false; bConnected = false;
bConnecting = false; bConnecting = false;
bAborted = true; bIsConnectionRecovery = false;
steamClient.Disconnect();
// flush callbacks until our disconnected event // flush callbacks until our disconnected event
while ( !bDidDisconnect ) while ( !bDidDisconnect )
{ {
@ -480,6 +490,12 @@ namespace DepotDownloader
} }
} }
private void Reconnect()
{
bIsConnectionRecovery = true;
steamClient.Disconnect();
}
public void TryWaitForLoginKey() public void TryWaitForLoginKey()
{ {
if ( logonDetails.Username == null || !credentials.LoggedOn || !ContentDownloader.Config.RememberPassword ) return; if ( logonDetails.Username == null || !credentials.LoggedOn || !ContentDownloader.Config.RememberPassword ) return;
@ -532,8 +548,9 @@ namespace DepotDownloader
private void DisconnectedCallback( SteamClient.DisconnectedCallback disconnected ) private void DisconnectedCallback( SteamClient.DisconnectedCallback disconnected )
{ {
bDidDisconnect = true; bDidDisconnect = true;
if ( disconnected.UserInitiated || bExpectingDisconnectRemote ) // When recovering the connection, we want to reconnect even if the remote disconnects us
if ( !bIsConnectionRecovery && ( disconnected.UserInitiated || bExpectingDisconnectRemote ) )
{ {
Console.WriteLine( "Disconnected from Steam" ); Console.WriteLine( "Disconnected from Steam" );
@ -557,6 +574,9 @@ namespace DepotDownloader
} }
Thread.Sleep( 1000 * ++connectionBackoff ); Thread.Sleep( 1000 * ++connectionBackoff );
// Any connection related flags need to be reset here to match the state after Connect
ResetConnectionFlags();
steamClient.Connect(); steamClient.Connect();
} }
} }
@ -615,10 +635,7 @@ namespace DepotDownloader
{ {
Console.Write( "Retrying Steam3 connection (TryAnotherCM)..." ); Console.Write( "Retrying Steam3 connection (TryAnotherCM)..." );
bExpectingDisconnectRemote = true; Reconnect();
Abort( false );
Connect();
return; return;
} }

Loading…
Cancel
Save