예제 #1
0
        private async Task <CDNClient> BuildConnection(uint appId, uint depotId, byte[] depotKey,
                                                       CDNClient.Server serverSeed, CancellationToken token)
        {
            CDNClient.Server server = null;
            CDNClient        client = null;

            while (client == null)
            {
                if (serverSeed != null)
                {
                    server     = serverSeed;
                    serverSeed = null;
                }
                else
                {
                    if (_availableServerEndpoints.Count < ServerEndpointMinimumSize)
                    {
                        _populateEvent.Set();
                    }

                    server = _availableServerEndpoints.Take(token);
                }

                client = new CDNClient(_client);

                try
                {
                    var cdnToken = "";

                    if (server.Type == "CDN" || server.Type == "SteamCache")
                    {
                        cdnToken = (await RequestCDNAuthToken(appId, depotId, server.Host))?.Token;
                    }

                    await client.ConnectAsync(server);

                    await client.AuthenticateDepotAsync(depotId, depotKey, cdnToken);
                }
                catch (Exception ex)
                {
                    client = null;
                    Console.WriteLine("Failed to connect to content server {0}: {1}", server, ex.Message);
                    _contentServerPenalty.TryGetValue(server.Host, out var penalty);
                    _contentServerPenalty[server.Host] = ++penalty;
                }
            }

            Console.WriteLine("Initialized connection to content server {0} with depot id {1}", server, depotId);
            _activeClientAuthed[client] = Tuple.Create(depotId, server);

            return(client);
        }
예제 #2
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);
        }
예제 #3
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 (server.Type == "CDN" || server.Type == "SteamCache")
                {
                    await 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);

                //await client.AuthenticateDepotAsync(depotId, depotKey, cdnAuthToken);
                activeClientAuthed[client] = Tuple.Create(depotId, server);
                return(true);
            }
            catch (Exception ex)
            {
                DebugLog.WriteLine("CDNClientPool", "Failed to reauth to content server " + server + ": " + ex.Message);
            }

            return(false);
        }
예제 #4
0
        private async Task <bool> AuthenticateConnection(CDNClient client, CDNClient.Server server, uint appId,
                                                         uint depotId, byte[] depotKey)
        {
            try
            {
                string cdnAuthToken = null;

                if (server.Type == "CDN" || server.Type == "SteamCache")
                {
                    cdnAuthToken = (await RequestCDNAuthToken(appId, depotId, server.Host))?.Token;
                }

                await client.AuthenticateDepotAsync(depotId, depotKey, cdnAuthToken);

                _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);
        }
예제 #5
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 (server.Type == "CDN" || server.Type == "SteamCache")
                    {
                        await 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.ConnectAsync(server);
                    await client.AuthenticateDepotAsync(depotId, depotKey, cdnAuthToken).ConfigureAwait(false);

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

                    DebugLog.WriteLine("CDNClientPool", "Failed to connect to content server " + server + ": " + ex.Message);

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

            DebugLog.WriteLine("CDNClientPool", "Initialized connection to content server " + server + " with depot id " + depotId);

            activeClientAuthed[client] = Tuple.Create(depotId, server);
            return(client);
        }
예제 #6
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);
        }
예제 #7
0
        async private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }

            try
            {
                ConfigItem item = datagridConfigs.Rows[e.RowIndex].DataBoundItem as ConfigItem;

                if (item != null)
                {
                    if (item.URL == "")
                    {
                        var callback = await steamWorkshop.RequestInfo(241100, item.Details.publishedfileid);

                        var itemInfo = callback.Items.FirstOrDefault();
                        var ticket   = await steamClient.GetHandler <SteamApps>().GetAppOwnershipTicket(241100);

                        var decryptKey = await steamClient.GetHandler <SteamApps>().GetDepotDecryptionKey(241100, 241100);

                        var cdn = new CDNClient(steamClient, ticket.Ticket);
                        // var servers = cdn.FetchServerList();
                        var servers = await cdn.FetchServerListAsync();

                        int i = 0;
                        foreach (CDNClient.Server server in servers)
                        {
                            Log.w($"Server{i}: {server}");
                            ++i;
                        }
                        await cdn.ConnectAsync(servers.First());

                        await cdn.AuthenticateDepotAsync(241100, decryptKey.DepotKey);

                        var manifest = await cdn.DownloadManifestAsync(241100, itemInfo.ManifestID);

                        manifest.DecryptFilenames(decryptKey.DepotKey);
                        if (manifest.Files.Count == 0)
                        {
                            MessageBox.Show("Steam Refused Download Request");
                            return;
                        }
                        var chunk = cdn.DownloadDepotChunkAsync(241100, manifest.Files.First().Chunks.First());
                        if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                        {
                            using (var wc = new WebClient())
                            {
                                using (var io = saveFileDialog1.OpenFile())
                                {
                                    io.Write(chunk.Result.Data, 0, chunk.Result.Data.Length);
                                    MessageBox.Show($"Download Done!\nSaved {saveFileDialog1.FileName}");
                                    Log.w($"Downloaded {saveFileDialog1.FileName}");
                                }
                            }
                        }
                    }
                    else
                    {
                        if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                        {
                            using (var wc = new WebClient())
                            {
                                wc.DownloadFile(new Uri(item.URL), saveFileDialog1.FileName);
                                MessageBox.Show("Download Done!");
                            }
                        }
                    }
                }
            }
            catch (TaskCanceledException)
            {
                MessageBox.Show("Timeout! This can happen if you're using anonymous account and trying to download.");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error Downloading Config: {ex.ToString()}");
            }
        }