public async void LoginToServerAsync()
        {
            if (loginForm.nameTx == string.Empty || loginForm.passTx == string.Empty)
            {
                MessageBox.Show("All the fields must be filled", "Empty field", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            TcpClient     TC     = new TcpClient("127.0.0.1", 5222);
            NetworkStream stream = TC.GetStream();
            XMPPclient    Xmpp   = new XMPPclient(stream, TC);
            int           x      = await Xmpp.auth2Async(loginForm.nameTx, loginForm.passTx);

            if (x == 1)
            {
                //failure
                MessageBox.Show("Username or Password incorrect", "Incorrect credentials", MessageBoxButtons.OK, MessageBoxIcon.Information);
                TC.Close();
                stream.Close();
            }
            else if (x == 0)
            {
                staticData.TC       = TC;
                staticData.stream   = stream;
                staticData.Xmpp     = Xmpp;
                staticData.Server   = Xmpp.server;
                staticData.Resource = Xmpp.Resource;
                staticData.Username = loginForm.nameTx;
                loginForm.Hide();
                var main = new MainWindow();
                main.Show();
            }
        }
Beispiel #2
0
        public async void RegisterToServerAsync()
        {
            if (RF.Pass1Txt == string.Empty || RF.Pass2Txt == string.Empty || RF.NameTx == string.Empty)
            {
                MessageBox.Show("All the fields must be filled", "Empty field", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (RF.Pass2Txt != RF.Pass1Txt)
            {
                MessageBox.Show("Passwords do not match", "No match", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //logic
            TcpClient     TC     = new TcpClient("127.0.0.1", 5222);
            NetworkStream stream = TC.GetStream();
            XMPPclient    Xmpp   = new XMPPclient(stream, TC);

            try
            {
                int x = await Xmpp.registerAsync(RF.NameTx, RF.Pass1Txt);

                if (x == 409)
                {
                    MessageBox.Show("The Username is already in use", "Username in use", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    stream.Close();
                    TC.Close();
                }
                else if (x == 500)
                {
                    MessageBox.Show("Can't create accounts so fast. Wait a moment.", "WOOOSH! Too fast bruh!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    stream.Close();
                    TC.Close();
                    Application.Exit();
                }
                else if (x > 0)
                {
                    MessageBox.Show("Unknown error occured. Try again later.", "Oh snap!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    stream.Close();
                    TC.Close();
                }
                else
                {
                    MessageBox.Show("Account successfuly created", "Registrations success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    stream.Close();
                    TC.Close();
                    RF.Close();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Except");
                Console.WriteLine(await Xmpp.receiveMsgAsync());
            }
        }