示例#1
0
        private void updateBeatmap()
        {
            if (BeatmapImport.IsProcessing)
            {
                return;
            }

            if (Lobby.SpectatingMatch == null)
            {
                return;
            }

            if ((Lobby.SpectatingMatch.activeMods & Mods.DoubleTime) > 0)
            {
                AudioEngine.CurrentPlaybackRate = 150;
            }
            else if ((Lobby.SpectatingMatch.activeMods & Mods.HalfTime) > 0)
            {
                AudioEngine.CurrentPlaybackRate = 75;
            }
            else
            {
                AudioEngine.CurrentPlaybackRate = 100;
            }

            if (BeatmapManager.Current?.BeatmapChecksum == Lobby.SpectatingMatch.beatmapChecksum)
            {
                currentSong.Text = BeatmapManager.Current?.DisplayTitleFullAuto ?? string.Empty;
            }
            else
            {
                currentSong.Text = Lobby.SpectatingMatch?.beatmapName ?? string.Empty;
            }
            playingIcon.Alpha = string.IsNullOrEmpty(currentSong.Text) ? 0 : 1;

            if (Lobby.SpectatingMatch.beatmapChecksum == BeatmapManager.Current?.BeatmapChecksum)
            {
                return;
            }

            if (string.IsNullOrEmpty(Lobby.SpectatingMatch.beatmapChecksum))
            {
                pickingUp = false;
            }
            else
            {
                var b = BeatmapManager.GetBeatmapByChecksum(Lobby.SpectatingMatch.beatmapChecksum);

                if (b == null)
                {
                    if (pickingUp)
                    {
                        return;
                    }
                    pickingUp = true;

                    OsuDirect.HandlePickup(Lobby.SpectatingMatch.beatmapChecksum, (o, e) =>
                    {
                        BeatmapImport.Start();
                        pickingUp = false;
                    }, null);
                }
                else
                {
                    BeatmapManager.Load(b);
                    clients.Reset();
                }
            }
        }
示例#2
0
        public static Score ReadReplayFromFile(string filename, bool handlePickup)
        {
            //Make sure the score manager is already initialized.
            InitializeScoreManager();

            Score inScore = null;

            bool success = false;

            try
            {
                using (Stream stream = File.Open(filename, FileMode.Open))
                {
                    SerializationReader sr = new SerializationReader(stream);
                    inScore = ScoreFactory.Create((PlayModes)sr.ReadByte(), null);
                    inScore.ReadHeaderFromStream(sr);
                    if (ModManager.CheckActive(inScore.EnabledMods, Mods.Target))
                    {
                        inScore = new ScoreTarget(inScore);
                    }
                    inScore.ReadFromStream(sr);
                    if (inScore.Date < DateTime.UtcNow + new TimeSpan(365 * 5, 0, 0, 0))
                    {
                        success = true;
                    }
                }
            }
            catch { }


            if (!success)
            {
                try
                {
                    using (Stream stream = File.Open(filename, FileMode.Open))
                        inScore = (Score)DynamicDeserializer.Deserialize(stream);
                }
                catch
                {
                    NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.ScoreManager_ReplayCorrupt));
                    return(null);
                }
            }

            if (inScore == null)
            {
                NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.ScoreManager_ReplayCorrupt));
                return(null);
            }

            if (inScore.Date.Year > 2050 || inScore.Date == DateTime.MinValue)
            {
                string[] split = filename.Split('-');
                if (split.Length > 1)
                {
                    long outfiletime = 0;
                    if (long.TryParse(split[1].Replace(@".osr", string.Empty), out outfiletime))
                    {
                        inScore.Date = DateTime.FromFileTimeUtc(outfiletime);
                    }
                }
            }

            if (inScore.Date.Year > 2050)
            {
                //this score is TOTALLY f****d.
                File.Delete(filename);
                NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.ScoreManager_ReplayCorrupt));
                return(null);
            }

            if (BeatmapManager.GetBeatmapByChecksum(inScore.FileChecksum) == null)
            {
                //attempt pickup.
                if (handlePickup)
                {
                    OsuDirect.HandlePickup(inScore.FileChecksum, null,
                                           delegate
                    {
                        NotificationManager.ShowMessage(LocalisationManager.GetString(OsuString.ScoreManager_DontHaveBeatmap));
                    });
                }
                return(null);
            }

            InsertScore(inScore, false);

            return(inScore);
        }