clean up
This commit is contained in:
Andrin Fassbind 2022-04-16 22:01:59 +02:00
parent 6498b8ab33
commit a189fedd76
2 changed files with 3 additions and 5 deletions

View File

@ -66,7 +66,4 @@ public class Message implements Serializable {
return text; return text;
} }
public void setSender(String sender) {
this.sender = sender;
}
} }

View File

@ -169,7 +169,6 @@ public class ServerConnectionHandler extends ConnectionHandler implements Runnab
*/ */
private void caseConnect(Message data) throws ChatProtocolException { private void caseConnect(Message data) throws ChatProtocolException {
if (this.state != NEW) throw new ChatProtocolException("Illegal state for connect request: " + state); 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 username not valid
if (connectionRegistry.containsKey(data.getSender())) { if (connectionRegistry.containsKey(data.getSender())) {
state = ERROR; state = ERROR;
@ -179,7 +178,9 @@ public class ServerConnectionHandler extends ConnectionHandler implements Runnab
throw new ChatProtocolException("User name already taken: " + data.getSender()); throw new ChatProtocolException("User name already taken: " + data.getSender());
} }
//if username valid //if username valid
if (!data.getSender().isBlank()) {
this.userName = data.getSender(); this.userName = data.getSender();
}
connectionRegistry.put(userName, this); connectionRegistry.put(userName, this);
sendData(USER_NONE, userName, getDataTypeConfirm(), "Registration successful for " + userName); sendData(USER_NONE, userName, getDataTypeConfirm(), "Registration successful for " + userName);
this.state = CONNECTED; this.state = CONNECTED;