Exemple #1
0
        public static async Task FixDuplicateScores(Presence pr, string channel, string message, string[] args)
        {
            await ChannelManager.BotMessage(pr, channel, "Start cleaning duplicate scores...");

            await using (var db = MySqlProvider.GetDbConnection())
            {
                var scoreHashes = new List <string>();
                var scores      = await db.QueryAsync <DbScore>("SELECT * FROM Scores");

                await ChannelManager.BotMessage(pr, channel, $"Scores to check: {scores.Count()}");

                foreach (var score in scores)
                {
                    var scoreHash = Crypto.ComputeHash($"sum:{score.Count50 + score.Count100 + score.Count300}c300" +
                                                       $"{score.Count300}c100{score.Count100}c50{score.Count50}cgeki{score.CountGeki}ckatu" +
                                                       $"{score.CountKatu}cmiss{score.CountMiss}beatmap{score.FileChecksum}accuracy{score.Accuracy}");

                    if (scoreHashes.Contains(scoreHash))
                    {
                        await db.ExecuteAsync($"DELETE FROM Scores WHERE Id = {score.Id}");
                    }
                    else
                    {
                        scoreHashes.Add(scoreHash);
                    }
                }
            }
            await ChannelManager.BotMessage(pr, channel, "Done!");
        }
Exemple #2
0
        public static async Task RecalculatePerformance(Presence pr, string channel, string message, string[] args)
        {
            await ChannelManager.BotMessage(pr, channel, "Start recalculating performance points...");

            await using (var db = MySqlProvider.GetDbConnection())
            {
                var scores = await db.QueryAsync <DbScore>("SELECT * FROM Scores");

                await ChannelManager.BotMessage(pr, channel, $"Scores to re-calculate: {scores.Count()}");

                foreach (var score in scores)
                {
                    try
                    {
                        var beatmap = (await BeatmapManager.Get(score.FileChecksum));
                        if (beatmap.Item1 is RankedStatus.NotSubmitted or RankedStatus.NeedUpdate)
                        {
                            continue;
                        }

                        double pp = 0;
                        if (beatmap.Item2.Status == RankedStatus.Loved)
                        {
                            pp = 0;
                        }
                        else
                        {
                            pp = await Calculator.CalculatePerformancePoints(score);
                        }
                        await db.ExecuteAsync($"UPDATE Scores SET PerformancePoints = @PP WHERE Id = {score.Id}", new
                        {
                            PP = pp
                        });
                    }
                    catch
                    {
                        // ignored
                    }
                }
            }
            await ChannelManager.BotMessage(pr, channel, "Done!");
        }
Exemple #3
0
        public static async Task <Score[]> GetRawScores(string beatmapMd5, PlayMode mode, RankedStatus status,
                                                        LeaderboardMode lbMode)
        {
            IEnumerable <DbScore> scores = null;

            await using (var db = MySqlProvider.GetDbConnection())
            {
                scores = await db.QueryAsync <DbScore>($"SELECT *, Scores.Id AS Id FROM Scores " +
                                                       $"JOIN Users ON Users.Id = Scores.UserId " +
                                                       $"WHERE Users.Privileges & {(int) Privileges.Normal} > 0 " +
                                                       $"AND FileChecksum = '{beatmapMd5}' " +
                                                       $"AND Completed = {(int) CompletedStatus.Best} " +
                                                       $"AND PlayMode = {(int) mode} " +
                                                       $"AND Relaxing = {lbMode == LeaderboardMode.Relax} " +
                                                       $"ORDER BY {(lbMode == LeaderboardMode.Relax ? "PerformancePoints" : "TotalScore")} DESC " +
                                                       $"LIMIT 50");
            }



            var dbScores = scores as DbScore[] ?? scores.ToArray();

            return(dbScores.Select(score => FromDb(score, status, dbScores)).ToArray());
        }
Exemple #4
0
        public static async Task UBan(Presence pr, string channel, string message, string[] args)
        {
            var user = Base.UserCache[args[0]];

            if (!user.Banned())
            {
                await ChannelManager.BotMessage(pr, channel, $"Bye, bye, {user.Username}");

                user.Privileges &= ~Privileges.Normal;

                await using (var db = MySqlProvider.GetDbConnection())
                    await db.ExecuteAsync($"UPDATE Users SET Privileges = {(int)user.Privileges} WHERE Id = {user.Id}");

                var target = PresenceManager.GetPresenceById(user.Id);

                if (target is not null)
                {
                    await target.LoginReply(LoginReplies.WrongCredentials);

                    await target.Notification("Your account is banned.");
                }

                new Thread(async() =>
                {
                    IEnumerable <DbScore> scores = null;
                    await using (var db = MySqlProvider.GetDbConnection())
                    {
                        scores = await db.QueryAsync <DbScore>($"SELECT * FROM Scores " +
                                                               $"WHERE UserId = {user.Id} " +
                                                               $"AND Completed = {(int)CompletedStatus.Best}");
                    }

                    foreach (var score in scores)
                    {
                        var lbMode  = score.Relaxing ? LeaderboardMode.Relax : LeaderboardMode.Vanilla;
                        var beatmap = (await BeatmapManager.Get(score.FileChecksum, "", 0, true, score.PlayMode)).Item2;
                        if (beatmap is not null)
                        {
                            await beatmap.UpdateLeaderboard(lbMode, score.PlayMode);
                        }
                    }
                }).Start();
            }
            else
            {
                await ChannelManager.BotMessage(pr, channel, $"Welcome back, {user.Username}");

                user.Privileges |= Privileges.Normal;

                await using (var db = MySqlProvider.GetDbConnection())
                {
                    await db.ExecuteAsync($"UPDATE Users SET Privileges = {(int)user.Privileges} WHERE Id = {user.Id}");
                }

                new Thread(async() =>
                {
                    IEnumerable <DbScore> scores = null;
                    await using (var db = MySqlProvider.GetDbConnection())
                    {
                        scores = await db.QueryAsync <DbScore>($"SELECT * FROM Scores " +
                                                               $"WHERE UserId = {user.Id} " +
                                                               $"AND Completed = {(int)CompletedStatus.Best}");
                    }

                    foreach (var score in scores)
                    {
                        var lbMode  = score.Relaxing ? LeaderboardMode.Relax : LeaderboardMode.Vanilla;
                        var beatmap = (await BeatmapManager.Get(score.FileChecksum, "", 0, true, score.PlayMode)).Item2;
                        if (beatmap is not null)
                        {
                            await beatmap.UpdateLeaderboard(lbMode, score.PlayMode);
                        }
                    }
                }).Start();
            }
        }