/// <summary> /// /// </summary> public void processServerClose() { string serverClosingMessage = SETMessengerUtilities.makeMessage(false, StatusCode.ServerClosing, "Closing server"); sendBroadcastMessage(serverClosingMessage); closeServerFlag = true; }
/* * Name: btnSend_Click * Description: This function sends the text that is in the message box, to either * a specific person, or to everyone in the chat */ private void btnSend_Click(object sender, RoutedEventArgs e) { string message = txtMsg.Text; //cuts out blank spaces from the messages on either end if (message.Trim().Length > 0) { //if the user is in the ALL tab if (tbControl.SelectedItem == tbAll) { txtAll.Text += "You: " + message + "\n"; scrollAll.ScrollToBottom(); message = SETMessengerUtilities.makeMessage(true, StatusCode.All, Alias, "all", message); } //if the user is in the private tab else if (tbControl.SelectedItem == tbPrivate) { txtPrivate.Text += "(" + selected + ") You: " + message + "\n"; scrollPrivate.ScrollToBottom(); message = SETMessengerUtilities.makeMessage(true, StatusCode.Whisper, Alias, selected, message); } //sends the message ClientPipe.sendMessage(message); if (!ClientPipe.connected) { MessageBox.Show("The server had an unexpected shutdown. Closing application now...", "Server Fault"); this.Close(); } //clears the message box and sets focus to it txtMsg.Clear(); txtMsg.Focus(); } }
private void processClientDisconnect(string who) { if (userList.ContainsKey(who)) { string disconnectMessage = SETMessengerUtilities.makeMessage(false, StatusCode.ClientDisconnected, who); //delete user when disconnect userList.Remove(who); sendBroadcastMessage(disconnectMessage); } }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="machineName"></param> private void processClientConnect(string name, string machineName) { //adds this user to the user list userList.Add(name, machineName); string connectMessage = SETMessengerUtilities.makeMessage(false, StatusCode.ClientConnected, name); sendBroadcastMessage(connectMessage); sendUserlist(machineName); }
private void processWhisper(string from, string to, string message) { string machineName = ""; if (userList.TryGetValue(to, out machineName) == true) { //contruct the whisper to send string messageToSend = SETMessengerUtilities.makeMessage(false, StatusCode.Whisper, from, message); //send the message sendMsg(messageToSend, machineName); } }
/// <summary> /// /// </summary> public void close() { if (MessageQueue.Exists(mQueueName)) { mq.Close(); mq.Dispose(); MessageQueue.Delete(mq.Path); } if (ClientPipe.connected) { string message = SETMessengerUtilities.makeMessage(true, StatusCode.ClientDisconnected, MainWindow.Alias); ClientPipe.sendMessage(message); ClientPipe.disconnect(); } }
/* * Name: btnConnect_Click * Description: The function handles when the user clicks the connect button. * if both the alias field and the server name field are filled out, * the client will try to connect to the server. */ private void btnConnect_Click(object sender, RoutedEventArgs e) { if (checkEmpty(txtAlias, txtServerName)) { //colons are not allowed, GET OUT OF HERE TROLLS while (txtAlias.Text.Contains(':')) { int index = txtAlias.Text.IndexOf(':'); txtAlias.Text.Remove(index, 1); } //take out white spaces on either side of the string MainWindow.Alias = txtAlias.Text.Trim(); ClientPipe.ServerName = txtServerName.Text; //try to connect to the server try { ClientPipe.connectToServer(); string msg = SETMessengerUtilities.makeMessage(true, StatusCode.ClientConnected, MainWindow.Alias); //send the connection message to the server ClientPipe.sendMessage(msg); ClientPipe.connected = true; //closes the start up window so the main window can run this.Close(); } catch (TimeoutException) { MessageBox.Show("Your connection time out, make sure you typed the server name correctly", "Connection Timeout Error"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } } }
/* * Name: processBroadcast * Parameters: string from -> this is the user name of the client that sent the message * string message -> this is the message to be sent to everyone on the user list * Description: This function sends a message to everyone on the user list, and tags the message * with the user name of the client who sent it. */ private void processBroadcast(string from, string message) { string messageToSend = SETMessengerUtilities.makeMessage(false, StatusCode.All, from, message); sendBroadcastMessage(messageToSend); }