Noticed enums can be treated as clases to an extent so added a HashSet that accociates strings with Enum fields of the Protocol.
ProtocolValidator might become redundant!
This commit is contained in:
parent
7f967f6818
commit
846d0a8187
@ -1,6 +1,7 @@
|
||||
package ch.unibas.dmi.dbis.cs108.Multiplayer.Protocol;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public enum NTtBCommands {
|
||||
/**
|
||||
@ -26,5 +27,18 @@ public enum NTtBCommands {
|
||||
* MSGRS: "Message recieved": Paramaters: a string detailing to the client that and what the server recieved as command.
|
||||
*/
|
||||
//Server Responses
|
||||
MSGRS,
|
||||
MSGRS;
|
||||
|
||||
//Allowes to associate strings with the enum objects. the enum fields are easier for switch statements.
|
||||
private HashMap<String,NTtBCommands> stringNTtBCommandsHashMap = new HashMap<>();
|
||||
|
||||
private NTtBCommands(){
|
||||
for(NTtBCommands cmd : NTtBCommands.values()){
|
||||
stringNTtBCommandsHashMap.put(cmd.name(), cmd);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isLegal(String s){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,23 @@
|
||||
package ch.unibas.dmi.dbis.cs108.Multiplayer.Protocol;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
//TODO Possibly redundant!!
|
||||
|
||||
public class ProtocolValidator {
|
||||
|
||||
//TODO String or NTtBCommands HashSet?
|
||||
public static HashSet<NTtBCommands> legalCommands = initializeLegalCommands();
|
||||
|
||||
//Initialize the legalCommands set with the protocol values.
|
||||
private static HashSet<NTtBCommands> initializeLegalCommands(){
|
||||
EnumSet<NTtBCommands> enumVals = EnumSet.allOf(NTtBCommands.class);
|
||||
return new HashSet<>(enumVals);
|
||||
}
|
||||
|
||||
public boolean validateCommand(String s) {
|
||||
//TODO implement if needed
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
package ch.unibas.dmi.dbis.cs108.Multiplayer.Server;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.Multiplayer.Protocol.NTtBCommands;
|
||||
import ch.unibas.dmi.dbis.cs108.Multiplayer.Protocol.ProtocolDecoder;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ClientMsgDecoder implements ProtocolDecoder {
|
||||
|
||||
private NTtBCommands protocol;
|
||||
|
||||
@Override
|
||||
public String decodeMsg(String msg) {
|
||||
@ -46,6 +47,6 @@ public class ClientMsgDecoder implements ProtocolDecoder {
|
||||
* of server agency according to client msg
|
||||
*/
|
||||
private @interface serverActionBuilder {
|
||||
//TODO implement what should happen server side
|
||||
//TODO implement what should happen server side(vote/chat/quit etc)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user