Exemplo n.º 1
0
        public static List <FortniteAccount> ValidateAndLoadAccounts(IEnumerable <string> files)
        {
            var accounts = new List <FortniteAccount>();

            foreach (var file in files)
            {
                var lines = File.ReadAllLines(file);

                // NOTE: These are the most common separators
                var accountDelimiters = new[]
                {
                    ':',
                    ';',
                    '|',
                    ','
                };

                foreach (var line in lines)
                {
                    var separatedAccount = line.Split(accountDelimiters);

                    var account = new FortniteAccount();

                    if (separatedAccount.Length != 2)
                    {
                        continue;
                    }

                    account.EmailAddress = separatedAccount[0];
                    account.Password     = separatedAccount[1];

                    accounts.Add(account);
                }
            }

            return(accounts);
        }
Exemplo n.º 2
0
        private async Task SaveProfileDataToCsv(FortniteProfileData data, FortniteAccount account)
        {
            // NOTE: Just in case, to prevent crash
            if (data.ProfileChanges.Count <= 0)
            {
                return;
            }

            var accountId = data.ProfileChanges[0].Profile.AccountId;

            var items = data.ProfileChanges[0].Profile.Item;

            var outfits    = SkinParser.GetOutfit(items);
            var backblings = SkinParser.GetBackBlings(items);
            var gliders    = SkinParser.GetGliders(items);
            var pickaxes   = SkinParser.GetPickaxes(items);

            var userProfileData = data.ProfileChanges[0].Profile;

            var createdAt       = userProfileData.Created;
            var lastUpdated     = userProfileData.Updated;
            var hasBattlePass   = userProfileData.Stats.Attributes.BookPurchased;
            var currentPassTier = userProfileData.Stats.Attributes.BookLevel;
            var lifetimeWins    = userProfileData.Stats.Attributes.LifetimeWins;
            var currentLevel    = userProfileData.Stats.Attributes.Level;
            var accountLevel    = userProfileData.Stats.Attributes.AccountLevel;

            var oldSeasons = new List <OldSeason>();

            foreach (var season in userProfileData.Stats.Attributes.PastSeasons)
            {
                oldSeasons.Add(new OldSeason
                {
                    SeasonNumber        = season.SeasonNumber,
                    PurchasedBattlePass = season.PurchasedVip,
                    BattlePassLevel     = season.BookLevel,
                    SeasonLevel         = season.SeasonLevel,
                    SeasonWins          = season.NumWins
                });
            }

            var fullProfile = new FortniteAccountFullData
            {
                AccountData            = account,
                AccountId              = accountId,
                CreatedAt              = createdAt,
                LastUpdate             = lastUpdated,
                HasBattlePassPurchased = hasBattlePass,
                CurrentBattlePassLevel = currentPassTier,
                LifetimeTotalWins      = lifetimeWins,
                CurrentSeasonalLevel   = currentLevel,
                AccountLevel           = accountLevel,
                //PastSeasons = oldSeasons,
                Outfits    = outfits,
                Backblings = backblings,
                Gliders    = gliders,
                Pickaxes   = pickaxes
            };

            _csvWriter.WriteRecord(fullProfile);

            // Write the fields for each previous season manually because CsvHelper doesn't support List<T>
            var seasonStats = new StringBuilder();

            foreach (var season in oldSeasons)
            {
                seasonStats.AppendLine("Season number: " + season.SeasonNumber);
                seasonStats.AppendLine("Season wins: " + season.SeasonWins);
                seasonStats.AppendLine("Season level: " + season.SeasonLevel);
                seasonStats.AppendLine("Season pass: "******"Season pass level: " + season.BattlePassLevel);

                _csvWriter.WriteField(seasonStats);

                seasonStats.Clear();
            }

            // Finish the row after writing the season data and go to next
            await _csvWriter.NextRecordAsync();

            _textWriter.Flush();
        }
Exemplo n.º 3
0
        private async Task <bool> CheckAccount(FortniteAccount account, IWebProxy proxy)
        {
            using (var httpClientHandler = new HttpClientHandler())
            {
                httpClientHandler.CookieContainer   = new CookieContainer();
                httpClientHandler.AllowAutoRedirect = false;

                if (proxy != null)
                {
                    httpClientHandler.UseDefaultCredentials = false;
                    httpClientHandler.PreAuthenticate       = true;
                    httpClientHandler.UseProxy = true;
                    httpClientHandler.Proxy    = proxy;
                }

                using (var httpClient = new HttpClient(httpClientHandler))
                {
                    httpClient.Timeout = TimeSpan.FromSeconds(10);
                    httpClient.DefaultRequestHeaders.Add("User-Agent", GlobalVariables.UserAgent);
                    httpClient.DefaultRequestHeaders.Add("Authorization", GlobalVariables.AuthorizationValue);
                    httpClient.DefaultRequestHeaders.ExpectContinue = true;

                    var postData = new FormUrlEncodedContent(new Dictionary <string, string>
                    {
                        { "grant_type", "password" },
                        { "username", account.EmailAddress },
                        { "password", account.Password },
                        { "includePerms", "true" },
                        { "token_type", "eg1" }
                    });

                    HttpResponseMessage postRequest = null;
                    try
                    {
                        postRequest = await httpClient.PostAsync(GlobalVariables.LoginUrl, postData);
                    }
                    catch (HttpRequestException e)
                    {
                        Console.WriteLine($@"Error while sending request.");
                        Console.WriteLine($@"--------------------------------------------------------------");
                        Console.WriteLine($@"Error message: {e.Message}.");
                        Console.WriteLine($@"Inner exception: {e.InnerException?.Message}.");
                        Console.WriteLine($@"Inner inner exception: {e.InnerException?.InnerException?.Message}.");

                        // NOTE: Account might be valid, but failed to send request (could be proxy issue)
                        return(false);
                    }

                    if (postRequest == null)
                    {
                        return(false);
                    }

                    var response = await postRequest.Content.ReadAsStringAsync();

                    if (!response.Contains("access_token"))
                    {
                        var errorResponse = JsonConvert.DeserializeObject <FortniteError>(response);

                        Console.WriteLine($@"An error occured while checking account {account.EmailAddress}.");
                        Console.WriteLine($@"--------------------------------------------------------------");
                        Console.WriteLine($@"Error: {errorResponse.Error} [code: {errorResponse.ErrorCode}] - Message: {errorResponse.ErrorMessage}.");

                        return(false);
                    }

                    var successResponse = JsonConvert.DeserializeObject <FortniteSuccess>(response);

                    var accessToken = successResponse.AccessToken;
                    var accountId   = successResponse.AccountId;

                    httpClient.DefaultRequestHeaders.Remove("Authorization");
                    httpClient.DefaultRequestHeaders.Add("Authorization", $@"bearer {accessToken}");

                    var jsonContent = new StringContent("{}", Encoding.UTF8, "application/json");

                    var getDataRequest = await httpClient.PostAsync(
                        $"https://fortnite-public-service-prod11.ol.epicgames.com/fortnite/api/game/v2/profile/{accountId}/client/QueryProfile?profileId=athena&rvn=-1",
                        jsonContent);

                    // NOTE: If the request isn't successful, it's still valid, but the data won't be parsed (skins, wins etc)
                    if (!getDataRequest.IsSuccessStatusCode)
                    {
                        return(true);
                    }

                    var userDataResponse = await getDataRequest.Content.ReadAsStringAsync();

                    var userDataParsed = JsonConvert.DeserializeObject <FortniteProfileData>(userDataResponse);

                    await SaveProfileDataToCsv(userDataParsed, account);

                    return(true);
                }
            }
        }