private async Task <(Common.Http.Client, CDPTree, CollectedBNetInfo)> ResolveDownloadInfo()
            {
                var info = new CollectedBNetInfo();

                var login_info = await Utils.FromEncryptedJson <BethesdaNetData>(DataName);

                var client = new Common.Http.Client();

                client.Headers.Add(("User-Agent", "bnet"));
                foreach (var header in login_info.headers.Where(h => h.Key.ToLower().StartsWith("x-")))
                {
                    client.Headers.Add((header.Key, header.Value));
                }

                var posted = await client.PostAsync("https://api.bethesda.net/beam/accounts/external_login",
                                                    new StringContent(login_info.body, Encoding.UTF8, "application/json"));

                info.AccessToken = (await posted.Content.ReadAsStringAsync()).FromJsonString <BeamLoginResponse>().access_token;

                client.Headers.Add(("x-cdp-app", "UGC SDK"));
                client.Headers.Add(("x-cdp-app-ver", "0.9.11314/debug"));
                client.Headers.Add(("x-cdp-lib-ver", "0.9.11314/debug"));
                client.Headers.Add(("x-cdp-platform", "Win/32"));

                posted = await client.PostAsync("https://api.bethesda.net/cdp-user/auth",
                                                new StringContent("{\"access_token\": \"" + info.AccessToken + "\"}", Encoding.UTF8,
                                                                  "application/json"));

                info.CDPToken = (await posted.Content.ReadAsStringAsync()).FromJsonString <CDPLoginResponse>().token;

                client.Headers.Add(("X-Access-Token", info.AccessToken));
                var got = await client.GetAsync($"https://api.bethesda.net/mods/ugc-workshop/content/get?content_id={ContentId}");

                JObject data = JObject.Parse(await got.Content.ReadAsStringAsync());

                var content = data["platform"] !["response"] !["content"] !;
Esempio n. 2
0
        public static async Task <bool> UploadPackagedInis(IEnumerable <Archive> archives)
        {
            archives = archives.ToArray(); // defensive copy
            Utils.Log($"Packaging {archives.Count()} inis");
            try
            {
                await using var ms = new MemoryStream();
                using (var z = new ZipArchive(ms, ZipArchiveMode.Create, true))
                {
                    foreach (var e in archives)
                    {
                        if (e.State == null)
                        {
                            continue;
                        }
                        var entry = z.CreateEntry(Path.GetFileName(e.Name));
                        await using var os = entry.Open();
                        await os.WriteAsync(Encoding.UTF8.GetBytes(string.Join("\n", e.State.GetMetaIni())));
                    }
                }

                var client   = new Common.Http.Client();
                var response = await client.PostAsync($"{Consts.WabbajackBuildServerUri}indexed_files/notify", new ByteArrayContent(ms.ToArray()));

                if (response.IsSuccessStatusCode)
                {
                    return(true);
                }

                Utils.Log("Error sending Inis");
                Utils.Log(await response.Content.ReadAsStringAsync());
                return(false);
            }
            catch (Exception ex)
            {
                Utils.Log(ex.ToString());
                return(false);
            }
        }
Esempio n. 3
0
        public async Task Send(Channel channel, DiscordMessage message)
        {
            try
            {
                string url = channel switch
                {
                    Channel.Spam => _settings.SpamWebHook,
                    Channel.Ham => _settings.HamWebHook,
                    _ => null
                };
                if (url == null)
                {
                    return;
                }

                var client = new Common.Http.Client();
                await client.PostAsync(url, new StringContent(message.ToJson(true), Encoding.UTF8, "application/json"));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.ToJson());
            }
        }