Exemplo n.º 1
0
 // File => Disconnect
 private void DisconnectToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!ClientNetworkEngine.Status)
     {
         return;
     }
     foreach (TabPage tabPage in TabControlClient.TabPages)
     {
         if (TabPagePrivateChatReceiveClientEvent != null)
         {
             TabPagePrivateChatReceiveClientEvent.Invoke(tabPage.Name, null, null, TabPagePrivateChatClient.TabCommand.Disconnected);
         }
     }
     ClientNetworkEngine.Disconnect();
     ClientStatistics.Stop();
     Thread.Sleep(50);
     BtnPubSnd.Enabled = false;
     Text = @"Chat: " + Client.Name + @"[Disconnected]";
     RichTextClientPub.SelectionStart     = _CursorPosition;
     RichTextClientPub.SelectionColor     = Color.Black;
     RichTextClientPub.SelectionBackColor = Color.Crimson;
     RichTextClientPub.SelectedText       = @"You are disonnected now " + Environment.NewLine;
     _CursorPosition = RichTextClientPub.SelectionStart;
     ListBoxClientList.Items.Clear();
     _ClientChatHistoryList.Clear();
 }
Exemplo n.º 2
0
 // Private stopped
 private void PrivateStopped(string clientName)
 {
     if (TabPagePrivateChatReceiveClientEvent != null)
     {
         TabPagePrivateChatReceiveClientEvent.Invoke(clientName, null, null, TabPagePrivateChatClient.TabCommand.Closed);
     }
 }
Exemplo n.º 3
0
 // Private start
 private void PrivateStart(string clientNamePrivate)
 {
     if (TabControlClient.TabPages.Cast <TabPage>().Any(tabPagePrivateChat => tabPagePrivateChat.Name == clientNamePrivate))
     {
         if (TabPagePrivateChatReceiveClientEvent != null)
         {
             TabPagePrivateChatReceiveClientEvent.Invoke(clientNamePrivate, null, null, TabPagePrivateChatClient.TabCommand.Resumed);
         }
         return;
     }
     Invoke(new Action((delegate
     {
         NewTabPagePrivateChatClient(clientNamePrivate);
         TabFormat.ItemEvenSize(TabControlClient);
     })));
 }
Exemplo n.º 4
0
 // Private message
 private void PrivateMessage(string clientName, string clientNamePrivate, string message)
 {
     if (TabPagePrivateChatReceiveClientEvent != null)
     {
         TabPagePrivateChatReceiveClientEvent.Invoke(clientName, clientNamePrivate, message, TabPagePrivateChatClient.TabCommand.Message);
     }
     if (Client.Name == clientNamePrivate)
     {
         ++ClientStatistics.MessagesPrivateReceived;
         FrmStatisticsUpdateEvent.Invoke(StatisticsEntry.MessagePrivateReceived);
         return;
     }
     ++ClientStatistics.MessagesPrivateSent;
     if (FrmStatisticsUpdateEvent != null)
     {
         FrmStatisticsUpdateEvent.Invoke(StatisticsEntry.MessagePrivateSent);
     }
 }
Exemplo n.º 5
0
 // Disconnect
 private void Disconnect()
 {
     ClientStatistics.Stop();
     Invoke(new Action((delegate
     {
         if (TabPagePrivateChatReceiveClientEvent != null)
         {
             TabPagePrivateChatReceiveClientEvent.Invoke(null, null, null, TabPagePrivateChatClient.TabCommand.Disconnect);
         }
         BtnPubSnd.Enabled = false;
         ListBoxClientList.Items.Clear();
         RichTextClientPub.SelectionStart = _CursorPosition;
         RichTextClientPub.SelectionColor = Color.Black;
         RichTextClientPub.SelectionBackColor = Color.Tomato;
         RichTextClientPub.SelectedText = Time.NowTime() + " Disconnected from the server" + Environment.NewLine;
         _CursorPosition = RichTextClientPub.SelectionStart;
     })));
 }
Exemplo n.º 6
0
        // Name change
        private void NameChange(string clientName, string clientNameNew, Color color)
        {
            Invoke(new Action((delegate
            {
                int index = ListBoxClientList.FindString(clientName);
                ListBoxClientList.Items[index] = clientNameNew;

                foreach (ClientChatHistory clientColor in _ClientChatHistoryList.Where(ClientChatHistory => ClientChatHistory.Name == clientName))
                {
                    clientColor.Name = clientNameNew;
                }
                RichTextClientPub.SelectionStart = _CursorPosition;
                RichTextClientPub.SelectionColor = Color.Black;
                RichTextClientPub.SelectionBackColor = Color.CornflowerBlue;
                RichTextClientPub.SelectedText = Time.NowTime() + " " + @"<<< " + clientName + @" have changed nickname to " + clientNameNew + @" >>>" + Environment.NewLine;
                _CursorPosition = RichTextClientPub.SelectionStart;
                if (Client.Name == clientNameNew)
                {
                    Text = @"Chat: " + clientNameNew;
                }
                if (TabPagePrivateChatReceiveClientEvent != null)
                {
                    TabPagePrivateChatReceiveClientEvent.Invoke(clientName, null, clientNameNew, TabPagePrivateChatClient.TabCommand.NameChange);
                }
                foreach (TabPage tabPage in TabControlClient.TabPages.Cast <TabPage>().Where(tabPage => tabPage.Name == clientName))
                {
                    tabPage.Name = clientNameNew;
                    tabPage.Text = clientNameNew;
                    TabControlClient.Invalidate();
                }
                TabFormat.ItemEvenSize(TabControlClient);
            })));
            Invoke(new Action((delegate
            {
                _FrmClientImages.Text = clientNameNew + @" Received Images";
            })));
            if (FrmClientImagesChangeNameEvent != null)
            {
                FrmClientImagesChangeNameEvent.Invoke(clientName, clientNameNew);
            }
            ColorChanged(clientName, color);
        }
Exemplo n.º 7
0
 // Logout
 private void Logout(string clientName, string message)
 {
     Invoke(new Action((delegate
     {
         ListBoxClientList.Items.Remove(clientName);
         for (int i = 0; i < _ClientChatHistoryList.Count; i++)
         {
             if (_ClientChatHistoryList[i].Name == clientName)
             {
                 _ClientChatHistoryList.Remove(_ClientChatHistoryList[i]);
                 if (TabPagePrivateChatReceiveClientEvent != null)
                 {
                     TabPagePrivateChatReceiveClientEvent.Invoke(clientName, null, null, TabPagePrivateChatClient.TabCommand.Disconnected);
                 }
             }
         }
         RichTextClientPub.SelectionStart = _CursorPosition;
         RichTextClientPub.SelectionColor = Color.Black;
         RichTextClientPub.SelectionBackColor = Color.Tomato;
         RichTextClientPub.SelectedText = Time.NowTime() + " " + message + Environment.NewLine;
         _CursorPosition = RichTextClientPub.SelectionStart;
     })));
 }
Exemplo n.º 8
0
        // Image message
        private void ImageMessage(string clientName, string clientNamePrivate, Image img)
        {
            if (clientNamePrivate != null)
            {
                if (Client.Name == clientName)
                {
                    ++ClientStatistics.ImagesPrivateSent;
                    if (FrmStatisticsUpdateEvent != null)
                    {
                        FrmStatisticsUpdateEvent.Invoke(StatisticsEntry.ImagesPrivateSent);
                    }
                    // Let the user know that the private photo he sent went thro
                    if (TabPagePrivateChatReceiveClientEvent != null)
                    {
                        TabPagePrivateChatReceiveClientEvent.Invoke(clientName, null, null, TabPagePrivateChatClient.TabCommand.ImageMessageSent);
                    }
                    return;
                }
                // Show the photo to the receiving user
                ++ClientStatistics.ImagesPrivateReceived;
                if (FrmStatisticsUpdateEvent != null)
                {
                    FrmStatisticsUpdateEvent.Invoke(StatisticsEntry.ImagesPrivateReceived);
                }
                _FrmClientImages.NewImage(img, clientName + " Private");
                if (TabPagePrivateChatReceiveClientEvent != null)
                {
                    TabPagePrivateChatReceiveClientEvent.Invoke(clientName, null, null, TabPagePrivateChatClient.TabCommand.ImageMessage);
                }
                if (_FrmClientImages.Visible == false)
                {
                    if (InvokeRequired)
                    {
                        BeginInvoke(new MethodInvoker(delegate
                        {
                            _FrmClientImages.Visible = true;
                            _FrmClientImages.BringToFront();
                        }));
                    }
                    else
                    {
                        _FrmClientImages.Visible = true;
                        _FrmClientImages.BringToFront();
                    }
                }
                return;
            }

            if (Client.Name == clientName)
            {
                ++ClientStatistics.ImagesSent;
                if (FrmStatisticsUpdateEvent != null)
                {
                    FrmStatisticsUpdateEvent.Invoke(StatisticsEntry.ImagesSent);
                }
                Invoke(new Action((delegate
                {
                    RichTextClientPub.SelectionStart = _CursorPosition;
                    RichTextClientPub.SelectionColor = Color.Black;
                    RichTextClientPub.SelectionBackColor = Color.Yellow;
                    RichTextClientPub.SelectedText = Time.NowTime() + " " + " ImageMessage sent successfully" + Environment.NewLine;
                    _CursorPosition = RichTextClientPub.SelectionStart;
                })));
                return;
            }
            ++ClientStatistics.ImagesReceived;
            if (FrmStatisticsUpdateEvent != null)
            {
                FrmStatisticsUpdateEvent.Invoke(StatisticsEntry.ImagesReceived);
            }
            _FrmClientImages.NewImage(img, clientName);
            if (_FrmClientImages.Visible == false)
            {
                if (InvokeRequired)
                {
                    BeginInvoke(new MethodInvoker(delegate
                    {
                        _FrmClientImages.Visible = true;
                        _FrmClientImages.BringToFront();
                    }));
                }
                else
                {
                    _FrmClientImages.Visible = true;
                    _FrmClientImages.BringToFront();
                }
            }
        }