Always process Disconnect callback before pausing for input. This prevents the Disconnect callback from being processed after the Connect

pull/25/head
Ryan Kistner 9 years ago
parent 63569977ec
commit 35aa666ea5

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading;
namespace DepotDownloader namespace DepotDownloader
{ {
@ -46,6 +47,9 @@ namespace DepotDownloader
bool bConnected; bool bConnected;
bool bConnecting; bool bConnecting;
bool bAborted; bool bAborted;
bool bExpectingDisconnectRemote;
bool bDidDisconnect;
int connectionBackoff;
int seq; // more hack fixes int seq; // more hack fixes
DateTime connectTime; DateTime connectTime;
@ -357,6 +361,9 @@ namespace DepotDownloader
bAborted = false; bAborted = false;
bConnected = false; bConnected = false;
bConnecting = true; bConnecting = true;
connectionBackoff = 0;
bExpectingDisconnectRemote = false;
bDidDisconnect = false;
this.connectTime = DateTime.Now; this.connectTime = DateTime.Now;
this.steamClient.Connect(); this.steamClient.Connect();
} }
@ -377,8 +384,11 @@ namespace DepotDownloader
bConnecting = false; bConnecting = false;
bAborted = true; bAborted = true;
// flush callbacks // flush callbacks until our disconnected event
callbacks.RunCallbacks(); while (!bDidDisconnect)
{
callbacks.RunWaitAllCallbacks(TimeSpan.FromMilliseconds(100));
}
} }
@ -416,11 +426,30 @@ namespace DepotDownloader
private void DisconnectedCallback(SteamClient.DisconnectedCallback disconnected) private void DisconnectedCallback(SteamClient.DisconnectedCallback disconnected)
{ {
if ((!bConnected && !bConnecting) || bAborted) bDidDisconnect = true;
return;
Console.WriteLine("Reconnecting"); if (disconnected.UserInitiated || bExpectingDisconnectRemote)
steamClient.Connect(); {
Console.WriteLine("Disconnected from Steam");
}
else if (connectionBackoff >= 10)
{
Console.WriteLine("Could not connect to Steam after 10 tries");
Abort(false);
}
else if (!bAborted)
{
if (bConnecting)
{
Console.WriteLine("Connection to Steam failed. Trying again");
} else
{
Console.WriteLine("Lost connection to Steam. Reconnecting");
}
Thread.Sleep(1000 * ++connectionBackoff);
steamClient.Connect();
}
} }
private void LogOnCallback(SteamUser.LoggedOnCallback loggedOn) private void LogOnCallback(SteamUser.LoggedOnCallback loggedOn)
@ -430,10 +459,11 @@ namespace DepotDownloader
if (isSteamGuard || is2FA) if (isSteamGuard || is2FA)
{ {
Console.WriteLine("This account is protected by Steam Guard."); bExpectingDisconnectRemote = true;
Abort(false); Abort(false);
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: ");

Loading…
Cancel
Save