Added CRTGM debug logger to JServerProtocolParser to see if command is reached. added "/g" as terminal command for client to issue CRTGM command. remobed respective todos from Protocol.java.

This commit is contained in:
sebaschi 2022-04-08 14:16:40 +02:00
parent e2a400d0ca
commit dd2beb559a
4 changed files with 20 additions and 8 deletions

View File

@ -47,6 +47,11 @@ public class MessageFormatter {
s = "U.N. Owen"; s = "U.N. Owen";
} }
break; break;
case "/g":
stringBuilder.append(Protocol.createNewGame + "$");
s = "";
//TODO add LOGGER msg. Find out if .info or .debug.
break;
default: default:
s = msg; s = msg;
} }

View File

@ -54,10 +54,10 @@ public class Protocol {
/** /**
* TODO: enable for client * 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 * TODO: add sever response
* Client sends this message when he wants to create a new game. * 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. * 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"; public static final String createNewGame = "CRTGM";

View File

@ -10,9 +10,10 @@ Implemented:
* CPING Ping from client to server. * CPING Ping from client to server.
* PINGB Pingback from client to server. * PINGB Pingback from client to server.
* NAMEC$name Change name to whatever is specified * NAMEC$name Change name to whatever is specified
* CRTGM Create a new game
Future / planned: Future / planned:
* CRTGM Create a new game
* CHATW whisper chat * CHATW whisper chat
* CHATG ghost chat * CHATG ghost chat
* LEAVG leave a game * LEAVG leave a game

View File

@ -7,6 +7,7 @@ import org.apache.logging.log4j.Logger;
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol;
public class JServerProtocolParser { public class JServerProtocolParser {
public static final Logger LOGGER = LogManager.getLogger(); public static final Logger LOGGER = LogManager.getLogger();
public static final BudaLogConfig l = new BudaLogConfig(LOGGER); 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. * Used by the server (i.e. ClientHandler) to parse an incoming protocol message. For
* For documentation on the individual Protocol messages, view the Protocol.java * documentation on the individual Protocol messages, view the Protocol.java class or hover over
* class or hover over the commands (e.g. Protocol.chatMsgToAll) with your mouse * the commands (e.g. Protocol.chatMsgToAll) with your mouse in this class.
* in this class.
* *
* @param msg the encoded message that needs to be parsed * @param msg the encoded message that needs to be parsed
* @param h this ClientHandler (required so this method can access the ClientHandler's methods) * @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) { public static void parse(String msg, ClientHandler h) {
//LOGGER.debug("got message: " + msg + "."); //LOGGER.debug("got message: " + msg + ".");
String header = ""; //"header" is the first 5 characters, i.e. the protocol part String header = ""; //"header" is the first 5 characters, i.e. the protocol part
try { try {
header = msg.substring(0, 5); header = msg.substring(0, 5);
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
System.out.println("Received unknown command"); System.out.println("Received unknown command");
@ -57,6 +57,12 @@ public class JServerProtocolParser {
case Protocol.clientQuitRequest: case Protocol.clientQuitRequest:
h.removeClientOnLogout(); h.removeClientOnLogout();
break; 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: default:
System.out.println("Received unknown command"); System.out.println("Received unknown command");
} }