/// <summary> /// Bans a client from the network when the kick button is pressed. /// </summary> /// <param name="sender">Object that invoked this event.</param> /// <param name="e">Reason why this event was invoked.</param> private void banPeerButton_Click(object sender, EventArgs e) { string selectedPeer = ""; int clientID = 0; if (peerListView.SelectedItems.Count != 0) { selectedPeer = peerListView.SelectedItems[0].Text; } if (int.TryParse(selectedPeer, out clientID) == false) { return; } // Open ban window. BanWindow banWindow = new BanWindow(); if (banWindow.ShowDialog(this) == DialogResult.OK) { NetworkPacket packet = new NetworkPacket(); packet.ID = "BAN".GetHashCode(); foreach (NetworkClient client in NetworkManager.Connection.ClientList) { if (client.ID == clientID) { // Send it the explanation packet. client.Connection.SendPacket(packet); // Create a ban. NetworkBan ban = new NetworkBan("000.000.000.000", -1, banWindow.BanExpiration); NetworkManager.BansList.Add(ban); // Add its IP to the black list. if (banWindow.BanIP == true) { string currentIP = client.Connection.Socket.RemoteEndPoint.ToString(); if (currentIP.IndexOf(":") >= 0) { currentIP = currentIP.Substring(0, currentIP.IndexOf(":")); } ban.IP = currentIP; } // Ban its account (if its logged in). if (banWindow.BanAccount == true && client.LoggedIn == true) { ban.AccountID = client.AccountID; } // Close its connection. client.Connection.Close(); } } DebugLogger.WriteLog("Banning client " + clientID + "."); } }
/// <summary> /// Bans a client from the network when the kick button is pressed. /// </summary> /// <param name="sender">Object that invoked this event.</param> /// <param name="e">Reason why this event was invoked.</param> private void banPeerButton_Click(object sender, EventArgs e) { string selectedPeer = ""; int clientID = 0; if (peerListView.SelectedItems.Count != 0) selectedPeer = peerListView.SelectedItems[0].Text; if (int.TryParse(selectedPeer, out clientID) == false) return; // Open ban window. BanWindow banWindow = new BanWindow(); if (banWindow.ShowDialog(this) == DialogResult.OK) { NetworkPacket packet = new NetworkPacket(); packet.ID = "BAN".GetHashCode(); foreach (NetworkClient client in NetworkManager.Connection.ClientList) if (client.ID == clientID) { // Send it the explanation packet. client.Connection.SendPacket(packet); // Create a ban. NetworkBan ban = new NetworkBan("000.000.000.000", -1, banWindow.BanExpiration); NetworkManager.BansList.Add(ban); // Add its IP to the black list. if (banWindow.BanIP == true) { string currentIP = client.Connection.Socket.RemoteEndPoint.ToString(); if (currentIP.IndexOf(":") >= 0) currentIP = currentIP.Substring(0, currentIP.IndexOf(":")); ban.IP = currentIP; } // Ban its account (if its logged in). if (banWindow.BanAccount == true && client.LoggedIn == true) ban.AccountID = client.AccountID; // Close its connection. client.Connection.Close(); } DebugLogger.WriteLog("Banning client " + clientID + "."); } }