Esempio n. 1
0
 public QueuedPacket(string name, PacketHandler packetHandler, byte[] packetBuffer, int realLength)
 {
     Name = name;
     PacketHandler = packetHandler;
     PacketBuffer = packetBuffer;
     RealLength = realLength;
 }
Esempio n. 2
0
        /// <summary>
        /// Determines the correct packet size of the packet, and if there is a packetHandler that will handle this packet.
        /// </summary>
        /// <param name="packetHandlers">List of possible packet handlers for this packet. A packet handler with length of -1 must be first, if any.</param>
        /// <param name="realLength">The real length of the packet.</param>
        /// <returns>True if there is a packetHandler that will handle this packet.</returns>
        private bool GetPacketSizeAndHandler(List <PacketHandler> packetHandlers, byte[] buffer, int offset, out int realLength, out PacketHandler packetHandler)
        {
            realLength    = 0;
            packetHandler = null;

            if (packetHandlers.Count == 0)
            {
                return(false);
            }

            foreach (PacketHandler ph in packetHandlers)
            {
                if (ph.Length == -1)
                {
                    realLength    = buffer[offset + 2] | (buffer[offset + 1] << 8);
                    packetHandler = ph;
                    return(true);
                }

                realLength    = ph.Length;
                packetHandler = ph;
                return(true);
            }

            return(false);
        }