From edf5c65da2754b68b5445ede2d372fc1d76142f2 Mon Sep 17 00:00:00 2001 From: Seraina Date: Sun, 17 Apr 2022 14:05:38 +0200 Subject: [PATCH 1/8] Added static field to ChatApp and set it to the current application in the start() --- .../dbis/cs108/multiplayer/client/Client.java | 10 ++++-- .../multiplayer/client/gui/ClientModel.java | 5 +++ .../cs108/multiplayer/client/gui/GUI.java | 15 ++++++++ .../multiplayer/client/gui/chat/ChatApp.java | 35 ++++++++++++++++++- .../client/gui/chat/ChatController.java | 2 +- 5 files changed, 63 insertions(+), 4 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 464f6e6..23c32f2 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 @@ -62,6 +62,7 @@ public class Client { sendMsgToServer(Protocol.clientLogin + "$" + systemName); this.chatApp = new ChatApp(new ClientModel(systemName, this)); this.chatGUi = new GUI(this.chatApp); + chatGUi.setName(systemName); clientPinger = new ClientPinger(this, this.socket); } catch (IOException e) { e.printStackTrace(); @@ -220,8 +221,10 @@ public class Client { cP.start(); client.userInputListener(); //this one blocks. //Start the GUI - Thread guiThread = new Thread(client.chatGUi); + GUI gui = new GUI(client.chatApp); + Thread guiThread = new Thread(gui); guiThread.start(); + LOGGER.info("7"); } catch (UnknownHostException e) { System.out.println("Invalid host IP"); } catch (IOException e) { @@ -240,14 +243,17 @@ public class Client { Thread cP = new Thread(client.clientPinger); cP.start(); client.userInputListener(); //this one blocks. - + LOGGER.info("7.1"); Thread guiThread = new Thread(client.chatGUi); + LOGGER.info("8"); guiThread.start(); + LOGGER.info("9"); } catch (UnknownHostException e) { System.out.println("Invalid host IP"); } catch (IOException e) { e.printStackTrace(); } + LOGGER.info("10"); } public Socket getSocket() { diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientModel.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientModel.java index cb060c9..1cd6058 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientModel.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/ClientModel.java @@ -1,8 +1,13 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui; +import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class ClientModel { + public static final Logger LOGGER = LogManager.getLogger(ClientModel.class); + public static final BudaLogConfig l = new BudaLogConfig(LOGGER); private String username; private Client client; diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java index 173db00..274073a 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/GUI.java @@ -1,14 +1,25 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui; +import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat.ChatApp; import javafx.application.Application; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class GUI implements Runnable{ + public static final Logger LOGGER = LogManager.getLogger(GUI.class); + public static final BudaLogConfig l = new BudaLogConfig(LOGGER); ChatApp chatApp; + private String name; public GUI (ChatApp chatApp) { this.chatApp = chatApp; } + + public void setName(String name) { + this.name = name; + } + /** * When an object implementing interface {@code Runnable} is used to create a thread, starting the * thread causes the object's {@code run} method to be called in that separately executing @@ -18,8 +29,12 @@ public class GUI implements Runnable{ * * @see Thread#run() */ + + @Override public void run() { + LOGGER.info("here"); + //String name = Application.launch(this.chatApp.getClass()); } } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatApp.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatApp.java index 2a852d5..26ed67a 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatApp.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatApp.java @@ -1,5 +1,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; +import ch.unibas.dmi.dbis.cs108.BudaLogConfig; +import ch.unibas.dmi.dbis.cs108.multiplayer.client.Client; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel; import java.net.URL; import java.util.Objects; @@ -8,19 +10,40 @@ import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class ChatApp extends Application { - ClientModel clientModel; + public static final Logger LOGGER = LogManager.getLogger(ChatApp.class); + public static final BudaLogConfig l = new BudaLogConfig(LOGGER); + + private static ClientModel clientModel; private ChatController chatController; public ChatApp() { super(); + LOGGER.info("Empty ChatApp constructor got called: "); + } + public ChatApp(ClientModel clientModel) { this.clientModel = clientModel; this.chatController = new ChatController(clientModel); } + public void setChatController( + ChatController chatController) { + this.chatController = chatController; + } + + public static void setClientModel(ClientModel clientM) { + clientModel = clientM; + } + + public static ClientModel getClientModel() { + return clientModel; + } + /** * The main entry point for all JavaFX applications. The start method is called after the init * method has returned, and after the system is ready for the application to begin running. @@ -36,8 +59,11 @@ public class ChatApp extends Application { */ @Override public void start(Stage primaryStage) throws Exception { + LOGGER.info("made it here"); + this.setClientModel(clientModel); URL resource = ChatApp.class.getResource( "splitPaneChatView.fxml"); + LOGGER.info("1"); if (resource == null) { System.out.println("File wasnt found"); } @@ -46,16 +72,23 @@ public class ChatApp extends Application { Parent root = FXMLLoader.load( Objects.requireNonNull(ChatApp.class.getResource( "splitPaneChatView.fxml"))); + LOGGER.info("2"); // TODO bin chatController.getChatPaneRoot() border to root border for rezising Scene scene = new Scene(root); + LOGGER.info("3"); scene.setRoot(root); + LOGGER.info("4"); primaryStage.setScene(scene); + LOGGER.info("5"); } catch (Exception e) { e.printStackTrace(); } primaryStage.setResizable(true); + LOGGER.info("6"); primaryStage.setTitle("Chat"); + LOGGER.info("7"); primaryStage.show(); + LOGGER.info("8"); } diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java index 18b3df8..caf52ef 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java @@ -68,7 +68,7 @@ public class ChatController implements Initializable { */ @Override public void initialize(URL location, ResourceBundle resources) { - + setClient(ChatApp.getClientModel()); vBoxChatMessages.getChildren().addListener(new ListChangeListener() { @Override public void onChanged(Change c) { From 28b0c08ddb096a6a8fa7f53720f5d2bf978f7380 Mon Sep 17 00:00:00 2001 From: Seraina Date: Sun, 17 Apr 2022 14:33:55 +0200 Subject: [PATCH 2/8] Added ChatController to the running application --- .../cs108/multiplayer/client/gui/chat/ChatApp.java | 8 ++++---- .../multiplayer/client/gui/chat/ChatController.java | 11 +++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatApp.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatApp.java index 26ed67a..52e7fb3 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatApp.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatApp.java @@ -18,7 +18,7 @@ public class ChatApp extends Application { public static final BudaLogConfig l = new BudaLogConfig(LOGGER); private static ClientModel clientModel; - private ChatController chatController; + private static ChatController chatController; public ChatApp() { super(); @@ -31,9 +31,9 @@ public class ChatApp extends Application { this.chatController = new ChatController(clientModel); } - public void setChatController( - ChatController chatController) { - this.chatController = chatController; + public static void setChatController( + ChatController chatC) { + chatController = chatC; } public static void setClientModel(ClientModel clientM) { diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java index caf52ef..eacfbc3 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java @@ -1,6 +1,7 @@ package ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.chat; +import ch.unibas.dmi.dbis.cs108.BudaLogConfig; import ch.unibas.dmi.dbis.cs108.multiplayer.client.gui.ClientModel; import ch.unibas.dmi.dbis.cs108.multiplayer.helpers.Protocol; import java.net.URL; @@ -23,8 +24,12 @@ import javafx.scene.control.TextField; import javafx.scene.layout.Background; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; public class ChatController implements Initializable { + public static final Logger LOGGER = LogManager.getLogger(ChatController.class); + public static final BudaLogConfig l = new BudaLogConfig(LOGGER); @FXML private SplitPane chatPaneRoot; @@ -49,12 +54,12 @@ public class ChatController implements Initializable { public ChatController() { //TODO: why does this get called super(); whisperTargetChosen = new SimpleBooleanProperty(); - cmd = ""; + cmd = "CHATA$"; } public ChatController(ClientModel client) { this.client = client; whisperTargetChosen = new SimpleBooleanProperty(); - cmd = ""; + cmd = "CHATA"; } @@ -69,6 +74,7 @@ public class ChatController implements Initializable { @Override public void initialize(URL location, ResourceBundle resources) { setClient(ChatApp.getClientModel()); + ChatApp.setChatController(this); vBoxChatMessages.getChildren().addListener(new ListChangeListener() { @Override public void onChanged(Change c) { @@ -100,6 +106,7 @@ public class ChatController implements Initializable { String msg = chatMsgField.getText(); if (!msg.isEmpty()) { client.getClient().sendMsgToServer(cmd.toString() + msg); + LOGGER.info("Message trying to send is: " + cmd.toString() + msg); Label l = new Label(client.getUsername() + " (you): " + msg); l.setBackground(Background.fill(Color.LAVENDER)); vBoxChatMessages.getChildren().add(l); From 74fdca0efddb5e88dbf33cd831c2a7b7ff46a0b8 Mon Sep 17 00:00:00 2001 From: Sebastian Lenzlinger Date: Sun, 17 Apr 2022 15:06:24 +0200 Subject: [PATCH 3/8] added whisper functionality for whisper in ClientHandler and Gui and deleted old recources that aren't needed. --- .../client/gui/chat/ChatController.java | 9 +- .../multiplayer/server/ClientHandler.java | 139 +++++++++++------- .../server/JServerProtocolParser.java | 5 +- .../cs108/resources/splitPaneChatView.fxml | 66 --------- 4 files changed, 97 insertions(+), 122 deletions(-) delete mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/resources/splitPaneChatView.fxml diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java index eacfbc3..316dd91 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/client/gui/chat/ChatController.java @@ -54,13 +54,14 @@ public class ChatController implements Initializable { public ChatController() { //TODO: why does this get called super(); whisperTargetChosen = new SimpleBooleanProperty(); - cmd = "CHATA$"; + cmd = ""; + LOGGER.info("ChatController empty constructor used"); } public ChatController(ClientModel client) { this.client = client; whisperTargetChosen = new SimpleBooleanProperty(); - cmd = "CHATA"; - + cmd = ""; + LOGGER.info("ChatController single parameter constructor used"); } @@ -138,7 +139,7 @@ public class ChatController implements Initializable { Boolean newValue) { //is true if {@code whisperTargetSelectedField} has content if (!newValue) { - cmd = whisper + "$"; + cmd = whisper + "$" + whisperTargetSelectField.getText() + "$"; } else { cmd = chatToLobby + "$"; } 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 5ba0654..3c11376 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 @@ -117,10 +117,10 @@ public class ClientHandler implements Runnable { } - /** * Lets the client change their username, if the username is already taken, a similar option is * chosen. + * * @param newName The desired new name to replace the old one with. */ public void changeUsername(String newName) { @@ -128,7 +128,7 @@ public class ClientHandler implements Runnable { this.clientUserName = nameDuplicateChecker.checkName(newName); broadcastAnnouncementToAll(helper + " has changed their nickname to " + clientUserName); try { - getLobby().getGame().getGameState().changeUsername(helper,newName); + getLobby().getGame().getGameState().changeUsername(helper, newName); } catch (NullPointerException e) { } } @@ -152,8 +152,8 @@ public class ClientHandler implements Runnable { } /** - * Returns the Lobby this ClientHandler is in. If this ClientHandler is not in a Lobby, - * it returns null. + * Returns the Lobby this ClientHandler is in. If this ClientHandler is not in a Lobby, it returns + * null. */ public Lobby getLobby() { try { @@ -164,8 +164,9 @@ public class ClientHandler implements Runnable { } /** - * Broadcasts a chat Message to all clients in the same lobby in the form "Username: @msg" - * If this client isn't in a lobby, it instead sends the message to everyone not in a lobby + * Broadcasts a chat Message to all clients in the same lobby in the form "Username: @msg" If this + * client isn't in a lobby, it instead sends the message to everyone not in a lobby + * * @param msg the Message to be broadcast */ public void broadcastChatMessageToLobby(String msg) { @@ -176,7 +177,7 @@ public class ClientHandler implements Runnable { } } else { //send msg to all clients who are not in a lobby. - for (ClientHandler client: connectedClients) { + for (ClientHandler client : connectedClients) { if (Lobby.clientIsInLobby(client) == -1) { client.sendMsgToClient(Protocol.printToClientChat + "$" + clientUserName + ": " + msg); } @@ -199,8 +200,9 @@ public class ClientHandler implements Runnable { } /** - * Broadcasts a chat Message to all clients across all lobbies & clients who are not in a lobby - * in the form "Username: @msg" + * Broadcasts a chat Message to all clients across all lobbies & clients who are not in a lobby in + * the form "Username: @msg" + * * @param msg the Message to be broadcast */ public void broadcastChatMessageToAll(String msg) { @@ -212,9 +214,11 @@ public class ClientHandler implements Runnable { /** * Broadcasts a non-chat Message to all active clients. This can be used for server messages / * announcements rather than chat messages. The message will be printed to the user exactly as it - * is given to this method. Unlike eg. broadcastChatMessageToLobby, it will also be printed onto the server - * console. - * @param msg the Message to be broadcast. Does not have to be protocol-formatted, this method will take care of that. + * is given to this method. Unlike eg. broadcastChatMessageToLobby, it will also be printed onto + * the server console. + * + * @param msg the Message to be broadcast. Does not have to be protocol-formatted, this method + * will take care of that. */ public static void broadcastAnnouncementToAll(String msg) { System.out.println(msg); @@ -224,12 +228,13 @@ public class ClientHandler implements Runnable { } /** - * Broadcasts a non-chat Message to all clients in the same lobby. This can be used for server messages / - * announcements rather than chat messages. The message will be printed to the user exactly as it - * is given to this method. The announcement will not be printed on the server console. - * If this clienthandler is not in a lobby, it will instead broadcast to all clients. + * Broadcasts a non-chat Message to all clients in the same lobby. This can be used for server + * messages / announcements rather than chat messages. The message will be printed to the user + * exactly as it is given to this method. The announcement will not be printed on the server + * console. If this clienthandler is not in a lobby, it will instead broadcast to all clients. * - * @param msg the Message to be broadcast. Does not have to be protocol-formatted, this method will take care of that. + * @param msg the Message to be broadcast. Does not have to be protocol-formatted, this method + * will take care of that. */ public void broadcastAnnouncementToLobby(String msg) { Lobby l = getLobby(); @@ -246,13 +251,17 @@ public class ClientHandler implements Runnable { } /** - * Sends a message only to the specified user, as well as sending a confirmation to the user who sent the message - * that it has been sent. Syntax: + * Sends a message only to the specified user, as well as sending a confirmation to the user who + * sent the message that it has been sent. Syntax: + * * @param target MUST NOT BE NULL! */ public void whisper(String msg, ClientHandler target) { - target.sendMsgToClient(Protocol.printToClientChat + "$" + this.getClientUserName() + " whispers: " + msg); - sendMsgToClient(Protocol.printToClientChat + "$You whispered to " + target.getClientUserName() + ": " + msg); + target.sendMsgToClient( + Protocol.printToClientChat + "$" + this.getClientUserName() + " whispers: " + msg); + sendMsgToClient( + Protocol.printToClientChat + "$You whispered to " + target.getClientUserName() + ": " + + msg); } /** @@ -275,34 +284,56 @@ public class ClientHandler implements Runnable { } /** - * Takes a msg of the form position$vote and extracts vote and position from it and saves it - * in VoteHandler.getClientVoteData - * @param msg the messaged to decode + * Decode a whisper mesage + * + * @param msg to decode. the command has been removed from the front + * @return a String[] containing the target at index 0 and the message at index 1. */ - public void decodeVote(String msg){ + public String[] decodeWhisper(String msg) { + int msgIndex = msg.indexOf('$'); + String target = ""; + String chatMsg = ""; + LOGGER.debug("incoming whisper to decode is:" + msg); + try { + target = msg.substring(0, msgIndex); + chatMsg = msg.substring(msgIndex + 1); + LOGGER.debug("whisper target is: " + target); + LOGGER.debug("whisper chatMsg is: " + chatMsg); + } catch (Exception e) { + LOGGER.warn("decode whisper issue: " + e.getMessage()); + } + return new String[]{target, chatMsg}; + } + + /** + * Takes a msg of the form position$vote and extracts vote and position from it and saves it in + * VoteHandler.getClientVoteData + * + * @param msg the messaged to decode + */ + public void decodeVote(String msg) { int msgIndex = msg.indexOf('$'); int vote = Integer.MAX_VALUE; int position = 0; LOGGER.debug("Message is " + msg); try { - position = Integer.parseInt(msg.substring(0,msgIndex)); + position = Integer.parseInt(msg.substring(0, msgIndex)); vote = Integer.parseInt(msg.substring(msgIndex + 1)); LOGGER.debug("Vote is:" + vote); } catch (Exception e) { LOGGER.warn("Invalid vote " + e.getMessage()); } LOGGER.debug("Vote is:" + vote); - if(vote != Integer.MAX_VALUE) { //gets MAX_VALUE when the vote wasn't valid - getLobby().getGame().getGameState().getClientVoteData().setVote(position,vote); + if (vote != Integer.MAX_VALUE) { //gets MAX_VALUE when the vote wasn't valid + getLobby().getGame().getGameState().getClientVoteData().setVote(position, vote); LOGGER.debug("Player vote: " + vote); - getLobby().getGame().getGameState().getClientVoteData().setHasVoted(position,true); + getLobby().getGame().getGameState().getClientVoteData().setHasVoted(position, true); } } /** - * Initializes a new Game instance and starts its run method in a new thread. - * Puts the game in the corresponding lobby. Only the admin of this lobby can start a new - * game. + * Initializes a new Game instance and starts its run method in a new thread. Puts the game in the + * corresponding lobby. Only the admin of this lobby can start a new game. */ public void startNewGame() { try { @@ -328,9 +359,9 @@ public class ClientHandler implements Runnable { } /** - * Sends an announcement to just this client. Essentially the same as broadcastAnnouncementToAll except - * it only sends an announcement to just this client instead of everyone. - * Can be used for private non-chat messages (e.g. "You are now a ghost"). + * Sends an announcement to just this client. Essentially the same as broadcastAnnouncementToAll + * except it only sends an announcement to just this client instead of everyone. Can be used for + * private non-chat messages (e.g. "You are now a ghost"). */ public void sendAnnouncementToClient(String msg) { sendMsgToClient(Protocol.printToClientConsole + "$" + msg); @@ -347,7 +378,8 @@ public class ClientHandler implements Runnable { connectedClients.remove(this); disconnectClient(); leaveLobby(); - broadcastAnnouncementToAll(getClientUserName() + " has left the server due to a connection loss."); + broadcastAnnouncementToAll( + getClientUserName() + " has left the server due to a connection loss."); disconnectedClients.add(this); } @@ -377,7 +409,9 @@ public class ClientHandler implements Runnable { } /** - * The client wants to join the lobby with the index i. If the lobby is closed, the client will be notified. + * The client wants to join the lobby with the index i. If the lobby is closed, the client will be + * notified. + * * @param i the number of the lobby to join */ public void joinLobby(int i) { @@ -386,7 +420,8 @@ public class ClientHandler implements Runnable { if (l.getLobbyIsOpen()) { l.addPlayer(this); } else { - sendAnnouncementToClient("The game in Lobby " + l.getLobbyID() + " has already started, or the lobby is already full."); + sendAnnouncementToClient("The game in Lobby " + l.getLobbyID() + + " has already started, or the lobby is already full."); } } else { sendAnnouncementToClient("Invalid Lobby nr."); @@ -403,7 +438,7 @@ public class ClientHandler implements Runnable { if (l != null) { l.removePlayer(this); Game game = l.getGame(); - if(game != null) { + if (game != null) { l.getGame().getGameState().handleClientDisconnect(this); } } @@ -411,8 +446,8 @@ public class ClientHandler implements Runnable { /** - * Lists all lobbies and their members, along with players outside lobbies - * to this clientHandler's client as an announcement. + * Lists all lobbies and their members, along with players outside lobbies to this clientHandler's + * client as an announcement. */ public void listLobbies() { if (Lobby.lobbies.isEmpty()) { @@ -420,7 +455,7 @@ public class ClientHandler implements Runnable { } else { for (Lobby l : Lobby.lobbies) { String lobbyStatus = "closed"; - if(l.getLobbyIsOpen()) { + if (l.getLobbyIsOpen()) { lobbyStatus = "open"; } sendAnnouncementToClient("Lobby nr. " + l.getLobbyID() + ": (" + lobbyStatus + ")"); @@ -434,7 +469,7 @@ public class ClientHandler implements Runnable { } } boolean helper = false; //used to print "Clients not in lobbies" only once, if needed. - for (ClientHandler c: connectedClients) { + for (ClientHandler c : connectedClients) { if (Lobby.clientIsInLobby(c) == -1) { if (!helper) { helper = true; @@ -449,8 +484,8 @@ public class ClientHandler implements Runnable { } /** - * Lists all players in the client's lobby. If the client is not in a Lobby, it will say - * "You are not in a lobby." + * Lists all players in the client's lobby. If the client is not in a Lobby, it will say "You are + * not in a lobby." */ public void listPlayersInLobby() { Lobby l = getLobby(); @@ -469,7 +504,8 @@ public class ClientHandler implements Runnable { } /** - * Lists all Games currenty running and already finished and displays it to the client handled by this + * Lists all Games currenty running and already finished and displays it to the client handled by + * this */ public void listGames() { if (Lobby.runningGames.isEmpty() && Lobby.finishedGames.isEmpty()) { @@ -478,7 +514,8 @@ public class ClientHandler implements Runnable { sendAnnouncementToClient("Running Games:"); try { for (Game runningGame : Lobby.runningGames) { - sendAnnouncementToClient(" - " + runningGame.getName() + ", Lobby" + runningGame.getLobby().getLobbyID()); + sendAnnouncementToClient( + " - " + runningGame.getName() + ", Lobby" + runningGame.getLobby().getLobbyID()); } } catch (Exception e) { sendAnnouncementToClient(" - No running Games"); @@ -486,7 +523,8 @@ public class ClientHandler implements Runnable { sendAnnouncementToClient("Finished Games:"); try { for (Game finishedGame : Lobby.finishedGames) { - sendAnnouncementToClient(" - " + finishedGame.getName() + ", Lobby" + finishedGame.getLobby().getLobbyID()); + sendAnnouncementToClient( + " - " + finishedGame.getName() + ", Lobby" + finishedGame.getLobby().getLobbyID()); } } catch (Exception e) { sendAnnouncementToClient(" - No finished Games"); @@ -501,8 +539,9 @@ public class ClientHandler implements Runnable { Lobby l = getLobby(); if (l != null) { Game g = l.getGame(); - if(g != null) - l.getGame().getGameState().handleClientDisconnect(this); + if (g != null) { + l.getGame().getGameState().handleClientDisconnect(this); + } } socket = this.getSocket(); in = this.getIn(); diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java index 3664a89..eb5006a 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/multiplayer/server/JServerProtocolParser.java @@ -47,8 +47,9 @@ public class JServerProtocolParser { //find ClientHandler try { ClientHandler target = null; - String targetName = msg.substring(6, msg.indexOf("$", 6)); - String chatMsg = msg.substring(msg.indexOf("$", 6)+1); + String[] targetAndMsg = h.decodeWhisper(msg.substring(6)); + String targetName = targetAndMsg[0]; + String chatMsg = targetAndMsg[1]; System.out.println(targetName); System.out.println(chatMsg); for (ClientHandler c : ClientHandler.getConnectedClients()) { diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/resources/splitPaneChatView.fxml b/src/main/java/ch/unibas/dmi/dbis/cs108/resources/splitPaneChatView.fxml deleted file mode 100644 index 1ae8b3e..0000000 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/resources/splitPaneChatView.fxml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -