コード例 #1
0
        public RakNetPacket(byte[] data)
        {
            Type = PacketType.RakNetPacket;
            var decoder = new RakDecoder(data);

            Flags = decoder.Byte();
            if (IsACKorNAK)
            {
                Enclosing    = new List <RakPacket>();
                Count        = decoder.Short();
                MinEqualsMax = decoder.Byte() != 0;
                if (MinEqualsMax)
                {
                    PacketMin = decoder.Triad();
                    PacketMax = PacketMin;
                    return;
                }
                PacketMax = decoder.Triad();
            }
            else
            {
                SequenceNumber = decoder.Triad();
                Enclosing      = new List <RakPacket>();
                while (!decoder.AtEnd)
                {
                    Enclosing.Add(RakPacket.Parse(ref decoder));
                }
            }
        }
コード例 #2
0
        public void SimplePacketTest()
        {
            Decoder = new RakDecoder(new byte[] { 0x01, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x11, 0x22, 0x00, 0xff, 0xff, 0x00, 0xfe, 0xfe, 0xfe, 0xfe, 0xfd, 0xfd, 0xfd, 0xfd, 0x12, 0x34, 0x56, 0x78 });

            Assert.AreEqual(Decoder.Byte(), 0x01);
            Assert.AreEqual(Decoder.Timestamp().ToString(), new RakTimestamp(0xAABBCCDDEEFF1122).ToString());
            Assert.DoesNotThrow(Decoder.Magic);
            Assert.AreEqual(Decoder.AtEnd, true);
            Assert.Throws <IndexOutOfRangeException>(() => { Decoder.Byte(); }, "Should be out of bounds.");
        }
コード例 #3
0
 public RemoveBlockPacket(ref RakDecoder decoder)
 {
     EID = decoder.Int();
     X   = decoder.Int();
     Z   = decoder.Int();
     Y   = decoder.Byte();
 }
コード例 #4
0
        public UnconnectedPingPacket(byte[] data)
        {
            RakDecoder decoder = new RakDecoder(data);

            Type           = (PacketType)decoder.Byte();
            TimeSinceStart = decoder.Timestamp();
            decoder.Magic();
        }
コード例 #5
0
        public OpenConnectionRequestPacket(byte[] data)
        {
            RakDecoder decoder = new RakDecoder(data);

            Type = (PacketType)decoder.Byte();
            decoder.Magic();
            switch (Type)
            {
            case PacketType.OpenConnectionRequest1:
                ProtocolVersion = decoder.Byte();
                break;

            case PacketType.OpenConnectionRequest2:
                Address  = decoder.Address();
                MtuSize  = decoder.Short();
                ClientID = decoder.Long().Unsigned();
                break;

            default: Debug.Assert(false, "Unreachable."); break;
            }

            // Null padding
            decoder.Raw(data.Length - decoder.Pos);
        }
コード例 #6
0
        public UseItemPacket(ref RakDecoder decoder)
        {
            X = decoder.Int();
            Y = decoder.Int();
            Z = decoder.Int();

            Face  = decoder.Int();
            Block = decoder.Short();
            Meta  = decoder.Byte();
            ID    = decoder.Int();

            Fx = decoder.Float();
            Fy = decoder.Float();
            Fz = decoder.Float();

            Px = decoder.Float();
            Py = decoder.Float();
            Pz = decoder.Float();
        }
コード例 #7
0
 public AnimatePacket(ref RakDecoder decoder)
 {
     Action = decoder.Byte();
     ID     = decoder.Int();
 }
コード例 #8
0
 public InteractPacket(ref RakDecoder decoder)
 {
     Action = decoder.Byte();
     EID    = decoder.Int();
     Target = decoder.Int();
 }
コード例 #9
0
 public ConnectionRequestPacket(ref RakDecoder decoder)
 {
     ClientGuid     = decoder.Long().Unsigned();
     TimeSinceStart = decoder.Timestamp();
     UseEncryption  = decoder.Byte();
 }
コード例 #10
0
 public ReadyPacket(ref RakDecoder decoder)
 {
     Status = decoder.Byte();
 }
コード例 #11
0
        // RakPacket should always be parsed from RakNetPacket
        // which provides the RakDecoder as there can be multiple.
        public static RakPacket Parse(ref RakDecoder decoder)
        {
            var  flags    = decoder.Byte();
            var  length   = decoder.Short();
            var  relnum   = RakTriad.FromInt(0, false);
            var  orderidx = RakTriad.FromInt(0, false);
            byte orderch  = 0;

            if ((flags & IS_RELIABLE) != 0)   // reliable
            {
                relnum = decoder.Triad();
            }
            if ((flags & IS_ORDERED) != 0)   // ordered
            {
                orderidx = decoder.Triad();
                orderch  = decoder.Byte();
            }
            var msgid  = (RakPacketType)decoder.Byte();
            var packet = new RakPacket();

            switch (msgid)
            {
            case RakPacketType.ConnectedPing: packet = new ConnectedPingPacket(ref decoder); break;

            case RakPacketType.ConnectionRequest: packet = new ConnectionRequestPacket(ref decoder); break;

            case RakPacketType.NewIncomingConnection: packet = new NewIncomingConnectionPacket(ref decoder); break;

            case RakPacketType.PlayerDisconnect: break;

            case RakPacketType.LoginRequest: packet = new LoginRequestPacket(ref decoder); break;

            case RakPacketType.Ready: packet = new ReadyPacket(ref decoder); break;

            case RakPacketType.RequestChunk: packet = new RequestChunkPacket(ref decoder); break;

            case RakPacketType.MovePlayer: packet = new MovePlayerPacket(ref decoder); break;

            case RakPacketType.SetHealth: packet = new SetHealthPacket(ref decoder); break;

            case RakPacketType.Animate: packet = new AnimatePacket(ref decoder); break;

            case RakPacketType.RemoveBlock: packet = new RemoveBlockPacket(ref decoder); break;

            case RakPacketType.Message: packet = new MessagePacket(ref decoder); break;

            case RakPacketType.UseItem: packet = new UseItemPacket(ref decoder); break;

            case RakPacketType.Interact: packet = new InteractPacket(ref decoder); break;

            default:
                Console.WriteLine($"[!!] Unhandled RakPacket Type {msgid}!");
                break;
            }
            packet.MessageFlags    = flags;
            packet.Length          = length;
            packet.ReliableNum     = relnum;
            packet.OrderingIndex   = orderidx;
            packet.OrderingChannel = orderch;
            packet.MessageID       = msgid;
            return(packet);
        }