Пример #1
0
        public async Task <Replay> GetReplayFromOnlineId(string onlineId, string mods, Beatmap beatmap)
        {
            string file   = Path.Combine(serverFolder, "replays", $"{onlineId}.osr");
            Replay replay = null;

            if (!File.Exists(file))
            {
                Logger.Log(Logging.ReplaysCacheMiss);
                await Logger.WriteLine("replay not found, downloading...");

                var data = await api.DownloadReplayFromId(onlineId);

                if (data != null)
                {
                    replay              = new Replay();
                    replay.Mods         = ConvertMods.StringToMods(mods);
                    replay.headerLoaded = true;
                    using (MemoryStream ms = new MemoryStream())
                        using (BinaryWriter bw = new BinaryWriter(ms))
                        {
                            bw.WriteNullableString(string.Empty);
                            bw.Write(DateTime.UtcNow.Ticks);
                            bw.Write(data.Length);
                            bw.Write(data);
                            bw.Write(ulong.Parse(onlineId));
                            ms.Seek(0, SeekOrigin.Begin);
                            using (BinaryReader reader = new BinaryReader(ms))
                            {
                                replay.replayReader = reader;
                                replay.Load();
                            }
                        }
                    replay.Save(file);
                }
            }
            else
            {
                replay = new Replay(file);
                Logger.Log(Logging.ReplaysCacheHit);
            }
            return(replay);
        }