Ejemplo n.º 1
0
        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;
                }
            }
        }
Ejemplo n.º 2
0
        private void btnListen_Click(object sender, EventArgs e)
        {
            ushort port     = GetPortSafe();
            string password = txtPassword.Text;

            if (port == 0)
            {
                MessageBox.Show("Lütfen 0'dan büyük geçerli bir port giriniz..", "Lütfen geçerli bir port giriniz.", MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                return;
            }

            if (password.Length < 3)
            {
                MessageBox.Show("Lütfen en az 3 karakterden oluşan geçerli ve güvenilir bir şifre kullanınız.",
                                "Güvenli bir şifre giriniz.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (btnListen.Text == "Dinlemeye Başla" && !_listenServer.Listening)
            {
                try
                {
                    AES.SetDefaultKey(password);

                    if (chkUseUpnp.Checked)
                    {
                        if (!UPnP.IsDeviceFound)
                        {
                            MessageBox.Show("Kullanılabilir hiçbir UPnP Cihazı Tespit Edilemedi!", "UPnP Cihazı Tespit Edilemedi", MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        }
                        else
                        {
                            int outPort;
                            UPnP.CreatePortMap(port, out outPort);
                            if (port != outPort)
                            {
                                MessageBox.Show("UPnP Cihazıyla Bir Port Map Oluşturma Başarısız.!\nLütfen cihazınızın UPnP Port Map desteği olup olmadığına bakınız.", "Port map oluşturumu başarısız", MessageBoxButtons.OK,
                                                MessageBoxIcon.Warning);
                            }
                        }
                    }
                    if (chkNoIPIntegration.Checked)
                    {
                        NoIpUpdater.Start();
                    }
                    _listenServer.Listen(port);
                }
                finally
                {
                    btnListen.Text      = "Dinlemeyi Durdur";
                    ncPort.Enabled      = false;
                    txtPassword.Enabled = false;
                }
            }
            else if (btnListen.Text == "Dinlemeyi Durdur" && _listenServer.Listening)
            {
                try
                {
                    _listenServer.Disconnect();
                    UPnP.DeletePortMap(port);
                }
                finally
                {
                    btnListen.Text      = "Dinlemeye Başla";
                    ncPort.Enabled      = true;
                    txtPassword.Enabled = true;
                }
            }
        }
Ejemplo n.º 3
0
        private void btnListen_Click(object sender, EventArgs e)
        {
            ushort port = GetPortSafe();

            if (port == 0)
            {
                MessageBox.Show("Please enter a valid port > 0.", "Please enter a valid port", MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                return;
            }

            if (btnListen.Text == "Start listening" && !_listenServer.Listening)
            {
                try
                {
                    if (chkUseUpnp.Checked)
                    {
                        if (!UPnP.IsDeviceFound)
                        {
                            MessageBox.Show(this, "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(this, "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, chkIPv6Support.Checked);
                }
                catch (SocketException ex)
                {
                    if (ex.ErrorCode == 10048)
                    {
                        MessageBox.Show(this, "The port is already in use.", "Socket Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(this, $"An unexpected socket error occurred: {ex.Message}\n\nError Code: {ex.ErrorCode}\n\n", "Unexpected Socket Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    _listenServer.Disconnect();
                }
                catch (Exception)
                {
                    _listenServer.Disconnect();
                }
                finally
                {
                    btnListen.Text         = "Stop listening";
                    ncPort.Enabled         = false;
                    chkIPv6Support.Enabled = false;
                }
            }
            else if (btnListen.Text == "Stop listening" && _listenServer.Listening)
            {
                try
                {
                    _listenServer.Disconnect();
                    UPnP.DeletePortMap(port);
                }
                finally
                {
                    btnListen.Text         = "Start listening";
                    ncPort.Enabled         = true;
                    chkIPv6Support.Enabled = true;
                }
            }
        }