Develop #1
@@ -84,13 +84,24 @@ public class ClientSession implements Runnable {
|
||||
private void handleChatMessage(ChatMessage msg) throws IOException {
|
||||
switch (msg.getType()) {
|
||||
case PUBLIC_MESSAGE -> {
|
||||
// TODO: Broadcast this message to every connected client.
|
||||
|
||||
for (ClientSession session: userManager.getAllSessions()) {
|
||||
session.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
case PRIVATE_MESSAGE -> {
|
||||
// TODO: Forward this message to the receiver user.
|
||||
|
||||
ClientSession receiver = userManager.getUser(msg.getSender());
|
||||
if (receiver != null) {
|
||||
receiver.sendMessage(msg);
|
||||
}
|
||||
else {
|
||||
sendMessage(new ChatMessage(MessageType.PUBLIC_MESSAGE, "Server", username, "User '" + msg.getReceiver() + "' is not online."));
|
||||
}
|
||||
}
|
||||
case USER_LIST -> {
|
||||
// TODO: Reply to the requester with the list of online users.
|
||||
|
||||
sendMessage(new ChatMessage(MessageType.USER_LIST, "Server", username, userManager.listUsers()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,6 +114,15 @@ public class ClientSession implements Runnable {
|
||||
Files.write(sentPath, fileMsg.getData());
|
||||
Files.write(recvPath, fileMsg.getData());
|
||||
|
||||
// TODO: Forward the received file-message to the destination user.
|
||||
ClientSession receiver = userManager.getUser(fileMsg.getReceiver());
|
||||
if (receiver != null) {
|
||||
receiver.sendMessage(fileMsg);
|
||||
} else {
|
||||
sendMessage(new ChatMessage(
|
||||
MessageType.PUBLIC_MESSAGE,
|
||||
"Server", username,
|
||||
"User '" + fileMsg.getReceiver() + "' is not online. File saved on server."
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user