Further work on CommandExecuter and adjustments to NightServerProtocol.

This commit is contained in:
Sebastian Lenzlinger
2022-03-26 13:32:27 +01:00
parent 8916d7f8b9
commit 46ee78d298
4 changed files with 49 additions and 107 deletions

View File

@@ -17,4 +17,5 @@
* MSGRS: "Message received": Paramaters: a string detailing to the client that and what the server received as command.
* SEROR: Server had an error. (used for debugging)
* SPING: Ping from server to client;
* NOCMD: Co command found.
*/

View File

@@ -21,7 +21,7 @@ public class NightTrainProtocol {
//Client Commands
CRTGM, CHATA, CHATW, CHATG, LEAVG, JOING, VOTEG, QUITS, LISTP, CUSRN,CPING,
//Server Responses
MSGRS, SEROR, SPING;
MSGRS, SEROR, SPING, NOCMD
}
private static HashMap<String, NTtBCommands> initializeMapping(){

View File

@@ -1,18 +1,19 @@
package ch.unibas.dmi.dbis.cs108.multiplayer.server.cmd.methods;
import ch.unibas.dmi.dbis.cs108.multiplayer.protocol.NTtBFormatMsg;
import ch.unibas.dmi.dbis.cs108.multiplayer.protocol.NightTrainProtocol.NTtBCommands;
import ch.unibas.dmi.dbis.cs108.multiplayer.server.ClientHandler;
import java.io.IOException;
/**
* This Class implements actually acting on the clients
* messages.
* This Class implements actually acting on the clients messages.
*/
public class CommandExecuter {
ClientHandler caller;
private ClientHandler caller;
private static String msgPrefix = "SERVER: ";
public static void execute(NTtBFormatMsg msg) {
public void execute(NTtBFormatMsg msg) {
switch (msg.getCommand()) {
case CRTGM:
break;
@@ -55,19 +56,55 @@ public class CommandExecuter {
case SPING:
pongC();
break;
default:
this.noCommand();
break;
}
}
private void wisper(String[] parameters) {
//TODO
}
private void changeNickname(String[] parameters) {
//TODO
}
private void quitServer() {
//TODO
}
private void pongC() {
//TODO
}
private void pongS() {
//TODO
}
private void noCommand() {
try {
caller.getOut().write(msgPrefix + String.valueOf(NTtBCommands.NOCMD));
} catch (IOException e) {
System.out.println("IOException in noCommand() in CommandExecuter.java");
e.printStackTrace();
}
}
/**
* boradcast chat message to everyone
* @param parameters should only have one entry i.e.
* parameters.length == 1
* should be true;
*
* @param parameters should only have one entry i.e. parameters.length == 1 should be true;
*/
private static void broadcastClientMsg(String[] parameters) throws IOException {
for(ClientHandler clients: ClientHandler.connectedClients) {
clients.getOut().write(parameters[0]);
private static void broadcastClientMsg(String[] parameters) {
try {
for (ClientHandler clients : ClientHandler.connectedClients) {
clients.getOut().write(parameters[0]);
}
} catch (IOException e) {
System.out.println("IOEXCEPTION in CommandExecuter.java at broadcastClientMsg");
}
}
}