Exemple #1
0
 private void HandleUnsequenced(ENetPeer peer, ENetProtocolSendUnsequenced packet, byte[] data)
 {
 }
Exemple #2
0
 private void HandleReliable(ENetPeer peer, ENetProtocol packet, bool isFragment, byte[] data)
 {
     if (peer.State != ENetPeerState.Connected && peer.State != ENetPeerState.DisconnectLater) return;
     var channel = peer.Channels[packet.Header.ChannelID];
     if (DropSequencedData(channel, packet.Header) || packet.Header.ReliableSequenceNumber == channel.IncomingSequenceNumber) return;
     if (!isFragment && packet.Header.ReliableSequenceNumber == (channel.IncomingSequenceNumber + 1))
     {
         if (OnData != null) OnData(peer, data);
         channel.IncomingSequenceNumber++;
         return;
     }
     lock (channel.IncomingCommandLock)
     {
         var command = new ENetIncomingCommand(packet.Header.ReliableSequenceNumber);
         var existingCommand = channel.IncomingCommands.Find(command); //Establish if we already have the packet
         if (existingCommand != null && !isFragment) return; //We already have the command, ignore it
         else if (existingCommand != null)
         {
             if (existingCommand.Value.FragmentsRemaining == 0) return;
         }
         if (isFragment)
         {
             command.FragmentsRemaining = packet.SendFragment.FragmentCount - 1;
         }
         if(packet.Header.ReliableSequenceNumber == (channel.IncomingSequenceNumber + 1))channel.IncomingCommands.AddFirst()
     }
 }
Exemple #3
0
 private void HandleUnreliable(ENetPeer peer, ENetProtocolSendUnreliable packet, byte[] data)
 {
     if (peer.State != ENetPeerState.Connected && peer.State != ENetPeerState.DisconnectLater) return;
     var channel = peer.Channels[packet.Header.ChannelID];
     if (DropSequencedData(channel, packet.Header) || packet.UnreliableSequenceNumber <= channel.IncomingSequenceNumber) return;
 }
Exemple #4
0
 private ENetPeer? HandleConnect(IPEndPoint from, ENetProtocolConnect packet)
 {
     lock (connectionLock)
     {
         foreach (var peer in Peers)
         {
             if (peer.Value.Address.Equals(from) && peer.Value.SessionID == packet.SessionID) return null;
         }
         ushort peerId;
         if (!AvailablePeerIds.TryDequeue(out peerId)) return null; //No peers available within the client limit
         ENetPeer newPeer = new ENetPeer(from, peerId, packet, ChannelLayout);
         ((IDictionary)Peers).Add(peerId, newPeer);
         return newPeer;
     }
 }