Beispiel #1
0
        private void login_button_Click(object sender, EventArgs e)
        {
            //start connection
            this.serverConnection = new ServerConnection();

            UserName = username.Text;

            PacketLogin loginPacket = new PacketLogin()
            {
                username = username.Text, password = password.Text
            };

            this.serverConnection.WritePacket(loginPacket);

            Packet _packet            = this.serverConnection.ReadPacket();
            PacketLoginResponse login = _packet as PacketLoginResponse;

            if (login != null)
            {
                if (login.loginOk)
                {
                    this.Hide();
                    new Client(this.serverConnection, username.Text, login.number).Show();
                    Console.WriteLine("good login");
                }
                else
                {
                    Console.WriteLine("failed login");
                }
            }
        }
Beispiel #2
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            try
            {
                //MessageBox.Show("check1");
                client = new TcpClient(Info.GetIp().ToString(), Info.Port);
                stream = client.GetStream();
            }
            catch (Exception)
            {
                MessageBox.Show("No connection with the server");
                Thread.CurrentThread.Abort();
            }
            //MessageBox.Show("check2");
            formatter = new BinaryFormatter();
            formatter.Serialize(stream, new PacketMonitor());

            //MessageBox.Show("check3");
            Packet loginPacket = new PacketLogin()
            {
                username = userNameTextBox.Text, password = passwordTextBox.Text
            };

            formatter.Serialize(stream, loginPacket);

            //MessageBox.Show("check4");
            PacketLoginResponse response = (PacketLoginResponse)formatter.Deserialize(stream);

            loginResponse(response.loginOk, response.dir);
            //loginResponse(true);
        }