示例#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);
        }
示例#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);
        }
示例#3
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);
        }