Legger til sjekk for unikt spillernavn

This commit is contained in:
Kristian Knarvik 2020-04-07 15:12:00 +02:00
parent 13255218f0
commit 485d04eb5f

View File

@ -88,7 +88,12 @@ class RoboRallyServerListener extends Listener {
public void received (Connection connection, Object object) {
if (object instanceof String) {
String playerName = (String) object;
playerNames.put(connection, playerName);
if (playerNames.values().contains(playerName)) {
String errorMessage = "The player name send is already taken.";
connection.sendTCP(new ErrorResponse(errorMessage, new IllegalArgumentException(errorMessage)));
} else {
playerNames.put(connection, playerName);
}
}
}