mirror of
https://github.com/Akomry/sae302_applicom.git
synced 2025-12-06 08:43:54 +00:00
feat(loginSet): limitation des salons en fonction des loginSet
This commit is contained in:
parent
6daa8c2fad
commit
58093d48a4
3 changed files with 47 additions and 4 deletions
|
|
@ -33,6 +33,10 @@ public class Room {
|
||||||
return this.roomName;
|
return this.roomName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLoginSet (HashSet<String> loginSet) {
|
||||||
|
this.loginSet = loginSet;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package rtgre.modeles;
|
package rtgre.modeles;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class RoomMap extends TreeMap<String, Room> {
|
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("#ducks"));
|
||||||
this.add(new Room("#mice"));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ public class ChatServer {
|
||||||
roomMap = new RoomMap();
|
roomMap = new RoomMap();
|
||||||
contactMap.loadDefaultContacts();
|
contactMap.loadDefaultContacts();
|
||||||
roomMap.loadDefaultRooms();
|
roomMap.loadDefaultRooms();
|
||||||
|
roomMap.setLoginSets();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
|
|
@ -305,10 +306,12 @@ public class ChatServer {
|
||||||
private void doListRoom(JSONObject content) {
|
private void doListRoom(JSONObject content) {
|
||||||
if (contactMap.getContact(user.getLogin()).isConnected()) {
|
if (contactMap.getContact(user.getLogin()).isConnected()) {
|
||||||
for (Room room: roomMap.values()) {
|
for (Room room: roomMap.values()) {
|
||||||
try {
|
if (room.getLoginSet().contains(user.getLogin())) {
|
||||||
send(new Event("ROOM", room.toJsonObject()).toJson());
|
try {
|
||||||
} catch (IOException e) {
|
send(new Event("ROOM", room.toJsonObject()).toJson());
|
||||||
throw new IllegalStateException();
|
} catch (IOException e) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue