From da5189311ea81fd0de6484ab97b189cc1e035093 Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Fri, 8 Apr 2022 19:28:01 +0200 Subject: [PATCH] Changed functionality of listAllLobbiesToClient(): Now it writes to the OutPutStream itself instead of sending a CHATM to client. Hope is that the JClientParser only has to parse once. --- .../dmi/dbis/cs108/multiplayer/client/Client.java | 1 + .../cs108/multiplayer/server/ClientHandler.java | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) 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 122c17a..a05bb25 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 @@ -88,6 +88,7 @@ public class Client { try { chatMsg = in.readLine(); //todo: maybe if if (chatMsg != null) { + //LOGGER.debug("chatMSG recieved from Server: " + chatMsg); parse(chatMsg); } else { System.out.println("chatMsg is null"); throw new IOException();} } catch (IOException e) { 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 f8bfc7b..cc44821 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 @@ -179,6 +179,7 @@ public class ClientHandler implements Runnable { */ public void sendMsgToClient(String msg) { try { + if(!msg.equals("SPING"))LOGGER.debug("Message sent to client: " + msg); out.write(msg); out.newLine(); out.flush(); @@ -236,19 +237,26 @@ public class ClientHandler implements Runnable { */ public void listAllLobbiesToClient() { StringBuilder response = new StringBuilder(); - response.append(Protocol.printToClientConsole); + response.append(Protocol.listLobbies); response.append("$"); if (serverData.getAllLobbies().isEmpty()) { response.append("There are currently no open lobbies"); LOGGER.debug("No open lobbies"); } else { for (Lobby l : serverData.getAllLobbies()) { - sendMsgToClient(response + l.getIdAndAdminAndFormat()); + response.append(l.getIdAndAdminAndFormat()); } } LOGGER.debug( "RESPONSE TO LISTL: " + response.toString() + " requested by: " + this.clientUserName); - //sendMsgToClient(response.toString()); + try { + out.write(response.toString()); + out.newLine(); + out.flush(); + } catch (IOException e) { + LOGGER.debug(e.getMessage()); + } + } /**