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; }); }
internal static void GetCurrentProfilePicture(string CurrentUser) { Bitmap CurrentProfilePicture = new Bitmap(ProfilePictures[Usernames.IndexOf(CurrentUser)]); CurrentProfilePicture.Save(AppDomain.CurrentDomain.BaseDirectory + "CurrentProfilePicture.png", ImageFormat.Png); MainWindowController.MainWindow.Dispatcher.Invoke(() => { ImageBrush ProfilePictureBrush = new ImageBrush(AuxiliaryClientWorker.BitmapToBitmapImage(CurrentProfilePicture)); ProfilePictureBrush.Stretch = Stretch.UniformToFill; MainWindowController.MainPage.UserProfilePicture.Fill = ProfilePictureBrush; }); }
internal static void UpdateUserProfilePicture(string UserToUpdate, byte[] Data) { byte[] DataToUse = Data; ProfilePictures[Usernames.IndexOf(UserToUpdate)] = AuxiliaryClientWorker.GetBitmapFromBytes(Data); if (UserToUpdate == LoginClientWorker.CurrentUser) { MainWindowController.MainWindow.Dispatcher.Invoke(() => { ImageBrush NewProfilePictureBrush = new ImageBrush(AuxiliaryClientWorker.BitmapToBitmapImage(AuxiliaryClientWorker.GetBitmapFromBytes(DataToUse))); MainWindowController.MainPage.UserProfilePicture.Fill = NewProfilePictureBrush; }); } }
internal static void DoAuthentication(string Username, string Password) { AntVaultClient.BytesReceived += MainClientWorker.AntVaultClient_BytesReceived; AntVaultClient.StartClient("AntVault.ddns.net", 8910); CurrentUser = Username; try { AntVaultClient.SendBytes(AuxiliaryClientWorker.MessageByte("/NewConnection -U " + Username + " -P " + Password + "."));//NewConnection -U Username -P Password. } catch { MessageBox.Show("Server is offline, therefore the authentication process could not take place, please try again later!", "Error! Server offline!", MessageBoxButton.OK, MessageBoxImage.Error); } }
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 RequestStatus(SimpleSocketClient AntVaultClient, string CurrentUser) { AntVaultClient.SendBytes(AuxiliaryClientWorker.MessageByte("/RequestStatus -U " + CurrentUser + "."));//RequestStatus -U Username. }
internal static void RequestProfilePictures(SimpleSocketClient AntVaultClient, string CurrentUser)//RequestProfilePictures -U Username. { AntVaultClient.SendBytes(AuxiliaryClientWorker.MessageByte("/RequestProfilePictures -U " + CurrentUser + ".")); }
internal static void SendMessage(string Message) { LoginClientWorker.AntVaultClient.SendBytes(AuxiliaryClientWorker.MessageByte("/Message -U " + LoginClientWorker.CurrentUser + " -Content " + Message + ".")); }
internal static void UpdateStatus(string NewStatus) { LoginClientWorker.AntVaultClient.SendBytes(AuxiliaryClientWorker.MessageByte("/UpdateStatus -U " + LoginClientWorker.CurrentUser + " -Content " + NewStatus + ".")); }
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); } }
internal static void UpdateUsername(SimpleSocketClient AntVaultClient, string CurrentUsername, string NewUsername)//UpdateUsername -U OldUsername -Content NewUsername. { AntVaultClient.SendBytes(AuxiliaryClientWorker.MessageByte("/UpdateUsername -U " + CurrentUsername + " -Content " + NewUsername + ".")); }
internal static void UpdatePassword(SimpleSocketClient AntVaultClient, string OldPassword, string NewPassword)//UpdatePassword -P OldPassword -Content NewPassword. { AntVaultClient.SendBytes(AuxiliaryClientWorker.MessageByte("/UpdatePassword -P " + OldPassword + " -Content " + NewPassword + ".")); }
internal static void UpdateProfilePicture(SimpleSocketClient AntVaultClient, byte[] NewProfilePictureBytes)//UpdateProfilePicture //byte[] //EndUpdateProfilePicture { AntVaultClient.SendBytes(AuxiliaryClientWorker.MessageByte("/UpdateProfilePicture")); Thread.Sleep(500); AntVaultClient.SendBytes(NewProfilePictureBytes); }