Example #1
0
        private void registerButton_Click(object sender, EventArgs e)
        {
            comunicator.SendMessage(stream, "2");
            if (textBoxName.Text.Length != 0 || textBoxPass.Text.Length != 0)
            {
                int permit = 1;
                if (checkBox1.Checked)
                {
                    permit = 0;
                }

                String credentials = textBoxName.Text + ";" + textBoxPass.Text + ";" + permit;
                comunicator.SendMessage(stream, credentials);
                var response = comunicator.ReadResponse(stream);
                if (!response.Equals("ACK"))
                {
                    responseLabel.ForeColor = Color.Red;
                    responseLabel.Text      = response;
                }
                else
                {
                    responseLabel.ForeColor = Color.Green;
                    responseLabel.Text      = "Successfully registered";
                }
            }
            else
            {
                String credentials = "a2z;b;1";
                comunicator.SendMessage(stream, credentials);
                responseLabel.ForeColor = Color.Red;
                responseLabel.Text      = "Invalid Credentials";
            }
        }
Example #2
0
        private void sendButton_Click(object sender, EventArgs e)
        {
            comunicator.SendMessage(stream, textBox1.Text);
            var response = comunicator.ReadResponse(stream);

            gameStatus.Text = response;
        }
Example #3
0
        //login button
        private void loginButton_Click(object sender, EventArgs e)
        {
            ClientComunicator comunicator = new ClientComunicator();

            comunicator.SendMessage(stream, "1");

            if (textBoxName.Text.Length != 0 || textBoxPass.Text.Length != 0)
            {
                String credentials = textBoxName.Text + ";" + textBoxPass.Text;
                comunicator.SendMessage(stream, credentials);
                var response = comunicator.ReadResponse(stream);
                if (response.Equals("DEC"))
                {
                    responseLabel.ForeColor = Color.Red;
                    responseLabel.Text      = "Invalid Credentials";
                }
                else
                {
                    response = comunicator.ReadResponse(stream);
                    if (response.Equals("ADM"))
                    {
                        Hide();
                        InteractionAdminWindow adminWindow = new InteractionAdminWindow(client, 0);
                        adminWindow.ShowDialog();
                    }
                    else
                    {
                        Hide();
                        InteractionWindow userWindow = new InteractionWindow(client, 1);
                        userWindow.ShowDialog();
                    }
                }
            }
            else
            {
                String credentials = "a1z ;a1z";
                comunicator.SendMessage(stream, credentials);
                responseLabel.ForeColor = Color.Red;
                responseLabel.Text      = "Invalid Credentials";
            }
        }
Example #4
0
        private void registerButton_Click(object sender, EventArgs e)
        {
            ClientComunicator comunicator = new ClientComunicator();

            comunicator.SendMessage(stream, "3");

            if (textBoxName.Text.Length != 0 || textBoxPass.Text.Length != 0 || newPasswordBox.Text.Length != 0)
            {
                String credentials = textBoxName.Text + ";" + textBoxPass.Text;
                comunicator.SendMessage(stream, credentials);
                var response = comunicator.ReadResponse(stream);
                if (response.Equals("DEC"))
                {
                    responseLabel.ForeColor = Color.Red;
                    responseLabel.Text      = "Invalid Credentials";
                }
                else
                {
                    credentials = newPasswordBox.Text;
                    comunicator.SendMessage(stream, credentials);

                    response = comunicator.ReadResponse(stream);
                    if (response == "BAD")
                    {
                        responseLabel.ForeColor = Color.Red;
                        responseLabel.Text      = "Bad new password";
                    }
                    else
                    {
                    }
                }
            }
            else
            {
                responseLabel.ForeColor = Color.Red;
                responseLabel.Text      = "Invalid Credentials";
            }
        }
Example #5
0
        public RankingWindow(TcpClient client, int permision)
        {
            InitializeComponent();
            stream         = client.GetStream();
            this.client    = client;
            this.permision = permision;

            if (permision == 1)
            {
                comunicator.SendMessage(stream, "2");
            }
            else
            {
                comunicator.SendMessage(stream, "4");
            }
            var response2 = comunicator.ReadResponse(stream);

            rankingTextBox.Text = response2;
        }
        private void removeButton_Click(object sender, EventArgs e)
        {
            comunicator.SendMessage(stream, "3");
            String login = textBoxName.Text;

            comunicator.SendMessage(stream, login);

            var respone = comunicator.ReadResponse(stream);

            if (!respone.Equals("ACK"))
            {
                responseLabel.ForeColor = Color.Red;
                responseLabel.Text      = respone;
            }
            else
            {
                responseLabel.ForeColor = Color.Green;
                responseLabel.Text      = "Successfully deleted";
            }
        }
Example #7
0
        public static void guessingGame(NetworkStream stream, MessageReader messageReader, ClientComunicator comunicator, User user)
        {
            int  nextGame = 1;
            Game game     = new Game();

            Console.WriteLine("Number to guess: " + game.numberValue);

            while (nextGame == 1)
            {
                var guessedVal = comunicator.ReadResponse(stream);

                String time = DateTime.Now.ToString("h:mm:ss");
                Console.WriteLine(time + " -> " + guessedVal);
                int guessedValInt;
                try
                {
                    guessedValInt = Int32.Parse(guessedVal);
                }
                catch (FormatException)
                {
                    guessedValInt = 102;
                }

                if ((guessedValInt > 100 || guessedValInt < 0) && guessedValInt != 10001)
                {
                    comunicator.SendMessage(stream, messageReader.getMessage("badValueMessage"));
                }
                else if (game.numberValue.Equals(guessedValInt))
                {
                    comunicator.SendMessage(stream, messageReader.getMessage("winningMessage"));
                    Console.WriteLine("Client guessed the number");
                    user.score = user.score + game.score;
                    game.score = 100;

                    var continueGame = comunicator.ReadResponse(stream);

                    nextGame = Int32.Parse(continueGame);
                    if (nextGame == 0)
                    {
                        comunicator.SendMessage(stream, messageReader.getMessage("endMessage"));
                    }
                    else if (nextGame == 10001)
                    {
                    }
                    else
                    {
                        game = new Game();
                        Console.WriteLine("Number to guess: " + game.numberValue);
                        comunicator.SendMessage(stream, messageReader.getMessage("guessMessage"));
                    }
                }
                else if (guessedValInt == 10001)
                {
                    nextGame = 0;
                }
                else
                {
                    string hotOrNotMessage = game.hotOrNot(guessedValInt);
                    comunicator.SendMessage(stream, hotOrNotMessage);
                }

                game.score = game.score - 3;
            }
        }