Esempio n. 1
0
        public void ClearAndReset()
        {
            var stream = new BinaryStream(new byte[]
            {
                0x11, 0x01, 0xff
            });

            stream.Clear();
            Assert.Throws <IndexOutOfRangeException>(() => { stream.ReadByte(); });
        }
Esempio n. 2
0
        public void Test()
        {
            var bs = new BinaryStream();

            new UnconnectedPong
            {
                Timestamp  = 0x0123456789ff,
                PongId     = 1,
                Magic      = Constants.Magic,
                ServerInfo = "MCBEProtocol Test Server"
            }.Encode(bs);
            Assert.Equal(bs.GetBuffer(), new byte[]
            {
                // Timestamp
                0xff, 0x89, 0x67, 0x45, 0x23, 0x01, 0x00, 0x00,
                // PongId
                0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                // Magic
                0x00, 0xff, 0xff, 0x00, 0xfe, 0xfe, 0xfe, 0xfe, 0xfd, 0xfd, 0xfd, 0xfd, 0x12, 0x34, 0x56, 0x78,
                // ServerName Length
                0x18, 0x00,
                // ServerName
                0x4d, 0x43, 0x42, 0x45, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72
            });
            bs.Clear();

            new UnconnectedPing
            {
                Timestamp = 0x0123456789ff,
                Magic     = Constants.Magic,
                ClientId  = 0xfedcba98765432
            }.Encode(bs);
            Assert.Equal(bs.GetBuffer(), new byte[]
            {
                // Timestamp
                0xff, 0x89, 0x67, 0x45, 0x23, 0x01, 0x00, 0x00,
                // Magic
                0x00, 0xff, 0xff, 0x00, 0xfe, 0xfe, 0xfe, 0xfe, 0xfd, 0xfd, 0xfd, 0xfd, 0x12, 0x34, 0x56, 0x78,
                // ClientId
                0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, 0x00
            });
            bs.Clear();
        }
Esempio n. 3
0
        public void Test()
        {
            var bs = new BinaryStream();

            bs.WriteAddress(new IPEndPoint(IPAddress.Parse("192.168.1.10"), 19132));
            Assert.Equal(bs.GetBuffer(), new byte[7] {
                0x04, 0x3f, 0x57, 0xfe, 0xf5, 0xbc, 0x4a
            });
            bs.Clear();

            bs.WriteAddress(new IPEndPoint(IPAddress.Parse("2404:6800:4004:0810:0000:0000:0000:2004"), 19132));
            Assert.Equal(bs.GetBuffer(), new byte[21]
            {
                0x06,
                0x17, 0x00,
                0xbc, 0x4a,
                0x24, 0x04, 0x68, 0x00, 0x40, 0x04, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x04
            });
        }