public void RemoveClient(Client client) { if (this == null || this.IsDisposed) { client.DataReceived -= client_DataReceived; client.Disconnected -= client_Disconnected; return; } foreach (TreeNode node in xClients.Nodes) { if (node.Tag == client) { Invoke((MethodInvoker)delegate { if (node.IsSelected) lstPlugins.Items.Clear(); node.Remove(); }); client.DataReceived -= client_DataReceived; client.Disconnected -= client_Disconnected; clients.Remove(client); break; } } }
public void AddClient(Client client) { client.DataReceived += new EventHandler<DataReceivedEventArgs>(client_DataReceived); client.Disconnected += new Client.DisconnectedEventHandler(client_Disconnected); TreeNode node = new TreeNode(); node.Text = client.Address.ToString().Split(':')[0]; node.Tag = client; Invoke((MethodInvoker)delegate { xClients.Nodes.Add(node); }); }
void listener_SocketAccepted(object sender, SocketConnectedEventArgs e) { Client client = new Client(e.AcceptedSocket); string addr = client.Address.Split(':')[0]; if (Settings.DupPrevnt) { if (conAddr.Contains(addr)) { PacketWriter wr = new PacketWriter(); wr.Write((int)PacketHeader.LIMIT); client.Send(wr.ToArray(true)); wr = null; Invoke((MethodInvoker)delegate { GlobalProperties.NI.ShowBalloonTip(2000, "Duplication Prevention", "A client has been disconnected to prevent duplication.", ToolTipIcon.Error); }); client.Close(); return; } else conAddr.Add(addr); } Clients.Add(client); client.Disconnected += new Client.DisconnectedEventHandler(client_Disconnected); client.DataSent += new EventHandler<DataSentEventArgs>(client_DataSent); client.DataReceived += new EventHandler<DataReceivedEventArgs>(client_DataReceived); client.BeginRead(); }
void client_Disconnected(Client e) { Clients.Remove(e); conAddr.Remove(e.Address.Split(':')[0]); if (pluginView != null && e.FullyConnected) pluginView.RemoveClient(e); e.DataReceived -= client_DataReceived; e.DataSent -= client_DataSent; e.Disconnected -= client_Disconnected; if (e.DisconnectNotify && e.FullyConnected) { GlobalProperties.Online--; updateOnline(); } if (!IsDisposed && e.DisconnectNotify) { Invoke((MethodInvoker)delegate { lstClients.Items.Remove(e.Lvi); if (e.DisconnectNotify) { if (Settings.NotifyDisconnected && e.FullyConnected) GlobalProperties.NI.ShowBalloonTip(2000, "Disconnection", (!xHideIPs.Checked ? e.Address.Split(':')[0] : "Client") + " Disconnected", ToolTipIcon.Error); } }); } e.Close(); }
void client_Disconnected(Client e) { RemoveClient(e); clients.Remove(e); }