New Parser structure
This commit is contained in:
parent
f5dd739dd4
commit
80644a934c
Binary file not shown.
@ -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.
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package ch.unibas.dmi.dbis.cs108.jonasStuff;
|
||||
|
||||
public class ClientProtocolParser {
|
||||
}
|
||||
@ -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.
|
||||
}
|
||||
@ -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();
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user