Ejemplo n.º 1
0
 public void ReadFromStream(IPacketCodec content)
 {
     EntityId   = content.ReadVarInt();
     PlayerUuid = content.ReadUuid();
     Position   = content.ReadVector3d();
     Rotation   = content.ReadAngleRotation();
 }
Ejemplo n.º 2
0
        public void ReadFromStream(IPacketCodec rawCodec, PacketBoundTo boundTo, Func <int> compressThresholdCallback, Func <ProtocolState> stateCallback)
        {
            BoundTo = boundTo;
            State   = stateCallback();
            var length = rawCodec.ReadVarInt(); // Length of Packet ID + Data

            PacketLength = length;
            var threshold = compressThresholdCallback();
            int dataLength;

            using var recvStream = new MemoryStream(); //no extra bytes read
            rawCodec.CopyTo(recvStream, length);
            var recvCodec = rawCodec.Clone(recvStream);

            recvStream.Position = 0;
            if (threshold == 0 || (dataLength = recvCodec.ReadVarInt()) < threshold)
            {
                DataLength = length;
                recvCodec.CopyTo(BaseStream, length);
                BaseStream.Position = 0;
                PacketId            = Content.ReadVarInt();
                return;
            }
            DataLength = dataLength;
            using var compressedStream = new InflaterInputStream(recvStream)
                  {
                      IsStreamOwner = false
                  };
            rawCodec.Clone(compressedStream).CopyTo(BaseStream, dataLength);
            BaseStream.Position = 0;
            PacketId            = Content.ReadVarInt();
        }
Ejemplo n.º 3
0
 public void WriteToStream(IPacketCodec content)
 {
     content.WriteVarInt(EntityId);
     content.Write(PlayerUuid);
     content.Write(Position);
     content.WriteAngleRotation(Rotation);
 }
Ejemplo n.º 4
0
 public void WriteToStream(IPacketCodec content)
 {
     content.WriteVarInt(ProtocolVersion);
     content.Write(ServerAddress);
     content.Write(ServerPort);
     content.WriteVarIntEnum(NextState);
 }
Ejemplo n.º 5
0
 public void ReadFromStream(IPacketCodec content)
 {
     ProtocolVersion = content.ReadVarInt();
     ServerAddress   = content.ReadString();
     ServerPort      = content.ReadUInt16();
     NextState       = content.ReadVarIntEnum <ProtocolState>();
 }
Ejemplo n.º 6
0
        public void WriteToStream(IPacketCodec rawCodec, Func <int> compressThresholdCallback)
        {
            var threshold = compressThresholdCallback();

            if (threshold == 0 || DataLength < threshold)
            {
                PacketLength = (int)BaseStream.Length;
                rawCodec.WriteVarInt(DataLength);
                Content.CopyTo(rawCodec.BaseStream, DataLength);
                return;
            }
            var stream  = new MemoryStream();
            var content = Content.Clone(stream);

            content.WriteVarInt(DataLength);
            var compressedStream = new DeflaterOutputStream(stream);

            Content.CopyTo(compressedStream, DataLength);
            compressedStream.Flush();
            stream.Position = 0;
            PacketLength    = (int)stream.Length;
            rawCodec.WriteVarInt(PacketLength);
            content.CopyTo(rawCodec.BaseStream, PacketLength);
            compressedStream.Dispose();
            stream.Dispose();
        }
Ejemplo n.º 7
0
 public void ReadFromStream(IPacketCodec content)
 {
     EntityId = content.ReadVarInt();
     Position = content.ReadVector3d();
     Rotation = content.ReadAngleRotation();
     OnGround = content.ReadBoolean();
 }
Ejemplo n.º 8
0
 public DotNettyListenerAdapter(ListenerOptions options, IServiceProvider serviceProvider)
 {
     _options         = options;
     _serviceProvider = serviceProvider;
     InternalLoggerFactory.DefaultFactory = _serviceProvider.GetService <ILoggerFactory>();
     _packetCodec = _serviceProvider.GetRequiredService <IPacketCodec>();
 }
Ejemplo n.º 9
0
 public void WriteToStream(IPacketCodec content)
 {
     content.WriteVarInt(EntityId);
     content.Write((short)(Delta.X * 4096));
     content.Write((short)(Delta.Y * 4096));
     content.Write((short)(Delta.Z * 4096));
     content.Write(OnGround);
 }
Ejemplo n.º 10
0
 public void WriteToStream(IPacketCodec content)
 {
     content.Write(Locale);
     content.Write(ViewDistance);
     content.WriteVarIntEnum(ChatMode);
     content.Write(ChatColors);
     content.Write(DisplayedSkinParts);
     content.WriteVarIntEnum(MainHand);
     content.Write(DisableTextFiltering);
 }
Ejemplo n.º 11
0
 public void ReadFromStream(IPacketCodec content)
 {
     Locale               = content.ReadString();
     ViewDistance         = content.ReadSByte();
     ChatMode             = content.ReadVarIntEnum <ChatMode>();
     ChatColors           = content.ReadBoolean();
     DisplayedSkinParts   = content.ReadEnum <SkinPart>();
     MainHand             = content.ReadVarIntEnum <HandSide>();
     DisableTextFiltering = content.ReadBoolean();
 }
Ejemplo n.º 12
0
        public void ReadFromStream(IPacketCodec content)
        {
            EntityId = content.ReadVarInt();
            var delta = new Vector3d {
                X = content.ReadInt16(), Y = content.ReadInt16(), Z = content.ReadInt16()
            };

            delta   *= 0.000244140625 /* 1/4096 */;
            Delta    = delta;
            OnGround = content.ReadBoolean();
        }
Ejemplo n.º 13
0
 public DotNettyMessageDecoder(IPacketCodec packetCodec)
     : base(packetCodec.IsLittleEndian ? ByteOrder.LittleEndian : ByteOrder.BigEndian,
            ushort.MaxValue,
            packetCodec.LengthFieldOffset,
            packetCodec.LengthFieldLength,
            packetCodec.HeaderLenght - packetCodec.LengthFieldOffset - packetCodec.LengthFieldLength,
            0,
            true)
 {
     _packetCodec = packetCodec;
 }
Ejemplo n.º 14
0
        public WebSocketServerHandler(IServiceProvider serviceProvider, ListenerOptions netListenerOptions)
        {
            this._appSessionContainer = serviceProvider.GetRequiredService <AppSessionContainer <AppSession> >();
            this._serviceProvider     = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
            this._netListenerOptions  = netListenerOptions ?? throw new ArgumentNullException(nameof(netListenerOptions));

            this._commandContainer = serviceProvider.GetRequiredService <ICommandDescriptorContainer>();
            this._commandActivator = serviceProvider.GetRequiredService <ICommandActivator>();
            this._packetCodec      = serviceProvider.GetRequiredService <IPacketCodec>();
            ILoggerFactory loggerFactory = serviceProvider.GetRequiredService <ILoggerFactory>();

            _logger = loggerFactory.CreateLogger <WebSocketServerHandler>();
        }
Ejemplo n.º 15
0
        public void ReadFromStream(IPacketCodec content)
        {
            Position = content.ReadVector3d();
            Rotation = content.ReadRotation();
            var flags = content.ReadSByte();

            XKind           = (CoordKind)(flags & 0x01);
            YKind           = (CoordKind)(flags >> 1 & 0x01);
            ZKind           = (CoordKind)(flags >> 2 & 0x01);
            YRotKind        = (CoordKind)(flags >> 3 & 0x01);
            XRotKind        = (CoordKind)(flags >> 4 & 0x01);
            TeleportId      = content.ReadVarInt();
            DismountVehicle = content.ReadBoolean();
        }
Ejemplo n.º 16
0
 public void WriteToStream(IPacketCodec content)
 {
     content.WriteVarInt(EntityId);
     content.WriteVarIntEnum(Type);
     if (Type == InteractType.InteractAt)
     {
         content.Write(Target);
     }
     if (Type == InteractType.Interact || Type == InteractType.InteractAt)
     {
         content.WriteVarIntEnum(Hand);
     }
     content.Write(Sneaking);
 }
Ejemplo n.º 17
0
 public void ReadFromStream(IPacketCodec content)
 {
     EntityId = content.ReadVarInt();
     Type     = content.ReadVarIntEnum <InteractType>();
     if (Type == InteractType.InteractAt)
     {
         Target = content.ReadVector3();
     }
     if (Type == InteractType.Interact || Type == InteractType.InteractAt)
     {
         Hand = content.ReadVarIntEnum <Hand>();
     }
     Sneaking = content.ReadBoolean();
 }
Ejemplo n.º 18
0
 public void ReadFromStream(IPacketCodec content)
 {
     EntityId            = content.ReadInt32();
     IsHardcore          = content.ReadBoolean();
     Gamemode            = content.ReadEnum <Gamemode>();
     PreviousGamemode    = content.ReadEnum <Gamemode>();
     WorldCount          = content.ReadVarInt();
     WorldNames          = content.ReadIdentifiers(WorldCount);
     DimensionCodec      = content.ReadNbtTag <NbtCompound>();
     Dimension           = content.ReadNbtTag <NbtCompound>();
     WorldName           = content.ReadString();
     HashedSeed          = content.ReadInt64();
     MaxPlayers          = content.ReadVarInt();
     ViewDistance        = content.ReadVarInt();
     ReducedDebugInfo    = content.ReadBoolean();
     EnableRespawnScreen = content.ReadBoolean();
     IsDebug             = content.ReadBoolean();
     IsFlat = content.ReadBoolean();
 }
Ejemplo n.º 19
0
 public void WriteToStream(IPacketCodec content)
 {
     content.Write(EntityId);
     content.Write(IsHardcore);
     content.Write(Gamemode);
     content.Write(PreviousGamemode);
     content.WriteVarInt(WorldCount);
     content.Write(WorldNames);
     content.Write(DimensionCodec);
     content.Write(Dimension);
     content.Write(WorldName);
     content.Write(HashedSeed);
     content.WriteVarInt(MaxPlayers);
     content.Write(ViewDistance);
     content.Write(ReducedDebugInfo);
     content.Write(EnableRespawnScreen);
     content.Write(IsDebug);
     content.Write(IsFlat);
 }
Ejemplo n.º 20
0
        public void ReadFromStream(IPacketCodec content)
        {
#if FixEndOfStream
            try
            {
                JsonData = content.ReadString();
                Position = content.ReadEnum <ChatMessagePosition>();
                Sender   = content.ReadUuid();
            }
            catch
            {
                // ignore
            }
#else
            JsonData = content.ReadString();
            Position = content.ReadEnum <ChatMessagePosition>();
            Sender   = content.ReadUuid();
#endif
        }
Ejemplo n.º 21
0
        public void WriteToStream(IPacketCodec content)
        {
            byte flags = 0;

            void PushFlag(CoordKind kind)
            {
                flags |= (byte)(flags << 1 & (byte)kind);
            }

            PushFlag(XKind);
            PushFlag(YKind);
            PushFlag(ZKind);
            PushFlag(YRotKind);
            PushFlag(XRotKind);
            content.Write(Position);
            content.Write(Rotation);
            content.Write(flags);
            content.WriteVarInt(TeleportId);
            content.Write(DismountVehicle);
        }
Ejemplo n.º 22
0
 public void WriteToStream(IPacketCodec content)
 {
     content.Write(Message);
 }
Ejemplo n.º 23
0
 public void ReadFromStream(IPacketCodec content)
 {
     Message = content.ReadString();
 }
Ejemplo n.º 24
0
 public void WriteToStream(IPacketCodec content)
 {
     content.Write(KeepAliveId);
 }
Ejemplo n.º 25
0
 public void ReadFromStream(IPacketCodec content)
 {
     KeepAliveId = content.ReadInt64();
 }
Ejemplo n.º 26
0
 public void WriteToStream(IPacketCodec content)
 {
     content.WriteVarInt(Threshold);
 }
Ejemplo n.º 27
0
 public void ReadFromStream(IPacketCodec content)
 {
     Threshold = content.ReadVarInt();
 }
Ejemplo n.º 28
0
 public void WriteToStream(IPacketCodec content)
 {
     //empty
 }
Ejemplo n.º 29
0
 public void ReadFromStream(IPacketCodec content)
 {
     //empty
 }
Ejemplo n.º 30
0
 public void WriteToStream(IPacketCodec content)
 {
     content.WriteVarInt(EntityId);
     content.WriteAngleRotation(Rotation);
     content.Write(OnGround);
 }