Merge pull request #36 from PM2-IT21bWIN-ruiz-mach-krea/SpecialCharacterUsername

Special character username
This commit is contained in:
Roman Schenk 2022-04-14 20:39:05 +02:00 committed by GitHub Enterprise
commit 4a998b0f61
2 changed files with 15 additions and 12 deletions

View File

@ -106,18 +106,22 @@ public class ChatWindowController {
private void startConnectionHandler() throws IOException { private void startConnectionHandler() throws IOException {
String userName = userNameField.getText(); String userName = userNameField.getText();
String serverAddress = serverAddressField.getText(); if(!userName.contains(" ")) {
int serverPort = Integer.parseInt(serverPortField.getText()); String serverAddress = serverAddressField.getText();
connectionHandler = new ClientConnectionHandler( int serverPort = Integer.parseInt(serverPortField.getText());
NetworkHandler.openConnection(serverAddress, serverPort), userName, connectionHandler = new ClientConnectionHandler(
messages); NetworkHandler.openConnection(serverAddress, serverPort), userName,
new Thread(connectionHandler).start(); messages);
new Thread(connectionHandler).start();
//register Listener //register Listener
startListener(); startListener();
// register window close handler // register window close handler
rootPane.getScene().getWindow().addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, windowCloseHandler); rootPane.getScene().getWindow().addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, windowCloseHandler);
} else {
addError("It is not allowed to have spaces in username!");
}
} }
private void terminateConnectionHandler() { private void terminateConnectionHandler() {

View File

@ -28,7 +28,7 @@ public class ClientConnectionHandler implements Runnable {
public static final String USER_NONE = ""; public static final String USER_NONE = "";
public static final String USER_ALL = "*"; 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 SimpleStringProperty userName;
private SimpleObjectProperty<State> state; private SimpleObjectProperty<State> state;
@ -63,7 +63,6 @@ public class ClientConnectionHandler implements Runnable {
public void setState (State newState) { public void setState (State newState) {
state.set(newState); state.set(newState);
} }
public void run () { public void run () {