Archived
1
0
Fork 0

Add channel check on message broadcast

This commit is contained in:
Ethanell 2022-01-07 10:25:57 +01:00
parent 38b86b16de
commit 14f40813b7
2 changed files with 17 additions and 7 deletions

View file

@ -0,0 +1,9 @@
package fr.univ.lyon1.common.exception;
import fr.univ.lyon1.common.Channel;
public class NotInChannel extends ChatException {
public NotInChannel(Channel channel) {
super("Your not in channel "+channel);
}
}

View file

@ -5,10 +5,7 @@ import fr.univ.lyon1.common.Message;
import fr.univ.lyon1.common.User;
import fr.univ.lyon1.common.command.Command;
import fr.univ.lyon1.common.command.CommandType;
import fr.univ.lyon1.common.exception.ChatException;
import fr.univ.lyon1.common.exception.LoginInvalid;
import fr.univ.lyon1.common.exception.LoginRequired;
import fr.univ.lyon1.common.exception.UnknownCommand;
import fr.univ.lyon1.common.exception.*;
import fr.univ.lyon1.server.models.ChannelModel;
import fr.univ.lyon1.server.models.UserModel;
@ -80,10 +77,14 @@ public class ConnectedClient implements Runnable {
}
}
private void commandMessage(Command cmd) {
private void commandMessage(Command cmd) throws NotInChannel {
Message msg = (Message) cmd.getArgs().get(0);
msg.setSender(this.user);
// ToDo: Check the user channel
ChannelModel chan = ChannelModel.get(msg.getChannel().getUUID());
if (chan == null || !chan.have(this.user))
throw new NotInChannel(chan);
else
server.broadcastMessage(msg, id);
}