예제 #1
0
 //what happens when log in button is pressed
 private void logInButton_Click(object sender, EventArgs e)
 {
     //checks is socket is connected
     if (socketConnect == true)
     {
         //if socket connected send the text in the username and password text box with an identifying letter at the start
         con.sendMessage("U" + usernameTextBox.Text);
         con.sendMessage("P" + passwordTextBox.Text);
         //receives the response of a 1 or 0 from server
         int response = Int32.Parse(con.getMessage());
         if (response == 0)
         {
             //if response is 0, it means username and password are wrong and prints that your log in is incorrect
             errorLabel.Text = "Username or Password is incorrect.";
         }
         else
         {
             //if response is 1, it means username and password are correct and opens the main client
             ClientPage form = new ClientPage();
             this.Hide();
             form.setUsername(usernameTextBox.Text + "#" + response);
             form.Show();
         }
     }
     //socket not connected message
     else
     {
         errorLabel.Text = "Not connected to server";
     }
 }
예제 #2
0
        private void newUserButton_Click(object sender, EventArgs e)
        {
            if (socketConnect == true)
            {
                string tempUser;
                string tempPass;
                tempUser = con.noPunc(usernameTextBox.Text);
                tempPass = con.noPunc(passwordTextBox.Text);

                if (usernameTextBox.Text != tempUser)
                {
                    errorLabel.Text = "Username cannot contain symbols. Only Letters and Numbers.";
                }
                else if (passwordTextBox.Text != tempPass)
                {
                    errorLabel.Text = "Password cannot contain symbols. Only Letters and Numbers.";
                }
                else
                {
                    con.sendMessage("N" + usernameTextBox.Text + "-" + passwordTextBox.Text);
                }
                string response    = con.getMessage();
                int    responseInt = Int32.Parse(response);
                if (responseInt != -1)
                {
                    ClientPage form = new ClientPage();
                    this.Hide();
                    form.setUsername(usernameTextBox.Text + "#" + response);
                    form.Show();
                }
                else
                {
                    errorLabel.Text = "Username is taken.";
                }
            }
            else
            {
                errorLabel.Text = "Not connected to a server";
            }
        }