Exemplo n.º 1
0
        // I could do that better but this looks nice :3
        public uint GetPosition(SoraDbContextFactory factory, PlayMode mode)
        {
            var pos = 0;

            switch (mode)
            {
            case PlayMode.Osu:
                pos = factory.Get().LeaderboardStd.Count(x => x.PerformancePointsOsu > PerformancePointsOsu);
                break;

            case PlayMode.Taiko:
                pos = factory.Get().LeaderboardStd.Count(x => x.PerformancePointsTaiko > PerformancePointsTaiko);
                break;

            case PlayMode.Ctb:
                pos = factory.Get().LeaderboardStd.Count(x => x.PerformancePointsCtb > PerformancePointsCtb);
                break;

            case PlayMode.Mania:
                pos = factory.Get().LeaderboardStd.Count(x => x.PerformancePointsMania > PerformancePointsMania);
                break;
            }

            return((uint)pos + 1);
        }
Exemplo n.º 2
0
        public static IEnumerable <Scores> GetScores(
            SoraDbContextFactory factory,
            string fileMd5, Users user, PlayMode playMode = PlayMode.Osu,
            bool relaxing    = false,
            bool friendsOnly = false, bool countryOnly = false, bool modOnly = false,
            Mod mods         = Mod.None, bool onlySelf = false)
        {
            CountryIds cid = 0;

            if (countryOnly)
            {
                cid = UserStats.GetUserStats(factory, user.Id).CountryId;
            }

            var query = factory.Get().Scores
                        .Where(score => score.FileMd5 == fileMd5 && score.PlayMode == playMode)
                        .Where(
                score
                => relaxing
                                           ? (score.Mods & Mod.Relax) != 0
                                           : (score.Mods & Mod.Relax) == 0
                )
                        .Where(
                score
                => !friendsOnly || factory.Get().Friends
                .Where(f => f.UserId == user.Id)
                .Select(f => f.FriendId)
                .Contains(score.UserId)
                )
                        .Where(
                score
                => !countryOnly || factory.Get().UserStats
                .Select(c => c.CountryId)
                .Contains(cid)
                )
                        .Where(score => !modOnly || score.Mods == mods)
                        .Where(score => !onlySelf || score.UserId == user.Id)
                        .OrderByDescending(score => score.TotalScore)
                        .GroupBy(s => s.UserId)
                        .Take(50);

            IEnumerable <Scores> result = query.ToArray().Select(s => s.Select(xs => xs).First()).ToList();

            foreach (var s in result)
            {
                s.Position = factory.Get().Scores
                             .Where(score => score.FileMd5 == fileMd5 && score.PlayMode == playMode)
                             .Where(
                    score
                    => relaxing
                                                ? (score.Mods & Mod.Relax) != 0
                                                : (score.Mods & Mod.Relax) == 0
                    )
                             .OrderByDescending(score => score.TotalScore)
                             .IndexOf(s) + 1;
            }
            return(result);
        }
Exemplo n.º 3
0
        public static BeatmapSets GetBeatmapSet(SoraDbContextFactory factory, int setId)
        {
            var sts = factory.Get().BeatmapSets.FirstOrDefault(s => s.Id == setId);

            if (sts != null)
            {
                sts.Beatmaps = factory.Get().Beatmaps.Where(s => s.BeatmapSetId == sts.Id).ToList();
            }

            return(sts);
        }
Exemplo n.º 4
0
 public static Beatmaps FetchFromDatabase(SoraDbContextFactory factory, string fileMd5, int beatmapId = -1)
 {
     return(factory.Get().Beatmaps.FirstOrDefault(
                bm => bm.FileMd5 == fileMd5 ||
                bm.Id == beatmapId
                ));
 }
Exemplo n.º 5
0
 public static IEnumerable <int> GetFriends(SoraDbContextFactory factory, int userId)
 {
     return(factory.Get()
            .Friends
            .Where(t => t.UserId == userId)
            .Select(x => x.FriendId).ToList());
 }
Exemplo n.º 6
0
        public static Scores GetScore(SoraDbContextFactory factory, int scoreId)
        {
            var s = factory.Get().Scores.First(score => score.Id == scoreId);

            s.ScoreOwner = Users.GetUser(factory, s.UserId);
            return(s);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Create Default Achievements
 /// </summary>
 /// <param name="factory">Context Factory</param>
 public static void CreateDefaultAchievements(SoraDbContextFactory factory)
 {
     if (factory.Get().Achievements.FirstOrDefault(x => x.Name == "oog") == null)
     {
         Achievements.NewAchievement(
             factory,
             "oog",
             "Oooooooooooooooog!",
             "You just oooged JSE",
             "https://onii-chan-please.come-inside.me/achivement_oog.png"
             );
     }
 }
Exemplo n.º 8
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvcCore();
            services.AddMemoryCache();

            var c = new MemoryCache(new MemoryCacheOptions {
                ExpirationScanFrequency = TimeSpan.FromDays(365)
            });
            var cfgUtil = new ConfigUtil(c);

            var scfg = cfgUtil.ReadConfig <Config>();

            var f = new SoraDbContextFactory();

            f.Get().Migrate();

            services.AddSingleton(scfg)
            .AddSingleton <IConfig>(scfg)
            .AddSingleton <IMySQLConfig>(scfg)
            .AddSingleton <ICheesegullConfig>(scfg)
            .AddSingleton <IServerConfig>(scfg)
            .AddSingleton <ConfigUtil>()
            .AddSingleton <SoraDbContextFactory>()
            .AddSingleton <PluginService>()
            .AddSingleton <PresenceService>()
            .AddSingleton <MultiplayerService>()
            .AddSingleton <PacketStreamService>()
            .AddSingleton <Cache>()
            .AddSingleton <ConsoleCommandService>()
            .AddSingleton <ChannelService>()
            .AddSingleton <Bot.Sora>()
            .AddSingleton <PerformancePointsProcessor>()
            .AddSingleton(new EventManager(new List <Assembly> {
                Assembly.GetEntryAssembly()
            }));

            services.Configure <FormOptions>(
                x =>
            {
                x.ValueLengthLimit             = int.MaxValue;
                x.MultipartBodyLengthLimit     = int.MaxValue;
                x.MemoryBufferThreshold        = int.MaxValue;
                x.BufferBodyLengthLimit        = int.MaxValue;
                x.MultipartBoundaryLengthLimit = int.MaxValue;
                x.MultipartHeadersLengthLimit  = int.MaxValue;
            }
                );
        }
Exemplo n.º 9
0
 public static Achievements GetAchievement(SoraDbContextFactory factory, string name)
 {
     return(factory.Get().Achievements.FirstOrDefault(x => x.Name == name));
 }
Exemplo n.º 10
0
 public static int GetTotalScores(SoraDbContextFactory factory, string fileMd5)
 {
     return(factory.Get().Scores.Count(score => score.FileMd5 == fileMd5));
 }