Example #1
0
        private async Task <bool> ReauthConnectionAsync(CDNClient client, CDNClient.Server server, uint appId, uint depotId, byte[] depotKey)
        {
            DebugLog.Assert(server.Type == "CDN" || server.Type == "SteamCache" || steamSession.AppTickets[depotId] == null, "CDNClientPool", "Re-authing a CDN or anonymous connection");

            String cdnAuthToken = null;

            try
            {
                if (DepotKeyStore.ContainsKey(depotId))
                {
                    ((ConcurrentDictionary <uint, byte[]>)(typeof(CDNClient).GetField("depotKeys", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(client))).GetOrAdd(depotId, depotKey);
                }
                else
                {
                    if (server.Type == "CDN" || server.Type == "SteamCache")
                    {
                        steamSession.RequestCDNAuthToken(appId, depotId, server.Host);

                        var cdnKey = string.Format("{0:D}:{1}", depotId, steamSession.ResolveCDNTopLevelHost(server.Host));
                        SteamApps.CDNAuthTokenCallback authTokenCallback;

                        if (steamSession.CDNAuthTokens.TryGetValue(cdnKey, out authTokenCallback))
                        {
                            cdnAuthToken = authTokenCallback.Token;
                        }
                        else
                        {
                            throw new Exception(String.Format("Failed to retrieve CDN token for server {0} depot {1}", server.Host, depotId));
                        }
                    }

                    await client.AuthenticateDepotAsync(depotId, depotKey, cdnAuthToken).ConfigureAwait(false);
                }
                activeClientAuthed[client] = Tuple.Create(depotId, server);
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to reauth to content server {0}: {1}", server, ex.Message);
            }

            return(false);
        }
Example #2
0
        static DepotDownloadInfo GetDepotInfo(uint depotId, uint appId, ulong manifestId, string branch)
        {
            if (steam3 != null && appId != INVALID_APP_ID)
            {
                steam3.RequestAppInfo(( uint )appId);
            }

            string contentName = GetAppOrDepotName(depotId, appId);

            // Skip requesting an app ticket
            steam3.AppTickets[depotId] = null;

            if (manifestId == INVALID_MANIFEST_ID)
            {
                manifestId = GetSteam3DepotManifest(depotId, appId, branch);
                if (manifestId == INVALID_MANIFEST_ID && branch != "public")
                {
                    Console.WriteLine("Warning: Depot {0} does not have branch named \"{1}\". Trying public branch.", depotId, branch);
                    branch     = "public";
                    manifestId = GetSteam3DepotManifest(depotId, appId, branch);
                }

                if (manifestId == INVALID_MANIFEST_ID)
                {
                    Console.WriteLine("Depot {0} ({1}) missing public subsection or manifest section.", depotId, contentName);
                    return(null);
                }
            }

            uint uVersion = GetSteam3AppBuildNumber(appId, branch);

            string installDir;

            if (!CreateDirectories(appId, appName, depotId, uVersion, contentName, out installDir))
            {
                Console.WriteLine("Error: Unable to create install directories!");
                return(null);
            }

            if (!DepotKeyStore.ContainsKey(depotId) && !AccountHasAccess(depotId))
            {
                Console.WriteLine("Depot {0} ({1}) is not available from this account and no key found in depot key store.", depotId, contentName);

                return(null);
            }

            byte[] depotKey;

            if (DepotKeyStore.ContainsKey(depotId))
            {
                depotKey = DepotKeyStore.Get(depotId);
            }
            else
            {
                steam3.RequestDepotKey(depotId, appId);
                if (!steam3.DepotKeys.ContainsKey(depotId))
                {
                    Console.WriteLine("No valid depot key for {0}, unable to download.", depotId);
                    return(null);
                }
                depotKey = steam3.DepotKeys[depotId];
            }



            var info = new DepotDownloadInfo(depotId, manifestId, installDir, contentName);

            info.depotKey = depotKey;

            File.WriteAllText($"depots\\{depotId}.key", BitConverter.ToString(depotKey).Replace("-", ""));
            return(info);
        }
Example #3
0
        static async Task <int> MainAsync(string[] args)
        {
            if (args.Length == 0)
            {
                PrintUsage();
                return(1);
            }

            DebugLog.Enabled = false;

            AccountSettingsStore.LoadFromFile("account.config");

            #region Common Options

            string username = GetParameter <string>(args, "-username") ?? GetParameter <string>(args, "-user");
            string password = GetParameter <string>(args, "-password") ?? GetParameter <string>(args, "-pass");
            ContentDownloader.Config.RememberPassword = HasParameter(args, "-remember-password");

            ContentDownloader.Config.DownloadManifestOnly = HasParameter(args, "-manifest-only");

            int cellId = GetParameter <int>(args, "-cellid", -1);
            if (cellId == -1)
            {
                cellId = 0;
            }

            ContentDownloader.Config.CellID = cellId;

            string   fileList = GetParameter <string>(args, "-filelist");
            string[] files    = null;

            if (fileList != null)
            {
                try
                {
                    string fileListData = File.ReadAllText(fileList);
                    files = fileListData.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

                    ContentDownloader.Config.UsingFileList        = true;
                    ContentDownloader.Config.FilesToDownload      = new List <string>();
                    ContentDownloader.Config.FilesToDownloadRegex = new List <Regex>();

                    foreach (var fileEntry in files)
                    {
                        try
                        {
                            Regex rgx = new Regex(fileEntry, RegexOptions.Compiled | RegexOptions.IgnoreCase);
                            ContentDownloader.Config.FilesToDownloadRegex.Add(rgx);
                        }
                        catch
                        {
                            ContentDownloader.Config.FilesToDownload.Add(fileEntry);
                            continue;
                        }
                    }

                    Console.WriteLine("Using filelist: '{0}'.", fileList);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Warning: Unable to load filelist: {0}", ex.ToString());
                }
            }

            string depotKeysList = GetParameter <string>(args, "-depotkeys");

            if (depotKeysList != null)
            {
                try
                {
                    string   depotKeysListData = File.ReadAllText(depotKeysList);
                    string[] lines             = depotKeysListData.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

                    DepotKeyStore.AddAll(lines);


                    Console.WriteLine("Using depot keys from '{0}'.", depotKeysList);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Warning: Unable to load filelist: {0}", ex.ToString());
                }
            }

            ContentDownloader.Config.InstallDirectory = GetParameter <string>(args, "-dir");

            ContentDownloader.Config.VerifyAll    = HasParameter(args, "-verify-all") || HasParameter(args, "-verify_all") || HasParameter(args, "-validate");
            ContentDownloader.Config.MaxServers   = GetParameter <int>(args, "-max-servers", 20);
            ContentDownloader.Config.MaxDownloads = GetParameter <int>(args, "-max-downloads", 4);
            ContentDownloader.Config.MaxServers   = Math.Max(ContentDownloader.Config.MaxServers, ContentDownloader.Config.MaxDownloads);

            #endregion

            ulong pubFile = GetParameter <ulong>(args, "-pubfile", ContentDownloader.INVALID_MANIFEST_ID);
            if (pubFile != ContentDownloader.INVALID_MANIFEST_ID)
            {
                #region Pubfile Downloading

                if (InitializeSteam(username, password))
                {
                    try
                    {
                        await ContentDownloader.DownloadPubfileAsync(pubFile).ConfigureAwait(false);
                    }
                    catch (Exception ex) when(
                        ex is ContentDownloaderException ||
                        ex is OperationCanceledException)
                    {
                        Console.WriteLine(ex.Message);
                        return(1);
                    }
                    finally
                    {
                        ContentDownloader.ShutdownSteam3();
                    }
                }
                else
                {
                    Console.WriteLine("Error: InitializeSteam failed");
                    return(1);
                }

                #endregion
            }
            else
            {
                #region App downloading

                string branch = GetParameter <string>(args, "-branch") ?? GetParameter <string>(args, "-beta") ?? ContentDownloader.DEFAULT_BRANCH;
                ContentDownloader.Config.BetaPassword = GetParameter <string>(args, "-betapassword");

                ContentDownloader.Config.DownloadAllPlatforms = HasParameter(args, "-all-platforms");
                string os = GetParameter <string>(args, "-os", null);

                if (ContentDownloader.Config.DownloadAllPlatforms && !String.IsNullOrEmpty(os))
                {
                    Console.WriteLine("Error: Cannot specify -os when -all-platforms is specified.");
                    return(1);
                }

                uint appId = GetParameter <uint>(args, "-app", ContentDownloader.INVALID_APP_ID);
                if (appId == ContentDownloader.INVALID_APP_ID)
                {
                    Console.WriteLine("Error: -app not specified!");
                    return(1);
                }

                uint depotId;
                bool isUGC = false;

                ulong manifestId = GetParameter <ulong>(args, "-ugc", ContentDownloader.INVALID_MANIFEST_ID);
                if (manifestId != ContentDownloader.INVALID_MANIFEST_ID)
                {
                    depotId = appId;
                    isUGC   = true;
                }
                else
                {
                    depotId    = GetParameter <uint>(args, "-depot", ContentDownloader.INVALID_DEPOT_ID);
                    manifestId = GetParameter <ulong>(args, "-manifest", ContentDownloader.INVALID_MANIFEST_ID);
                    if (depotId == ContentDownloader.INVALID_DEPOT_ID && manifestId != ContentDownloader.INVALID_MANIFEST_ID)
                    {
                        Console.WriteLine("Error: -manifest requires -depot to be specified");
                        return(1);
                    }
                }

                if (InitializeSteam(username, password))
                {
                    try
                    {
                        await ContentDownloader.DownloadAppAsync(appId, depotId, manifestId, branch, os, isUGC).ConfigureAwait(false);
                    }
                    catch (Exception ex) when(
                        ex is ContentDownloaderException ||
                        ex is OperationCanceledException)
                    {
                        Console.WriteLine(ex.Message);
                        return(1);
                    }
                    finally
                    {
                        ContentDownloader.ShutdownSteam3();
                    }
                }
                else
                {
                    Console.WriteLine("Error: InitializeSteam failed");
                    return(1);
                }

                #endregion
            }
            return(0);
        }
Example #4
0
        private async Task <CDNClient> BuildConnectionAsync(uint appId, uint depotId, byte[] depotKey, CDNClient.Server serverSeed, CancellationToken token)
        {
            CDNClient.Server server = null;
            CDNClient        client = null;

            while (client == null)
            {
                // if we want to re-initialize a specific content server, try that one first
                if (serverSeed != null)
                {
                    server     = serverSeed;
                    serverSeed = null;
                }
                else
                {
                    if (availableServerEndpoints.Count < ServerEndpointMinimumSize)
                    {
                        populatePoolEvent.Set();
                    }

                    server = availableServerEndpoints.Take(token);
                }

                client = new CDNClient(steamSession.steamClient, steamSession.AppTickets[depotId]);

                string cdnAuthToken = null;

                try
                {
                    if (DepotKeyStore.ContainsKey(depotId))
                    {
                        ((ConcurrentDictionary <uint, byte[]>)(typeof(CDNClient).GetField("depotKeys", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(client))).GetOrAdd(depotId, depotKey);
                        await client.ConnectAsync(server).ConfigureAwait(false);
                    }
                    else
                    {
                        if (server.Type == "CDN" || server.Type == "SteamCache")
                        {
                            steamSession.RequestCDNAuthToken(appId, depotId, server.Host);

                            var cdnKey = string.Format("{0:D}:{1}", depotId, steamSession.ResolveCDNTopLevelHost(server.Host));
                            SteamApps.CDNAuthTokenCallback authTokenCallback;

                            if (steamSession.CDNAuthTokens.TryGetValue(cdnKey, out authTokenCallback))
                            {
                                cdnAuthToken = authTokenCallback.Token;
                            }
                            else
                            {
                                throw new Exception(String.Format("Failed to retrieve CDN token for server {0} depot {1}", server.Host, depotId));
                            }
                        }
                        await client.ConnectAsync(server).ConfigureAwait(false);

                        await client.AuthenticateDepotAsync(depotId, depotKey, cdnAuthToken).ConfigureAwait(false);
                    }
                }
                catch (Exception ex)
                {
                    client = null;

                    Console.WriteLine("Failed to connect to content server {0}: {1}", server, ex.Message);

                    int penalty = 0;
                    AccountSettingsStore.Instance.ContentServerPenalty.TryGetValue(server.Host, out penalty);
                    AccountSettingsStore.Instance.ContentServerPenalty[server.Host] = penalty + 1;
                }
            }

            Console.WriteLine("Initialized connection to content server {0} with depot id {1}", server, depotId);

            activeClientAuthed[client] = Tuple.Create(depotId, server);
            return(client);
        }