Exemplo n.º 1
0
 /*************************** Game Lobby **************************************
  * initializes the lobby and allows only the exit button and the login button the
  * be available before connecting to the server.
  */
 public gameLobby()
 {
     InitializeComponent();
     CreateButton.Hide();
     ListGamesButton.Hide();
     JoinButton.Hide();
     SendButton.Hide();
     this.AcceptButton = SendButton;
 } // end of gameLobby
Exemplo n.º 2
0
        } // end of sendButton

        /*************************** Login Button *************************************
         * Takes the users name they typed in the username textbox and requests a connction
         * with the server, then logs in to the server enabling the create button, list
         * games button, and join button.
         */
        private void LoginButton_Click_1(object sender, EventArgs e)
        {
            // handle a blank username and don't allow people to have names longer than 16 characters
            if (textBox3.Text.Trim() == "")
            {
                textBox1.Text = "Please enter a Username before logging in";
                return;
            }
            if (textBox3.Text.Length > 16)
            {
                textBox1.Text = "You shall not enter names longer than 16 characters!";
                return;
            }
            // Username is what was typed into the textbox
            clientNo = textBox3.Text;

            try
            {
                // Try to connect to the server
                clientSocket.Connect("18.216.181.228", 13000);

                // *** Loopback can be uncommented out for testing on local machine ***
                // just make sure you comment out the IP above

                //clientSocket.Connect("127.0.0.1", 13000);

                serverStream = clientSocket.GetStream();

                // Send the user name to the server
                byte[] outStream = System.Text.Encoding.ASCII.GetBytes(textBox3.Text + "|");

                serverStream.Write(outStream, 0, outStream.Length);
                serverStream.Flush();

                // Create a new thread top handle the client
                Thread ctThread = new Thread(getMessage);
                ctThread.Start();
            }
            catch (Exception ex)
            {
                textBox1.AppendText(ex.ToString());
            }
            if (clientSocket.Connected)
            {
                // If the client connects successfully, enables button functions
                LoginButton.Hide();
                CreateButton.Show();
                ListGamesButton.Show();
                JoinButton.Show();
                SendButton.Show();
            }
        } // end of LoginButton