示例#1
0
 public static void PushShort(short number, ref byte[] curArray)
 {
     byte[] intArray = BitConverter.GetBytes(number);
     MsgParse.ReverseBytes(ref intArray);
     byte[] combimeArray = new byte[curArray.Length + 2];
     Buffer.BlockCopy(curArray, 0, combimeArray, 0, curArray.Length);
     Buffer.BlockCopy(intArray, 0, combimeArray, curArray.Length, 2);
     curArray = combimeArray;
 }
示例#2
0
 public static short PopShort(ref byte[] data)
 {
     byte[] intArray = new byte[2];
     Buffer.BlockCopy(data, 0, intArray, 0, 2);
     MsgParse.ReverseBytes(ref intArray);
     byte[] newData = new byte[data.Length - 2];
     Buffer.BlockCopy(data, 2, newData, 0, data.Length - 2);
     data = newData;
     return(BitConverter.ToInt16(intArray, 0));
 }
示例#3
0
 public static int PopInt(ref byte[] data)
 {
     byte[] intArray = new byte[4];
     Buffer.BlockCopy(data, 0, intArray, 0, 4);
     MsgParse.ReverseBytes(ref intArray);
     byte[] newData = new byte[data.Length - 4];
     Buffer.BlockCopy(data, 4, newData, 0, data.Length - 4);
     data = newData;
     return(BitConverter.ToInt32(intArray, 0));
 }
示例#4
0
        public bool Serialize <T>(T packet, Stream destination) where T : GameFramework.Network.Packet
        {
            var c2SPacket = (object)packet as Q3Packet;
            var dataArray = c2SPacket.args;

            byte[] sendArray = new byte[2 + dataArray.Length];
            var    sizeArray = BitConverter.GetBytes((short)dataArray.Length);

            MsgParse.ReverseBytes(ref sizeArray);
            sendArray[0] = sizeArray[0];
            sendArray[1] = sizeArray[1];

            Buffer.BlockCopy(dataArray, 0, sendArray, 2, dataArray.Length);
            destination.Write(sendArray, 0, sendArray.Length);
            return(true);
        }
示例#5
0
        public IPacketHeader DeserializePacketHeader(Stream source, out object customErrorData)
        {
            Q3PacketHeader header = new Q3PacketHeader();

            try
            {
                byte[] buffer = new byte[2];
                source.Read(buffer, 0, 2);
                MsgParse.ReverseBytes(ref buffer);
                header.PacketLength = BitConverter.ToInt16(buffer, 0);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
            customErrorData = null;
            return(header);
        }