示例#1
0
 public void ReadFromStream(MStreamReader sr)
 {
     Time         = sr.ReadInt32();
     Id           = sr.ReadByte();
     Count300     = sr.ReadUInt16();
     Count100     = sr.ReadUInt16();
     Count50      = sr.ReadUInt16();
     CountGeki    = sr.ReadUInt16();
     CountKatu    = sr.ReadUInt16();
     CountMiss    = sr.ReadUInt16();
     TotalScore   = sr.ReadInt32();
     MaxCombo     = sr.ReadUInt16();
     CurrentCombo = sr.ReadUInt16();
     Perfect      = sr.ReadBoolean();
     CurrentHp    = sr.ReadByte();
     TagByte      = sr.ReadByte();
     ScoreV2      = sr.ReadBoolean();
     ComboPortion = ScoreV2 ? sr.ReadDouble() : 0;
     BonusPortion = ScoreV2 ? sr.ReadDouble() : 0;
 }
示例#2
0
        public void ReadFromStream(MStreamReader sr)
        {
            SetId = sr.ReadInt32();

            var count = sr.ReadInt32();

            ChildrenBeatmaps = new List <ChildrenBeatmap>();
            for (var i = 0; i < count; i++)
            {
                ChildrenBeatmaps.Add(sr.ReadData <ChildrenBeatmap>());
            }

            RankedStatus = (BeatmapSetOnlineStatus)sr.ReadSByte();

            if (DateTime.TryParse(sr.ReadString(), out var res))
            {
                ApprovedDate = res;
            }

            if (DateTime.TryParse(sr.ReadString(), out res))
            {
                LastUpdate = res;
            }

            if (DateTime.TryParse(sr.ReadString(), out res))
            {
                LastChecked = res;
            }

            Artist     = sr.ReadString();
            Title      = sr.ReadString();
            Creator    = sr.ReadString();
            Source     = sr.ReadString();
            Tags       = sr.ReadString();
            HasVideo   = sr.ReadBoolean();
            Genre      = (Genre)sr.ReadSByte();
            Language   = (Language)sr.ReadSByte();
            Favourites = sr.ReadInt64();
            Disabled   = sr.ReadBoolean();
        }
示例#3
0
        public void ReadFromStream(MStreamReader sr)
        {
            MatchId     = sr.ReadInt16();
            InProgress  = sr.ReadBoolean();
            MatchType   = (MatchType)sr.ReadByte();
            ActiveMods  = (Mod)sr.ReadUInt32();
            Name        = sr.ReadString();
            Password    = sr.ReadString();
            BeatmapName = sr.ReadString();
            BeatmapId   = sr.ReadInt32();
            BeatmapMd5  = sr.ReadString();

            for (var i = 0; i < MaxPlayers; i++)
            {
                Slots[i].Status = (MultiSlotStatus)sr.ReadByte();
            }

            for (var i = 0; i < MaxPlayers; i++)
            {
                Slots[i].Team = (MultiSlotTeam)sr.ReadByte();
            }

            for (var i = 0; i < MaxPlayers; i++)
            {
                Slots[i].UserId = (Slots[i].Status & (MultiSlotStatus)124) > 0 ? sr.ReadInt32() : -1;
            }

            HostId       = sr.ReadInt32();
            PlayMode     = (PlayMode)sr.ReadByte();
            ScoringType  = (ScoringType)sr.ReadByte();
            TeamType     = (TeamType)sr.ReadByte();
            SpecialModes = (MatchSpecialModes)sr.ReadByte();

            if (SpecialModes == MatchSpecialModes.Freemods)
            {
                for (var i = 0; i < MaxPlayers; i++)
                {
                    Slots[i].Mods = (Mod)sr.ReadUInt32();
                }
            }

            Seed = sr.ReadInt32();
        }
示例#4
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());
        }
示例#5
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());
        }