diff --git a/DepotDownloader/Steam3Session.cs b/DepotDownloader/Steam3Session.cs index f8648355..af729488 100644 --- a/DepotDownloader/Steam3Session.cs +++ b/DepotDownloader/Steam3Session.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using SteamKit2; using System.Diagnostics; +using System.Net; namespace DepotDownloader { @@ -78,6 +79,7 @@ namespace DepotDownloader this.callbacks = new CallbackManager(this.steamClient); this.callbacks.Register(new Callback(ConnectedCallback)); + this.callbacks.Register(new Callback(DisconnectedCallback)); this.callbacks.Register(new Callback(LogOnCallback)); this.callbacks.Register(new Callback(SessionTokenCallback)); this.callbacks.Register(new Callback(LicenseListCallback)); @@ -259,7 +261,6 @@ namespace DepotDownloader private void Abort(bool sendLogOff=true) { - bAborted = true; Disconnect(sendLogOff); } public void Disconnect(bool sendLogOff=true) @@ -271,6 +272,7 @@ namespace DepotDownloader steamClient.Disconnect(); bConnected = false; + bAborted = true; } @@ -305,6 +307,27 @@ namespace DepotDownloader } } + private static int retry_count = 0; + + private void DisconnectedCallback(SteamClient.DisconnectedCallback disconnected) + { + if (bAborted) + return; + + Console.WriteLine("Reconnecting"); + + if ( ++retry_count < 2 ) + { + steamClient.Connect(); + } + else + { + var addresses = Dns.GetHostAddresses( "cm0.steampowered.com" ); + Random random = new Random(); + steamClient.Connect( addresses[ random.Next( addresses.Length ) ] ); + } + } + private void LogOnCallback(SteamUser.LoggedOnCallback loggedOn) { if (loggedOn.Result == EResult.AccountLogonDenied)