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:
parent
208b0d6586
commit
30986d2d86
@ -4,6 +4,7 @@ package ch.unibas.dmi.dbis.cs108.Multiplayer.Protocol;
|
|||||||
|
|
||||||
public enum NTtBCommands {
|
public enum NTtBCommands {
|
||||||
/**
|
/**
|
||||||
|
* Client commands:
|
||||||
* CRTGM: Create a new game
|
* CRTGM: Create a new game
|
||||||
* CHATA: chat to all
|
* CHATA: chat to all
|
||||||
* CHATW: whisper chat
|
* CHATW: whisper chat
|
||||||
@ -15,5 +16,15 @@ public enum NTtBCommands {
|
|||||||
* QUITS: quit server/ leave servr
|
* QUITS: quit server/ leave servr
|
||||||
* LISTP: list players/clients in session with the Server
|
* 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,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,4 @@
|
|||||||
|
package ch.unibas.dmi.dbis.cs108.Multiplayer.Protocol;
|
||||||
|
|
||||||
|
public class ProtocolValidator {
|
||||||
|
}
|
||||||
@ -6,11 +6,21 @@ import java.util.List;
|
|||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class ClientMsgDecoder implements ProtocolDecoder {
|
public class ClientMsgDecoder implements ProtocolDecoder {
|
||||||
Scanner sc = new Scanner();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String decodeMsg(String msg) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user