Enforced duplication check on nickname change

This commit is contained in:
Seraina 2022-03-27 17:04:05 +02:00
parent 1c03b5d9c7
commit bc7896dafa
2 changed files with 5 additions and 2 deletions

View File

@ -7,7 +7,7 @@ public class MessageFormatter {
* handle it. May need to be redesigned one the games uses a GUI * handle it. May need to be redesigned one the games uses a GUI
* *
* @param msg the Messaged to be reformatted * @param msg the Messaged to be reformatted
* @return the reformatted message * @return the reformatted message in the form HEADR$msg
*/ */
public static String formatMsg(String msg) { public static String formatMsg(String msg) {

View File

@ -99,9 +99,12 @@ public class ClientHandler implements Runnable {
} }
public void changeUsername(String newName) { public void changeUsername(String newName) {
if (AllClientNames.allNames("").contains(newName)) {
newName = NameGenerator.randomName(newName);
}
String h = this.clientUserName; //just a friendly little helper String h = this.clientUserName; //just a friendly little helper
this.clientUserName = newName; this.clientUserName = newName;
AllClientNames.allNames(newName);
broadcastMessage(h +" have changed their nickname to " + clientUserName); broadcastMessage(h +" have changed their nickname to " + clientUserName);
} }