Fix (user could join a room twice) + Simon's request

Simon's request
This commit is contained in:
Clément
2025-03-01 09:46:27 +01:00
parent aaf2e83b35
commit 5986b2f43c
2 changed files with 4 additions and 6 deletions

View File

@@ -9,15 +9,13 @@ public class ChatApp {
Server server = new Server(6665);
Client client = new Client(new InetSocketAddress("localhost", 6665));
client.SendCreateRoom("Room1");
client.RequestRoomList();
client.SendChatMessage("Hello");
client.SendCreateRoom("101");
Scanner scanner = new Scanner(System.in);
while (true) {
String message = scanner.nextLine();
System.out.print("\033[1A"); // Déplacer le curseur une ligne vers le haut
System.out.print("\r\033[2K"); // Effacer la ligne entière
System.out.print("\033[1A");
System.out.print("\r\033[2K");
System.out.flush();
client.visitMessage(message);
}

View File

@@ -63,7 +63,7 @@ public class Server implements PacketHandler {
}
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);
return;
}