예제 #1
0
        private void GetP2PPacket(IBasePacket packet, out byte[] data, out int dataLength, out int channel, out SendType send)
        {
            _buffer.Position    = 0;
            _buffer.LengthBytes = 0;

            SocketMan.WritePacketHeader(_buffer, packet);
            packet.Write(_buffer);

            send = SendType.Unreliable;
            switch (packet.Sc.DeliveryMethod)
            {
            case NetDeliveryMethod.ReliableSequenced:
            case NetDeliveryMethod.ReliableOrdered:
            case NetDeliveryMethod.ReliableUnordered:
                send = SendType.Reliable;
                break;

            case NetDeliveryMethod.Unreliable:
            case NetDeliveryMethod.UnreliableSequenced:
                send = SendType.Unreliable;
                break;
            }

            data       = _buffer.Data;
            dataLength = _buffer.LengthBytes;
            //channel = packet.Sc.SequenceChannel;
            channel = 1;

            if (packet.Sc == SendCategory.FileTransfer)
            {
                send    = SendType.Reliable;
                channel = 2;
            }
        }
예제 #2
0
        private void _SendPacket(NetPeer peer, IBasePacket packet)
        {
            if (_server == null ||
                !_server.IsRunning ||
                peer == null ||
                peer.ConnectionState != ConnectionState.Connected)
            {
                return;
            }

            _writeBuffer.Position    = 0;
            _writeBuffer.LengthBytes = 0;
            SocketMan.WritePacketHeader(_writeBuffer, packet);
            packet.Write(_writeBuffer);

            var dm = DeliveryMethod.ReliableOrdered;

            switch (packet.Sc.DeliveryMethod)
            {
            case Lidgren.Network.NetDeliveryMethod.ReliableOrdered:
                dm = DeliveryMethod.ReliableOrdered;
                break;

            case Lidgren.Network.NetDeliveryMethod.ReliableSequenced:
                dm = DeliveryMethod.ReliableSequenced;
                break;

            case Lidgren.Network.NetDeliveryMethod.ReliableUnordered:
                dm = DeliveryMethod.ReliableUnordered;
                break;

            case Lidgren.Network.NetDeliveryMethod.Unreliable:
            case Lidgren.Network.NetDeliveryMethod.UnreliableSequenced:
                dm = DeliveryMethod.Unreliable;
                break;

            case Lidgren.Network.NetDeliveryMethod.Unknown:
                dm = DeliveryMethod.Unreliable;
                break;
            }

            peer.Send(_writeBuffer.Data, 0, _writeBuffer.LengthBytes, (byte)packet.Sc.SequenceChannel, dm);
        }
예제 #3
0
        public override void SendPacket(IBasePacket packet)
        {
            if (_client == null || !_client.IsRunning)
            {
                return;
            }

            _writeBuffer.Position    = 0;
            _writeBuffer.LengthBytes = 0;
            SocketMan.WritePacketHeader(packet, _writeBuffer);
            packet.Write(_writeBuffer);

            var dm = DeliveryMethod.ReliableOrdered;

            switch (packet.Sc.DeliveryMethod)
            {
            case Lidgren.Network.NetDeliveryMethod.ReliableOrdered:
                dm = DeliveryMethod.ReliableOrdered;
                break;

            case Lidgren.Network.NetDeliveryMethod.ReliableSequenced:
                dm = DeliveryMethod.ReliableSequenced;
                break;

            case Lidgren.Network.NetDeliveryMethod.ReliableUnordered:
                dm = DeliveryMethod.ReliableUnordered;
                break;

            case Lidgren.Network.NetDeliveryMethod.Unreliable:
            case Lidgren.Network.NetDeliveryMethod.UnreliableSequenced:
                dm = DeliveryMethod.Unreliable;
                break;

            case Lidgren.Network.NetDeliveryMethod.Unknown:
                dm = DeliveryMethod.Unreliable;
                break;
            }

            _client.SendToAll(_writeBuffer.Data, 0, _writeBuffer.LengthBytes, (byte)packet.Sc.SequenceChannel, dm);
        }