예제 #1
0
 private void BCall_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count == 0)
     {
         MessageBox.Show("Nie wybrano żadnego znajomego!", "Błąd!");
     }
     else if (listView1.SelectedItems[0].ImageIndex == 0)
     {
         Program.client = new SynchronousClient(Program.serverAddress);
         Communique.CallState(Program.userLogin, listView1.SelectedItems[0].Text, DateTime.Now, TimeSpan.Zero);
         string[] historyDetails = new string[3];
         historyDetails[0] = listView1.SelectedItems[0].Text;
         historyDetails[1] = DateTime.Now.ToString();
         historyDetails[2] = "nieodebrane";
         listView2.Items.Insert(0, (new ListViewItem(historyDetails)));
         listView2.Refresh();
         MessageBox.Show("Znajomy nie jest dostępny! Wysłano powiadomienie o próbie nawiązania połączenia.", "Niedostępny znajomy!");
         Program.client.Disconnect();
     }
     else
     {
         LUserCallOut.Text = "z " + listView1.SelectedItems[0].Text.ToString();
         gBCallOut.Visible = true;
         Program.voice.Call();
         timerCallOut.Start();
         gBChangePass.Enabled = false;
         gBDelAcc.Enabled     = false;
     }
 }
예제 #2
0
        void waitForCommuniques()
        {
            string response     = String.Empty;
            int    numberOfComm = 0;

            string[] comms = null;
            while (!Program.secConv.Visible)
            {
            }
            while (numberOfComm < 2)
            {
                try
                {
                    response = Program.client.Receive();
                    if (response.Length > 0)
                    {
                        comms = response.Split(new string[] { " <EOF>" }, StringSplitOptions.None);
                        comms = comms.Take(comms.Length - 1).ToArray();
                        foreach (var comm in comms)
                        {
                            Communique.commFromServer(comm);
                            numberOfComm++;
                        }
                    }
                }
                catch (Exception)
                {
                    numberOfComm += comms.Length;
                }
            }
            Program.client.Disconnect();
        }
예제 #3
0
 private void BDeleteAccount_Click(object sender, EventArgs e)
 {
     if (TPassword.Text == "")
     {
         MessageBox.Show("Wymagane pole jest nieuzupełnione!", "Błąd!");
     }
     else
     {
         try
         {
             Program.client = new SynchronousClient(Program.serverAddress);
             if (Communique.AccDel(Program.userLogin, TPassword.Text) == true)
             {
                 MessageBox.Show("Usunięcie konta użytkownika " + Program.userLogin + " przebiegło pomyślnie!", "Sukces!");
                 DialogResult = DialogResult.No;
                 Program.client.Disconnect();
                 this.Close();
             }
             else
             {
                 Program.client.Disconnect();
                 MessageBox.Show("Podane dane logowania są niepoprawne!", "Błąd!");
             }
         }
         catch (Exception)
         {
             MessageBox.Show("Problem z połączeniem z serwerem!", "Błąd!");
         }
     }
 }
예제 #4
0
        private void BAddFriend_Click(object sender, EventArgs e)
        {
            string promptValue = Prompt.ShowDialog();

            if (promptValue != "" && promptValue != Program.userLogin)
            {
                try
                {
                    Program.client = new SynchronousClient(Program.serverAddress);
                    if (Communique.AddFriend(Program.userLogin, promptValue) == true)
                    {
                        MessageBox.Show("Pomyślnie dodano " + promptValue + " do znajomych!", "Sukces!");
                        string[]     friendDetails = { promptValue, "0" };
                        ListViewItem friend        = new ListViewItem(friendDetails, 0);
                        Program.secConv.listView1.Items.Add(friend);
                        listView1.Refresh();
                    }
                    else
                    {
                        MessageBox.Show("Nie znaleziono użytkownika o podanym loginie lub masz już go w znajomych!", "Błąd!");
                    }
                    Program.client.Disconnect();
                }
                catch (Exception)
                {
                    MessageBox.Show("Problem z połączeniem z serwerem!", "Błąd!");
                }
            }
        }
예제 #5
0
 private void BDeleteFriend_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count == 0)
     {
         MessageBox.Show("Nie wybrano żadnego znajomego!", "Błąd!");
     }
     else
     {
         try
         {
             Program.client = new SynchronousClient(Program.serverAddress);
             if (Communique.DelFriend(Program.userLogin, listView1.SelectedItems[0].Text) == true)
             {
                 MessageBox.Show("Pomyślnie usunięto " + listView1.SelectedItems[0].Text + " ze znajomych!", "Sukces!");
                 listView1.Items.Remove(listView1.SelectedItems[0]);
                 listView1.Refresh();
             }
             else
             {
                 MessageBox.Show("Nastąpił błąd podczas usuwania znajomego!", "Błąd!");
             }
             Program.client.Disconnect();
         }
         catch (Exception)
         {
             MessageBox.Show("Problem z połączeniem z serwerem!", "Błąd!");
         }
     }
 }
예제 #6
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     try
     {
         Program.client = new SynchronousClient(Program.serverAddress);
         Communique.Iam(Program.userLogin);
         Program.client.Disconnect();
     }
     catch (Exception)
     {  }
 }
예제 #7
0
 private void BRegister_Click(object sender, EventArgs e)
 {
     if (TLogin.Text == "" || TPassword1.Text == "" || TPassword2.Text == "" || TServerIP.Text == "")
     {
         MessageBox.Show("Przynajmniej jedno z wymaganych pól jest nieuzupełnione!", "Błąd!");
     }
     else if (TPassword1.Text != TPassword2.Text)
     {
         MessageBox.Show("Podane hasła nie są identyczne!", "Błąd!");
     }
     else
     {
         Regex regex = new Regex(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$");
         Match match = regex.Match(TPassword1.Text);
         if (match.Success)
         {
             try
             {
                 Program.client = new SynchronousClient(TServerIP.Text);
                 var serverKey = Communique.KeyExchange();
                 if (serverKey != null)
                 {
                     var sessKey = Program.security.SetSessionKey(serverKey);
                     if (Communique.Register(TLogin.Text, TPassword1.Text, sessKey) == true)
                     {
                         MessageBox.Show("Rejestracja użytkownika " + TLogin.Text + " przebiegła pomyślnie!", "Sukces!");
                         this.DialogResult = DialogResult.No;
                         this.Close();
                     }
                     else
                     {
                         MessageBox.Show("Podany login jest już zajęty!", "Błąd!");
                         Program.client.Disconnect();
                     }
                 }
                 else
                 {
                     Program.client.Disconnect();
                     MessageBox.Show("Problem z połączeniem z serwerem!", "Błąd!");
                 }
             }
             catch (Exception)
             {
                 MessageBox.Show("Problem z połączeniem z serwerem lub adres jest niepoprawny!", "Błąd!");
             }
         }
         else
         {
             MessageBox.Show("Hasło nie spełnia kryteriów!", "Błąd!");
         }
     }
 }
예제 #8
0
 private void BCancel_Click(object sender, EventArgs e)
 {
     timerCallOut.Stop();
     Program.voice.CancelCall();
     Program.client = new SynchronousClient(Program.serverAddress);
     Communique.CallState(Program.userLogin, listView1.SelectedItems[0].Text, DateTime.Now, TimeSpan.Zero);
     string[] historyDetails = new string[3];
     historyDetails[0] = listView1.SelectedItems[0].Text;
     historyDetails[1] = DateTime.Now.ToString();
     historyDetails[2] = "nieodebrane";
     listView2.Items.Insert(0, (new ListViewItem(historyDetails)));
     listView2.Refresh();
     Program.client.Disconnect();
     gBChangePass.Enabled = true;
     gBDelAcc.Enabled     = true;
 }
예제 #9
0
        private void SecConv_FormClosed(object sender, FormClosedEventArgs e)
        {
            timerIAM.Stop();
            if (commThread.IsAlive)
            {
                Program.client.Disconnect();
                commThread.Abort();
            }
            try
            {
                if (gBCallIn.Visible == true)
                {
                    BDecline_Click(null, null);
                }
                else if (gBCallOut.Visible == true)
                {
                    BCancel_Click(null, null);
                }
                else if (gbConv.Visible == true)
                {
                    BDisconnect_Click(null, null);
                }
                Program.client = new SynchronousClient(Program.serverAddress);
                Communique.LogOut(Program.userLogin);
                Program.client.Disconnect();
            }
            catch (Exception)
            {
                MessageBox.Show("Problem z połączeniem z serwerem!", "Błąd!");
            }
            Program.userLogin            = "";
            Program.serverAddress        = "";
            Program.sessionKeyWithServer = null;

            if (Program.voice.player != null)
            {
                Program.voice.player.Stop();
            }
            if (Program.voice.clientSocket != null)
            {
                Program.voice.clientSocket.Shutdown(SocketShutdown.Both);
                Program.voice.clientSocket.Close();
            }
            Program.voice = null;
        }
예제 #10
0
 private void BDisconnect_Click(object sender, EventArgs e)
 {
     end = DateTime.Now;
     timerConv.Stop();
     Program.voice.DropCall();
     //wyslij do serwera
     Program.client = new SynchronousClient(Program.serverAddress);
     if (isReceiver == true)
     {
         Communique.CallState(LUserConv.Text.Remove(0, 2), Program.userLogin, begin, (end - begin));
     }
     else
     {
         Communique.CallState(Program.userLogin, LUserConv.Text.Remove(0, 2), begin, (end - begin));
     }
     Program.client.Disconnect();
     isReceiver = false;
 }
예제 #11
0
 private void BChangePassword_Click(object sender, EventArgs e)
 {
     if (TPasswordOld.Text == "" || TPassword1.Text == "" || TPassword2.Text == "")
     {
         MessageBox.Show("Przynajmniej jedno z wymaganych pól jest nieuzupełnione!", "Błąd!");
     }
     else if (TPassword1.Text != TPassword2.Text)
     {
         MessageBox.Show("Podane hasła nie są identyczne!", "Błąd!");
     }
     else
     {
         Regex regex = new Regex(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$");
         Match match = regex.Match(TPassword1.Text);
         if (match.Success)
         {
             try
             {
                 Program.client = new SynchronousClient(Program.serverAddress);
                 if (Communique.PassChng(Program.userLogin, TPasswordOld.Text, TPassword1.Text) == true)
                 {
                     MessageBox.Show("Zmiana hasła przebiegła pomyślnie!\nZaloguj się ponownie!", "Sukces!");
                     DialogResult = DialogResult.No;
                     Program.client.Disconnect();
                     this.Close();
                 }
                 else
                 {
                     Program.client.Disconnect();
                     MessageBox.Show("Stare hasło jest niepoprawne!", "Błąd!");
                 }
             }
             catch (Exception)
             {
                 MessageBox.Show("Problem z połączeniem z serwerem!", "Błąd!");
             }
         }
         else
         {
             MessageBox.Show("Hasło nie spełnia kryteriów!", "Błąd!");
         }
     }
 }
예제 #12
0
 private void BLogIn_Click(object sender, EventArgs e)
 {
     if (TLogin.Text == "" || TPassword.Text == "" || TServerIP.Text == "")
     {
         MessageBox.Show("Przynajmniej jedno z wymaganych pól jest nieuzupełnione!", "Błąd!");
     }
     else
     {
         try
         {
             Program.client = new SynchronousClient(TServerIP.Text);
             var serverKey = Communique.KeyExchange();
             if (serverKey != null)
             {
                 var sessKey = Program.security.SetSessionKey(serverKey);
                 if (Communique.LogIn(TLogin.Text, TPassword.Text, sessKey) == true)
                 {
                     Program.userLogin            = TLogin.Text;
                     Program.serverAddress        = TServerIP.Text;
                     this.DialogResult            = DialogResult.Yes;
                     Program.sessionKeyWithServer = sessKey;
                     this.Close();
                 }
                 else
                 {
                     MessageBox.Show("Podane dane logowania są niepoprawne lub użytkownik jest już zalogowany!", "Błąd!");
                 }
             }
             else
             {
                 Program.client.Disconnect();
                 MessageBox.Show("Problem z połączeniem z serwerem!", "Błąd!");
             }
         }
         catch (Exception)
         {
             MessageBox.Show("Problem z połączeniem z serwerem lub adres jest niepoprawny!", "Błąd!");
         }
     }
 }
예제 #13
0
        /*
         * Commands are received asynchronously. OnReceive is the handler for them.
         */
        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                EndPoint receivedFromEP = new IPEndPoint(IPAddress.Any, 0);

                //Get the IP from where we got a message.
                clientSocket.EndReceiveFrom(ar, ref receivedFromEP);

                //Convert the bytes received into an object of type Data.
                string message = Encoding.ASCII.GetString(byteData);

                //Data msgReceived = new Data(byteData);
                //Act according to the received message.
                switch (message[0])
                {
                //We have an incoming call.
                case (char)10:
                {
                    if (Program.secConv.gBCallOut.Visible == true)
                    {
                        Program.secConv.Invoke((MethodInvoker) delegate
                            {
                                Program.secConv.timerCallOut.Stop();
                                Program.secConv.gBCallOut.Visible = false;
                                player.Stop();
                            });
                    }
                    player        = new System.Media.SoundPlayer();
                    player.Stream = Properties.Resources.Call1;
                    player.PlayLooping();
                    string msgTmp = string.Empty;
                    if (bIsCallActive == false)
                    {
                        //split message
                        //message = comm + " " + Program.userLogin + " " + vocoder + " <EOF>";
                        string [] msgTable = message.Split(' ');
                        //We have no active call.

                        //Ask the user to accept the call or not.
                        //if (MessageBox.Show("Call coming from " + msgReceived.strName + ".\r\n\r\nAccept it?",
                        //   "VoiceChat", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)

                        Program.secConv.Invoke((MethodInvoker) delegate
                            {
                                Program.secConv.gBCallIn.Visible     = true;
                                Program.secConv.LUserCallIn.Text     = msgTable[1];
                                Program.secConv.gBChangePass.Enabled = false;
                                Program.secConv.gBDelAcc.Enabled     = false;
                            });
                        Program.secConv.callerEndPoint = receivedFromEP;
                        Program.secConv.isReceiver     = true;
                        //Program.secConv.Refresh();
                    }
                    else
                    {
                        DeclineCall(receivedFromEP);
                    }
                    break;
                }

                //OK is received in response to an Invite.
                case (char)5:
                {
                    //callOut.Close();
                    //Start a call.
                    Program.secConv.Invoke((MethodInvoker) delegate
                        {
                            Program.secConv.timerCallOut.Stop();
                        });
                    InitializeCall();
                    break;
                }

                //Remote party is busy.
                case (char)6:     //FAIL
                {
                    player.Stop();
                    //send msg to DB with history

                    string[] historyDetails = new string[3];
                    if (Program.secConv.isReceiver == false)      //somebody call - you decline
                    {
                        Program.client = new SynchronousClient(Program.serverAddress);
                        Program.secConv.Invoke((MethodInvoker) delegate
                            {
                                Program.secConv.timerCallOut.Stop();
                                Communique.CallState(Program.userLogin, Program.secConv.listView1.SelectedItems[0].Text, DateTime.Now, TimeSpan.Zero);
                                historyDetails[0] = Program.secConv.listView1.SelectedItems[0].Text;
                            });
                        Program.client.Disconnect();

                        //Communique.CallState(Program.userLogin, Program.secConv.LUserCallIn.Text, DateTime.Now, TimeSpan.Zero);
                    }
                    else         //somebody call - somebody decline
                    {
                        historyDetails[0] = Program.secConv.LUserCallIn.Text;
                    }
                    //{
                    Program.secConv.isReceiver = false;
                    //}
                    //refresh user panel with histories


                    historyDetails[1] = DateTime.Now.ToString();
                    historyDetails[2] = "nieodebrane";
                    Program.secConv.listView2.Items.Insert(0, (new ListViewItem(historyDetails)));
                    Program.secConv.listView2.Refresh();
                    //disconect with server

                    //close ring panel
                    Program.secConv.Invoke((MethodInvoker) delegate
                        {
                            Program.secConv.gBCallIn.Visible     = false;
                            Program.secConv.gBChangePass.Enabled = true;
                            Program.secConv.gBDelAcc.Enabled     = true;
                        });
                    if (Program.secConv.gBCallOut.Visible == true)
                    {
                        Program.secConv.Invoke((MethodInvoker) delegate
                            {
                                Program.secConv.gBCallOut.Visible = false;
                            });
                        //CancelCall();
                        MessageBox.Show("Połączenie odrzucone.", "SecConv", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    break;
                }

                case (char)12:     //BYE
                {
                    //Check if the Bye command has indeed come from the user/IP with which we have
                    //a call established. This is used to prevent other users from sending a Bye, which
                    //would otherwise end the call.
                    if (receivedFromEP.Equals(otherPartyEP) == true)
                    {
                        //tu zatrzymaj timer
                        Program.secConv.timerConv.Stop();

                        //if (conv != null && !conv.IsDisposed)
                        //{
                        //    conv.Close();
                        //}
                        //End the call.
                        UninitializeCall();
                    }
                    break;
                }
                }

                byteData = new byte[1024];
                //Get ready to receive more commands.
                clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref receivedFromEP, new AsyncCallback(OnReceive), null);
            }
            catch (Exception)
            {
                //MessageBox.Show("Wystąpił problem podczas odbierania pakietów!", "OnReceive", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }