/// <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(LLUDPClient client, UDPPacketBuffer buffer, ThrottleOutPacketType category, UnackedPacketMethod method)
 {
     Client        = client;
     Buffer        = buffer;
     Category      = category;
     UnackedMethod = method;
 }
Ejemplo n.º 2
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(LLUDPClient client, UDPPacketBuffer buffer, ThrottleOutPacketType category, UnackedPacketMethod method)
 {
     Client = client;
     Buffer = buffer;
     Category = category;
     UnackedMethod = method;
 }
        /// <summary>
        ///     This is the starting point for sending a simulator packet out to the client
        /// </summary>
        /// <param name="pack">Packet to send</param>
        /// <param name="throttlePacketType">Throttling category for the packet</param>
        /// <param name="doAutomaticSplitting">
        ///     True to automatically split oversized
        ///     packets (the default), or false to disable splitting if the calling code
        ///     handles splitting manually
        /// </param>
        /// <param name="resendMethod">Method that will be called if the packet needs resent</param>
        /// <param name="finishedMethod">Method that will be called when the packet is sent</param>
        void OutPacket(Packet pack, ThrottleOutPacketType throttlePacketType, bool doAutomaticSplitting,
                       UnackedPacketMethod resendMethod, UnackedPacketMethod finishedMethod)
        {
            if (m_debugPacketLevel > 0 || m_debugPackets.Contains(pack.Type.ToString()))
            {
                bool outputPacket = true;

                if (m_debugPacketLevel <= 255 &&
                    (pack.Type == PacketType.SimStats || pack.Type == PacketType.SimulatorViewerTimeMessage))
                {
                    outputPacket = false;
                }

                if (m_debugPacketLevel <= 200 &&
                    (pack.Type == PacketType.ImagePacket ||
                     pack.Type == PacketType.ImageData ||
                     pack.Type == PacketType.LayerData ||
                     pack.Type == PacketType.CoarseLocationUpdate))
                {
                    outputPacket = false;
                }

                if (m_debugPacketLevel <= 100 &&
                    (pack.Type == PacketType.AvatarAnimation ||
                     pack.Type == PacketType.ViewerEffect))
                {
                    outputPacket = false;
                }

                if (m_debugPacketLevel <= 50 &&
                    (pack.Type == PacketType.ImprovedTerseObjectUpdate ||
                     pack.Type == PacketType.ObjectUpdate))
                {
                    outputPacket = false;
                }

                if (m_debugPacketLevel <= 25 &&
                    pack.Type == PacketType.ObjectPropertiesFamily)
                {
                    outputPacket = false;
                }

                if (m_debugPackets.Contains(pack.Type.ToString()))
                {
                    outputPacket = true;
                }

                if (outputPacket && !m_debugRemovePackets.Contains(pack.Type.ToString()))
                {
                    MainConsole.Instance.DebugFormat("[CLIENT ({1})]: Packet OUT {0}", pack.Type, Name);
                }
            }

            m_udpServer.SendPacket(m_udpClient, pack, throttlePacketType, doAutomaticSplitting, resendMethod,
                                   finishedMethod);
        }
Ejemplo n.º 4
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>
 /// <param name="resendMethod">The delegate to be called if this packet is determined to be unacknowledged</param>
 /// <param name="finishedMethod">The delegate to be called when this packet is sent</param>
 public OutgoingPacket(LLUDPClient client, UDPPacketBuffer buffer,
     ThrottleOutPacketType category, UnackedPacketMethod resendMethod,
     UnackedPacketMethod finishedMethod, Packet packet)
 {
     Client = client;
     Buffer = buffer;
     Category = category;
     UnackedMethod = resendMethod;
     FinishedMethod = finishedMethod;
     Packet = packet;
 }
Ejemplo n.º 5
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>
 /// <param name="resendMethod">The delegate to be called if this packet is determined to be unacknowledged</param>
 /// <param name="finishedMethod">The delegate to be called when this packet is sent</param>
 /// <param name="packet"></param>
 public OutgoingPacket(LLUDPClient client, UDPPacketBuffer buffer,
                       ThrottleOutPacketType category, UnackedPacketMethod resendMethod,
                       UnackedPacketMethod finishedMethod, Packet packet)
 {
     Client         = client;
     Buffer         = buffer;
     Category       = category;
     UnackedMethod  = resendMethod;
     FinishedMethod = finishedMethod;
     Packet         = packet;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Start the process of sending a packet to the client.
        /// </summary>
        /// <param name="udpClient"></param>
        /// <param name="data"></param>
        /// <param name="type"></param>
        /// <param name="category"></param>
        /// <param name="method">
        /// The method to call if the packet is not acked by the client.  If null, then a standard
        /// resend of the packet is done.
        /// </param>
        public void SendPacketData(
            LLUDPClient udpClient, byte[] data, PacketType type, ThrottleOutPacketType category, UnackedPacketMethod method)
        {
            int dataLength = data.Length;
            bool doZerocode = (data[0] & Helpers.MSG_ZEROCODED) != 0;
            bool doCopy = true;

            // Frequency analysis of outgoing packet sizes shows a large clump of packets at each end of the spectrum.
            // The vast majority of packets are less than 200 bytes, although due to asset transfers and packet splitting
            // there are a decent number of packets in the 1000-1140 byte range. We allocate one of two sizes of data here
            // to accomodate for both common scenarios and provide ample room for ACK appending in both
            int bufferSize = (dataLength > 180) ? LLUDPServer.MTU : 200;

            UDPPacketBuffer buffer = new UDPPacketBuffer(udpClient.RemoteEndPoint, bufferSize);

            // Zerocode if needed
            if (doZerocode)
            {
                try
                {
                    dataLength = Helpers.ZeroEncode(data, dataLength, buffer.Data);
                    doCopy = false;
                }
                catch (IndexOutOfRangeException)
                {
                    // The packet grew larger than the bufferSize while zerocoding.
                    // Remove the MSG_ZEROCODED flag and send the unencoded data
                    // instead
                    m_log.Debug("[LLUDPSERVER]: Packet exceeded buffer size during zerocoding for " + type + ". DataLength=" + dataLength +
                        " and BufferLength=" + buffer.Data.Length + ". Removing MSG_ZEROCODED flag");
                    data[0] = (byte)(data[0] & ~Helpers.MSG_ZEROCODED);
                }
            }

            // If the packet data wasn't already copied during zerocoding, copy it now
            if (doCopy)
            {
                if (dataLength <= buffer.Data.Length)
                {
                    Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
                }
                else
                {
                    bufferSize = dataLength;
                    buffer = new UDPPacketBuffer(udpClient.RemoteEndPoint, bufferSize);

                    // m_log.Error("[LLUDPSERVER]: Packet exceeded buffer size! This could be an indication of packet assembly not obeying the MTU. Type=" +
                    //     type + ", DataLength=" + dataLength + ", BufferLength=" + buffer.Data.Length + ". Dropping packet");
                    Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
                }
            }

            buffer.DataLength = dataLength;

            #region Queue or Send

            OutgoingPacket outgoingPacket = new OutgoingPacket(udpClient, buffer, category, null);
            // If we were not provided a method for handling unacked, use the UDPServer default method
            outgoingPacket.UnackedMethod = ((method == null) ? delegate(OutgoingPacket oPacket) { ResendUnacked(oPacket); } : method);

            // If a Linden Lab 1.23.5 client receives an update packet after a kill packet for an object, it will 
            // continue to display the deleted object until relog.  Therefore, we need to always queue a kill object
            // packet so that it isn't sent before a queued update packet.
            bool requestQueue = type == PacketType.KillObject;
            if (!outgoingPacket.Client.EnqueueOutgoing(outgoingPacket, requestQueue))
                SendPacketFinal(outgoingPacket);

            #endregion Queue or Send
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Start the process of sending a packet to the client.
        /// </summary>
        /// <param name="udpClient"></param>
        /// <param name="packet"></param>
        /// <param name="category"></param>
        /// <param name="allowSplitting"></param>
        /// <param name="method">
        /// The method to call if the packet is not acked by the client.  If null, then a standard
        /// resend of the packet is done.
        /// </param>
        public virtual void SendPacket(
            LLUDPClient udpClient, Packet packet, ThrottleOutPacketType category, bool allowSplitting, UnackedPacketMethod method)
        {
            // CoarseLocationUpdate packets cannot be split in an automated way
            if (packet.Type == PacketType.CoarseLocationUpdate && allowSplitting)
                allowSplitting = false;

            if (allowSplitting && packet.HasVariableBlocks)
            {
                byte[][] datas = packet.ToBytesMultiple();
                int packetCount = datas.Length;

                if (packetCount < 1)
                    m_log.Error("[LLUDPSERVER]: Failed to split " + packet.Type + " with estimated length " + packet.Length);

                for (int i = 0; i < packetCount; i++)
                {
                    byte[] data = datas[i];
                    SendPacketData(udpClient, data, packet.Type, category, method);
                }
            }
            else
            {
                byte[] data = packet.ToBytes();
                SendPacketData(udpClient, data, packet.Type, category, method);
            }

            PacketPool.Instance.ReturnPacket(packet);

            m_dataPresentEvent.Set();
        }
Ejemplo n.º 8
0
        public void SendPacketData(LLUDPClient udpClient, byte[] data, Packet packet, ThrottleOutPacketType category, UnackedPacketMethod resendMethod, UnackedPacketMethod finishedMethod)
        {
            int dataLength = data.Length;
            bool doZerocode = (data[0] & Helpers.MSG_ZEROCODED) != 0;
            bool doCopy = true;

            // Frequency analysis of outgoing packet sizes shows a large clump of packets at each end of the spectrum.
            // The vast majority of packets are less than 200 bytes, although due to asset transfers and packet splitting
            // there are a decent number of packets in the 1000-1140 byte range. We allocate one of two sizes of data here
            // to accomodate for both common scenarios and provide ample room for ACK appending in both
            int bufferSize = dataLength * 2;

            UDPPacketBuffer buffer = new UDPPacketBuffer(udpClient.RemoteEndPoint, bufferSize);

            // Zerocode if needed
            if (doZerocode)
            {
                try
                {
                    dataLength = Helpers.ZeroEncode(data, dataLength, buffer.Data);
                    doCopy = false;
                }
                catch (IndexOutOfRangeException)
                {
                    // The packet grew larger than the bufferSize while zerocoding.
                    // Remove the MSG_ZEROCODED flag and send the unencoded data
                    // instead
                    m_log.Info("[LLUDPSERVER]: Packet exceeded buffer size during zerocoding for " + packet.Type + ". DataLength=" + dataLength +
                        " and BufferLength=" + buffer.Data.Length + ". Removing MSG_ZEROCODED flag");
                    data[0] = (byte)(data[0] & ~Helpers.MSG_ZEROCODED);
                }
            }

            // If the packet data wasn't already copied during zerocoding, copy it now
            if (doCopy)
            {
                if (dataLength <= buffer.Data.Length)
                {
                    Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
                }
                else
                {
                    bufferSize = dataLength;
                    buffer = new UDPPacketBuffer(udpClient.RemoteEndPoint, bufferSize);

                    // m_log.Error("[LLUDPSERVER]: Packet exceeded buffer size! This could be an indication of packet assembly not obeying the MTU. Type=" +
                    //     type + ", DataLength=" + dataLength + ", BufferLength=" + buffer.Data.Length + ". Dropping packet");
                    Buffer.BlockCopy(data, 0, buffer.Data, 0, dataLength);
                }
            }

            buffer.DataLength = dataLength;

            #region Queue or Send

            OutgoingPacket outgoingPacket = new OutgoingPacket(udpClient, buffer, category, resendMethod, finishedMethod, packet);

            if (!outgoingPacket.Client.EnqueueOutgoing(outgoingPacket))
                SendPacketFinal(outgoingPacket);

            #endregion Queue or Send
        }
Ejemplo n.º 9
0
        public void BroadcastPacket(Packet packet, ThrottleOutPacketType category, bool sendToPausedAgents, bool allowSplitting, UnackedPacketMethod resendMethod, UnackedPacketMethod finishedMethod)
        {
            // CoarseLocationUpdate and AvatarGroupsReply packets cannot be split in an automated way
            if ((packet.Type == PacketType.CoarseLocationUpdate || packet.Type == PacketType.AvatarGroupsReply) && allowSplitting)
                allowSplitting = false;

            if (allowSplitting && packet.HasVariableBlocks)
            {
                byte[][] datas = packet.ToBytesMultiple();
                int packetCount = datas.Length;

                if (packetCount < 1)
                    m_log.Error("[LLUDPSERVER]: Failed to split " + packet.Type + " with estimated length " + packet.Length);

                for (int i = 0; i < packetCount; i++)
                {
                    byte[] data = datas[i];
                    m_scene.ForEachClient(
                        delegate(IClientAPI client)
                        {
                            if (client is LLClientView)
                                SendPacketData(((LLClientView)client).UDPClient, data, packet, category, resendMethod, finishedMethod);
                        }
                    );
                }
            }
            else
            {
                byte[] data = packet.ToBytes();
                m_scene.ForEachClient(
                    delegate(IClientAPI client)
                    {
                        if (client is LLClientView)
                            SendPacketData(((LLClientView)client).UDPClient, data, packet, category, resendMethod, finishedMethod);
                    }
                );
            }
        }
Ejemplo n.º 10
0
        public void SendPacket(LLUDPClient udpClient, Packet packet, ThrottleOutPacketType category, bool allowSplitting,
            UnackedPacketMethod resendMethod, UnackedPacketMethod finishedMethod)
        {
            // CoarseLocationUpdate packets cannot be split in an automated way
            if (packet.Type == PacketType.CoarseLocationUpdate && allowSplitting)
                allowSplitting = false;

            if (allowSplitting && packet.HasVariableBlocks)
            {
                byte[][] datas = packet.ToBytesMultiple();
                int packetCount = datas.Length;

                if (packetCount < 1)
                    MainConsole.Instance.Error("[LLUDPSERVER]: Failed to split " + packet.Type +
                                               " with estimated length " +
                                               packet.Length);

                for (int i = 0; i < packetCount; i++)
                {
                    byte[] data = datas[i];
                    SendPacketData(udpClient, data, packet, category, resendMethod, finishedMethod);
                    data = null;
                }
                datas = null;
            }
            else
            {
                byte[] data = packet.ToBytes();
                SendPacketData(udpClient, data, packet, category, resendMethod, finishedMethod);
                data = null;
            }
            packet = null;
        }
 /// <summary>
 ///     This is the starting point for sending a simulator packet out to the client
 /// </summary>
 /// <param name="packet">Packet to send</param>
 /// <param name="throttlePacketType">Throttling category for the packet</param>
 /// <param name="doAutomaticSplitting">
 ///     True to automatically split oversized
 ///     packets (the default), or false to disable splitting if the calling code
 ///     handles splitting manually
 /// </param>
 /// <param name="resendMethod">Method that will be called if the packet needs resent</param>
 void OutPacket(Packet packet, ThrottleOutPacketType throttlePacketType, bool doAutomaticSplitting,
                UnackedPacketMethod resendMethod)
 {
     OutPacket(packet, throttlePacketType, doAutomaticSplitting, resendMethod, null);
 }
Ejemplo n.º 12
0
 public override void SendPacket(
     LLUDPClient udpClient, Packet packet, ThrottleOutPacketType category, bool allowSplitting, UnackedPacketMethod method)
 {
     PacketsSent.Add(packet);
 }