Beispiel #1
0
 private void RequestConvo(object sender, EventArgs e)
 {
     try
     {
         KeyValuePair <User, IPEndPoint> keyVal = onlineUsers.ElementAt(this.dataGridView1.CurrentCell.RowIndex);
         if (keyVal.Key.Nick != null && keyVal.Key.Nick != "" && keyVal.Key.Nick != self.Nick)
         {
             if (chatWindow.ChatStarted(keyVal.Key.Nick))
             {
                 chatWindow.Show();
             }
             else
             {
                 IMessenger iMessenger = (IMessenger)RemotingServices.Connect(typeof(IMessenger), Util.URL(keyVal.Value));
                 if (iMessenger.ProcessRequest(self))
                 {
                     chatWindow.NewTab(self, keyVal.Key, keyVal.Value);
                     chatWindow.Show();
                 }
                 else
                 {
                     MessageBox.Show(keyVal.Key.Nick + " refused your request", "Refused", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message + " -- " + ex.StackTrace);
     }
 }
Beispiel #2
0
        private void OpenChatWindow()
        {
            ChatWindow chatWindow = new ChatWindow(this.usernameBox.Text);

            chatWindow.Show();
            Close();
        }
        private void Connector_PrivateMessageEvent(object sender, MessageDictionary e)
        {
            bool   found        = false;
            Sender s            = (Sender)Enum.Parse(typeof(Sender), e[MesKeyStr.Sender]);
            string targetUserID = s == Sender.others ? e[MesKeyStr.UserID] : e[MesKeyStr.TargetUserID];

            foreach (ChatWindow cw in privateWindows)
            {
                if (cw.TargetUser.UserID.Equals(targetUserID))
                {
                    found = true;
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        cw.MessageArrive(e);
                    });
                }
            }
            if (found == false)
            {
                User       target     = new User(e[MesKeyStr.UserID], e[MesKeyStr.NickName]);
                ChatWindow chatWindow = null;
                Application.Current.Dispatcher.Invoke(() =>
                {
                    chatWindow = new ChatWindow(target);
                    chatWindow.ManualCloseEvent += ChatWindow_ManualCloseEvent;
                    chatWindow.Show();
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        chatWindow.MessageArrive(e);
                    });
                });
                privateWindows.Add(chatWindow);
            }
        }
Beispiel #4
0
        private void OpenChatWindow() //On successful login takes the user to the ChatWindow
        {
            ChatWindow chatWindow = new ChatWindow(this.usernameBox.Text);

            chatWindow.Show();
            Close();
        }
 public void PushMessage(String mess, Boolean isMe)
 {
     chatWindow.Dispatcher.Invoke(() =>
     {
         chatWindow.Show();
         chatWindow.PushMessage(mess, false);
     });
 }
 public void StartChatting()
 {
     currentUser     = ((App)Application.Current).CurrentUser;
     GroupChatWindow = new ChatWindow();
     GroupChatWindow.PrivateChatEvent += GroupChatWindow_PrivateChatEvent;
     GroupChatWindow.Closed           += GroupChatWindow_Closed;
     GroupChatWindow.Show();
 }
        private void GroupChatWindow_PrivateChatEvent(object sender, User e)
        {
            foreach (ChatWindow cw in privateWindows)
            {
                if (cw.TargetUser.UserID.Equals(e.UserID))
                {
                    cw.Activate();
                    return;
                }
            }
            ChatWindow privateChatWindow = new ChatWindow(e);

            privateChatWindow.ManualCloseEvent += ChatWindow_ManualCloseEvent;
            privateWindows.Add(privateChatWindow);
            privateChatWindow.Show();
        }
Beispiel #8
0
        private void btn_join_Click(object sender, RoutedEventArgs e)
        {
            string username = txt_username.Text;

            if (!ValidateUsername(username))
            {
                MessageBox.Show("Type in a valid username.", "", MessageBoxButton.OK);
                return;
            }

            ClientChatImpl.ClientName = username;
            ClientChatImpl.UserEnteredChat();
            var window = new ChatWindow();

            window.Show(); // open the chat window

            Close();       // closes this window
        }
Beispiel #9
0
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            string username = txbUsername.Text;
            string password = txbPassword.Text;

            bool isAccepted = this._loginService.CheckLogin(username, password);

            if (isAccepted)
            {
                ChatWindow chatWindow = new ChatWindow(username, _messageService);
                this.Close();
                chatWindow.Show();
            }
            else
            {
                lblError.Content = "Username or password is invalid";
            }
        }
Beispiel #10
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            if (this.CheckIfLegalIPAddress(this.ipAddressTextBox.Text) == false)
            {
                MessageBox.Show("Please enter a legal IPv4 address!", "Chat", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            }
            else if (CheckIfLegalPort(this.portTextBox.Text) == false)
            {
                MessageBox.Show("The port must be between 3000 and 9000!", "Chat", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            }
            else if (this.usernameTextBox.Text.ToCharArray().Length < 3)
            {
                MessageBox.Show("The username must be at least 3 characters long!", "Chat", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            }
            else
            {
                this.networkWatcher = new NetworkWatcher(IPAddress.Parse(this.ipAddressTextBox.Text), int.Parse(this.portTextBox.Text));
                this.networkWatcher.ConnectionLost += this.ConnectionLost;
                this.networkWatcher.DataReceived   += this.DataReceived;
                this.networkWatcher.Start();

                if (this.networkWatcher.Connected == true)
                {
                    this.networkWatcher.Send(ProtocolCreator.LogIn(this.usernameTextBox.Text));

                    if (this.WaitForSessionKey(1000) == true)
                    {
                        this.networkWatcher.ConnectionLost -= this.ConnectionLost;
                        this.networkWatcher.DataReceived   -= this.DataReceived;
                        this.Hide();

                        ChatWindow chatWindow = new ChatWindow(this.usernameTextBox.Text, this.sessionkey, this.networkWatcher);
                        chatWindow.FormClosed += this.ChatWindowClosed;
                        chatWindow.Show();
                    }
                }
            }
        }
Beispiel #11
0
        private void Start_Chat(object sender, EventArgs e)
        {
            ChatWindow chatWindow = new ChatWindow((sender as Button).Text);

            chatWindow.Show();
        }