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:
parent
83991587d6
commit
0e39f06f9e
@ -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;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.client;
|
||||
package ch.unibas.dmi.dbis.cs108.multiplayer.server;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
Reference in New Issue
Block a user