diff --git a/protocol/src/main/java/ch/zhaw/pm2/multichat/protocol/Message.java b/protocol/src/main/java/ch/zhaw/pm2/multichat/protocol/Message.java index d64ee80..9509b0f 100644 --- a/protocol/src/main/java/ch/zhaw/pm2/multichat/protocol/Message.java +++ b/protocol/src/main/java/ch/zhaw/pm2/multichat/protocol/Message.java @@ -66,7 +66,4 @@ public class Message implements Serializable { return text; } - public void setSender(String sender) { - this.sender = sender; - } } diff --git a/server/src/main/java/ch/zhaw/pm2/multichat/server/ServerConnectionHandler.java b/server/src/main/java/ch/zhaw/pm2/multichat/server/ServerConnectionHandler.java index 0dda2e7..0dc8aee 100644 --- a/server/src/main/java/ch/zhaw/pm2/multichat/server/ServerConnectionHandler.java +++ b/server/src/main/java/ch/zhaw/pm2/multichat/server/ServerConnectionHandler.java @@ -169,7 +169,6 @@ public class ServerConnectionHandler extends ConnectionHandler implements Runnab */ private void caseConnect(Message data) throws ChatProtocolException { if (this.state != NEW) throw new ChatProtocolException("Illegal state for connect request: " + state); - if (data.getSender().isBlank()) data.setSender(this.userName); //if username not valid if (connectionRegistry.containsKey(data.getSender())) { state = ERROR; @@ -179,7 +178,9 @@ public class ServerConnectionHandler extends ConnectionHandler implements Runnab throw new ChatProtocolException("User name already taken: " + data.getSender()); } //if username valid - this.userName = data.getSender(); + if (!data.getSender().isBlank()) { + this.userName = data.getSender(); + } connectionRegistry.put(userName, this); sendData(USER_NONE, userName, getDataTypeConfirm(), "Registration successful for " + userName); this.state = CONNECTED;