internal ENetPeer(IPEndPoint Address, ushort IncomingPeerID, ENetProtocolConnect packet, ENetChannelTypeLayout channelLayout) { this.Address = Address; this.SessionID = packet.SessionID; this.MTU = packet.MTU <PROTOCOL_MINIMUM_MTU?PROTOCOL_MINIMUM_MTU : packet.MTU> PROTOCOL_MAXIMUM_MTU ? PROTOCOL_MAXIMUM_MTU : packet.MTU; this.FragmentLength = (MTU - ENetCommand.SEND_FRAGMENT.Size()) - sizeof(ENetProtocolHeader); this.OutgoingPeerID = packet.OutgoingPeerID; this.IncomingPeerID = IncomingPeerID; this.WindowSize = PROTOCOL_MAXIMUM_WINDOW_SIZE > packet.WindowSize ? packet.WindowSize : PROTOCOL_MAXIMUM_WINDOW_SIZE; this.Channels = new ConcurrentDictionary <byte, ENetChannel>(); for (byte i = 0; i < channelLayout.ChannelCount(); i++) { Channels[i] = new ENetChannel(channelLayout[i]); } }
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; } }