Пример #1
0
        public void Send(IConnection connection, Network.ByteOutStream header, Queue <Network.IStreamWriter> data, bool reliable)
        {
            if (data.Count == 0)
            {
                return;
            }

            int mtu         = MTU;
            int headerSize  = header.Size;
            int messageSize = mtu - headerSize;

            IStreamWriter     writer        = null;
            NetConnection     netConnection = ((LidgrenConnection)connection).Connection;
            ByteOutStream     stream        = new ByteOutStream(messageSize);
            NetDeliveryMethod delivery      = reliable ? NetDeliveryMethod.ReliableOrdered : NetDeliveryMethod.UnreliableSequenced;

            while (data.Count > 0)
            {
                writer = data.Dequeue();

                if (writer == null)
                {
                    log.Warn("A null value was queued on the outgoing message queue for {0}", connection);
                    continue;
                }

                if (stream.Size + writer.Size > messageSize && stream.Size > 0)
                {
                    sendStream(connection.Player, netConnection, delivery, stream, header, mtu);
                    stream.Reset();
                }

                writer.WriteToStream(connection.Player, stream);
            }

            if (stream.Size > 0)
            {
                sendStream(connection.Player, netConnection, delivery, stream, header, mtu);
            }
        }