Added ProtocolValidator class

added MSGRS command (message recieved, sent for server to client after recieving a msg with what was recieved as aprameters) to NTtBCommands
continued work on ClientMsgDecoder
This commit is contained in:
Sebastian Lenzlinger 2022-03-25 12:17:42 +01:00
parent 208b0d6586
commit 30986d2d86
3 changed files with 28 additions and 3 deletions

View File

@ -4,6 +4,7 @@ package ch.unibas.dmi.dbis.cs108.Multiplayer.Protocol;
public enum NTtBCommands {
/**
* Client commands:
* CRTGM: Create a new game
* CHATA: chat to all
* CHATW: whisper chat
@ -15,5 +16,15 @@ public enum NTtBCommands {
* QUITS: quit server/ leave servr
* LISTP: list players/clients in session with the Server
*/
CRTGM, CHATA, CHATW, CHATG, LEAVG, JOING, VOTEG, QUITS, LISTP, CUSRN
//Client Commands
CRTGM, CHATA, CHATW, CHATG, LEAVG, JOING, VOTEG, QUITS, LISTP, CUSRN,
/**
* MSGRS: "Message recieved": Paramaters: a string detailing to the client that and what the server recieved as command.
*/
//Server Responses
MSGRS,
}

View File

@ -0,0 +1,4 @@
package ch.unibas.dmi.dbis.cs108.Multiplayer.Protocol;
public class ProtocolValidator {
}

View File

@ -6,11 +6,21 @@ import java.util.List;
import java.util.Scanner;
public class ClientMsgDecoder implements ProtocolDecoder {
Scanner sc = new Scanner();
@Override
public String decodeMsg(String msg) {
List<String> msgTokens = tokenizeMsg(msg);
List<String> msgTokens = tokenizeMsg(msg); //List where we'll put the string tokens seperated by $.
String cmd; //The command token
try{
cmd = getCommand(msgTokens);
} catch (NoCommandTokenException e) {
//TODO: decide what to do here. How can we catch this smartly and where do we send it?
System.out.println(("ClientMsgDecoder cannot find a command token"));
e.printStackTrace(System.out);
return"ERROR$command token not found"; //TODO This is a very unelegant solution.
}
return null;
}