示例#1
0
 private PayVault(FlurlClient client, string xsrfToken, DeveloperGame game, long start_balance, long coins_added, long coins_used, long end_balance)
 {
     this.StartBalance = start_balance;
     this.CoinsAdded   = coins_added;
     this.CoinsUsed    = coins_used;
     this.EndBalance   = end_balance;
 }
示例#2
0
        internal static async Task <DeveloperAccount> LoadAsync(
            FlurlClient client,
            CancellationToken cancellationToken = default
            )
        {
            var flurlRequest       = client.Request("/my/account/details");
            var angleSharpResponse = await flurlRequest.ToAngleSharpResponse(executionPredicate : null, cancellationToken).ConfigureAwait(false);

            var browsingContext        = BrowsingContext.New(Configuration.Default);
            var accountDetailsDocument = await browsingContext.OpenAsync(angleSharpResponse, cancellationToken).ConfigureAwait(false);

            var username = accountDetailsDocument.QuerySelector("#accountinfo").QuerySelector("a").TextContent;
            var email    = accountDetailsDocument.QuerySelector("#Email").GetAttribute("value");

            var gamesTasks = new List <Task <DeveloperGame> >();

            // TODO: lazy load games
            foreach (var element in accountDetailsDocument.QuerySelector("#mygamesdropdown .scrollcontainer").Children)
            {
                var path = (element as IHtmlAnchorElement)?.PathName ?? throw new Exception("library broke, pls fix");

                gamesTasks.Add(DeveloperGame.LoadAsync(client, path, cancellationToken));
            }

            var games = await Task.WhenAll(gamesTasks).ConfigureAwait(false);

            // we cast down List<T> to an IReadOnlyList<T> so we can claim type safety and not permit modifications,
            // but also allow the end user to cast back to a List<T> if they need to mess with it for whatever reason.
            return(new DeveloperAccount(username, email, games));
        }
示例#3
0
        private BigDB(FlurlClient client, string xsrfToken, DeveloperGame game, List <Table> tables)
        {
            _client    = client;
            _xsrfToken = xsrfToken;

            this.Game   = game;
            this.Tables = tables;
        }
示例#4
0
        public static async Task <PayVault> LoadAsync(FlurlClient client, string xsrfToken, DeveloperGame game, CancellationToken cancellationToken = default)
        {
            var payVaultAnalytics = await client.Request($"/my/payvault/start/{game.NavigationId}/{xsrfToken}")
                                    .LoadDocumentAsync(cancellationToken)
                                    .ConfigureAwait(false);

            var start_balance = long.Parse(payVaultAnalytics.QuerySelectorAll("h5").Where(h => h.TextContent == "Start Balance").First().NextElementSibling.TextContent);
            var coins_added   = long.Parse(payVaultAnalytics.QuerySelectorAll("h5").Where(h => h.TextContent == "Coins Added").First().NextElementSibling.TextContent);
            var coins_used    = long.Parse(payVaultAnalytics.QuerySelectorAll("h5").Where(h => h.TextContent == "Coins Used").First().NextElementSibling.TextContent);
            var end_balance   = long.Parse(payVaultAnalytics.QuerySelectorAll("h5").Where(h => h.TextContent == "End Balance").First().NextElementSibling.TextContent);

            return(new PayVault(client, xsrfToken, game, start_balance, coins_added, coins_used, end_balance));
        }
示例#5
0
        public static async Task <BigDB> LoadAsync(FlurlClient client, string xsrfToken, DeveloperGame game, CancellationToken cancellationToken = default)
        {
            var tables = new List <Table>();

            var bigdbDetails = await client.Request($"/my/bigdb/tables/{game.NavigationId}/{xsrfToken}")
                               .LoadDocumentAsync(cancellationToken)
                               .ConfigureAwait(false);

            var rows     = bigdbDetails.QuerySelector(".innermainrail").QuerySelector(".box").QuerySelector("tbody").QuerySelectorAll("tr.colrow");
            var contents = rows.Select(row => new
            {
                Name         = row.QuerySelectorAll("a.big").First()?.TextContent,
                Description  = row.QuerySelectorAll("p").First()?.TextContent,
                ExtraDetails = row.QuerySelectorAll("td").Skip(1).Take(1).First()?.Text().Replace("\n", "").Replace("\r", "").Replace("\t", "")
            });

            foreach (var table in contents)
            {
                tables.Add(new Table()
                {
                    Name         = table.Name,
                    Description  = table.Description,
                    ExtraDetails = table.ExtraDetails
                });
            }

            return(new BigDB(client, xsrfToken, game, tables));
        }