/// <summary>
        /// 6 Bytes
        /// </summary>
        internal void PrependHeader()
        {
            if (!HasId)
            {
                throw new NetException(string.Format("Cannot set packet header, it does not have an Id! Type: {0}", Type));
            }
            if (headerPrepended)
            {
                throw new NetException(string.Format("Header already prepended for this packet! Id: {0}, Type: {1}", Id, Type));
            }

            headerPrepended = true;

            byte[] packetData = data;
            data     = new byte[6 + packetData.Length];
            position = 0;

            Write(PACKET_PREFIX);           // 2
            Write((byte)Type);              // 1
            Write(Id);                      // 2
            ByteFlag flag = new ByteFlag();

            flag.Set(0, DeliveryMethod != NetDeliveryMethod.Unreliable);
            flag.Set(1, isChunked);
            flag.Set(2, isCompressed);
            flag.Set(3, isEncrypted);
            flag.Set(4, isPartial);
            Write(flag);                    // 1

            // Put the original data back
            WriteBytes(packetData);

            ReadOnly = true;
        }
 public override bool Equals(object obj)
 {
     if (obj.GetType() == GetType())
     {
         ByteFlag other = (ByteFlag)obj;
         return(internalByte == other.internalByte);
     }
     else
     {
         return(false);
     }
 }
Example #3
0
 /// <summary>
 /// Writes a ByteFlag to the buffer (as 1 byte).
 /// </summary>
 /// <param name="byteFlag">The ByteFlag.</param>
 public void Write(ByteFlag byteFlag)
 {
     Write(byteFlag.internalByte);
 }