public MainWindow() { InitializeComponent(); DataContext = this; Client = new Client(); var registered = false; do { var input = new UserNameInput(); input.ShowDialog(); var name = input.NicknameBox.Text.Trim(); try { registered = Client.Register(name); } catch (EndpointNotFoundException) { MessageBox.Show("Cannot connect to server, are you sure it is running?", "No server found", MessageBoxButton.OK, MessageBoxImage.Error); Close(); return; } if (!registered) { MessageBox.Show("There is already a user with selected username, please choose another one!", "Username already exist", MessageBoxButton.OK, MessageBoxImage.Information); } } while (!registered); Client.SendConnectionMessage(); Client.MessageIncomeEvent += ClientOnMessageIncomeEvent; Client.NewUserJoinedEvent += ClientOnNewUserJoinedEvent; Client.UserDisconnectEvent += ClientOnUserDisconnectEvent; Client.UserIsOnlineEvent += ClientOnUserIsOnlineEvent; Client.ImageMessageIncomeEvent += ClientOnImageMessageIncomeEvent; ChatBox.IsReadOnly = true; ReceiverComboBox.Items.Add("All"); ReceiverComboBox.SelectedIndex = 0; Title += $": {Client.Name}"; FocusManager.SetFocusedElement(this, InputBox); ChatBox.Document = new FlowDocument(); }
static void Main() { Client = new Client("127.0.0.1", 13000); StartMessageHandleThread(); while (IsApplicationExecuting) { Console.WriteLine("(l) Login with existing account"); Console.WriteLine("(r) Register a new account"); var loginRegisterInput = Console.ReadKey(); if (loginRegisterInput.Key == ConsoleKey.L) { Console.Clear(); Console.WriteLine("Login:"******"Username: "******"Password: "******"Connecting to server."); Client.Connect(username, password); while (Client.IsConnecting) { } if (Client.IsConnected) { Client.CheckSavedMessages(username); } while (Client.IsConnected) { Console.WriteLine("Nachricht eingeben:"); var input = Console.ReadLine(); if (input.StartsWith("/user") && input != "/users") { ReturnId(input); } else if (input.StartsWith("/message")) { Client.SendDirectMessage(input); continue; } else { switch (input) { case "/users": PrintUsers(); break; case "/disconnect": Client.Disconnect(); break; case "/exit": Client.Disconnect(); IsApplicationExecuting = false; break; default: Client.SendChatMessage(input); break; } } } } if (loginRegisterInput.Key == ConsoleKey.R) { Console.Clear(); Console.WriteLine("Register"); Console.WriteLine("Username: "******"Password: "); var password = Console.ReadLine(); Client.Register(username, password); } } }
static void Main() { Client = new Client("127.0.0.1", 13000); StartMessageHandleThread(); while (IsApplicationExecuting) { Console.WriteLine("Do you want to login (l) or to register (r)?"); var loginRegisterInput = Console.ReadKey(); if (loginRegisterInput.Key == ConsoleKey.L) { Console.Clear(); Console.WriteLine("Login"); Console.WriteLine("Username: "******"Password: "******"Connecting to server."); Client.Connect(username, password); while (Client.IsConnecting) { } while (Client.IsConnected) { Console.WriteLine("Nachricht eingeben:"); var input = Console.ReadLine(); switch (input) { case "/disconnect": Client.Disconnect(); break; case "/exit": Client.Disconnect(); IsApplicationExecuting = false; break; default: Client.SendChatMessage(input); break; } } } if (loginRegisterInput.Key == ConsoleKey.R) { Console.Clear(); Console.WriteLine("Register"); Console.WriteLine("Username: "******"Password: "); var password = Console.ReadLine(); Client.Register(username, password); } } }