Beispiel #1
0
        internal void CreateChannels(List <ChannelType> types)
        {
            Channels = new Channel[types.Count];

            for (byte i = 0; i < types.Count; i++)
            {
                switch (types[i])
                {
                case ChannelType.Reliable:
                {
                    Channels[i] = new ReliableChannel(i);
                }
                break;

                case ChannelType.ReliableSequenced:
                {
                    Channels[i] = new ReliableSequencedChannel(i);
                }
                break;

                case ChannelType.Unreliable:
                {
                    Channels[i] = new UnreliableChannel(i);
                }
                break;

                case ChannelType.UnreliableOrdered:
                {
                    Channels[i] = new UnreliableSequencedChannel(i);
                }
                break;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates an unreliable packet channel
        /// </summary>
        /// <returns></returns>
        public UnreliableChannel <TPacket> CreateUnreliableChannel()
        {
            var channel = new UnreliableChannel <TPacket>();

            ConfigurePacketChannel(channel);
            return(channel);
        }
Beispiel #3
0
            internal void Configure(ReliableChannel reliable, UnreliableChannel unreliable)
            {
                this.reliableChannel   = reliable;
                this.unreliableChannel = unreliable;

                this.reliableChannel.listener = this;
            }
Beispiel #4
0
        public void TestUnreliableChannelDoesNotDiscardsOldMessages()
        {
            // Create 3 packets, add them in the order 1, 3, 2.
            // 2 should be discarded.
            var channel = new UnreliableChannel();

            channel.QueueIncomingPacket(EndPoint, new Packet(PacketType.UnconnectedMessage, Channel.None, 1, new byte[10] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 0
            }));
            channel.QueueIncomingPacket(EndPoint, new Packet(PacketType.UnconnectedMessage, Channel.None, 3, new byte[0]));
            channel.QueueIncomingPacket(EndPoint, new Packet(PacketType.UnconnectedMessage, Channel.None, 2, new byte[0]));

            UnreliableChannel.PendingPacket packet;
            Assert.IsTrue(channel.TryGetNextIncomingPacket(out packet), "Should have got packet 1");
            Assert.IsNotNull(packet, "Packet 1 should not be null.");
            Assert.AreEqual(1, packet.Sequence, $"Packet sequence should be 1 but was {packet.Sequence}");
            Assert.AreEqual(new byte[10] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 0
            }, packet.Data, "Packet 1 data did not match.");

            Assert.IsTrue(channel.TryGetNextIncomingPacket(out packet));
            Assert.IsNotNull(packet);
            Assert.AreEqual(3, packet.Sequence);

            Assert.IsTrue(channel.TryGetNextIncomingPacket(out packet));
            Assert.IsNotNull(packet);
            Assert.AreEqual(2, packet.Sequence);
        }
 public MessageAckHelper(UnreliableChannel sender, IClientMessageRouter rerouter, int maxRetryCount = 3, double intervalBetweenRetries = 1.0)
 {
     this.sender           = sender;
     this.rerouter         = rerouter;
     this.retryCount       = maxRetryCount;
     this.interval         = intervalBetweenRetries;
     this.referenceMessage = new TIngoingMessage();
 }
        void IUnreliableChannelListener.ChannelDidReceiveMessage(UnreliableChannel channel, MessageContainer container, NetEndPoint from)
        {
            ThreadChecker.AssertUnreliableChannel();

            if (this.identifiedCollection.TryGetPlayer(from, out INetworkServerMessageListener listener))
            {
                listener?.NetworkServerDidReceiveMessage(container);
            }
            else
            {
                this.listener?.NetworkServerDidReceiveUnidentifiedMessage(container, from);
            }
        }
Beispiel #7
0
        private void Init()
        {
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, 1000);

            packetFactory = new PacketFactory <TPacket>();
            buffer        = new IO.Buffer(Max_Packet_Size);

            timer          = new System.Timers.Timer(Connection_Retry_Delay / 2);
            timer.Elapsed += OnTimer;

            defaultChannel = new UnreliableChannel <TPacket>();
            ConfigurePacketChannel(defaultChannel);

            channels = new PacketChannel <TPacket> [packetFactory.TypeCount + 1];
            for (int i = 0; i < channels.Length; i++)
            {
                channels[i] = defaultChannel; // set every channel to the default
            }
        }
        void INetworkServerListener.NetworkServerDidAcceptPlayer(ReliableChannel reliable, UnreliableChannel unreliable)
        {
            ThreadChecker.AssertReliableChannel();

            this.clientAcceptor.NetworkServerDidAcceptPlayer(reliable, unreliable);
        }
 void IUnreliableChannelListener.ChannelDidReceiveMessage(UnreliableChannel channel, MessageContainer container, NetEndPoint from)
 {
     this.listener?.NetworkClientDidReceiveMessage(container, from);
 }