private void btnListen_Click(object sender, EventArgs e) { ushort port = GetPortSafe(); string password = txtPassword.Text; if (port == 0) { MessageBox.Show("Please enter a valid port > 0.", "Please enter a valid port", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (password.Length < 3) { MessageBox.Show("Please enter a secure password with more than 3 characters.", "Please enter a secure password", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (btnListen.Text == "Start listening" && !_listenServer.Listening) { try { AES.PreHashKey(password); if (chkUseUpnp.Checked) { if (!UPnP.IsDeviceFound) { MessageBox.Show("No available UPnP device found!", "No UPnP device", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { int outPort; UPnP.CreatePortMap(port, out outPort); if (port != outPort) { MessageBox.Show("Creating a port map with the UPnP device failed!\nPlease check if your device allows to create new port maps.", "Creating port map failed", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } if (chkNoIPIntegration.Checked) { NoIpUpdater.Start(); } _listenServer.Listen(port); } finally { btnListen.Text = "Stop listening"; ncPort.Enabled = false; txtPassword.Enabled = false; } } else if (btnListen.Text == "Stop listening" && _listenServer.Listening) { try { _listenServer.Disconnect(); UPnP.DeletePortMap(port); } finally { btnListen.Text = "Start listening"; ncPort.Enabled = true; txtPassword.Enabled = true; } } }