public void RemoveClient(IPAddress address) { Client client = mClients.Find(c => c.Address.Equals(address)); if (client != null) { mClients.Remove(client); OnClientRemoved?.Invoke(client); } }
public void RemoveClient(string id) { Client client = mClients.Find(c => c.Id == id); if (client != null) { mClients.Remove(client); OnClientRemoved?.Invoke(client); } }
public void RemoveClient(Client client) { Client dummy; Clients.TryRemove(client.SocketId, out dummy); // Process client disconnected event. client.OnClientRemoved(); OnClientRemoved?.Invoke(client); }
///<summary>Removes the specified Client from the client list.</summary> ///<param name="client">The client to remove from the client list.</param> protected void RemoveClient(Client client) { lock (m_ClientsLock) { if (Clients.Contains(client)) { Clients.Remove(client); if (OnClientRemoved != null) { OnClientRemoved.Invoke(client); } } } }
private void ProcessItem(IP2PBase Item, IPEndPoint EP = null) { if (Item.GetType() == typeof(Message)) { Message m = (Message)Item; ClientInfo CI = Clients.FirstOrDefault(x => x.ID == Item.ID); if (m.ID == 0) { if (OnResultsUpdate != null) { OnResultsUpdate.Invoke(this, m.From + ": " + m.Content); } } if (m.ID != 0 & EP != null & CI != null) { if (OnMessageReceived != null) { OnMessageReceived.Invoke(EP, new MessageReceivedEventArgs(CI, m, EP)); } } } else if (Item.GetType() == typeof(ClientInfo)) { ClientInfo CI = Clients.FirstOrDefault(x => x.ID == Item.ID); if (CI == null) { Clients.Add((ClientInfo)Item); if (OnClientAdded != null) { OnClientAdded.Invoke(this, (ClientInfo)Item); } } else { CI.Update((ClientInfo)Item); if (OnClientUpdated != null) { OnClientUpdated.Invoke(this, (ClientInfo)Item); } } } else if (Item.GetType() == typeof(Notification)) { Notification N = (Notification)Item; if (N.Type == NotificationsTypes.Disconnected) { ClientInfo CI = Clients.FirstOrDefault(x => x.ID == long.Parse(N.Tag.ToString())); if (CI != null) { if (OnClientRemoved != null) { OnClientRemoved.Invoke(this, CI); } Clients.Remove(CI); } } else if (N.Type == NotificationsTypes.ServerShutdown) { if (OnResultsUpdate != null) { OnResultsUpdate.Invoke(this, "Server shutting down."); } ConnectOrDisconnect(); } } else if (Item.GetType() == typeof(Req)) { Req R = (Req)Item; ClientInfo CI = Clients.FirstOrDefault(x => x.ID == R.ID); if (CI != null) { if (OnResultsUpdate != null) { OnResultsUpdate.Invoke(this, "Received Connection Request from: " + CI.ToString()); } IPEndPoint ResponsiveEP = FindReachableEndpoint(CI); if (ResponsiveEP != null) { if (OnResultsUpdate != null) { OnResultsUpdate.Invoke(this, "Connection Successfull to: " + ResponsiveEP.ToString()); } if (OnClientConnection != null) { OnClientConnection.Invoke(CI, ResponsiveEP); } if (OnClientUpdated != null) { OnClientUpdated.Invoke(this, CI); } } } } else if (Item.GetType() == typeof(Ack)) { Ack A = (Ack)Item; if (A.Responce) { AckResponces.Add(A); } else { ClientInfo CI = Clients.FirstOrDefault(x => x.ID == A.ID); if (CI.ExternalEndpoint.Address.Equals(EP.Address) & CI.ExternalEndpoint.Port != EP.Port) { if (OnResultsUpdate != null) { OnResultsUpdate.Invoke(this, "Received Ack on Different Port (" + EP.Port + "). Updating ..."); } CI.ExternalEndpoint.Port = EP.Port; if (OnClientUpdated != null) { OnClientUpdated.Invoke(this, CI); } } List <string> IPs = new List <string>(); CI.InternalAddresses.ForEach(new Action <IPAddress>(delegate(IPAddress IP) { IPs.Add(IP.ToString()); })); if (!CI.ExternalEndpoint.Address.Equals(EP.Address) & !IPs.Contains(EP.Address.ToString())) { if (OnResultsUpdate != null) { OnResultsUpdate.Invoke(this, "Received Ack on New Address (" + EP.Address + "). Updating ..."); } CI.InternalAddresses.Add(EP.Address); } A.Responce = true; A.RecipientID = LocalClientInfo.ID; SendMessageUDP(A, EP); } } }
/// <summary> /// Removes a client from the session. /// This should be called whenever a client disconnects. /// </summary> /// <param name="identifier"></param> public virtual void RemoveClient(int identifier) { clients.Remove(identifier); OnClientRemoved?.Invoke(identifier); }