Added Alexandrs "Added name duplicate handler by modifying the ClientHandler class as well as adding a class where all Client names are stored" commit

This commit is contained in:
Seraina 2022-03-27 14:44:55 +02:00
parent 83991587d6
commit 0e39f06f9e
3 changed files with 7 additions and 2 deletions

View File

@ -2,7 +2,6 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ClientPinger;
import java.net.Socket;
import java.io.*;
import java.net.UnknownHostException;

View File

@ -29,6 +29,12 @@ public class ClientHandler implements Runnable {
this.out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
this.in = new BufferedReader((new InputStreamReader((socket.getInputStream()))));
this.clientUserName = in.readLine();
// duplicate handling: if username already taken, assign random name to client
if (AllClientNames.allNames("").contains(clientUserName)) {
clientUserName = NameGenerator.randomName();
}
// add username to list of all client names for future duplicate checking
AllClientNames.allNames(clientUserName);
connectedClients.add(this);
serverPinger = new ServerPinger(out, socket);
Thread sP = new Thread(serverPinger);

View File

@ -1,4 +1,4 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.client;
package ch.unibas.dmi.dbis.cs108.multiplayer.server;
import java.util.Random;