Beispiel #1
0
        // Call RefreshRank() only when you hold the mutex to the internal dictionaries.
        private async Task RefreshRank(ulong discordID, string r6TabID)
        {
            try
            {
                TrackerDataSnippet data = await TRNHttpProvider.UpdateAndGetData(r6TabID);

                Rank fetchedRank = data.ToRank();

                bool updateRequired = true;
                if (await _data.TrackingContains(discordID))
                {
                    Rank curRank = await _data.QueryRank(discordID);

                    if (curRank.Equals(fetchedRank))
                    {
                        updateRequired = false;
                    }
                    else
                    {
                        Console.WriteLine("The fetched rank and the stored rank disagree for the user " + discordID);
                        Console.WriteLine($"The fetched rank equals {fetchedRank} and the stored rank is {curRank}.");
                    }
                }
                else
                {
                    Console.WriteLine("The user with DiscordID " + discordID + " is not yet in the database of ranks.");
                }

                if (updateRequired)
                {
                    await _data.UpdateRanks(discordID, fetchedRank);
                    await UpdateRoles(discordID, fetchedRank);
                }
                else
                {
                    // System.Console.WriteLine("Ranks match for player " + player.Username);
                }
            }
            catch (RankParsingException)
            {
                Console.WriteLine("Failed to update rank for player " + discordID);
            }
            catch (System.Net.Http.HttpRequestException)
            {
                Console.WriteLine("Network unrechable, delaying update.");
                return;
            }
        }
Beispiel #2
0
        public static Rank GuessRank(List <string> UserRoles)
        {
            Rank          ret       = new Rank(Metal.Undefined, 0);
            List <string> specRoles = FilterSpectralRoles(UserRoles);

            foreach (string specRole in specRoles)
            {
                Rank guess = FindRankFromSpectral(specRole);
                if (!guess.Equals(ret))
                {
                    ret = guess;
                    break;
                }
            }
            return(ret);
        }
Beispiel #3
0
        public async Task SyncRankRolesAndData()
        {
            // Note: we currently do not take access locks for the data structure.
            // We only touch it in a read-only way, so it should be okay.
            // This function should only be called at the initialization time anyway.
            int updates   = 0;
            int preserved = 0;

            foreach ((var discordID, var uplayID) in _data.DiscordUplay)
            {
                foreach (var guild in guilds.byID.Values)
                {
                    SocketGuildUser player = guild._socket.Users.FirstOrDefault(x => x.Id == discordID);
                    if (player == null)
                    {
                        continue;
                    }

                    List <string> allRoles    = player.Roles.Select(x => x.Name).ToList();
                    Rank          guessedRank = Ranking.GuessRank(allRoles);
                    Rank          queriedRank = await _data.QueryRank(discordID);

                    if (!guessedRank.Equals(queriedRank))
                    {
                        try
                        {
                            Console.WriteLine($"Guessed and queried rank of user {player.Username} on guild {guild.GetName()} do not match, guessed: ({guessedRank.FullPrint()},{guessedRank.level}), queried: ({queriedRank.FullPrint()},{queriedRank.level})");
                            await UpdateRoles(discordID, queriedRank);
                        }
                        catch (RankParsingException)
                        {
                            Console.WriteLine($"Failed to fix mismatch for Discord user {player.Username}");
                        }
                        updates++;
                    }
                    else
                    {
                        preserved++;
                    }
                }
                // TODO: Possibly erase from the DB if the user IS null.
            }
            System.Console.WriteLine($"Bootstrap: {updates} players have their roles updated, {preserved} have the same roles.");
            roleInitComplete = true;
        }
Beispiel #4
0
        /// <summary>
        /// Computes the rank based on the internal mmr and played matches this season.
        /// <returns>True if deduced data changed, false if they stayed the same.</returns>
        /// </summary>
        public bool DeduceRankData()
        {
            Rank oldRank = deducedRank;

            if (!enoughMatchesPlayed)
            {
                deducedRank = new Rank(Metal.Rankless, 0);
            }
            else
            {
                deducedRank = Ranking.MMRToRank(MMR);
            }

            if (oldRank == null || !oldRank.Equals(deducedRank))
            {
                return(true);
            }

            return(false);
        }