Esempio n. 1
0
        private void ButtonConnect_Click(object sender, RoutedEventArgs e)
        {
            ServerWindow okno      = new ServerWindow();
            bool         connected = true;

            if (connected)
            {
                SoundSender soundSender = new SoundSender();
                soundSender.Send(soundSender.Get_privateIP(), 2000);

                this.Close();
                okno.ShowDialog();
            }
            else
            {
                MessageBox.Show("PUPA, nie połączyłeś się :/", "",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 2
0
        //try to connect with server
        private void ButtonConnect_Click(object sender, RoutedEventArgs e)
        {
            bool valid = true;

            string login    = TextBoxLogin.Text;
            string password = TextBoxPassword.Password;
            var    selected = ComboBoxServerList.SelectedItem;

            SaveLastNickname(login);
            string ip   = "";
            int    port = 0;

            if (String.IsNullOrEmpty(login))
            {
                TextBoxLogin.BorderBrush = new SolidColorBrush(Colors.Red);
                WarningLogin.Visibility  = Visibility.Visible;
                valid = false;
            }

            if (selected == null)
            {
                if (!String.IsNullOrEmpty(ComboBoxServerList.Text))
                {
                    Match match = MatchIP(ComboBoxServerList.Text);
                    if (match.Success)
                    {
                        ComboBoxServerList.BorderBrush = new SolidColorBrush(Color.FromRgb(Convert.ToByte("89"), Convert.ToByte("000"), Convert.ToByte("000")));
                        WarningSerwer.Visibility       = Visibility.Hidden;

                        string[] tab = match.Value.Split(':');

                        ip   = tab[0];
                        port = Int32.Parse(tab[1]);
                    }
                    else
                    {
                        ComboBoxServerList.BorderBrush = new SolidColorBrush(Colors.Red);
                        WarningSerwer.Visibility       = Visibility.Visible;
                        valid = false;
                    }
                }
            }
            else
            {
                var x = selected as ServerInfo;

                Match match = MatchIP(x.IP + ":" + x.Port);
                if (match.Success)
                {
                    ComboBoxServerList.BorderBrush = new SolidColorBrush(Color.FromRgb(Convert.ToByte("89"), Convert.ToByte("000"), Convert.ToByte("000")));
                    WarningSerwer.Visibility       = Visibility.Hidden;

                    ip   = x.IP;
                    port = Int32.Parse(x.Port);
                }
                else
                {
                    ComboBoxServerList.BorderBrush = new SolidColorBrush(Colors.Red);
                    WarningSerwer.Visibility       = Visibility.Visible;
                    Console.WriteLine("No match.");
                    valid = false;
                }
            }

            if (valid)
            {
                TCPManager client = new TCPManager(ip, port);

                string connected = client.Connect(login, password);

                string[] data = connected.Split('/');
                switch (data[0])
                {
                case "BAD_CHECKSUM":
                    Console.WriteLine("EROR-------WRONG CHECKSUM");
                    MessageBox.Show("Nie udało się zalogować do serwera.", "",
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                    break;

                case "FULL":
                    MessageBox.Show("Serwer jest pełen.", "",
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                    break;

                case "LOGIN_ACK":
                    ServerWindow okno = new ServerWindow(client, data[1]);
                    okno.Left = this.Left;
                    okno.Top  = this.Top;
                    this.Close();
                    okno.ShowDialog();

                    break;

                case "LOGIN_NAK":
                    MessageBox.Show("Niepoprawne hasło.", "",
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                    break;

                default:
                    MessageBox.Show(connected, "Not Connected",
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                    break;
                }
            }
        }