diff --git a/DepotDownloader/Steam3Session.cs b/DepotDownloader/Steam3Session.cs index 83f0978da..970a56900 100644 --- a/DepotDownloader/Steam3Session.cs +++ b/DepotDownloader/Steam3Session.cs @@ -44,7 +44,6 @@ public ReadOnlyCollection Licenses readonly CallbackManager callbacks; readonly bool authenticatedUser; - bool bConnected; bool bConnecting; bool bAborted; bool bExpectingDisconnectRemote; @@ -52,15 +51,11 @@ public ReadOnlyCollection Licenses bool bIsConnectionRecovery; int connectionBackoff; int seq; // more hack fixes - DateTime connectTime; AuthSession authSession; // input readonly SteamUser.LogOnDetails logonDetails; - static readonly TimeSpan STEAM3_TIMEOUT = TimeSpan.FromSeconds(30); - - public Steam3Session(SteamUser.LogOnDetails details) { this.logonDetails = details; @@ -109,7 +104,7 @@ public bool WaitUntilCallback(Action submitter, WaitCondition waiter) { lock (steamLock) { - WaitForCallbacks(); + callbacks.RunWaitCallbacks(TimeSpan.FromSeconds(1)); } } while (!bAborted && this.seq == seq && !waiter()); } @@ -328,14 +323,11 @@ private void ResetConnectionFlags() void Connect() { bAborted = false; - bConnected = false; bConnecting = true; connectionBackoff = 0; authSession = null; ResetConnectionFlags(); - - this.connectTime = DateTime.Now; this.steamClient.Connect(); } @@ -352,7 +344,6 @@ public void Disconnect(bool sendLogOff = true) } bAborted = true; - bConnected = false; bConnecting = false; bIsConnectionRecovery = false; steamClient.Disconnect(); @@ -372,28 +363,13 @@ private void Reconnect() steamClient.Disconnect(); } - private void WaitForCallbacks() - { - callbacks.RunWaitCallbacks(TimeSpan.FromSeconds(1)); - - var diff = DateTime.Now - connectTime; - - if (diff > STEAM3_TIMEOUT && !bConnected) - { - Console.WriteLine("Timeout connecting to Steam3."); - Abort(); - } - } - private async void ConnectedCallback(SteamClient.ConnectedCallback connected) { Console.WriteLine(" Done!"); bConnecting = false; - bConnected = true; // Update our tracking so that we don't time out, even if we need to reconnect multiple times, // e.g. if the authentication phase takes a while and therefore multiple connections. - connectTime = DateTime.Now; connectionBackoff = 0; if (!authenticatedUser) @@ -534,16 +510,18 @@ private void DisconnectedCallback(SteamClient.DisconnectedCallback disconnected) } else if (!bAborted) { + connectionBackoff += 1; + if (bConnecting) { - Console.WriteLine("Connection to Steam failed. Trying again"); + Console.WriteLine($"Connection to Steam failed. Trying again (#{connectionBackoff})..."); } else { 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();