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";
}
break;
case "/g":
stringBuilder.append(Protocol.createNewGame + "$");
s = "";
//TODO add LOGGER msg. Find out if .info or .debug.
break;
default:
s = msg;
}

View File

@ -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";

View File

@ -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

View File

@ -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");
}