mirror of
https://github.com/Akomry/sae302_applicom.git
synced 2025-12-06 08:43:54 +00:00
feat(Room): Récupéraiton des salons depuis le serveur, usine à cellule et affichage dans le client
This commit is contained in:
parent
d99405160d
commit
29cf0a3b43
6 changed files with 149 additions and 1 deletions
|
|
@ -24,6 +24,7 @@ public class ChatServer {
|
|||
private Vector<ChatClientHandler> clientList;
|
||||
private PostVector postVector;
|
||||
private ContactMap contactMap;
|
||||
private RoomMap roomMap;
|
||||
|
||||
static {
|
||||
try {
|
||||
|
|
@ -53,7 +54,9 @@ public class ChatServer {
|
|||
clientList = new Vector<>();
|
||||
contactMap = new ContactMap();
|
||||
postVector = new PostVector();
|
||||
roomMap = new RoomMap();
|
||||
contactMap.loadDefaultContacts();
|
||||
roomMap.loadDefaultRooms();
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
|
|
@ -254,6 +257,10 @@ public class ChatServer {
|
|||
doListPost(event.getContent());
|
||||
LOGGER.info("Sending Posts");
|
||||
return true;
|
||||
} else if (event.getType().equals(Event.LIST_ROOMS)) {
|
||||
doListRoom(event.getContent());
|
||||
LOGGER.info("Sending Rooms");
|
||||
return true;
|
||||
} else if (event.getType().equals(Event.QUIT)) {
|
||||
LOGGER.info("Déconnexion");
|
||||
return false;
|
||||
|
|
@ -263,6 +270,22 @@ public class ChatServer {
|
|||
}
|
||||
}
|
||||
|
||||
private void doListRoom(JSONObject content) {
|
||||
System.out.println(contactMap.getContact(user.getLogin()).isConnected());
|
||||
if (contactMap.getContact(user.getLogin()).isConnected()) {
|
||||
for (Room room: roomMap.values()) {
|
||||
System.out.println(room);
|
||||
try {
|
||||
System.out.println(new Event("ROOM", room.toJsonObject()).toJson());
|
||||
send(new Event("ROOM", room.toJsonObject()).toJson());
|
||||
} catch (IOException e) {
|
||||
System.out.println(e.getMessage());
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void doListPost(JSONObject content) throws JSONException, IllegalStateException {
|
||||
|
||||
if (contactMap.getContact(user.getLogin()).isConnected()) {
|
||||
|
|
@ -371,6 +394,7 @@ public class ChatServer {
|
|||
sock.close();
|
||||
removeClient(this);
|
||||
user.setConnected(false);
|
||||
contactMap.get(user.getLogin()).setConnected(false);
|
||||
sendEventToAllContacts(new Event(Event.CONT, user.toJsonObject()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue