From b47d98b9603d635b1462b0b2d20438a2c4c4acbb Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Thu, 14 Apr 2022 12:11:03 +0200 Subject: [PATCH 1/2] fixed Issue #19 by changing messagePattern --- .../ch/zhaw/pm2/multichat/client/ClientConnectionHandler.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/src/main/java/ch/zhaw/pm2/multichat/client/ClientConnectionHandler.java b/client/src/main/java/ch/zhaw/pm2/multichat/client/ClientConnectionHandler.java index 9da83da..9ff948a 100644 --- a/client/src/main/java/ch/zhaw/pm2/multichat/client/ClientConnectionHandler.java +++ b/client/src/main/java/ch/zhaw/pm2/multichat/client/ClientConnectionHandler.java @@ -28,7 +28,7 @@ public class ClientConnectionHandler implements Runnable { public static final String USER_NONE = ""; public static final String USER_ALL = "*"; - private final Pattern messagePattern = Pattern.compile( "^(?:@(\\w*))?\\s*(.*)$" ); + private final Pattern messagePattern = Pattern.compile( "^(?:@(\\S*))?\\s*(.*)$" ); private SimpleStringProperty userName; private SimpleObjectProperty state; @@ -63,7 +63,6 @@ public class ClientConnectionHandler implements Runnable { public void setState (State newState) { state.set(newState); - } public void run () { From b6fd5b569d08a2494f7afc13228647ab401c32c9 Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Thu, 14 Apr 2022 19:33:18 +0200 Subject: [PATCH 2/2] fixed Issue #28 by checking if username contains space before starting connection --- .../client/ChatWindowController.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java b/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java index 1a8a9c6..c657f44 100644 --- a/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java +++ b/client/src/main/java/ch/zhaw/pm2/multichat/client/ChatWindowController.java @@ -106,18 +106,22 @@ public class ChatWindowController { private void startConnectionHandler() throws IOException { String userName = userNameField.getText(); - String serverAddress = serverAddressField.getText(); - int serverPort = Integer.parseInt(serverPortField.getText()); - connectionHandler = new ClientConnectionHandler( - NetworkHandler.openConnection(serverAddress, serverPort), userName, - messages); - new Thread(connectionHandler).start(); + if(!userName.contains(" ")) { + String serverAddress = serverAddressField.getText(); + int serverPort = Integer.parseInt(serverPortField.getText()); + connectionHandler = new ClientConnectionHandler( + NetworkHandler.openConnection(serverAddress, serverPort), userName, + messages); + new Thread(connectionHandler).start(); - //register Listener - startListener(); + //register Listener + startListener(); - // register window close handler - rootPane.getScene().getWindow().addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, windowCloseHandler); + // register window close handler + rootPane.getScene().getWindow().addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, windowCloseHandler); + } else { + addError("It is not allowed to have spaces in username!"); + } } private void terminateConnectionHandler() {