From 46ee78d298b68b75707f09ad09543934b00889ef Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Sat, 26 Mar 2022 13:32:27 +0100 Subject: [PATCH] Further work on CommandExecuter and adjustments to NightServerProtocol. --- ...dmi.dbis.cs108.example.HelloWorldTest.html | 96 ------------------- .../protocol/NTtB_Protocol_Definition.txt | 1 + .../protocol/NightTrainProtocol.java | 2 +- .../server/cmd/methods/CommandExecuter.java | 57 +++++++++-- 4 files changed, 49 insertions(+), 107 deletions(-) delete mode 100644 build/reports/tests/test/classes/ch.unibas.dmi.dbis.cs108.example.HelloWorldTest.html diff --git a/build/reports/tests/test/classes/ch.unibas.dmi.dbis.cs108.example.HelloWorldTest.html b/build/reports/tests/test/classes/ch.unibas.dmi.dbis.cs108.example.HelloWorldTest.html deleted file mode 100644 index 4b6b755..0000000 --- a/build/reports/tests/test/classes/ch.unibas.dmi.dbis.cs108.example.HelloWorldTest.html +++ /dev/null @@ -1,96 +0,0 @@ - - - - - -Test results - HelloWorldTest - - - - - -
-

HelloWorldTest

- -
- - - - - -
-
- - - - - - - -
-
-
1
-

tests

-
-
-
-
0
-

failures

-
-
-
-
0
-

ignored

-
-
-
-
0.013s
-

duration

-
-
-
-
-
-
100%
-

successful

-
-
-
-
- -
-

Tests

- - - - - - - - - - - - - -
TestDurationResult
testMain()0.013spassed
-
-
- -
- - diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/protocol/NTtB_Protocol_Definition.txt b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/protocol/NTtB_Protocol_Definition.txt index e694e0f..43ccec3 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/protocol/NTtB_Protocol_Definition.txt +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/protocol/NTtB_Protocol_Definition.txt @@ -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. */ \ No newline at end of file diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/protocol/NightTrainProtocol.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/protocol/NightTrainProtocol.java index 54b4335..1d4e8f9 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/protocol/NightTrainProtocol.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/protocol/NightTrainProtocol.java @@ -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 initializeMapping(){ diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/cmd/methods/CommandExecuter.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/cmd/methods/CommandExecuter.java index 78533a5..b3c3e34 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/cmd/methods/CommandExecuter.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/cmd/methods/CommandExecuter.java @@ -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"); } + } }