Пример #1
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public OutgoingPacket(object client, byte[] buffer, int category, int dataSize, IPEndPoint destination,
                              bool fromBufferPool, Packets.PacketType type)
        {
            SequenceNumber = 0;
            ResendCount    = 0;
            TickCount      = 0;

            Client    = client;
            Category  = category;
            _fromPool = fromBufferPool;
            Type      = type;
            DataSize  = dataSize;
            Buffer    = new UDPPacketBuffer(buffer, dataSize, destination, category, fromBufferPool);
        }
Пример #2
0
        public static byte[] SerializePacket <T>(Packets.PacketType type, T packet)
            where T : struct
        {
            Packets.TypeHeader header;
            header.type = type;
            byte[] headerPacket = Packets.Serialize(header);
            byte[] bodyPacket   = Packets.Serialize(packet);

            MemoryStream stream = new MemoryStream();

            stream.Write(headerPacket, 0, headerPacket.Length);
            stream.Write(bodyPacket, 0, bodyPacket.Length);
            return(stream.ToArray());
        }
Пример #3
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="client">Reference to the client this packet is destined for</param>
        /// <param name="buffer">Serialized packet data. If the flags or sequence number
        /// need to be updated, they will be injected directly into this binary buffer</param>
        /// <param name="category">Throttling category for this packet</param>
        public OutgoingPacket(object client, byte[] buffer, int category, int dataSize, IPEndPoint destination,
                              bool fromBufferPool, Packets.PacketType type)
        {
            SequenceNumber = 0;
            ResendCount    = 0;
            TickCount      = 0;

            Client      = client;
            Buffer      = buffer;
            Category    = category;
            DataSize    = dataSize;
            Destination = destination;

            byte flags = buffer[0];

            IsReliable = (flags & Helpers.MSG_RELIABLE) != 0;

            BufferFromPool = fromBufferPool;
            Type           = type;
        }
Пример #4
0
 public void WritePacketType(Packets.PacketType packetType)
 {
     WriteByte((byte)packetType);
 }