Beispiel #1
0
        private void login_Click(object sender, EventArgs e)
        {
            Boolean             error    = false;
            String              pseudo   = usernameBox.Text;
            String              password = passwordText.Text;
            ClientTopicsManager client   = new ClientTopicsManager();

            try { // Client connection to the server
                client.setServer("127.0.0.1", 2453);
                client.connect();
            } catch (SocketException exception) {
                error = true;
                MessageBox.Show(exception.Message, "Error server", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (pseudo.Equals(""))
            {
                MessageBox.Show("Use an username", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (password == "")
            {
                MessageBox.Show("Use a password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                List <String> log = new List <String>();
                log.Add(pseudo);
                log.Add(password);

                client.sendMessage(new Projet.net.Message(Header.LOGIN, log));
                Projet.net.Message response = client.getMessage();
                if (response == null)
                {
                    error = true; // Exception occured : server not started
                }
                else if (response.Data[0].Equals("ok"))
                {
                    error = false;
                }
                else
                {
                    error = true;
                    MessageBox.Show(response.Data[0], "Login error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            if (error == false)
            {
                Form chat = new Form2(client, pseudo, password);
                chat.Show();
                this.Hide();
            }
        }
Beispiel #2
0
 public Form2(ClientTopicsManager client, String pseudo, String password)
 {
     transm.AddReceiveDel(receiveMessage);
     this.client   = client;
     this.pseudo   = pseudo;
     this.password = password;
     this.topic    = "";
     this.Text     = pseudo;
     InitializeComponent();
     textChat   += new UpdateChat(this.showText);
     textTopic  += new UpdateTopic(this.showTopic);
     textMember += new UpdateMember(this.showMember);
     showTopic();
 }
Beispiel #3
0
        private void signup_Click(object sender, EventArgs e)
        {
            String pseudo              = usernameBox.Text;
            String password            = passwordText.Text;
            ClientTopicsManager client = new ClientTopicsManager();

            try { // Client connection to the server
                client.setServer("127.0.0.1", 2453);
                client.connect();
            } catch (SocketException exception) {
                MessageBox.Show(exception.Message, "Error server", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }


            if (pseudo.Equals(""))
            {
                MessageBox.Show("Use an username", "Error");
            }
            else if (password == "")
            {
                MessageBox.Show("Use a password", "Error");
            }
            else
            {
                List <String> log = new List <String>();
                log.Add(pseudo);
                log.Add(password);

                client.sendMessage(new Projet.net.Message(Header.REGISTRATION, log));
                Projet.net.Message response = client.getMessage();

                if (response == null)
                {
                    // Exception occured : server not started
                }
                else if (response.Data[0] == "ok")
                {
                    MessageBox.Show("Successful registration !", "Sign up", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    MessageBox.Show(response.Data[0], "Sign up error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            ClientTopicsManager ctm = new ClientTopicsManager();

            ctm.SetServer("127.0.0.1", 26763);
            ctm.Connect();
            Console.WriteLine("Create user, Connect with a name and password");

            string name     = Console.ReadLine();
            string password = Console.ReadLine();
            string error    = "";

            if (ctm.Login(name, password, ref error))
            {
                List <string> topics = ctm.ListTopics();

                if (!topics.Contains("Jeux Vidéo"))
                {
                    ctm.CreateTopic("Jeux Vidéo");
                }


                ClientChatRoom clientChatRoom = (ClientChatRoom)ctm.JoinTopic("Jeux Vidéo");
                TextChatter    c = new TextChatter(name);
                clientChatRoom.Join(c);
                string quit = "no";
                while (quit == "no")
                {
                    string msg = Console.ReadLine();

                    if (msg == "yes")
                    {
                        quit = msg;
                    }
                    clientChatRoom.Post(msg, c);
                }
                clientChatRoom.Disconnect();
                ctm.Disconnect();
            }


            Console.Read();
        }