예제 #1
0
        public Utilizator()
        {
            pChat = new PrivateChat(this);
            InitializeComponent();



            // FormServer qq = new FormServer();
            Client = new ClientSettings();

            //  this.Text = "TCP Chat - " + ip + " - (Connected as: " + formLogin.getUser() + ")";
        }
예제 #2
0
        public void _client_Received(WindowsFormsApp3.ClientSettings cs, string received)
        {
            var cmd = received.Split('|');

            switch (cmd[0])
            {
            case "admin":

                this.Invoke(() =>
                {
                    if (getThisUser().Trim() == cmd[1])
                    {
                        this.Hide();
                        admin.ShowDialog();
                    }
                });
                break;

            case "Users":
                this.Invoke(() =>
                {
                    mListBoxUsersList.Items.Clear();
                    for (int i = 1; i < cmd.Length; i++)
                    {
                        if (cmd[i] != "Connected" | cmd[i] != "RefreshChat" | cmd[i] != "Poftim")
                        {
                            mListBoxUsersList.Items.Add(cmd[i]);
                        }
                    }
                });
                break;

            case "Message":
                this.Invoke(() =>
                {
                    mTextBoxReceiveMessages.Text += cmd[1] + "\r\n";

                    if (cmd[1] == "RefreshChat")
                    {
                        mListBoxUsersList.Items.Clear();
                        for (int i = 2; i < cmd.Length; i++)
                        {
                            if (cmd[i] != "Connected" | cmd[i] != "RefreshChat" | cmd[i] != "Message")
                            {
                                mListBoxUsersList.Items.Add(cmd[i]);
                            }
                            // mTextBoxReceiveMessages.Text += cmd[1] + "\r\n";
                        }
                    }
                });
                break;

            case ".":
                this.Invoke(() =>
                {
                    mListBoxUsersList.Items.Clear();
                    for (int i = 1; i < cmd.Length; i++)
                    {
                        mListBoxUsersList.Items.Add(cmd[i]);
                    }
                });
                break;

            //case "pMessage":
            //    this.Invoke(() =>
            //    {
            //        pChat.Text = pChat.Text.Replace("user", formLogin.getUser());
            //        pChat.Show();
            //    });
            case "AifostBanat":

                if (getThisUser().Trim() == cmd[1])
                {
                    MessageBox.Show("Ai fost banat!E irevocabil, bafta!");
                    this.Hide();
                }

                break;

            case "RefreshChat":
                this.Invoke(() =>
                {
                    //  mListBoxUsersList.Items.Clear();
                    //mListBoxUsersList.Items.Clear();
                    mTextBoxReceiveMessages.Text = cmd[1];

                    //for (int i = 2; i < cmd.Length; i++)
                    //{
                    //    if (cmd[i] != "Connected" | cmd[i] != "RefreshChat" | cmd[i] != "Message")
                    //    {
                    //        mListBoxUsersList.Items.Add(cmd[i]);
                    //    }
                    //    // mTextBoxReceiveMessages.Text += cmd[1] + "\r\n";
                    //}
                    //foreach (var item in cmd[2])
                    //{
                    //    mListBoxUsersList.Items.Add(cmd[2]);
                    //}
                });
                break;

            case "pMessage":
                this.Invoke(() =>
                {
                    //bool leg = false;
                    //foreach (var item in nrLegatura)
                    //{
                    //    if(item == cmd[4])
                    //    {
                    //        leg = true;
                    //    }
                    //}

                    // mTextBoxReceiveMessages.Text += cmd[1] + "\r\n";

                    //vorbitor = String.Empty;
                    //mesaj = String.Empty;
                    //// PrivateChat pc = new PrivateChat(this);
                    ////  MessageBox.Show("aoleu");
                    //mesaj = cmd[1].Trim();
                    //vorbitor = cmd[3].Trim();
                    //nrPrimit = String.Empty;

                    //nrPrimit = cmd[4].Trim();
                    //MessageBox.Show("a" + cmd[2].Trim());
                    //MessageBox.Show("a" +vorbitor);
                    //MessageBox.Show("a" +mesaj);
                    //MessageBox.Show("a" + nrPrimit);

                    //  mTextBoxReceiveMessages.Text = mesaj;



                    //MessageBox.Show("aoelu");
                    //pChat.Text = formLogin.getUser();
                    //pChat.Show();
                });


                break;

            case "mesajDecriptat":
                this.Invoke(() =>
                {
                    //bool leg = false;
                    //foreach (var item in nrLegatura)
                    //{
                    //    if(item == cmd[4])
                    //    {
                    //        leg = true;
                    //    }
                    //}

                    // mTextBoxReceiveMessages.Text += cmd[1] + "\r\n";
                    if (getThisUser().Trim() == cmd[2].Trim())
                    {
                        vorbitor = String.Empty;
                        mesaj    = String.Empty;
                        // PrivateChat pc = new PrivateChat(this);
                        //  MessageBox.Show("aoleu");
                        mesaj    = cmd[1].Trim();
                        vorbitor = cmd[2].Trim();
                        nrPrimit = String.Empty;

                        nrPrimit = cmd[4].Trim();
                        //MessageBox.Show("a" + cmd[2].Trim());
                        //MessageBox.Show("a" +vorbitor);
                        //MessageBox.Show("a" +mesaj);
                        //MessageBox.Show("a" + nrPrimit);

                        //  mTextBoxReceiveMessages.Text = mesaj;
                    }



                    //MessageBox.Show("aoelu");
                    //pChat.Text = formLogin.getUser();
                    //pChat.Show();
                });


                break;

            case "DeLaServerPtAlaCautat":
                this.Invoke(() =>
                {
                    if (getThisUser().Trim() == cmd[4].Trim())
                    {
                        byte[] mesaj1       = HttpServerUtility.UrlTokenDecode(cmd[1]);
                        byte[] chestie      = HttpServerUtility.UrlTokenDecode(cmd[2]);
                        byte[] cheiePublica = HttpServerUtility.UrlTokenDecode(cmd[3]);
                        mesaj    = String.Empty;
                        mesaj    = r.Receive(mesaj1, chestie, cheiePublica);
                        nrPrimit = String.Empty;
                        vorbitor = String.Empty;
                        vorbitor = getThisUser();
                        nrPrimit = cmd[5].Trim();
                    }
                });


                break;


            case "cheieServerReceiver":
                this.Invoke(() =>
                {
                    if (cmd[3].Trim() == getThisUser())
                    {
                        ServerCheie = String.Empty;
                        ServerCheie = cmd[1].Trim();
                        //nrPrimit = String.Empty;
                        //nrPrimit = cmd[2].Trim();


                        byte[] cheieServer = HttpServerUtility.UrlTokenDecode(ServerCheie);
                        s.Mesaj(cheieServer);

                        byte[] mesajCriptat    = s.sendToReceiver(cheieServer, nou);
                        byte[] chestiaAia      = s.sendChestiaAia();
                        byte[] senderPublicKey = s.getSenderPublicKey();
                        string mesajul         = HttpServerUtility.UrlTokenEncode(mesajCriptat);
                        string chestie         = HttpServerUtility.UrlTokenEncode(chestiaAia);
                        string cheiePublica    = HttpServerUtility.UrlTokenEncode(senderPublicKey);
                        //   MessageBox.Show("in utilizator sender   ::: " + mesajul);
                        formLogin.Client.Send("mesajCriptat|" + getThisUser().Trim() + "|" + cmd[2].Trim() + "|" + nrCautat + "|" + mesajul + "|" + chestie + "|" + cheiePublica);
                    }
                    else if (cmd[4].Trim() == getThisUser())
                    {
                        System.Threading.Thread.Sleep(100);
                        byte[] receiverPublicKey    = r.ReceiverPublicKey();
                        string cheiePublicaReceiver = HttpServerUtility.UrlTokenEncode(receiverPublicKey);
                        //MessageBox.Show("in utilizator receiver cheie   ::: " + cheiePublicaReceiver);
                        formLogin.Client.Send("CheieReceiver|" + getThisUser().Trim() + "|" + cmd[2].Trim() + "|" + cheiePublicaReceiver);     //acesta + nr + cheiaMea
                    }
                    // nrPrimit = String.Empty;
                });
                break;

            case "privateChat":
                this.Invoke(() =>
                {
                    // mTextBoxReceiveMessages.Text += cmd[1] + "\r\n";
                    if (getThisUser().Trim() == cmd[1].Trim())
                    {
                        //string[] str = null;
                        //list.Trim();
                        //list.ToString();
                        //str = list.Split('+');
                        //  recipient = cmd[1].Trim();
                        string t       = cmd[3].Trim();
                        persoana       = cmd[2].Trim();
                        PrivateChat pc = new PrivateChat(this);
                        pc.MyProperty  = t;
                        // recipient = getThisUser().Trim();
                        //   persoana = cmd[2].Trim();
                        verificare = true;
                        // ala = cmd[2].Trim();
                        //  qwe.Add(cmd[2].Trim());


                        //  MessageBox.Show("aoleu");
                        pc.Text = cmd[2].Trim();
                        pc.Show();
                    }
                    if (getThisUser().Trim() == cmd[2].Trim())
                    {
                        string t       = cmd[3].Trim();
                        PrivateChat cc = new PrivateChat(this);
                        cc.MyProperty  = t;
                        cc.Text        = getUserForPChat();
                        cc.Show();
                        verificare = false;
                        //cc.Text = getUserForPChat();
                        //cc.Client = Client;
                        // qwe.Add(cmd[1].Trim());
                    }

                    //MessageBox.Show("aoelu");
                    //pChat.Text = formLogin.getUser();
                    //pChat.Show();
                });
                break;

            case "LogInFailed":
                if (getThisUser().Trim() == cmd[1].Trim())
                {
                    MessageBox.Show("UserName sau Password gresite");
                    Application.Restart();
                }
                break;

            case "Disconnect":
                this.Invoke(() =>
                {
                    if (getThisUser().Trim() == cmd[1].Trim())
                    {
                        // mListBoxUsersList.Items.Clear();
                        this.Hide();
                    }
                });
                break;

            case "Ban":
                this.Invoke(() =>
                {
                    if (getThisUser().Trim() == cmd[1].Trim())
                    {
                        // mListBoxUsersList.Items.Clear();
                        this.Hide();
                    }
                });
                break;
                //     default:
                //         this.Invoke(() =>
                //{
                //    mListBoxUsersList.Items.Clear();
                //    for (int i = 1; i < cmd.Length; i++)
                //    {
                //        if (cmd[i] != "Users" | cmd[i] != "Connected" | cmd[i] != "RefreshChat" | cmd[i] != "Message")
                //        {
                //            mListBoxUsersList.Items.Add(cmd[i]);
                //        }
                //        mTextBoxReceiveMessages.Text += cmd[1] + "\r\n";
                //    }
                //});
                //         break;
            }
        }