diff --git a/java_pid21340.hprof b/java_pid21340.hprof deleted file mode 100644 index 5d5f257..0000000 Binary files a/java_pid21340.hprof and /dev/null differ diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/jonasStuff/ClientProtocol.java b/src/main/java/ch/unibas/dmi/dbis/cs108/jonasStuff/ClientProtocol.java new file mode 100644 index 0000000..346bb0f --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/jonasStuff/ClientProtocol.java @@ -0,0 +1,8 @@ +package ch.unibas.dmi.dbis.cs108.jonasStuff; + +public enum ClientProtocol { + MSGRS, //"Message received": Parameters: a string detailing to the client that and what the server received as command. + SEROR, //Server had an error. (used for debugging) + SPING, //Ping from server to client; + NOCMD //No command found. +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/jonasStuff/ClientProtocolParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/jonasStuff/ClientProtocolParser.java new file mode 100644 index 0000000..54aecb7 --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/jonasStuff/ClientProtocolParser.java @@ -0,0 +1,4 @@ +package ch.unibas.dmi.dbis.cs108.jonasStuff; + +public class ClientProtocolParser { +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/jonasStuff/ServerProtocol.java b/src/main/java/ch/unibas/dmi/dbis/cs108/jonasStuff/ServerProtocol.java new file mode 100644 index 0000000..e214c3f --- /dev/null +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/jonasStuff/ServerProtocol.java @@ -0,0 +1,15 @@ +package ch.unibas.dmi.dbis.cs108.jonasStuff; + +public enum ServerProtocol { + CRTGM, //Create a new game + CHATA, //chat to all + CHATW, //whisper chat + CHATG, //ghost chat + LEAVG, //leave a game + JOING, //join a game + VOTEG, //ghost voting who to infect + VOTEH, //humans voting who is the ghost + QUITS, //quit server/ leave server + LISTP, //list players/clients in session with the Server + CPING, //Ping from client to server. +} diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java index 3aa6a19..8b7d40a 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/Client.java @@ -37,21 +37,9 @@ public class Client { Scanner sc = new Scanner(System.in); while (socket.isConnected()) { String msg = sc.nextLine(); - String encodedMsg = ""; - try { - encodedMsg = encodeMessage(msg); - } catch (NoLegalProtocolCommandStringFoundException e) { - System.out.println("ERROR: no legal command found"); - encodedMsg = ""; - } catch (EmptyClientInputException e) { - //Maybe this exception shouldn't do anything. - } finally { - out.write(encodedMsg); - out.newLine(); - out.flush(); - } - - + out.write(msg); + out.newLine(); + out.flush(); } } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/protocol/NTtB_Protocol_Definition.txt b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/protocol/NTtB_Protocol_Definition.txt index 43ccec3..f61a161 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/protocol/NTtB_Protocol_Definition.txt +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/protocol/NTtB_Protocol_Definition.txt @@ -14,7 +14,7 @@ */ /** Server Commands: - * MSGRS: "Message received": Paramaters: a string detailing to the client that and what the server received as command. + * MSGRS: "Message received": Parameters: a string detailing to the client that and what the server received as command. * SEROR: Server had an error. (used for debugging) * SPING: Ping from server to client; * NOCMD: Co command found. diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java index 5ffa196..d396825 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/ClientHandler.java @@ -66,22 +66,16 @@ public class ClientHandler implements Runnable { @Override /** - * The main logik of the client handler. + * The main logic of the client handler. * Since every client is put on a string this is where - * most interactions between client and server are held.. + * most interactions between client and server are held */ public void run() { String msg; - NTtBFormatMsg response; while(socket.isConnected()) { try { - msg = in.readLine(); - response = clientMsgDecoder.decodeMsg(msg); //The response of the server to the clients message - out.write(response.getMessage()); - out.newLine(); - out.flush(); - //TODO if merely an acknowledgement is sent back to the client, how does the client recieve game updates? + JServerProtocolParser.parse(msg, this); } catch (IOException e) { e.printStackTrace(); closeEverything(socket, in, out);