Example #1
0
        private void Listen_Load(object sender, EventArgs e)
        {
            while (true)
            {
                LogInSingUp login = new LogInSingUp(ip, port);
                //load log in form
                login.ShowDialog();

                //closes the main form
                if (login.DialogResult == DialogResult.OK)
                {
                    username = login.Username;
                    password = login.Password;
                    ip = login.IP;

                    UserAuthenticationResult result = UserAuthenticationResult.UnknownResult;
                    try
                    {

                        // Open connection to server and attempt to validate the user.
                        serverConnection = new ServerConnection(ip, port);
                        serverConnection.AudioListReceived += new ServerConnection.TrackListEventHandler(serverConnection_AudioListReceived);
                        serverConnection.AudioPacketReceived += new ServerConnection.DataReceivedEventHandler(serverConnection_AudioPacketReceived);
                        //valadate log in information
                        serverConnection.OpenConnection();
                        result = serverConnection.Authenticate(username, password);

                        if (result == UserAuthenticationResult.Success)
                        {
                            serverConnection.RequestAudioList();
                            return;
                        }
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("There was a problem connecting to the server.");
                    }

                    if (result != UserAuthenticationResult.Success)
                    {
                        MessageBox.Show("Connection or validation error.");
                    }

                }
                else
                {
                    this.Close();
                    break;
                }
            }
        }
Example #2
0
        // verify log in information when button clicked
        private void logInButton_Click(object sender, EventArgs e)
        {
            username = userNameBox.Text;
            password = passwordBox.Text;

            if (password == "" || username == "")// make sure textboxes are not empty
            {
                MessageBox.Show("Please enter information in the User Name and Password fields");
                return;
            }
            else//when information is correct
            {
            //connect to server
            UserAuthenticationResult result = UserAuthenticationResult.UnknownResult;
            try
            {
                // Open connection to server and attempt to validate the user.
                using (ServerConnection serverConnection = new ServerConnection(ip, port))
                {
                    //valadate log in information
                    serverConnection.OpenConnection();
                    result = serverConnection.Authenticate(username, password);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("There was a problem connecting to the server.");
                return;
            }

            switch (result)
            {
                case UserAuthenticationResult.UnknownResult:
                    MessageBox.Show("I'm not sure what happened.");
                    break;
                case UserAuthenticationResult.Success://if log in info is valadated go to program

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                    break;
                case UserAuthenticationResult.InvalidUser://if username info not valadated

                    MessageBox.Show("User Name not Accepted");
                    userNameBox.Clear();
                    passwordBox.Clear();
                    break;
                case UserAuthenticationResult.InvalidPassword://if password info not valadated

                    MessageBox.Show("Password not Accepted");
                    userNameBox.Clear();
                    passwordBox.Clear();
                    break;
                default:
                    break;
                }
            }
        }
Example #3
0
        private bool TryCheckConnection()
        {
            if (serverConnection.Connected)
            {
                return true;
            }

            try
            {
                serverConnection = new ServerConnection(ip, port);
                serverConnection.AudioListReceived += new ServerConnection.TrackListEventHandler(serverConnection_AudioListReceived);
                serverConnection.AudioPacketReceived += new ServerConnection.DataReceivedEventHandler(serverConnection_AudioPacketReceived);
                serverConnection.OpenConnection();

                if (serverConnection.Authenticate(username, password) == UserAuthenticationResult.Success)
                {
                    return true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("There was a problem with the connection to the audio server: \n" + ex.Message);
            }

            return false;
        }