public void OnPeerDisconnected(ChannelEventArgs e) { _connectionList = UiServiceProvider.GetService("ConnectionList") as ConnectionListService; if (_connectionList != null) { var item = _connectionList.FindItem(itm => itm != null && Equals(itm.AssociatedPeer.Identity, e.Peer.Identity)); _connectionList.RemoveItem(item); } }
void OperationPacketReceived(object sender, uNet2.Packet.Events.OperationPacketEventArgs e) { if (e.Packet is SystemInformationPacket) { var packet = e.Packet as SystemInformationPacket; var peer = (e.Channel as TcpServerChannel).ConnectedPeers.FirstOrDefault( p => p.Identity.Guid == e.Operation.ConnectionGuid); _connectionList = UiServiceProvider.GetService("ConnectionList") as ConnectionListService; var lvItm = new ConnectionListItem(peer, e.Channel as TcpServerChannel); lvItm.Text = peer.Endpoint.ToString(); lvItm.SubItems.Add(packet.ComputerName); lvItm.SubItems.Add(packet.OperatingSystem); lvItm.SubItems.Add(packet.CountryCode); lvItm.SubItems.Add(packet.IsAdmin); lvItm.SubItems.Add(Math.Truncate(peer.PingDelay) + " ms"); _connectionList.AddItem(lvItm); } e.Operation.CloseOperation(); }