diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/MessageFormatter.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/MessageFormatter.java index 43b7301..2dd2872 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/MessageFormatter.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/MessageFormatter.java @@ -47,6 +47,11 @@ public class MessageFormatter { s = "U.N. Owen"; } break; + case "/g": + stringBuilder.append(Protocol.createNewGame + "$"); + s = ""; + //TODO add LOGGER msg. Find out if .info or .debug. + break; default: s = msg; } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/Protocol.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/Protocol.java index d1d6c1b..9ba1014 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/Protocol.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/Protocol.java @@ -54,10 +54,10 @@ public class Protocol { /** * TODO: enable for client - * TODO: add to JClientProtocolParser {@link ch.unibas.dmi.dbis.cs108.multiplayer.client.JClientProtocolParser} - * TODO: add to JSeverProtocolParser {@link ch.unibas.dmi.dbis.cs108.multiplayer.server.JServerProtocolParser} * TODO: add sever response * Client sends this message when he wants to create a new game. + * Client issues this command in {@link ch.unibas.dmi.dbis.cs108.multiplayer.client.MessageFormatter} + * using "/g". * First a lobby {@link ch.unibas.dmi.dbis.cs108.sebaschi.Lobby} is created of which the requesting client is the admin of. */ public static final String createNewGame = "CRTGM"; diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/Protocol.txt b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/Protocol.txt index 95de010..7f2bdec 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/Protocol.txt +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/helpers/Protocol.txt @@ -10,9 +10,10 @@ Implemented: * CPING Ping from client to server. * PINGB Pingback from client to server. * NAMEC$name Change name to whatever is specified + * CRTGM Create a new game Future / planned: - * CRTGM Create a new game + * CHATW whisper chat * CHATG ghost chat * LEAVG leave a game diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java index cabf363..9c6de6f 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java @@ -7,6 +7,7 @@ import org.apache.logging.log4j.Logger; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; public class JServerProtocolParser { + public static final Logger LOGGER = LogManager.getLogger(); public static final BudaLogConfig l = new BudaLogConfig(LOGGER); @@ -17,10 +18,9 @@ public class JServerProtocolParser { /** - * Used by the server (i.e. ClientHandler) to parse an incoming protocol message. - * For documentation on the individual Protocol messages, view the Protocol.java - * class or hover over the commands (e.g. Protocol.chatMsgToAll) with your mouse - * in this class. + * Used by the server (i.e. ClientHandler) to parse an incoming protocol message. For + * documentation on the individual Protocol messages, view the Protocol.java class or hover over + * the commands (e.g. Protocol.chatMsgToAll) with your mouse in this class. * * @param msg the encoded message that needs to be parsed * @param h this ClientHandler (required so this method can access the ClientHandler's methods) @@ -28,7 +28,7 @@ public class JServerProtocolParser { public static void parse(String msg, ClientHandler h) { //LOGGER.debug("got message: " + msg + "."); String header = ""; //"header" is the first 5 characters, i.e. the protocol part - try { + try { header = msg.substring(0, 5); } catch (IndexOutOfBoundsException e) { System.out.println("Received unknown command"); @@ -57,6 +57,12 @@ public class JServerProtocolParser { case Protocol.clientQuitRequest: h.removeClientOnLogout(); break; + case Protocol.createNewGame: + // TODO add h.openLobby(h) method + LOGGER.debug(Protocol.createNewGame + + " command reached in JServerProtocolParser. Command issued by: " + + h.getClientUserName()); + break; default: System.out.println("Received unknown command"); }