Exemple #1
0
        public void ReceiveDisconnectMessage(string guestId)
        {
            _log.LogInformation($"-> SignalRHost.{nameof(ReceiveDisconnectMessage)}");
            _log.LogDebug($"{nameof(guestId)} {guestId}");
            _log.LogDebug($"Local UserId: {PeerInfo.Message.PeerId}");

            var success = Guid.TryParse(guestId, out Guid guestGuid);

            if (!success ||
                guestGuid == Guid.Empty)
            {
                _log.LogWarning($"GuestId is not a GUID");
                return;
            }

            var existingGuest = ConnectedPeers.FirstOrDefault(g => g.PeerId == guestId);

            if (existingGuest == null)
            {
                _log.LogWarning("No existing guest found");
                return;
            }

            ConnectedPeers.Remove(existingGuest);
            UpdateConnectedPeers(null);
            RaiseUpdateEvent();
            _log.LogInformation($"SignalRHost.{nameof(ReceiveDisconnectMessage)} ->");
        }
        /// <summary>
        /// Disconnects a peer from this channel
        /// </summary>
        /// <param name="pred">The predicate used to determine what peer to disconnect</param>
        public void DisconnectPeer(Predicate <Peer.Peer> pred)
        {
            var peer = ConnectedPeers.First(new Func <Peer.Peer, bool>(pred));

            peer.Disconnect();
            lock (_lockObj)
                ConnectedPeers.Remove(peer);
        }
        /// <summary>
        /// Disconnects a peer from this channel
        /// </summary>
        /// <param name="id">The ID of the peer to disconnect</param>
        public void DisconnectPeer(int id)
        {
            var peer = ConnectedPeers.First(p => p.Identity.Id == id);

            peer.Disconnect();
            lock (_lockObj)
                ConnectedPeers.Remove(peer);
        }
Exemple #4
0
        private void PeerDisconnect(object sender, PeerEventArgs e)
        {
            if (OnPeerDisconnected != null)
            {
                OnPeerDisconnected(null, e);
            }

            ConnectedPeers.Remove(e.Peer);

            if (_debug)
            {
                Debug.Print("Peer disconnected from: {0} with reason: {1}", e.Peer.RemoteEndPoint,
                            ((PeerDisconnectedEventArgs)e).DisconnectReason);
            }
        }
 private void AcceptPeer(Peer.Peer newPeer)
 {
     newPeer.OnPeerSynchronized +=
         (sender, e) => OnPeerConnected.Raise(this, new ChannelEventArgs(this, e.Peer));
     newPeer.OnPeerDisconnected +=
         (sender, e) =>
     {
         e.Peer.Dispose();
         lock (_lockObj)
             ConnectedPeers.Remove(e.Peer);
     };
     newPeer.OnRawPacketReceived        += RawPacketReceived;
     newPeer.OnSequenceFragmentReceived += (sender, e) => OnSequenceFragmentReceived.Raise(sender, e);
     lock (_lockObj)
         ConnectedPeers.Add(newPeer);
 }
 /// <summary>
 /// Disconnects a peer from this channel
 /// </summary>
 /// <param name="peer">The peer to disconnect</param>
 public void DisconnectPeer(Peer.Peer peer)
 {
     peer.Disconnect();
     lock (_lockObj)
         ConnectedPeers.Remove(peer);
 }