Archived
1
0
Fork 0

Add command / support

This commit is contained in:
Ethanell 2022-01-30 17:41:43 +01:00
parent 538b2d30f4
commit 58ffe690fe
2 changed files with 21 additions and 3 deletions

View file

@ -8,6 +8,7 @@ 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.NotInChannel;
import fr.univ.lyon1.common.exception.UnknownCommand;
import fr.univ.lyon1.gui.handlers.ServerConfigurationHandler;
import javafx.application.Platform;
@ -249,14 +250,31 @@ public class ApplicationController {
if (this.currentChannel != null) {
try {
// Send the message to the server
this.sendObject(new Command(CommandType.message, List.of(new Message(textToSend, this.currentChannel))));
} catch (IOException e) {
parsInput(textToSend);
} catch (ChatException | IOException e) {
System.out.println("Can not send message to server : " + e.getMessage());
e.printStackTrace();
}
}
}
private void parsInput(String textToSend) throws UnknownCommand, NotInChannel, IOException {
if (textToSend.startsWith("/")) {
List<String> args = Arrays.asList(textToSend.split(" "));
String commandName = args.get(0).replace("/", "");
CommandType commandType;
try {
commandType = CommandType.valueOf(commandName);
} catch (IllegalArgumentException e) {
throw new UnknownCommand(commandName);
}
this.sendObject(new Command(commandType, new ArrayList<>(args.subList(1, args.size()))));
} else
this.sendObject(new Command(CommandType.message, List.of(new Message(textToSend, this.currentChannel))));
}
/**
* Clear the current textarea message
*/

View file

@ -162,7 +162,7 @@ public class ConnectedClient implements Runnable {
send(new Command(CommandType.join, List.of((Channel) chan)));
server.broadcastMessage(new Message(chan, Server.getServerUser(), user.getUsername()+" joined the channel !"), -1);
server.broadcastMessage(new Message(chan, Server.getServerUser(), user.getUsername()+" joined the channel !\n"), -1);
}
/**