From a189fedd7633c4bc69c6789cd0fc3f886eba429b Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Sat, 16 Apr 2022 22:01:59 +0200 Subject: [PATCH] fixed #49 clean up --- .../main/java/ch/zhaw/pm2/multichat/protocol/Message.java | 3 --- .../zhaw/pm2/multichat/server/ServerConnectionHandler.java | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) 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;