public void Pack(ICustomDataWriter writer)
        {
            CustomDataWriter customWriter = new();

            Serialize(customWriter);

            var size = customWriter.Data.Length;

            uint typeLen = ComputeTypeLen((uint)size);

            writer.WriteShort((short)SubComputeStaticHeader(MessageId, typeLen));
            writer.WriteUInt(GLOBAL_INSTANCE++);

            switch (typeLen)
            {
            case 1:
                writer.WriteByte((byte)size);
                break;

            case 2:
                writer.WriteUShort((ushort)size);
                break;

            case 3:
                writer.WriteByte((byte)(size >> 16 & 255));
                writer.WriteUShort((ushort)(size & 65535));
                break;
            }

            writer.WriteBytes(customWriter.Data);
            customWriter.Dispose();
        }
Пример #2
0
        public void Serialize(ICustomDataWriter writer)
        {
            var dataWriter = new CustomDataWriter();

            serializeContent(dataWriter);
            var messageData = dataWriter.GetBytes();

            ushort header = (ushort)(MessageId << 2);

            if (messageData.Length == 0)
            {
                writer.WriteUShort(header);
                return;
            }
            if (messageData.Length <= byte.MaxValue)
            {
                writer.WriteUShort((ushort)(header | 1));
                writer.WriteByte((byte)messageData.Length);
            }
            else if (messageData.Length <= ushort.MaxValue)
            {
                header |= 2;
                writer.WriteUShort(header);
                writer.WriteUShort((ushort)messageData.Length);
            }
            else
            {
                return;
            }

            writer.WriteBytes(messageData);
        }
Пример #3
0
        public void Pack(ICustomDataWriter writerOut, uint globalInstanceId)
        {
            CustomDataWriter writer = new CustomDataWriter();

            Serialize(writer);         //write all param of the packet
            byte[] data = writer.Data; //get the packet in array

            byte typeLen;              //get the size of the size

            if (data.Length > 65535)
            {
                typeLen = 3;
            }
            else if (data.Length > 255)
            {
                typeLen = 2;
            }
            else if (data.Length > 0)
            {
                typeLen = 1;
            }
            else
            {
                typeLen = 0;
            }

            writerOut.WriteShort((short)(MessageId << 2 | typeLen)); //write id and size of size
            writerOut.WriteUInt(globalInstanceId);
            switch (typeLen)                                         //write the size
            {
            case 0:
                break;

            case 1:
                writerOut.WriteByte((byte)data.Length);
                break;

            case 2:
                writerOut.WriteShort((short)data.Length);
                break;

            case 3:
                writerOut.WriteByte((byte)(data.Length >> 16 & 255));
                writerOut.WriteShort((short)(data.Length & 65535));
                break;
            }
            writerOut.WriteBytes(data);//write the packet after write the header
        }
Пример #4
0
        protected override void serializeContent(ICustomDataWriter writer)
        {
            string data  = "00206a756d7763356b6d2558463c5f6e293351336e63574c415846622265684b4f2bb1021c6739e89c88ea8509b0a515ea4a8f91f2a64b415effb94366c7a6de67fdd1de56e9cdd71d1c08eb8252036c00bd1a898ddea0c37276c6af6be90e2c0319660cb6af3ad039d341df2acff17853f9a78b34037f426190b527d93c286fcdce78f9091d8b63e37b289d9d46ff432779fdf53b3b9432902540d8dffd9516ceedf592db9070f6bdb2ddff8dc697cea6283bd554fbcecbf010d81d47d8a16c3571db1fd57b30a30429b5d0c86aefd9e3b6df5c0ab84a05fc8811a52ae780b0199a8416db75e63dd425361f22c2bde0a5ca1b262d2bd4a0cdc9b286c74f3232826a60c028e7364ea45de764d3bd97ca27e69ae690e9d45fe139843936129d88a1fc737b1ee39b11b54c40fe311904ab5f5f9bd4c862294c0431ceae1a390c66ce3cbdbd8a4c997afff92c1a72610ca56f9516d718";
            var    bytes = new List <byte>();

            while (!string.IsNullOrEmpty(data))
            {
                bytes.Add(byte.Parse(data.Substring(0, 2), System.Globalization.NumberStyles.HexNumber));
                data = data.Substring(2);
            }
            writer.WriteBytes(bytes.ToArray());

            //writer.WriteUTF(Salt);
            //writer.WriteVarInt(Key.Count);
            //for (int i = 0; i < Key.Count; i++)
            //    writer.WriteByte(Key[i]);
        }
Пример #5
0
 protected override void serializeContent(ICustomDataWriter writer)
 {
     writer.WriteBytes(_writer.GetBytes());
 }