Fix (user could join a room twice) + Simon's request
Simon's request
This commit is contained in:
@@ -9,15 +9,13 @@ public class ChatApp {
|
|||||||
Server server = new Server(6665);
|
Server server = new Server(6665);
|
||||||
Client client = new Client(new InetSocketAddress("localhost", 6665));
|
Client client = new Client(new InetSocketAddress("localhost", 6665));
|
||||||
|
|
||||||
client.SendCreateRoom("Room1");
|
client.SendCreateRoom("101");
|
||||||
client.RequestRoomList();
|
|
||||||
client.SendChatMessage("Hello");
|
|
||||||
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
Scanner scanner = new Scanner(System.in);
|
||||||
while (true) {
|
while (true) {
|
||||||
String message = scanner.nextLine();
|
String message = scanner.nextLine();
|
||||||
System.out.print("\033[1A"); // Déplacer le curseur une ligne vers le haut
|
System.out.print("\033[1A");
|
||||||
System.out.print("\r\033[2K"); // Effacer la ligne entière
|
System.out.print("\r\033[2K");
|
||||||
System.out.flush();
|
System.out.flush();
|
||||||
client.visitMessage(message);
|
client.visitMessage(message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class Server implements PacketHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void joinRoom(String roomName, ServerConnexion connexion) throws SocketException {
|
public void joinRoom(String roomName, ServerConnexion connexion) throws SocketException {
|
||||||
if(roomNames.containsKey(roomName)) {
|
if(roomNames.containsKey(roomName) && !roomNames.get(roomName).contains(connexion)) {
|
||||||
roomNames.get(roomName).add(connexion);
|
roomNames.get(roomName).add(connexion);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user