private static TerrPacket Parse(byte[] data, int expectedLength, ushort packetProvidedLength, LogManager log)
        {
            if (expectedLength != packetProvidedLength)
            {
                if (GetType(data) == TerrPacketType.SendSection)
                {
                    log.Critical("Dropped send section in Parse");
                    return null;
                }

                /*
                if we hit expectedLength > packetProvidedLength
                  that probably means there are more packets then one in the buffer,
                  go into a while loop like the one we see in netbuffer
                if its the opposite
                  probably means incomplete packet, not sure if this even happens
                */

                log.Critical($"Expected != provided: {expectedLength} != {packetProvidedLength} in Parse");
                return null;
            }

            if (packetProvidedLength == 0)
            {
                log.Critical($"Received 0 length data buffer in Parse.");
                return null;
            }

            //if the lenght of the data array isin't the same as the one we got from the array data then it's probably a malformed packet.

            TerrPacket retval = new TerrPacket
            {
                Length = packetProvidedLength,
                Type = GetType(data)
            };

            //extract payload
            byte[] payloadBuffer = new byte[packetProvidedLength - Index_Payload];

            Buffer.BlockCopy(data, Index_Payload, payloadBuffer, 0, payloadBuffer.Length);
            retval.Payload = payloadBuffer;

            return retval;
        }
 public PacketReceivedEventArgs(TerrPacket packet)
 {
     Packet = packet;
 }
 internal void OnPacketReceived(TerrPacket packet)
 {
     if (TerrPacket.IsValidType(packet.Type))
         PacketReceived(this, new PacketReceivedEventArgs(packet));
 }