Esempio n. 1
0
        /*
            Name: confirmLoginCredentials()
            Description: As the name implies, this method is called and used to validate that the user has entered the correct login credentials
            and a correct IPv4 address to connect to the server
            Parameter(s): None
            Return: bool status indicating if the login credentials were entered correctly or incorrectly. Or if IPv4 was not correct.
        */
        private bool confirmLoginCredentials()
        {
            clientConnect = null;
            int port = 9000;
            bool retStatus = false;

            if (IP_Address.Text == "")
            {
                login_Error_Msg.Text = "*Do not leave IP Adress blank!";
                login_Error_Msg.Visible = true; //Show error message
            }

            login_Error_Msg.Visible = false; //Show error message

            try
            {
                clientConnect = new TriviaLib.TCPIPconnectorClient(port, IPAddress.Parse(IP_Address.Text)); //Entered IPv4 Address by the user
            }
            catch (Exception)
            {
                login_Error_Msg.Text = "*Invalid IPv4 Address!";
                login_Error_Msg.Visible = true; //Show error message
            }

            if (verifyAdminName == "root" && verifyAdminPassword == "root")
            {
                try
                {
                    User admin = new User();

                    if (clientConnect.Connect() == "")
                    {
                        clientConnect.Send("!admin");
                        clientConnect.Read();

                        login_Error_Msg.Visible = false; //Hide the error message when user enters credentials in correctly

                        admin.name = verifyAdminName;
                        admin.password = verifyAdminPassword;

                        clientConnect.Send(User.Serialize(admin)); //Notify the server you want to access admin
                        clientConnect.Read(); //Read the garbage value
                        retStatus = true; //Leave the function with a success and going into the main administrative screen
                    }
                    else
                    {
                        login_Error_Msg.Text = "*Unable to Connect to Server!";
                        login_Error_Msg.Visible = true; //Show error message
                    }
                }
                catch (Exception)
                {
                    login_Error_Msg.Text = "*Server Unavailable!";
                    login_Error_Msg.Visible = true; //Show error message
                }
            }
            else
            {
                login_Error_Msg.Text = "*Invalid User Name or Password!";
                login_Error_Msg.Visible = true; //Show error message
            }

            return retStatus;
        }
Esempio n. 2
0
        private void ButtonName_Click(object sender, EventArgs e)
        {
            string returnMessage = "";
            string errorMessage = "";
            bool status = false;
            //validation to check if it empty
            if ((UserNameTextBox.Text == "") || (IPTextBox.Text == ""))
            {
                errorMessage = "Enter a name\nEnter a IP adress\n";
                ErrorMessage.Text = errorMessage;
                //no thing
            }
            else
            {
                if (this.checkPunc(UserNameTextBox.Text) == true)
                {
                    ErrorMessage.Text = "Please do not use punctuation";
                }
                else
                {

                    try
                    {
                        //connection to server
                        this.myConnectionToServer = new TCPIPconnectorClient(9000, System.Net.IPAddress.Parse(IPTextBox.Text.ToString()));
                    }
                    catch (Exception ex)
                    {
                        errorMessage = "Cannot establish a \nconnection to server\n";
                        ErrorMessage.Text = errorMessage;
                        status = true;
                    }
                    //if status equal to false continue with the program
                    if (status == false)
                    {

                        ErrorMessage.Text = "";
                        //establish connection
                        returnMessage = myConnectionToServer.Connect();
                        //if returnMessage is empty then continue
                        if (returnMessage == "")
                        {
                            //disable the username and IP
                            UserNameTextBox.Enabled = false;
                            IPTextBox.Enabled = false;
                            //undisable the question options
                            QuestionA.Checked = true;
                            QuestionB.Checked = true;
                            QuestionC.Checked = true;
                            QuestionD.Checked = true;
                            QuestionGroupBox.Enabled = true;
                            ErrorMessage.Text = "";
                            //create new user
                            this.myConnectionToServer.Send("!newUser");
                            //wait for the server name
                            this.myConnectionToServer.Read();
                            //create new user
                            User user = new User();
                            //username
                            user.name = UserNameTextBox.Text;
                            user.password = "";
                            ButtonName.Enabled = false;

                            //send an object so it will be seralized
                            this.myConnectionToServer.Send(User.Serialize(user));

                            System.Threading.Thread.Sleep(500);

                            this.myConnectionToServer.Send("!question1");

                            byte[] buffer = this.myConnectionToServer.ReadObject();
                            Question q = Question.Deserialize(buffer);
                            //establish the first questions
                            lbQuestion.Text = "[1] " + q.content;
                            QuestionA.Text = "A) " + q.a;
                            QuestionB.Text = "B) " + q.b;
                            QuestionC.Text = "C) " + q.c;
                            QuestionD.Text = "D) " + q.d;
                            GameCounter.Enabled = true;
                            connection = true;
                            NextButton.Enabled = true;
                        }
                        else
                        {
                            //return error message
                            ErrorMessage.Text = "Count not connect";
                        }
                    }
                }
            }
        }