Beispiel #1
0
        public ActionResult DumpDatabase(string key)
        {
            if (key != Environment.GetEnvironmentVariable("PRIVATE_API_KEY"))
            {
                return(Unauthorized("Key is wrong!"));
            }

            lock (_lock) {
                var tmpStorage = _storage.GetStorageForDirectory("tmp");

                if (tmpStorage.Exists("dump.piss"))
                {
                    System.IO.File.Delete(tmpStorage.GetFullPath("dump.piss"));
                }

                using (var dumpStream = tmpStorage.GetStream("dump.piss", FileAccess.Write))
                    using (var sw = new MStreamWriter(dumpStream))
                    {
                        sw.Write(_contextFactory.Get().BeatmapSet.Count());
                        foreach (var bmSet in _contextFactory.Get().BeatmapSet)
                        {
                            bmSet.ChildrenBeatmaps = _contextFactory.Get().Beatmaps.Where(bm => bm.ParentSetId == bmSet.SetId).ToList();
                            sw.Write(bmSet);
                        }
                    }
                return(File(tmpStorage.GetStream("dump.piss"),
                            "application/octet-stream",
                            "dump.piss"));
            }
        }
Beispiel #2
0
 public void WriteToStream(MStreamWriter sw)
 {
     sw.Write(Msg.Username);
     sw.Write(Msg.Message);
     sw.Write(Msg.ChannelTarget);
     sw.Write(Msg.SenderId);
 }
Beispiel #3
0
 public void WriteToStream(MStreamWriter sw)
 {
     sw.Write(ButtonState);
     sw.Write(Button);
     sw.Write(MouseX);
     sw.Write(MouseY);
     sw.Write(Time);
 }
Beispiel #4
0
 public void WriteToStream(MStreamWriter sw)
 {
     sw.Write((byte)Status.Status);
     sw.Write(Status.StatusText);
     sw.Write(Status.BeatmapChecksum);
     sw.Write((uint)Status.CurrentMods);
     sw.Write((byte)Status.Playmode);
     sw.Write(Status.BeatmapId);
 }
Beispiel #5
0
 public void WriteToStream(MStreamWriter sw)
 {
     sw.Write(Extra);
     sw.Write((short)ReplayFrames.Count);
     foreach (var rframe in ReplayFrames)
     {
         sw.Write(rframe);
     }
     sw.Write(Action);
     sw.Write(ScoreFrame);
 }
Beispiel #6
0
        public void WriteToStream(MStreamWriter sw)
        {
            sw.Write((short)MatchId);
            sw.Write(InProgress);

            sw.Write((byte)MatchType);
            sw.Write((uint)ActiveMods);

            sw.Write(Name);
            sw.Write(Password.Length > 0 ? Crypto.RandomString(16) : null, true);

            sw.Write(BeatmapName);
            sw.Write(BeatmapId);
            sw.Write(BeatmapMd5);

            foreach (var slot in Slots)
            {
                sw.Write((byte)slot.Status);
            }

            foreach (var slot in Slots)
            {
                sw.Write((byte)slot.Team);
            }

            foreach (var slot in Slots)
            {
                if ((slot.Status & (MultiSlotStatus)0x7c) > 0)
                {
                    sw.Write(slot.UserId);
                }
            }

            sw.Write(HostId);
            sw.Write((byte)PlayMode);
            sw.Write((byte)ScoringType);
            sw.Write((byte)TeamType);
            sw.Write((byte)SpecialModes);

            if (SpecialModes == MatchSpecialModes.Freemods)
            {
                foreach (var slot in Slots)
                {
                    sw.Write((uint)slot.Mods);
                }
            }

            sw.Write(Seed);
        }
Beispiel #7
0
 public void WriteToStream(MStreamWriter sw)
 {
     sw.Write(BeatmapId);
     sw.Write(ParentSetId);
     sw.Write(DiffName, true);
     sw.Write(FileMd5, true);
     sw.Write((sbyte)Mode);
     sw.Write(Bpm);
     sw.Write(Ar);
     sw.Write(Od);
     sw.Write(Cs);
     sw.Write(Hp);
     sw.Write(TotalLength);
     sw.Write(Playcount);
     sw.Write(Passcount);
     sw.Write(MaxCombo);
     sw.Write(DifficultyRating);
 }
Beispiel #8
0
        public void WriteToStream(MStreamWriter sw)
        {
            sw.Write(Info.Count);

            ushort i = 0;

            foreach (var info in Info)
            {
                sw.Write(i);
                sw.Write(info.BeatmapId);
                sw.Write(info.SetId);
                sw.Write(0); // ???
                sw.Write((byte)info.OsuRank);
                sw.Write((byte)info.TaikoRank);
                sw.Write((byte)info.CatchRank);
                sw.Write((byte)info.ManiaRank);
                sw.Write(info.FileMd5);
                i++;
            }
        }
Beispiel #9
0
        public void WritePackets(MStreamWriter writer)
        {
            if (this["IRC"] != null && (bool)this["IRC"])
            {
                return;
            }

            try
            {
                _rwl.AcquireWriterLock(5000);
                foreach (var packet in _packets)
                {
                    writer.Write(packet);
                }
                _packets.Clear();
            }
            finally
            {
                _rwl.ReleaseWriterLock();
            }
        }
Beispiel #10
0
        public MemoryStream GetOutput()
        {
            LastRequest.Restart();

            IPacket[] copy;
            lock (locker)
            {
                copy = new IPacket[packetList.Count];
                packetList.CopyTo(copy);
                packetList.Clear();
            }

            var res = MStreamWriter.New();

            foreach (var p in copy)
            {
                res.Write(p);
            }

            res.BaseStream.Position = 0;

            return((MemoryStream)res.BaseStream);
        }
Beispiel #11
0
 public void WriteToStream(MStreamWriter sw)
 {
     sw.Write(SetId);
     sw.Write(ChildrenBeatmaps.Count);
     foreach (var bm in ChildrenBeatmaps)
     {
         sw.Write(bm);
     }
     sw.Write((sbyte)RankedStatus);
     sw.Write(ApprovedDate?.ToString(), true);
     sw.Write(LastUpdate?.ToString(), true);
     sw.Write(LastChecked?.ToString(), true);
     sw.Write(Artist, true);
     sw.Write(Title, true);
     sw.Write(Creator, true);
     sw.Write(Source, true);
     sw.Write(Tags, true);
     sw.Write(HasVideo);
     sw.Write((sbyte)Genre);
     sw.Write((sbyte)Language);
     sw.Write(Favourites);
     sw.Write(Disabled);
 }
Beispiel #12
0
 public void WriteToStream(MStreamWriter sw)
 {
     sw.Write(Time);
     sw.Write(Id);
     sw.Write(Count300);
     sw.Write(Count100);
     sw.Write(Count50);
     sw.Write(CountGeki);
     sw.Write(CountKatu);
     sw.Write(CountMiss);
     sw.Write(TotalScore);
     sw.Write(MaxCombo);
     sw.Write(CurrentCombo);
     sw.Write(Perfect);
     sw.Write(CurrentHp);
     sw.Write(TagByte);
     sw.Write(ScoreV2);
     if (!ScoreV2)
     {
         return;
     }
     sw.Write(ComboPortion);
     sw.Write(BonusPortion);
 }
Beispiel #13
0
 private void Success(MStreamWriter dataWriter, int userid)
 {
     dataWriter.Write(new LoginResponse((LoginResponses)userid));
 }
Beispiel #14
0
 public void WriteToStream(MStreamWriter sw)
 {
     sw.Write(Frame);
 }
Beispiel #15
0
 public void WriteToStream(MStreamWriter sw)
 {
     sw.Write((int)ErrorState);
 }
Beispiel #16
0
 public void WriteToStream(MStreamWriter sw)
 {
 }
Beispiel #17
0
        public async Task <IActionResult> IndexPost([FromHeader(Name = "osu-token")] string clientToken = null)
        {
            try
            {
                Response.Headers["cho-protocol"] = "19";
                Response.Headers["Connection"]   = "keep-alive";
                Response.Headers["Keep-Alive"]   = "timeout=60, max=100";
                Response.Headers["cho-server"]   = "Sora (https://github.com/Mempler/Sora)";

                Response.StatusCode = 200;

                await using var body = new MemoryStream();
                await Request.Body.CopyToAsync(body);

                body.Position = 0;

                await using var mw = MStreamWriter.New();
                using var mr       = new MStreamReader(body);
                var pr = new Presence(new User());
                if (string.IsNullOrEmpty(clientToken))
                {
                    Response.Headers["cho-token"] = pr.Token.ToString();
                    string ip = Request.Headers["X-Real-IP"];

                    if (string.IsNullOrEmpty(ip))
                    {
                        ip = "127.0.0.1";
                    }

                    await _evManager.RunEvent(EventType.BanchoLoginRequest, new BanchoLoginRequestArgs
                    {
                        Reader    = mr,
                        Writer    = mw,
                        Pr        = pr,
                        IpAddress = ip
                    });

                    mw.Flush();

                    return(await RetOut(mw.BaseStream));
                }

                if (_presenceService.TryGet(new Token(clientToken.Trim()), out pr))
                {
                    while (true)
                    {
                        try
                        {
                            pr["LAST_PONG"] = DateTime.Now;

                            if (Request.ContentLength - body.Position < 7)
                            {
                                break; // Dont handle any invalid packets! (less then bytelength of 7)
                            }
                            var packetId = (PacketId)mr.ReadInt16();
                            mr.ReadBoolean();
                            var packetData = mr.ReadBytes();

                            await using var packetDataStream = new MemoryStream(packetData);
                            using var packetDataReader       = new MStreamReader(packetDataStream);
                            await _evManager.RunEvent(
                                EventType.BanchoPacket,
                                new BanchoPacketArgs { Pr = pr, PacketId = packetId, Data = packetDataReader }
                                );
                        }
                        catch (Exception ex)
                        {
                            Logger.Err(ex);
                            break;
                        }
                    }
                    try
                    {
                        await using var m = new MemoryStream();
                        if (Response.Body.CanWrite)
                        {
                            pr.WritePackets(m);
                        }

                        return(await RetOut(m));
                    }
                    catch (Exception ex)
                    {
                        Logger.Err(ex);
                        // Ignored because it may throw an exception.
                    }
                }
                else
                {
                    return(StatusCode(403));
                }
            }
            catch (Exception ex)
            {
                Logger.Err(ex);
            }

            return(Ok());
        }
Beispiel #18
0
 public void WriteToStream(MStreamWriter sw)
 {
     sw.Write(UserIds);
 }
Beispiel #19
0
        //[Produces("application/octet-stream")]
        public async Task <IActionResult> IndexPOST(
            [FromHeader(Name = "osu-token")] string clientToken = null
            )
        {
            try
            {
                Response.Headers["cho-protocol"] = "19";
                Response.Headers["Connection"]   = "keep-alive";
                Response.Headers["Keep-Alive"]   = "timeout=60, max=100";
                Response.Headers["cho-server"]   = "Sora (https://github.com/Mempler/Sora)";

                Response.StatusCode = 200;

                await using var body = new MemoryStream();
                await Request.Body.CopyToAsync(body);

                body.Position = 0;

                await using var mw = MStreamWriter.New();
                using var mr       = new MStreamReader(body);

                Presence pr;
                try
                {
                    if (string.IsNullOrEmpty(clientToken))
                    {
                        pr = new Presence(_cs);
                        Response.Headers["cho-token"] = pr.Token;
                        string ip = Response.Headers["X-Forwarded-For"];

                        if (string.IsNullOrEmpty(ip))
                        {
                            ip = "127.0.0.1";
                        }

                        await _evmng.RunEvent(
                            EventType.BanchoLoginRequest,
                            new BanchoLoginRequestArgs { pr = pr, Reader = mr, Writer = mw, IPAddress = ip }
                            );

                        mw.Flush();

                        return(await RetOut(mw.BaseStream));
                    }
                } catch (Exception ex)
                {
                    Logger.Err(ex);
                    mw.Write(new LoginResponse(LoginResponses.Exception));
                    return(await RetOut(mw.BaseStream));
                }

                pr = _ps.GetPresence(Request.Headers["osu-token"]);
                if (pr == null)
                {
                    Logger.Warn(
                        "Presence of token%#F94848%", Request.Headers["osu-token"], "%#FFFFFF%hasn't been found!"
                        );
                    Response.StatusCode = 403; // Presence is not known, force the client to send login info.
                    return(await RetOut(mw.BaseStream));
                }

                while (true)
                {
                    try
                    {
                        pr.LastRequest.Restart();
                        if (Request.ContentLength - body.Position < 7)
                        {
                            break; // Dont handle any invalid packets! (less then bytelength of 7)
                        }
                        var packetId = (PacketId)mr.ReadInt16();
                        mr.ReadBoolean();
                        var packetData = mr.ReadBytes();

                        await using var packetDataStream = new MemoryStream(packetData);
                        using var packetDataReader       = new MStreamReader(packetDataStream);

                        await _evmng.RunEvent(
                            EventType.BanchoPacket,
                            new BanchoPacketArgs { pr = pr, PacketId = packetId, Data = packetDataReader }
                            );
                    } catch (Exception ex)
                    {
                        Logger.Err(ex);
                        break;
                    }
                }

                try
                {
                    if (Response.Body.CanWrite)
                    {
                        pr.GetOutput()
                        .WriteTo(Response.Body);
                    }
                    return(await RetOut(mw.BaseStream));
                } catch
                {
                    // Ignored because it may throw an exception.
                }

                if (pr.Get <bool>("IS_LAST_REQUEST"))
                {
                    _ps.EndPresence(pr, true);
                }
            } catch (Exception ex)
            {
                Logger.Err(ex);
            }

            return(Ok());
        }
Beispiel #20
0
 private void Exception(MStreamWriter dataWriter)
 {
     dataWriter.Write(new LoginResponse(LoginResponses.Exception));
 }
Beispiel #21
0
 public void WriteToStream(MStreamWriter sw)
 {
     throw new NotImplementedException();
 }
Beispiel #22
0
 public void WriteToStream(MStreamWriter sw)
 {
     sw.Write(Protocol);
 }
Beispiel #23
0
 public void WriteToStream(MStreamWriter sw)
 {
     sw.Write(ChannelName);
 }
Beispiel #24
0
 private void LoginFailed(MStreamWriter dataWriter)
 {
     dataWriter.Write(new LoginResponse(LoginResponses.Failed));
 }