Beispiel #1
0
        public AccountDialog(IGSAccount account) : base()
        {
            var hostTextBox = new TextBox()
            {
                Text = account.Server
            };
            var portUpDown = new NumericUpDown()
            {
                Minimum = 0,
                Maximum = UInt16.MaxValue,
                Value   = account.Port
            };
            var nameTextBox = new TextBox()
            {
                MaxLength = 10,
                Text      = account.Name
            };
            var passwordTextBox = new TextBox()
            {
                PasswordChar = '*',
                Text         = account.Password
            };
            var savePasswordCheckBox = new CheckBox()
            {
                Text    = "Save Password (plaintext)?",
                Checked = account.PasswordSpecified
            };

            getAccount = () =>
                         new IGSAccount(hostTextBox.Text,
                                        Convert.ToInt32(portUpDown.Value),
                                        nameTextBox.Text,
                                        passwordTextBox.Text,
                                        savePasswordCheckBox.Checked);

            foreach (var item in new Control[] { hostTextBox, portUpDown, nameTextBox, passwordTextBox, savePasswordCheckBox })
            {
                Layout.Resize(item);
            }

            Layout.Bind(
                Layout.PropertyTable(
                    Layout.Label("Host:"), hostTextBox,
                    Layout.Label("Port:"), portUpDown,
                    Layout.Label("Name:"), nameTextBox,
                    Layout.Label("Password:"), passwordTextBox,
                    null, savePasswordCheckBox),
                this);
        }
Beispiel #2
0
        public bool Connect(IGSAccount account)
        {
            try
            {
                EnsureNetworkConnection();
                tcpClient = new TcpClient(account.Server, account.Port);
            }
            catch (SocketException)
            {
                MessageBox.Show("Couldn't connect to " + account.Server + ":" + account.Port,
                                "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                return(false);
            }

            networkStream = tcpClient.GetStream();
            if (networkStream == null)
            {
                MessageBox.Show("Couldn't connect to " + account.Server + ":" + account.Port,
                                "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                return(false);
            }
            Connected = true;
            var guest = false;

            connectionTime = DateTime.Now;

            ReadUntil("Login:"******"1 1", "Password:"******"#>") != "#>")
            {
                WriteLine(account.Password);

                var line = ReadUntil("39 ", "1 5", "#>", "1 0", "Login:"******"1 0" || line == "Login:"******"Wrong password",
                                    "Error",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation,
                                    MessageBoxDefaultButton.Button1);
                    networkStream.Close();
                    Connected = false;

                    account.Password          = "";
                    account.PasswordSpecified = false;

                    return(false);
                }
            }
            else
            {
                MessageBox.Show("Logged as guest, some commands will be disabled",
                                "Note",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Asterisk,
                                MessageBoxDefaultButton.Button1);
                guest = true;
            }
            if (!Connected)
            {
                MessageBox.Show("Couldn't connect to " + account.Server + ":" + account.Port,
                                "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation,
                                MessageBoxDefaultButton.Button1);
                return(false);
            }

            listenerThread              = new Thread(Listen);
            listenerThread.Priority     = ThreadPriority.BelowNormal;
            listenerThread.IsBackground = true;
            listenerThread.Start();

            WriteLine("toggle client on");
            WriteLine("toggle quiet on");
            WriteLine("toggle newundo on");
            WriteLine("toggle nmatch on");
            WriteLine("toggle seek on");
            WriteLine("toggle review on");
            if (!guest)
            {
                WriteLine("nmatchrange BWN 0-9 2-19 0-900 0-3600 0-25 0 0 0-0");
                WriteLine("friend start");
            }

            CurrentAccount = account;

            return(true);
        }
Beispiel #3
0
 public IGSClient(IGSAccount account) : this()
 {
     Connect(account);
 }