private static void HandleMessage(string MessageString) { string Sender = AuxiliaryClientWorker.GetElement(MessageString, "-U ", " -Content"); string Message = AuxiliaryClientWorker.GetElement(MessageString, "-Content ", "."); MainWindowController.MainWindow.Dispatcher.Invoke(() => { #region Profile picture before the text System.Windows.Shapes.Ellipse ImageToShowFrame = new System.Windows.Shapes.Ellipse(); ImageToShowFrame.Height = 30; ImageToShowFrame.Width = 30; ImageToShowFrame.Stroke = System.Windows.Media.Brushes.Black; ImageToShowFrame.StrokeThickness = 1.5; ImageBrush ImageToShowBrush = new ImageBrush(AuxiliaryClientWorker.BitmapToBitmapImage(ProfilePictures[Usernames.IndexOf(Sender)])); ImageToShowFrame.Fill = ImageToShowBrush; ImageToShowFrame.MouseLeftButtonDown += This; #endregion MainWindowController.ChatParagraph.Inlines.Add(ImageToShowFrame); #region Text to add after the profile picture System.Windows.Controls.Label TextToShow = new System.Windows.Controls.Label(); TextToShow.FontSize = 16; TextToShow.Foreground = System.Windows.Media.Brushes.Black; TextToShow.Content = "[" + Sender + "]: " + Message; #endregion MainWindowController.ChatParagraph.Inlines.Add(TextToShow); MainWindowController.ChatParagraph.Inlines.Add(Environment.NewLine); MainWindowController.ChatDocument.Blocks.Add(MainWindowController.ChatParagraph); MainWindowController.MainPage.ClientChatTextBox.Document = MainWindowController.ChatDocument; }); }
internal static void SetStatus(string MessageString)//SendStatus -Content Status. { string CurrentStatus = AuxiliaryClientWorker.GetElement(MessageString, "-Content ", "."); MainWindowController.MainWindow.Dispatcher.Invoke(() => { MainWindowController.MainPage.StatusTextBox.Text = CurrentStatus; }); }
private static void HandleStatus(string MessageString) { string Sender = AuxiliaryClientWorker.GetElement(MessageString, "-U ", " -Content"); string Message = AuxiliaryClientWorker.GetElement(MessageString, "-Content ", "."); MainWindowController.MainWindow.Dispatcher.Invoke(() => { #region Status updater System.Windows.Controls.Label StatusLabel = new System.Windows.Controls.Label(); StatusLabel.FontSize = 18; StatusLabel.FontStyle = FontStyles.Oblique; StatusLabel.FontStyle = FontStyles.Italic; StatusLabel.Foreground = System.Windows.Media.Brushes.Black; StatusLabel.MouseLeftButtonDown += This; StatusLabel.Content = Sender + " has updated their status to " + Message; #endregion MainWindowController.ChatParagraph.Inlines.Add(StatusLabel); MainWindowController.ChatParagraph.Inlines.Add(Environment.NewLine); MainWindowController.ChatDocument.Blocks.Add(MainWindowController.ChatParagraph); MainWindowController.MainPage.ClientChatTextBox.Document = MainWindowController.ChatDocument; }); }
private static void HandleNewUser(SimpleSocketClient AntVaultClient, string MessageString) { string Sender = AuxiliaryClientWorker.GetElement(MessageString, "-U ", "."); RequestUsersList(AntVaultClient, LoginClientWorker.CurrentUser); MainWindowController.MainWindow.Dispatcher.Invoke(() => { #region New user joined pulse System.Windows.Controls.Label StatusLabel = new System.Windows.Controls.Label(); StatusLabel.FontSize = 18; StatusLabel.FontStyle = FontStyles.Oblique; StatusLabel.FontStyle = FontStyles.Italic; StatusLabel.Foreground = System.Windows.Media.Brushes.Black; StatusLabel.MouseLeftButtonDown += This; StatusLabel.Content = Sender + " has joined the vault!"; #endregion MainWindowController.ChatParagraph.Inlines.Add(StatusLabel); MainWindowController.ChatParagraph.Inlines.Add(Environment.NewLine); MainWindowController.ChatDocument.Blocks.Add(MainWindowController.ChatParagraph); MainWindowController.MainPage.ClientChatTextBox.Document = MainWindowController.ChatDocument; }); }
internal static void AntVaultClient_BytesReceived(SimpleSocketClient AntVaultClient, byte[] MessageBytes) { string MessageString = AuxiliaryClientWorker.MessageString(MessageBytes); if (MessageString.StartsWith("/AcceptConnection")) { Thread LoginThread = new Thread(() => DoLogin(LoginClientWorker.CurrentUser)); LoginThread.Start(); Thread UsersListThread = new Thread(() => RequestUsersList(AntVaultClient, LoginClientWorker.CurrentUser)); UsersListThread.Start(); } if (MessageString.StartsWith("/SendStatus")) { SetStatus(MessageString); Thread.Sleep(200); RequestFriendsList(AntVaultClient, LoginClientWorker.CurrentUser); } if (MessageString.StartsWith("/SendUsernames") || ReceivingUsernames == true) { if (MessageString.StartsWith("/SendUsernames") == true && ReceivingUsernames == false) { ReceivingProfilePictureUpdatePulse = false; ReceivingFriendsList = false; ReceivingProfilePictures = false; ReceivingUsernames = true; } else if (MessageString.StartsWith("/SendUsernames") == false && ReceivingUsernames == true) { ReceivingUsernames = false; Usernames = AuxiliaryClientWorker.GetStringsFromBytes(MessageBytes); RequestProfilePictures(AntVaultClient, LoginClientWorker.CurrentUser); } } if (MessageString.StartsWith("/SendProfilePictures") || ReceivingProfilePictures == true) { if (MessageString.StartsWith("/SendProfilePictures") == true && ReceivingProfilePictures == false) { ReceivingProfilePictureUpdatePulse = false; ReceivingFriendsList = false; ReceivingUsernames = false; ReceivingProfilePictures = true; } else if (MessageString.StartsWith("/SendProfilePicures") == false && ReceivingProfilePictures == true) { ReceivingProfilePictures = false; ProfilePictures = AuxiliaryClientWorker.GetPicturesFromBytes(MessageBytes);//Last data request GetCurrentProfilePicture(LoginClientWorker.CurrentUser); RequestStatus(AntVaultClient, LoginClientWorker.CurrentUser); } } if (MessageString.StartsWith("/SendFriendsList") || ReceivingFriendsList == true) { if (MessageString.StartsWith("/SendFriendsList") == true && ReceivingFriendsList == false) { ReceivingProfilePictureUpdatePulse = false; ReceivingProfilePictures = false; ReceivingUsernames = false; ReceivingFriendsList = true; } else if (MessageString.StartsWith("/SendFriendsList") == false && ReceivingFriendsList == true) { ReceivingFriendsList = false; FriendsList = AuxiliaryClientWorker.GetStringsFromBytes(MessageBytes); GetFriendsList(); } } if (MessageString.StartsWith("/Message")) { Thread MessageThread = new Thread(() => HandleMessage(MessageString)); MessageThread.Start(); } if (MessageString.StartsWith("/UpdateStatus"))//UpdateStatus -U Username -Content Msg. { HandleStatus(MessageString); } if (MessageString.StartsWith("/UserUpdatedPicture") || ReceivingProfilePictureUpdatePulse == true)//UserUpdatedPicture -U + UsernameToUpdate. { if (SenderDefined == false) { UpdateSender = AuxiliaryClientWorker.GetElement(MessageString, "-U ", "."); SenderDefined = true; } if (MessageString.StartsWith("/UserUpdatedPicture") == true && ReceivingProfilePictureUpdatePulse == false) { ReceivingFriendsList = false; ReceivingProfilePictures = false; ReceivingUsernames = false; ReceivingProfilePictureUpdatePulse = true; } else if (MessageString.StartsWith("/UserUpdatedPicture") == false && ReceivingProfilePictureUpdatePulse == true) { UpdateUserProfilePicture(UpdateSender, MessageBytes); ReceivingProfilePictureUpdatePulse = false; SenderDefined = false; } } if (MessageString.StartsWith("/UserConnected")) { HandleNewUser(AntVaultClient, MessageString); } }