From 31d3947175e38536d07940e00c46a4cc1cca045c Mon Sep 17 00:00:00 2001 From: Mathis Ginkel Date: Fri, 10 Apr 2026 13:21:34 +0200 Subject: [PATCH 1/5] Add: CSS-Style changes to the ChatBox --- .../components/chatui/chatbox.fxml | 34 +++++------- .../ui-structure/components/chatui/chatui.css | 52 +++++++++++++++++-- 2 files changed, 59 insertions(+), 27 deletions(-) diff --git a/src/main/resources/ui-structure/components/chatui/chatbox.fxml b/src/main/resources/ui-structure/components/chatui/chatbox.fxml index 21cedf6..e88c640 100644 --- a/src/main/resources/ui-structure/components/chatui/chatbox.fxml +++ b/src/main/resources/ui-structure/components/chatui/chatbox.fxml @@ -2,11 +2,7 @@ - - - - - - - - + - + - - - - - - - + + \ No newline at end of file diff --git a/src/main/resources/ui-structure/components/chatui/chatui.css b/src/main/resources/ui-structure/components/chatui/chatui.css index 280f95e..81578b0 100644 --- a/src/main/resources/ui-structure/components/chatui/chatui.css +++ b/src/main/resources/ui-structure/components/chatui/chatui.css @@ -5,7 +5,7 @@ -fx-border-color: #5c3d10 #3d260a #3d260a #5c3d10; -fx-border-width: 12; -fx-padding: 20; - -fx-effect: dropshadow(one-pass-box, rgba(0,0,0,1), 0, 0, 15, 15); + /*-fx-effect: dropshadow(one-pass-box, rgba(0,0,0,1), 0, 0, 15, 15);*/ } .chat-header { @@ -154,11 +154,53 @@ -fx-pref-height: 10; } -.tab-pane .tab-header-area { - -fx-background-color: #0d763b; +.tab-pane .tab-header-area .tab-header-background { + -fx-opacity: 0; + -fx-background-color: #0d9e3b; + -fx-background-radius: 18; + -fx-border-radius: 10; + -fx-border-color: #5c3d10 #3d260a #3d260a #5c3d10; + -fx-border-width: 5; + -fx-padding: 10; + -fx-effect: dropshadow(one-pass-box, rgba(0,0,0,1), 0, 0, 15, 15); + -fx-max-height: 10; } +.tab-pane .tab { + -fx-background-color: #0d9e3b; + -fx-background-radius: 18; + -fx-border-radius: 10; + -fx-border-color: #5c3d10 #3d260a #3d260a #5c3d10; + -fx-border-width: 5; + -fx-padding: 10; +} + +.tab-pane .tab:selected { + -fx-background-color: #0d763b; + -fx-background-radius: 18; + -fx-border-radius: 10; + -fx-border-color: #5c3d10 #3d260a #3d260a #5c3d10; + -fx-border-width: 5; + -fx-padding: 10; +} + +.tab-pane .tab .tab-close-button { + -fx-text-fill: #0d9e3b; +} + +.tab-pane .tab-header-area .headers-region { + -fx-background-color: #0d9e3b; +} + + .tab .tab-label { - -fx-font-family: "Courier New"; + -fx-alignment: CENTER; + -fx-text-fill: #ffffff; + -fx-font-size: 12px; -fx-font-weight: bold; -} \ No newline at end of file +} + +.tab:selected .tab-label { + -fx-alignment: CENTER; + -fx-text-fill: #ffffff; +} -- 2.52.0 From 97e5a55042abdc304c5b259f9f6ec7639820c3d2 Mon Sep 17 00:00:00 2001 From: Mathis Ginkel Date: Fri, 10 Apr 2026 22:43:23 +0200 Subject: [PATCH 2/5] Style: Apply Spotless --- .../casono/client/chat/ChatController.java | 7 +- .../cs108/casono/client/chat/ChatModel.java | 11 +-- .../cs108/casono/client/chat/Message.java | 87 ++++++++++--------- .../casono/client/network/ClientService.java | 32 +++---- .../client/ui/chatui/ChatBoxController.java | 28 +++--- .../client/ui/chatui/ChatViewController.java | 26 +++--- .../GetMessageCountHandler.java | 11 ++- .../GetMessageCountParser.java | 6 +- .../GetMessageCountRequest.java | 6 +- .../GetMessageCountResponse.java | 5 +- .../GetNextMessageHandler.java | 10 +-- .../GetNextMessageParser.java | 7 +- .../GetNextMessageRequest.java | 6 +- .../GetNextMessageResponse.java | 5 +- .../send_message/SendMessageHandler.java | 8 +- .../send_message/SendMessageParser.java | 6 +- .../dbis/cs108/casono/client/chat/Chat.java | 6 +- .../casono/client/chat/ChatApplication.java | 20 +---- 18 files changed, 136 insertions(+), 151 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatController.java index 1ebaf41..161397a 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatController.java @@ -3,10 +3,13 @@ package ch.unibas.dmi.dbis.cs108.casono.client.chat; import ch.unibas.dmi.dbis.cs108.casono.client.network.ChatClient; import ch.unibas.dmi.dbis.cs108.casono.client.network.ClientService; import ch.unibas.dmi.dbis.cs108.casono.client.ui.chatui.ChatBoxController; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Timer; +import java.util.TimerTask; import org.jspecify.annotations.Nullable; -import java.util.*; - /** * responsible for the transferring of messages from the server to the ChatModel or from the * ChatViewController to the server diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatModel.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatModel.java index 87c9b8f..69cdecb 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatModel.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatModel.java @@ -1,10 +1,9 @@ package ch.unibas.dmi.dbis.cs108.casono.client.chat; -import javafx.beans.property.IntegerProperty; -import javafx.beans.property.SimpleIntegerProperty; - import java.util.ArrayList; import java.util.function.Consumer; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.SimpleIntegerProperty; /** * ChatModel, stores the data for a specific chat @@ -48,6 +47,7 @@ public class ChatModel { /** * Returns the type of chat this model represents. + * * @return The {@link ChatType}. */ public ChatType getChattype() { @@ -55,8 +55,8 @@ public class ChatModel { } /** - * Adds a new message to the history and notifies all registered listeners. - * This method is synchronized to ensure thread safety when updating the message list. + * Adds a new message to the history and notifies all registered listeners. This method is + * synchronized to ensure thread safety when updating the message list. * * @param msg The {@link Message} to be added. */ @@ -76,6 +76,7 @@ public class ChatModel { /** * Returns the target user for this chat, primarily used for whispers. + * * @return The target username or null. */ public String getTarget() { diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/Message.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/Message.java index f2ab7d2..8ed83b8 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/Message.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/Message.java @@ -3,16 +3,13 @@ package ch.unibas.dmi.dbis.cs108.casono.client.chat; import ch.unibas.dmi.dbis.cs108.casono.server.network.command.parsing.RequestParameter; import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBody; import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBodyBuilder; -import org.jspecify.annotations.NonNull; - import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.List; import java.util.Optional; +import org.jspecify.annotations.NonNull; -/** - * Message Object for internal handling of Chat-Messages - */ +/** Message Object for internal handling of Chat-Messages */ public class Message { private final ChatType type; private final String message; @@ -22,15 +19,15 @@ public class Message { public String target = null; /** - * Constructs a Message with a provided timestamp. Typically used when - * reconstructing messages received from the server. + * Constructs a Message with a provided timestamp. Typically used when reconstructing messages + * received from the server. * - * @param type The chat category (e.g., GLOBAL, LOBBY, or WHISPER). - * @param lobbyId The ID of the lobby, or -1 if not applicable. - * @param sender The username of the message creator. - * @param target The username of the recipient (required for whispers, otherwise null). + * @param type The chat category (e.g., GLOBAL, LOBBY, or WHISPER). + * @param lobbyId The ID of the lobby, or -1 if not applicable. + * @param sender The username of the message creator. + * @param target The username of the recipient (required for whispers, otherwise null). * @param timestamp The formatted time string (e.g., "HH:mm"). - * @param message The actual text content of the message. + * @param message The actual text content of the message. */ public Message( ChatType type, @@ -48,13 +45,13 @@ public class Message { } /** - * Constructs a new Message for the current user. Automatically generates - * a timestamp based on the local system time ("HH:mm"). + * Constructs a new Message for the current user. Automatically generates a timestamp based on + * the local system time ("HH:mm"). * - * @param type The chat category (e.g., GLOBAL, LOBBY, or WHISPER). + * @param type The chat category (e.g., GLOBAL, LOBBY, or WHISPER). * @param lobbyId The ID of the lobby, or -1 if not applicable. - * @param sender The username of the current user. - * @param target The username of the recipient (for whispers). + * @param sender The username of the current user. + * @param target The username of the recipient (for whispers). * @param message The actual text content to be sent. */ public Message(ChatType type, int lobbyId, String sender, String target, String message) { @@ -87,8 +84,8 @@ public class Message { } /** - * Formats the message object into a string representation compatible with - * the network protocol arguments. + * Formats the message object into a string representation compatible with the network protocol + * arguments. * * @return A formatted string containing all message attributes for server transmission. */ @@ -110,8 +107,8 @@ public class Message { } /** - * Parses a list of network request parameters to reconstruct a Message object. - * Handles different chat types (GLOBAL, LOBBY, WHISPER) and their specific requirements. + * Parses a list of network request parameters to reconstruct a Message object. Handles + * different chat types (GLOBAL, LOBBY, WHISPER) and their specific requirements. * * @param parameters A list of {@link RequestParameter} received from the network. * @return A new {@link Message} instance populated with the parsed data. @@ -120,27 +117,30 @@ public class Message { String typeString = getParString(parameters, "TYPE"); ChatType type = ChatType.valueOf(typeString); return switch (type) { - case GLOBAL -> new Message( - ChatType.GLOBAL, - -1, - getParString(parameters, "USER"), - null, - getParString(parameters, "TIME"), - getParString(parameters, "TEXT")); - case LOBBY -> new Message( - ChatType.LOBBY, - Integer.parseInt(getParString(parameters, "GAME")), - getParString(parameters, "USER"), - null, - getParString(parameters, "TIME"), - getParString(parameters, "TEXT")); - case WHISPER -> new Message( - ChatType.WHISPER, - Integer.parseInt(getParString(parameters, "GAME", "-1")), - getParString(parameters, "USER"), - getParString(parameters, "TARGET"), - getParString(parameters, "TIME"), - getParString(parameters, "TEXT")); + case GLOBAL -> + new Message( + ChatType.GLOBAL, + -1, + getParString(parameters, "USER"), + null, + getParString(parameters, "TIME"), + getParString(parameters, "TEXT")); + case LOBBY -> + new Message( + ChatType.LOBBY, + Integer.parseInt(getParString(parameters, "GAME")), + getParString(parameters, "USER"), + null, + getParString(parameters, "TIME"), + getParString(parameters, "TEXT")); + case WHISPER -> + new Message( + ChatType.WHISPER, + Integer.parseInt(getParString(parameters, "GAME", "-1")), + getParString(parameters, "USER"), + getParString(parameters, "TARGET"), + getParString(parameters, "TIME"), + getParString(parameters, "TEXT")); }; } @@ -158,7 +158,8 @@ public class Message { } /** - * Helper method to extract a specific parameter value by its key, with a fallback default value. + * Helper method to extract a specific parameter value by its key, with a fallback default + * value. * * @param parameters The list of parameters to search. * @param keyString The key to look for. diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/network/ClientService.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/network/ClientService.java index 833ffb8..4ede0c1 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/network/ClientService.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/network/ClientService.java @@ -3,9 +3,6 @@ package ch.unibas.dmi.dbis.cs108.casono.client.network; import ch.unibas.dmi.dbis.cs108.casono.server.network.command.parsing.RequestParameter; import ch.unibas.dmi.dbis.cs108.casono.server.network.transport.RawPacket; import ch.unibas.dmi.dbis.cs108.casono.server.network.transport.TcpTransport; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import java.io.IOException; import java.net.Socket; import java.util.ArrayList; @@ -17,6 +14,8 @@ import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicInteger; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; /** * The ClientService class is responsible for managing the connection to the server, sending @@ -35,11 +34,11 @@ public class ClientService { private final Logger logger; /** - * Constructs a ClientService with the given server IP and port. It establishes - * a socket connection to the server and initializes the TcpTransport and - * ExecutorService for communication. + * Constructs a ClientService with the given server IP and port. It establishes a socket + * connection to the server and initializes the TcpTransport and ExecutorService for + * communication. * - * @param ip The IP address of the server to connect to. + * @param ip The IP address of the server to connect to. * @param port The port number of the server to connect to. */ public ClientService(String ip, int port) { @@ -64,8 +63,8 @@ public class ClientService { "(?\\w+)=(('(?([^']|\\')+)')|(?[+-]?[\\d\\w:]+))"); /** - * Removes escape characters from a string, specifically converting escaped - * single quotes (\') back to regular single quotes ('). + * Removes escape characters from a string, specifically converting escaped single quotes (\') + * back to regular single quotes ('). * * @param input The escaped string to process. * @return The unescaped string. @@ -75,9 +74,9 @@ public class ClientService { } /** - * Converts a list of raw string parameters into a list of {@link RequestParameter} objects. - * It uses a regex matcher to distinguish between quoted strings (which are unescaped) - * and primitive values. + * Converts a list of raw string parameters into a list of {@link RequestParameter} objects. It + * uses a regex matcher to distinguish between quoted strings (which are unescaped) and + * primitive values. * * @param input A list of raw strings to be parsed. * @return A list of parsed {@link RequestParameter} objects. @@ -102,13 +101,14 @@ public class ClientService { } /** - * Sends a command to the server and processes the multi-line response. - * It handles the protocol handshake (expecting +OK), strips leading tabs from - * response lines, and collects them until the "END" marker is reached. + * Sends a command to the server and processes the multi-line response. It handles the protocol + * handshake (expecting +OK), strips leading tabs from response lines, and collects them until + * the "END" marker is reached. * * @param message The raw command string to be sent to the transport layer. * @return A list of response lines received from the server (excluding protocol markers). - * @throws RuntimeException if the server responds with an error or if a communication failure occurs. + * @throws RuntimeException if the server responds with an error or if a communication failure + * occurs. */ protected List processCommand(String message) { List response = new ArrayList<>(); diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatBoxController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatBoxController.java index 65e38fe..618d309 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatBoxController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatBoxController.java @@ -3,6 +3,9 @@ package ch.unibas.dmi.dbis.cs108.casono.client.ui.chatui; import ch.unibas.dmi.dbis.cs108.casono.client.chat.ChatController; import ch.unibas.dmi.dbis.cs108.casono.client.chat.ChatModel; import ch.unibas.dmi.dbis.cs108.casono.client.chat.ChatType; +import java.io.IOException; +import java.net.URL; +import java.util.List; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Node; @@ -13,10 +16,6 @@ import javafx.scene.control.TabPane; import javafx.scene.layout.Priority; import javafx.scene.layout.VBox; -import java.io.IOException; -import java.net.URL; -import java.util.List; - public class ChatBoxController { private String username; @@ -41,9 +40,9 @@ public class ChatBoxController { } /** - * Initializes the chat interface by creating the global chat model and - * adding the corresponding "GLOBAL" tab to the interface. - * It also registers the global chat in the {@link ChatController}'s model map. + * Initializes the chat interface by creating the global chat model and adding the corresponding + * "GLOBAL" tab to the interface. It also registers the global chat in the {@link + * ChatController}'s model map. */ @FXML public void initialize() { @@ -56,9 +55,8 @@ public class ChatBoxController { } /** - * Adds a specific user to the list of available whisper targets. - * Creates a new menu item for the user and defines the action to open - * a private chat tab when selected. + * Adds a specific user to the list of available whisper targets. Creates a new menu item for + * the user and defines the action to open a private chat tab when selected. * * @param targetUserName The username of the person to be added to the whisper list. */ @@ -70,8 +68,8 @@ public class ChatBoxController { } /** - * Creates a new private (whisper) chat model for a specific target user, - * registers it within the chat system, and opens a new chat tab. + * Creates a new private (whisper) chat model for a specific target user, registers it within + * the chat system, and opens a new chat tab. * * @param target The username of the recipient for the private messages. */ @@ -84,9 +82,9 @@ public class ChatBoxController { } /** - * Dynamically loads a new chat tab from an FXML resource and attaches it - * to the TabPane. It initializes a {@link ChatViewController} for the tab - * and sets up a listener to display incoming messages in real-time. + * Dynamically loads a new chat tab from an FXML resource and attaches it to the TabPane. It + * initializes a {@link ChatViewController} for the tab and sets up a listener to display + * incoming messages in real-time. * * @param title The title to be displayed on the tab header. * @param chatModel The {@link ChatModel} containing the data and logic for this specific chat. diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatViewController.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatViewController.java index 879427f..397e8f3 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatViewController.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/client/ui/chatui/ChatViewController.java @@ -3,6 +3,8 @@ package ch.unibas.dmi.dbis.cs108.casono.client.ui.chatui; import ch.unibas.dmi.dbis.cs108.casono.client.chat.ChatController; import ch.unibas.dmi.dbis.cs108.casono.client.chat.ChatModel; import ch.unibas.dmi.dbis.cs108.casono.client.chat.Message; +import java.net.URL; +import java.util.ResourceBundle; import javafx.application.Platform; import javafx.fxml.FXML; import javafx.fxml.Initializable; @@ -13,9 +15,6 @@ import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; -import java.net.URL; -import java.util.ResourceBundle; - /** Responsible for the presentation of the ChatModel to the Client */ public class ChatViewController implements Initializable { @@ -44,11 +43,11 @@ public class ChatViewController implements Initializable { this.username = username; this.chatModel = chatModel; } + /** - * Initializes the controller after the FXML root element has been processed. - * Sets up event handlers for sending messages via the input field or button - * and ensures the ScrollPane automatically scrolls to the bottom when new - * messages are added. + * Initializes the controller after the FXML root element has been processed. Sets up event + * handlers for sending messages via the input field or button and ensures the ScrollPane + * automatically scrolls to the bottom when new messages are added. * * @param location The location used to resolve relative paths for the root object. * @param resourceBundle The resources used to localize the root object. @@ -61,9 +60,9 @@ public class ChatViewController implements Initializable { } /** - * Retrieves the text from the input field, creates a new {@link Message} object - * using the current model state, and passes it to the {@link ChatController} - * for network transmission. The input field is cleared after sending. + * Retrieves the text from the input field, creates a new {@link Message} object using the + * current model state, and passes it to the {@link ChatController} for network transmission. + * The input field is cleared after sending. */ public void sendMessage() { String message = inputField.getText().trim(); @@ -81,10 +80,9 @@ public class ChatViewController implements Initializable { } /** - * Displays a message in the chat interface. This method creates a new Label - * for the message text and adds it to the message container. - * It uses {@link Platform#runLater(Runnable)} to ensure the UI update - * happens on the JavaFX Application Thread. + * Displays a message in the chat interface. This method creates a new Label for the message + * text and adds it to the message container. It uses {@link Platform#runLater(Runnable)} to + * ensure the UI update happens on the JavaFX Application Thread. * * @param msg The {@link Message} object containing the content and metadata to display. */ diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountHandler.java index 46203c4..dcfe216 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountHandler.java @@ -11,8 +11,8 @@ public class GetMessageCountHandler extends CommandHandler { /** - * Parses a raw {@link PrimitiveRequest} into a {@link GetMessageCountRequest}. - * This method wraps the request context from the network layer into a - * structured message count request object. + * Parses a raw {@link PrimitiveRequest} into a {@link GetMessageCountRequest}. This method + * wraps the request context from the network layer into a structured message count request + * object. * * @param primitiveRequest The raw request containing parameters and context from the network. * @return A new {@link GetMessageCountRequest} instance. diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountRequest.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountRequest.java index 93f99c5..a1d0f7d 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountRequest.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountRequest.java @@ -5,9 +5,9 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestCo public class GetMessageCountRequest extends Request { /** - * Constructs a new GetMessageCountRequest with the specified request context. - * This request is used by a client to query the number of pending messages - * currently waiting in their server-side queue. + * Constructs a new GetMessageCountRequest with the specified request context. This request is + * used by a client to query the number of pending messages currently waiting in their + * server-side queue. * * @param context The {@link RequestContext} associated with this request. */ diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountResponse.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountResponse.java index 87c212d..a58edd6 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountResponse.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_message_count/GetMessageCountResponse.java @@ -6,9 +6,8 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder. public class GetMessageCountResponse extends SuccessResponse { /** - * Constructs a new GetMessageCountResponse. It creates a response body - * containing the "COUNT" parameter and associates it with the original - * request context. + * Constructs a new GetMessageCountResponse. It creates a response body containing the "COUNT" + * parameter and associates it with the original request context. * * @param context The {@link RequestContext} of the original request. * @param count The number of pending messages to be returned to the client. diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageHandler.java index f024d24..deb5773 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageHandler.java @@ -6,7 +6,6 @@ import ch.unibas.dmi.dbis.cs108.casono.server.domain.user.UserRegistry; import ch.unibas.dmi.dbis.cs108.casono.server.network.command.execution.CommandHandler; import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.ErrorResponse; import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.dispatcher.ResponseDispatcher; - import java.util.Optional; public class GetNextMessageHandler extends CommandHandler { @@ -22,11 +21,12 @@ public class GetNextMessageHandler extends CommandHandler super(responseDispatcher); this.userRegistry = userRegistry; } + /** - * Executes the request to retrieve the next message for a specific user. - * It identifies the user via their session ID, dequeues the next available message, - * and dispatches a {@link GetNextMessageResponse}. If the user cannot be identified, - * an {@link ErrorResponse} is sent instead. + * Executes the request to retrieve the next message for a specific user. It identifies the user + * via their session ID, dequeues the next available message, and dispatches a {@link + * GetNextMessageResponse}. If the user cannot be identified, an {@link ErrorResponse} is sent + * instead. * * @param request The {@link GetNextMessageRequest} containing the session and context. */ diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageParser.java index e75577c..185c5b5 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageParser.java @@ -6,10 +6,9 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.accessor. public class GetNextMessageParser implements CommandParser { /** - * Parses a raw {@link PrimitiveRequest} into a {@link GetNextMessageRequest}. - * This method initializes a parameter accessor (though not currently used - * for extraction) and returns a structured request object containing - * the original request context. + * Parses a raw {@link PrimitiveRequest} into a {@link GetNextMessageRequest}. This method + * initializes a parameter accessor (though not currently used for extraction) and returns a + * structured request object containing the original request context. * * @param primitiveRequest The raw request containing parameters and context from the network. * @return A new {@link GetNextMessageRequest} instance. diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageRequest.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageRequest.java index 77c8b57..76f6678 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageRequest.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageRequest.java @@ -5,9 +5,9 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestCo public class GetNextMessageRequest extends Request { /** - * Constructs a new GetNextMessageRequest with the specified request context. - * This request is typically used by a client to poll or retrieve the next - * available message from the server's queue. + * Constructs a new GetNextMessageRequest with the specified request context. This request is + * typically used by a client to poll or retrieve the next available message from the server's + * queue. * * @param context The {@link RequestContext} associated with this request. */ diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageResponse.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageResponse.java index ecb3c12..1fd9378 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageResponse.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/get_next_message/GetNextMessageResponse.java @@ -7,9 +7,8 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder. public class GetNextMessageResponse extends SuccessResponse { /** - * Constructs a new GetNextMessageResponse. It converts the provided {@link Message} - * into a network-compatible response body and associates it with the original - * request context. + * Constructs a new GetNextMessageResponse. It converts the provided {@link Message} into a + * network-compatible response body and associates it with the original request context. * * @param context The {@link RequestContext} of the request being answered. * @param msg The {@link Message} to be sent back to the client. diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/send_message/SendMessageHandler.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/send_message/SendMessageHandler.java index 805afcc..0bf5b95 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/send_message/SendMessageHandler.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/send_message/SendMessageHandler.java @@ -22,8 +22,8 @@ public class SendMessageHandler extends CommandHandler { /** * Processes a message send request. This method extracts the message from the request, - * broadcasts it to all connected users, and dispatches a success response (OK) - * back to the sender. + * broadcasts it to all connected users, and dispatches a success response (OK) back to the + * sender. * * @param request The {@link SendMessageRequest} containing the message and context. */ @@ -36,8 +36,8 @@ public class SendMessageHandler extends CommandHandler { } /** - * Distributes a message to every user currently registered in the system. - * Each user's message queue is updated with the new message. + * Distributes a message to every user currently registered in the system. Each user's message + * queue is updated with the new message. * * @param message The {@link Message} object to be broadcast. */ diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/send_message/SendMessageParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/send_message/SendMessageParser.java index c13ac3d..eb8cf95 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/send_message/SendMessageParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/send_message/SendMessageParser.java @@ -7,9 +7,9 @@ import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.Primitive public class SendMessageParser implements CommandParser { /** - * Parses a raw {@link PrimitiveRequest} into a specific {@link SendMessageRequest}. - * This method extracts the message details from the request parameters and - * wraps them along with the request context into a structured request object. + * Parses a raw {@link PrimitiveRequest} into a specific {@link SendMessageRequest}. This method + * extracts the message details from the request parameters and wraps them along with the + * request context into a structured request object. * * @param primitiveRequest The raw request containing parameters and context from the network. * @return A structured {@link SendMessageRequest} containing the parsed {@link Message}. diff --git a/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/Chat.java b/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/Chat.java index 15b81d7..6088f22 100644 --- a/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/Chat.java +++ b/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/Chat.java @@ -3,7 +3,7 @@ package ch.unibas.dmi.dbis.cs108.casono.client.chat; import javafx.application.Application; public class Chat { - public static void main(String[] args) { - Application.launch(ChatApplication.class); - } + public static void main(String[] args) { + Application.launch(ChatApplication.class); + } } diff --git a/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatApplication.java b/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatApplication.java index c44f4fd..6974c0d 100644 --- a/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatApplication.java +++ b/src/test/java/ch/unibas/dmi/dbis/cs108/casono/client/chat/ChatApplication.java @@ -3,13 +3,12 @@ package ch.unibas.dmi.dbis.cs108.casono.client.chat; import ch.unibas.dmi.dbis.cs108.casono.client.network.ClientService; import ch.unibas.dmi.dbis.cs108.casono.client.network.CoreClient; import ch.unibas.dmi.dbis.cs108.casono.client.ui.chatui.ChatBoxController; +import java.io.IOException; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.stage.Stage; -import java.io.IOException; - public class ChatApplication extends Application { private static final int SCENE_WIDTH = 1200; @@ -21,30 +20,19 @@ public class ChatApplication extends Application { public ChatApplication() {} public void start(Stage stage) throws IOException { - FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/ui-structure/components/chatui/chatbox.fxml")); + FXMLLoader fxmlLoader = + new FXMLLoader( + getClass().getResource("/ui-structure/components/chatui/chatbox.fxml")); ClientService clientService = new ClientService(ip, port); CoreClient coreClient = new CoreClient(clientService); - // TODO login UI coreClient.login(username); ChatController chatController = new ChatController(username, clientService); ChatBoxController chatBoxController = new ChatBoxController(username, chatController); fxmlLoader.setController(chatBoxController); - /*fxmlLoader.setControllerFactory(type -> { - if (type == ChatBoxController.class) { - return chatController.getChatBoxController(); - } else { - try { - return type.getConstructor().newInstance(); - } catch (Throwable e) { - throw new RuntimeException(e); - } - } - });*/ Scene scene = new Scene(fxmlLoader.load(), SCENE_WIDTH, SCENE_HEIGHT); stage.setTitle("Chat"); stage.setScene(scene); stage.show(); } - } -- 2.52.0 From 9c09927d099ae45b61ad295d7a81fa8fd89d14b8 Mon Sep 17 00:00:00 2001 From: Mathis Ginkel Date: Fri, 10 Apr 2026 23:25:05 +0200 Subject: [PATCH 3/5] Docs: Adding Server Commands for Client Chat to the protocol document manually reverting changes --- .../networking/commands/protocol-document.md | 99 +++++++++++++++++++ .../dbis/cs108/casono/server/ServerApp.java | 7 +- .../check_nick/CheckUsernameHandler.java | 6 +- .../check_nick/CheckUsernameParser.java | 4 +- .../check_nick/CheckUsernameRequest.java | 6 +- .../check_nick/CheckUsernameResponse.java | 7 +- .../server/domain/message/MessageManager.java | 16 --- 7 files changed, 109 insertions(+), 36 deletions(-) delete mode 100644 src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/message/MessageManager.java diff --git a/documents/docs/networking/commands/protocol-document.md b/documents/docs/networking/commands/protocol-document.md index b08cf7f..e53c3d4 100644 --- a/documents/docs/networking/commands/protocol-document.md +++ b/documents/docs/networking/commands/protocol-document.md @@ -341,4 +341,103 @@ LIST_USERS END END END +``` + +## SEND_MESSAGE command +The `SEND_MESSAGE` command is used to transfer the chat message sent by a user to the server. +### Required pre-execution checks +None. + +### Request Parameters + +| Field | Type | Description | +|:---------|:----------------|:-------------------------------------------------------------------| +| `TYPE` | `Enum { private final UserRegistry userRegistry; - /** * Creates a new handler for checking username availability. * @@ -20,7 +17,6 @@ public class CheckUsernameHandler extends CommandHandler { super(responseDispatcher); this.userRegistry = userRegistry; } - /** * Executes the username availability check for the given request. * @@ -40,4 +36,4 @@ public class CheckUsernameHandler extends CommandHandler { } responseDispatcher.dispatch(new CheckUsernameResponse(request.getContext(), availability)); } -} +} \ No newline at end of file diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/CheckUsernameParser.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/CheckUsernameParser.java index a60f499..1add299 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/CheckUsernameParser.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/CheckUsernameParser.java @@ -1,9 +1,7 @@ package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.check_nick; - import ch.unibas.dmi.dbis.cs108.casono.server.network.command.parsing.CommandParser; import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.PrimitiveRequest; import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.accessor.RequestParameterAccessor; -import ch.unibas.dmi.dbis.cs108.casono.server.app.commands.check_nick.CheckUsernameRequest; /** Parses a primitive request into a {@link CheckUsernameRequest}. */ public class CheckUsernameParser implements CommandParser { /** @@ -18,4 +16,4 @@ public class CheckUsernameParser implements CommandParser new RequestParameterAccessor(primitiveRequest.parameters()); return new CheckUsernameRequest(primitiveRequest.context(), accessor.require("USERNAME")); } -} +} \ No newline at end of file diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/CheckUsernameRequest.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/CheckUsernameRequest.java index 7247b0e..d58ef7d 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/CheckUsernameRequest.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/CheckUsernameRequest.java @@ -1,12 +1,9 @@ package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.check_nick; - import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.Request; import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestContext; - /** Request implementation used to check whether a username is available or already taken */ public class CheckUsernameRequest extends Request { private final String username; - /** * Constructs a new CheckUsernameRequest with the given context and username to check * @@ -18,7 +15,6 @@ public class CheckUsernameRequest extends Request { super(context); this.username = username; } - /** * Returns the provided username in the request * @@ -27,4 +23,4 @@ public class CheckUsernameRequest extends Request { public String getUsername() { return username; } -} +} \ No newline at end of file diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/CheckUsernameResponse.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/CheckUsernameResponse.java index 5901a80..81c75dd 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/CheckUsernameResponse.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/CheckUsernameResponse.java @@ -2,8 +2,7 @@ package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.check_nick; import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.request.RequestContext; import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.SuccessResponse; -import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBody; - +import ch.unibas.dmi.dbis.cs108.casono.server.network.protocol.response.builder.ResponseBodyBuilder; /** Response indicating the availability status of a username check. */ public class CheckUsernameResponse extends SuccessResponse { /** @@ -13,6 +12,6 @@ public class CheckUsernameResponse extends SuccessResponse { * @param availability the availability status of the requested username */ public CheckUsernameResponse(RequestContext context, UsernameAvailability availability) { - super(context, ResponseBody.builder().param("STATUS", availability).build()); + super(context, new ResponseBodyBuilder().param("STATUS", availability).build()); } -} +} \ No newline at end of file diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/message/MessageManager.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/message/MessageManager.java deleted file mode 100644 index 8de0f89..0000000 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/domain/message/MessageManager.java +++ /dev/null @@ -1,16 +0,0 @@ -package ch.unibas.dmi.dbis.cs108.casono.server.domain.message; - -import ch.unibas.dmi.dbis.cs108.casono.server.domain.user.UserRegistry; - -/** NOT USED * */ -public class MessageManager { - private final UserRegistry userRegistry; - - public MessageManager(UserRegistry userRegistry) { - this.userRegistry = userRegistry; - } - - public void broadcast(Message message) { - // userRegistry.getAllUsers().forEach(user -> user.enqueueMessage(message)); - } -} -- 2.52.0 From 66d3826509b57ac79fcbed5251f46a6e69ac7035 Mon Sep 17 00:00:00 2001 From: Mathis Ginkel Date: Sat, 11 Apr 2026 11:16:21 +0200 Subject: [PATCH 4/5] Docs: Delete outdated network protocol document --- .../Network-Protocol-Documentation.md | 63 ------------------- .../check_nick/UsernameAvailability.java | 6 +- 2 files changed, 2 insertions(+), 67 deletions(-) delete mode 100644 documents/docs/networking/Network-Protocol-Documentation.md diff --git a/documents/docs/networking/Network-Protocol-Documentation.md b/documents/docs/networking/Network-Protocol-Documentation.md deleted file mode 100644 index 7099c7e..0000000 --- a/documents/docs/networking/Network-Protocol-Documentation.md +++ /dev/null @@ -1,63 +0,0 @@ -This Document states the Network-Protocol as it is currently implemented - -## GET_MESSAGE_COUNT -This Command gets the number of messages, currently stored in the queue for the specific client. -(Is used together with GET_NEXT_MESSAGE, to get all messages that are currently in the queue) - -Example: - -``` -GET_MESSAGE_COUNT - -1 -+OK -``` - -## GET_NEXT_MESSAGE -This Command gets the next Message that is being stored in the queue for the client. -(Command is being sent the amount of times, the GET_MESSAGE_COUNT Command returns) - -Example: - -``` -GET_NEXT_MESSAGE - -TYPE=LOBBY GAME=1 USER=player1 TARGET=null TIME=9:30 TEXT="Guten Tag" -+OK -``` - -## SEND_MESSAGE -This Command gets sent if the user of that client writes a message to one of the three possible chats - -(The Arguments / Parameters of the Command describe all the parameters of the Object "Message" being used internally by both the Client and the Server) - -Example: -``` -SEND_MESSAGE TYPE=LOBBY GAME=1 USER=player1 TARGET=null TIME=10:30 TEXT="Hallo Welt" - -+OK -``` - -## LOG_IN -This Command is used to create a user on the server and associate that user with a username -Server returns the username, slightly changed if it is already used by someone else, and an ID to identify the client. - -Example: - -``` -LOG_IN USERNAME="Peter" - -USERNAME="Peter" ID= -+OK -``` - -## LOG_OUT -This Command is used to quit the connection between client and server. - -Example: - -``` -LOG_OUT - -+OK -``` diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/UsernameAvailability.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/UsernameAvailability.java index c728971..40974bd 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/UsernameAvailability.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/UsernameAvailability.java @@ -1,10 +1,8 @@ package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.check_nick; - /** Represents the availability status of a username */ -public enum UsernameAvailability { +enum UsernameAvailability { /** Username is available */ FREE, - /** Username is already in use */ TAKEN -} +} \ No newline at end of file -- 2.52.0 From 590a9aa65851368ad84062b89754b22d339ca289 Mon Sep 17 00:00:00 2001 From: Mathis Ginkel Date: Sat, 11 Apr 2026 11:56:06 +0200 Subject: [PATCH 5/5] Style: Manually revert changes made to UsernameAvailability enum --- .../app/commands/check_nick/UsernameAvailability.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/UsernameAvailability.java b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/UsernameAvailability.java index 40974bd..c728971 100644 --- a/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/UsernameAvailability.java +++ b/src/main/java/ch/unibas/dmi/dbis/cs108/casono/server/app/commands/check_nick/UsernameAvailability.java @@ -1,8 +1,10 @@ package ch.unibas.dmi.dbis.cs108.casono.server.app.commands.check_nick; + /** Represents the availability status of a username */ -enum UsernameAvailability { +public enum UsernameAvailability { /** Username is available */ FREE, + /** Username is already in use */ TAKEN -} \ No newline at end of file +} -- 2.52.0