From 24ecfcbb43a52a62936aa249b389fc501890fd47 Mon Sep 17 00:00:00 2001 From: "Azu@Azu-PC" Date: Sat, 17 Dec 2011 22:32:40 -0700 Subject: [PATCH] Added retry to Steam3 FetchServerList --HG-- extra : rebase_source : 053cb4ea8409980314fcd40a52f5af8faf85a9c7 --- DepotDownloader/ContentDownloader.cs | 39 +++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/DepotDownloader/ContentDownloader.cs b/DepotDownloader/ContentDownloader.cs index a32eb4f2..bc00beaf 100644 --- a/DepotDownloader/ContentDownloader.cs +++ b/DepotDownloader/ContentDownloader.cs @@ -9,6 +9,7 @@ using System.IO.Compression; using System.Diagnostics; using System.Text.RegularExpressions; using System.Net.Sockets; +using System.Threading; namespace DepotDownloader { @@ -16,6 +17,7 @@ namespace DepotDownloader { const string DEFAULT_DIR = "depots"; const int MAX_STORAGE_RETRIES = 500; + const int MAX_STEAM3_RETRIES = 10; public static DownloadConfig Config = new DownloadConfig(); @@ -417,13 +419,33 @@ namespace DepotDownloader List serverList = steam3.steamClient.GetServersOfType(EServerType.ServerTypeCS); List cdnServers = null; + int tries = 0, counterDeferred = 0, counterCDN = 0; - foreach(var endpoint in serverList) + for(int i = 0; ; i++ ) { + IPEndPoint endpoint = serverList[i % serverList.Count]; + cdnServers = CDNClient.FetchServerList(new CDNClient.ClientEndPoint(endpoint.Address.ToString(), endpoint.Port), Config.CellID); + if (cdnServers == null) counterDeferred++; + else if (cdnServers.Count == 0) counterCDN++; + if (cdnServers != null && cdnServers.Count > 0) break; + + if (((i+1) % serverList.Count) == 0) + { + if (++tries > MAX_STEAM3_RETRIES) + { + Console.WriteLine("\nGiving up finding Steam3 content server."); + return; + } + + Console.Write("\nSearching for content servers... (deferred: {0}, CDN: {1})", counterDeferred, counterCDN); + counterDeferred = 0; + counterCDN = 0; + Thread.Sleep(2000); + } } if (cdnServers == null || cdnServers.Count == 0) @@ -435,9 +457,20 @@ namespace DepotDownloader Console.WriteLine(" Done!"); Console.Write("Downloading depot manifest..."); - CDNClient cdnClient = new CDNClient(cdnServers[0], steam3.AppTickets[(uint)depotId]); + CDNClient cdnClient = null; + + foreach (var server in cdnServers) + { + CDNClient client = new CDNClient(cdnServers[0], steam3.AppTickets[(uint)depotId]); + + if (client.Connect()) + { + cdnClient = client; + break; + } + } - if (!cdnClient.Connect()) + if (cdnClient == null) { Console.WriteLine("\nCould not initialize connection with CDN."); return;