Add channel check on message broadcast
This commit is contained in:
parent
38b86b16de
commit
14f40813b7
2 changed files with 17 additions and 7 deletions
9
src/fr/univ/lyon1/common/exception/NotInChannel.java
Normal file
9
src/fr/univ/lyon1/common/exception/NotInChannel.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,10 +5,7 @@ import fr.univ.lyon1.common.Message;
|
||||||
import fr.univ.lyon1.common.User;
|
import fr.univ.lyon1.common.User;
|
||||||
import fr.univ.lyon1.common.command.Command;
|
import fr.univ.lyon1.common.command.Command;
|
||||||
import fr.univ.lyon1.common.command.CommandType;
|
import fr.univ.lyon1.common.command.CommandType;
|
||||||
import fr.univ.lyon1.common.exception.ChatException;
|
import fr.univ.lyon1.common.exception.*;
|
||||||
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.server.models.ChannelModel;
|
import fr.univ.lyon1.server.models.ChannelModel;
|
||||||
import fr.univ.lyon1.server.models.UserModel;
|
import fr.univ.lyon1.server.models.UserModel;
|
||||||
|
|
||||||
|
@ -80,11 +77,15 @@ public class ConnectedClient implements Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void commandMessage(Command cmd) {
|
private void commandMessage(Command cmd) throws NotInChannel {
|
||||||
Message msg = (Message) cmd.getArgs().get(0);
|
Message msg = (Message) cmd.getArgs().get(0);
|
||||||
msg.setSender(this.user);
|
msg.setSender(this.user);
|
||||||
// ToDo: Check the user channel
|
|
||||||
server.broadcastMessage(msg, id);
|
ChannelModel chan = ChannelModel.get(msg.getChannel().getUUID());
|
||||||
|
if (chan == null || !chan.have(this.user))
|
||||||
|
throw new NotInChannel(chan);
|
||||||
|
else
|
||||||
|
server.broadcastMessage(msg, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void commandList() throws IOException {
|
private void commandList() throws IOException {
|
||||||
|
|
Reference in a new issue