Add command / support
This commit is contained in:
parent
538b2d30f4
commit
58ffe690fe
2 changed files with 21 additions and 3 deletions
|
@ -8,6 +8,7 @@ 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.ChatException;
|
||||||
import fr.univ.lyon1.common.exception.LoginInvalid;
|
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.common.exception.UnknownCommand;
|
||||||
import fr.univ.lyon1.gui.handlers.ServerConfigurationHandler;
|
import fr.univ.lyon1.gui.handlers.ServerConfigurationHandler;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
|
@ -249,14 +250,31 @@ public class ApplicationController {
|
||||||
if (this.currentChannel != null) {
|
if (this.currentChannel != null) {
|
||||||
try {
|
try {
|
||||||
// Send the message to the server
|
// Send the message to the server
|
||||||
this.sendObject(new Command(CommandType.message, List.of(new Message(textToSend, this.currentChannel))));
|
parsInput(textToSend);
|
||||||
} catch (IOException e) {
|
} catch (ChatException | IOException e) {
|
||||||
System.out.println("Can not send message to server : " + e.getMessage());
|
System.out.println("Can not send message to server : " + e.getMessage());
|
||||||
e.printStackTrace();
|
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
|
* Clear the current textarea message
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -162,7 +162,7 @@ public class ConnectedClient implements Runnable {
|
||||||
|
|
||||||
send(new Command(CommandType.join, List.of((Channel) chan)));
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Reference in a new issue