Chat adjustments:
-Multiple lines are now cut off before sending, and are not printed to sender chat -"something went wrong while whispering" is now printed to chat rather than console -Chat message is sent to lobby rather than broadcast, from the start -whispering person sees who they whisper to
This commit is contained in:
parent
a6fac4c1b3
commit
c89eb7c5de
@ -10,7 +10,6 @@ import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ClientPinger;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.server.JServerProtocolParser;
|
||||
import java.net.InetAddress;
|
||||
import java.net.Socket;
|
||||
import java.io.*;
|
||||
@ -32,7 +31,7 @@ public class Client {
|
||||
public ClientPinger clientPinger;
|
||||
|
||||
private ChatApp chatApp;
|
||||
private GUI chatGUi;
|
||||
private GUI chatGui;
|
||||
|
||||
/**
|
||||
* Saves the position of the client, gets refreshed everytime the client gets a vote request.
|
||||
@ -62,8 +61,8 @@ public class Client {
|
||||
}
|
||||
sendMsgToServer(Protocol.clientLogin + "$" + systemName);
|
||||
this.chatApp = new ChatApp(new ClientModel(systemName, this));
|
||||
this.chatGUi = new GUI(this.chatApp);
|
||||
chatGUi.setName(systemName);
|
||||
this.chatGui = new GUI(this.chatApp);
|
||||
chatGui.setName(systemName);
|
||||
clientPinger = new ClientPinger(this, this.socket);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@ -251,7 +250,7 @@ public class Client {
|
||||
cP.start();
|
||||
client.userInputListener(); //this one blocks.
|
||||
LOGGER.info("7.1");
|
||||
Thread guiThread = new Thread(client.chatGUi);
|
||||
Thread guiThread = new Thread(client.chatGui);
|
||||
LOGGER.info("8");
|
||||
guiThread.start();
|
||||
LOGGER.info("9");
|
||||
|
||||
@ -56,7 +56,7 @@ public class ChatController implements Initializable {
|
||||
public ChatController() { //TODO: why does this get called
|
||||
super();
|
||||
whisperTargetChosen = new SimpleBooleanProperty();
|
||||
cmd = "CHATA$";
|
||||
cmd = Protocol.chatMsgToLobby + "$";
|
||||
LOGGER.info("ChatController empty constructor used");
|
||||
}
|
||||
|
||||
@ -102,19 +102,21 @@ public class ChatController implements Initializable {
|
||||
});
|
||||
|
||||
/**
|
||||
* Initialize what heppens when the sen button is pressed
|
||||
* Initialize what happens when the sen button is pressed
|
||||
*/
|
||||
sendButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent event) {
|
||||
String msg = chatMsgField.getText();
|
||||
String msg = chatMsgField.getText().split("\\R")[0]; //cut off extra lines, if present.
|
||||
if (!msg.isEmpty()) {
|
||||
client.getClient().sendMsgToServer(cmd.toString() + msg);
|
||||
LOGGER.info("Message trying to send is: " + cmd.toString() + msg);
|
||||
Label l = new Label(client.getUsername() + " (you): " + msg);
|
||||
if (cmd.contains(whisper)) {
|
||||
Label l;
|
||||
if (cmd.startsWith(whisper)) {
|
||||
l = new Label("You whispered to " + whisperTargetSelectField.getText() + ": " + msg);
|
||||
l.setBackground(Background.fill(Color.LAVENDERBLUSH));
|
||||
} else {
|
||||
l = new Label(client.getUsername() + " (you): " + msg);
|
||||
l.setBackground(Background.fill(Color.LAVENDER));
|
||||
}
|
||||
vBoxChatMessages.getChildren().add(l);
|
||||
|
||||
@ -275,7 +275,7 @@ public class ClientHandler implements Runnable {
|
||||
Protocol.printToClientChat + "$" + this.getClientUserName() + " whispers: " + msg);
|
||||
/*sendMsgToClient(
|
||||
Protocol.printToClientChat + "$You whispered to " + target.getClientUserName() + ": "
|
||||
+ msg);*/ // no confirmation messge needed. will be colorcoded in gui
|
||||
+ msg);*/ // no confirmation message needed. will be colorcoded in gui
|
||||
LOGGER.info(
|
||||
Protocol.printToClientChat + "$You whispered to " + target.getClientUserName() + ": "
|
||||
+ msg);
|
||||
@ -301,7 +301,7 @@ public class ClientHandler implements Runnable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a whisper mesage
|
||||
* Decode a whisper message
|
||||
*
|
||||
* @param msg to decode. the command has been removed from the front
|
||||
* @return a String[] containing the target at index 0 and the message at index 1.
|
||||
|
||||
@ -51,8 +51,6 @@ public class JServerProtocolParser {
|
||||
String[] targetAndMsg = h.decodeWhisper(msg.substring(6));
|
||||
String targetName = targetAndMsg[0];
|
||||
String chatMsg = targetAndMsg[1];
|
||||
System.out.println(targetName);
|
||||
System.out.println(chatMsg);
|
||||
for (ClientHandler c : ClientHandler.getConnectedClients()) {
|
||||
if (c.getClientUserName().equals(targetName)) {
|
||||
target = c;
|
||||
@ -61,7 +59,7 @@ public class JServerProtocolParser {
|
||||
assert target != null;
|
||||
h.whisper(chatMsg, target);
|
||||
} catch (Exception ignored) {
|
||||
h.sendAnnouncementToClient("Something went wrong.");
|
||||
h.sendMsgToClient(Protocol.printToClientChat + "$Something went wrong while whispering.");
|
||||
}
|
||||
break;
|
||||
case Protocol.clientLogin:
|
||||
|
||||
Reference in New Issue
Block a user