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.
This commit is contained in:
Sebastian Lenzlinger 2022-04-08 19:28:01 +02:00
parent e23a749f55
commit da5189311e
2 changed files with 12 additions and 3 deletions

View File

@ -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) {

View File

@ -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());
}
}
/**