Relocated message formating from server to client
This commit is contained in:
parent
2f7db70df7
commit
ced0f0aa9e
@ -2,10 +2,12 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.ClientPinger;
|
||||
|
||||
import ch.unibas.dmi.dbis.cs108.multiplayer.server.MessageFormatter;
|
||||
import java.net.Socket;
|
||||
import java.io.*;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Scanner;
|
||||
import org.apache.logging.log4j.message.Message;
|
||||
|
||||
public class Client {
|
||||
|
||||
@ -39,7 +41,8 @@ public class Client {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
while (socket.isConnected()) {
|
||||
String msg = sc.nextLine();
|
||||
out.write(msg);
|
||||
String formattedMSG = MessageFormatter.formatMsg(msg);
|
||||
out.write(formattedMSG);
|
||||
out.newLine();
|
||||
out.flush();
|
||||
}
|
||||
|
||||
@ -11,16 +11,15 @@ public class JServerProtocolParser {
|
||||
*/
|
||||
public static void parse(String msg, ClientHandler h) {
|
||||
String header = ""; //"header" is the first 5 characters, i.e. the protocol part
|
||||
String formattedMSG = MessageFormatter.formatMsg(msg);
|
||||
try {
|
||||
header = formattedMSG.substring(0, 5);
|
||||
try {
|
||||
header = msg.substring(0, 5);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
System.out.println("Received unknown command");
|
||||
}
|
||||
//System.out.println(header); helpful for debugging
|
||||
switch (header) {
|
||||
case "CHATA":
|
||||
h.broadcastMessage(formattedMSG.substring(6));
|
||||
h.broadcastMessage(msg.substring(6));
|
||||
break;
|
||||
case "CPING":
|
||||
h.sendMsgToClient("PINGB");
|
||||
|
||||
@ -30,6 +30,8 @@ public class MessageFormatter {
|
||||
stringBuilder.append("QUITS");
|
||||
s = msg.substring(2);
|
||||
break;
|
||||
case "/n":
|
||||
stringBuilder.append("NAMEC");
|
||||
default:
|
||||
s = msg;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user