Merge branch 'dev-loginset' into 'dev'

feat(loginSet): limitation des salons en fonction des loginSet

See merge request iut_rt/but2/sae302-applicom/bouclyma!12
This commit is contained in:
Emi Boucly 2025-01-29 23:01:27 +01:00
commit 80885345fe
3 changed files with 47 additions and 4 deletions

View file

@ -33,6 +33,10 @@ public class Room {
return this.roomName;
}
public void setLoginSet (HashSet<String> loginSet) {
this.loginSet = loginSet;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View file

@ -1,5 +1,6 @@
package rtgre.modeles;
import java.util.HashSet;
import java.util.TreeMap;
public class RoomMap extends TreeMap<String, Room> {
@ -13,4 +14,39 @@ public class RoomMap extends TreeMap<String, Room> {
this.add(new Room("#ducks"));
this.add(new Room("#mice"));
}
public void setLoginSets() {
HashSet<String> juniors = new HashSet<>();
juniors.add("riri");
juniors.add("fifi");
juniors.add("loulou");
this.get("#juniors").setLoginSet(juniors);
HashSet<String> ducks = new HashSet<>();
ducks.add("riri");
ducks.add("fifi");
ducks.add("loulou");
ducks.add("donald");
ducks.add("daisy");
ducks.add("picsou");
this.get("#ducks").setLoginSet(ducks);
HashSet<String> mice = new HashSet<>();
mice.add("mickey");
mice.add("minnie");
this.get("#mice").setLoginSet(mice);
HashSet<String> all = new HashSet<>();
all.add("riri");
all.add("fifi");
all.add("loulou");
all.add("donald");
all.add("daisy");
all.add("picsou");
all.add("mickey");
all.add("minnie");
all.add("dingo");
this.get("#all").setLoginSet(all);
}
}

View file

@ -58,6 +58,7 @@ public class ChatServer {
roomMap = new RoomMap();
contactMap.loadDefaultContacts();
roomMap.loadDefaultRooms();
roomMap.setLoginSets();
}
public void close() throws IOException {
@ -305,6 +306,7 @@ public class ChatServer {
private void doListRoom(JSONObject content) {
if (contactMap.getContact(user.getLogin()).isConnected()) {
for (Room room: roomMap.values()) {
if (room.getLoginSet().contains(user.getLogin())) {
try {
send(new Event("ROOM", room.toJsonObject()).toJson());
} catch (IOException e) {
@ -313,6 +315,7 @@ public class ChatServer {
}
}
}
}
private void doListPost(JSONObject content) throws JSONException, IllegalStateException {
if (contactMap.getContact(user.getLogin()).isConnected()) {