From 05f164cb6b6f913a2ec8a80fff578a4f511f8aea Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Mon, 5 Feb 2024 15:10:27 +0100 Subject: [PATCH 01/30] test commit --- src/main/java/ChatServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index aaf8810..c4b258f 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -4,7 +4,7 @@ import java.net.ServerSocket; import java.net.Socket; public class ChatServer { - + // haha private ServerSocket serverSocket; public ChatServer(int port) { From ad0ef73647cd64e67d446194e0b9de82e34f5d3b Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Tue, 6 Feb 2024 10:48:23 +0100 Subject: [PATCH 02/30] Simple signup function with username and password --- src/main/java/SignUp.java | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/main/java/SignUp.java diff --git a/src/main/java/SignUp.java b/src/main/java/SignUp.java new file mode 100644 index 0000000..97b4128 --- /dev/null +++ b/src/main/java/SignUp.java @@ -0,0 +1,42 @@ +public class SignUp { + private String name; + private String password; + + // Constructor + public SignUp(String name, String password) { + this.name = name; + this.password = password; + } + + // Getters and Setters + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + // Function to create user + public static SignUp createUser(String name, String password) { + // add validation logic here + return new SignUp(name, password); + } + + public static void main(String[] args) { + // Example + SignUp user = createUser("JohnDoe", "password123"); + + // Example of accessing properties + System.out.println("User Name: " + user.getName()); + System.out.println("User Password: " + user.getPassword()); + } +} \ No newline at end of file From b40578f83ea1b809ab2d73b82ddf7ee69690b778 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Tue, 6 Feb 2024 10:51:51 +0100 Subject: [PATCH 03/30] Added some validation logic for the username and password --- src/main/java/ChatServer.java | 1 - src/main/java/SignUp.java | 13 ++++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index c4b258f..0fd0416 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -4,7 +4,6 @@ import java.net.ServerSocket; import java.net.Socket; public class ChatServer { - // haha private ServerSocket serverSocket; public ChatServer(int port) { diff --git a/src/main/java/SignUp.java b/src/main/java/SignUp.java index 97b4128..1eefbfd 100644 --- a/src/main/java/SignUp.java +++ b/src/main/java/SignUp.java @@ -27,13 +27,20 @@ public class SignUp { // Function to create user public static SignUp createUser(String name, String password) { - // add validation logic here - return new SignUp(name, password); + if (name == null || name.isEmpty()) { + throw new IllegalArgumentException("Username cannot be empty"); + } + if (password == null || password.isEmpty()) { + throw new IllegalArgumentException("Password cannot be empty"); + } + if (password.length() < 6) { + throw new IllegalArgumentException("Password must be at least 6 characters long"); + } return new SignUp(name, password); } public static void main(String[] args) { // Example - SignUp user = createUser("JohnDoe", "password123"); + SignUp user = createUser("TestUser", "TestPasswort"); // Example of accessing properties System.out.println("User Name: " + user.getName()); From f9335426159a403649d17b08e8124fde00ea95b3 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Tue, 6 Feb 2024 11:27:34 +0100 Subject: [PATCH 04/30] Added Gson as dependency, added JSON file creation for user signup --- pom.xml | 10 ++++++++++ src/main/java/SignUp.java | 40 ++++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 05188ae..21bd5b6 100644 --- a/pom.xml +++ b/pom.xml @@ -3,4 +3,14 @@ org.progmethoden java-chat 0.0.1-SNAPSHOT + + + + + com.google.code.gson + gson + 2.10.1 + + + \ No newline at end of file diff --git a/src/main/java/SignUp.java b/src/main/java/SignUp.java index 1eefbfd..ca443dd 100644 --- a/src/main/java/SignUp.java +++ b/src/main/java/SignUp.java @@ -1,3 +1,7 @@ +import com.google.gson.Gson; +import java.io.FileWriter; +import java.io.IOException; + public class SignUp { private String name; private String password; @@ -25,25 +29,43 @@ public class SignUp { this.password = password; } - // Function to create user + // Function to create user with validation public static SignUp createUser(String name, String password) { if (name == null || name.isEmpty()) { - throw new IllegalArgumentException("Username cannot be empty"); + throw new IllegalArgumentException("Username cannot be empty"); } if (password == null || password.isEmpty()) { - throw new IllegalArgumentException("Password cannot be empty"); + throw new IllegalArgumentException("Password cannot be empty"); } if (password.length() < 6) { - throw new IllegalArgumentException("Password must be at least 6 characters long"); + throw new IllegalArgumentException("Password must be at least 6 characters long"); } return new SignUp(name, password); } + + // Function to save to JSON file, replace with database call later + public void saveToJsonFile(String filename) { + try (FileWriter fileWriter = new FileWriter(filename)) { + Gson gson = new Gson(); + gson.toJson(this, fileWriter); + System.out.println("User information saved to " + filename); + } catch (IOException e) { + System.out.println("Error occurred while saving user information to JSON file: " + e.getMessage()); + } + } public static void main(String[] args) { - // Example - SignUp user = createUser("TestUser", "TestPasswort"); + try { + // Example usage + SignUp user = createUser("Test User", "TestPasswort"); - // Example of accessing properties - System.out.println("User Name: " + user.getName()); - System.out.println("User Password: " + user.getPassword()); + // Example of accessing properties + System.out.println("User Name: " + user.getName()); + System.out.println("User Password: " + user.getPassword()); + + // Save user information to a JSON file + user.saveToJsonFile("user.json"); + } catch (IllegalArgumentException e) { + System.out.println("Error: " + e.getMessage()); + } } } \ No newline at end of file From e756deaa3038ce6e49f09e4d8f71fc0382642fa6 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Tue, 6 Feb 2024 14:26:05 +0100 Subject: [PATCH 05/30] Added a birthday variable to the signup function --- src/main/java/SignUp.java | 36 ++++++++++++++++++++++++------------ user.json | 1 + 2 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 user.json diff --git a/src/main/java/SignUp.java b/src/main/java/SignUp.java index ca443dd..fe9ada6 100644 --- a/src/main/java/SignUp.java +++ b/src/main/java/SignUp.java @@ -3,22 +3,24 @@ import java.io.FileWriter; import java.io.IOException; public class SignUp { - private String name; + private String userName; private String password; + private String birthday; // Constructor - public SignUp(String name, String password) { - this.name = name; + public SignUp(String name, String password, String birthday) { + this.userName = name; this.password = password; + this.birthday = birthday; } // Getters and Setters - public String getName() { - return name; + public String getUserName() { + return userName; } - public void setName(String name) { - this.name = name; + public void setName(String userName) { + this.userName = userName; } public String getPassword() { @@ -28,10 +30,18 @@ public class SignUp { public void setPassword(String password) { this.password = password; } + + public String getBirthday() { + return birthday; + } + + public void setBirthday(String birthday) { + this.birthday = birthday; + } // Function to create user with validation - public static SignUp createUser(String name, String password) { - if (name == null || name.isEmpty()) { + public static SignUp createUser(String userName, String password, String birthday) { + if (userName == null || userName.isEmpty()) { throw new IllegalArgumentException("Username cannot be empty"); } if (password == null || password.isEmpty()) { @@ -39,7 +49,7 @@ public class SignUp { } if (password.length() < 6) { throw new IllegalArgumentException("Password must be at least 6 characters long"); - } return new SignUp(name, password); + } return new SignUp(userName, password, birthday); } // Function to save to JSON file, replace with database call later @@ -56,11 +66,13 @@ public class SignUp { public static void main(String[] args) { try { // Example usage - SignUp user = createUser("Test User", "TestPasswort"); + SignUp user = createUser("Test User", "TestPasswort", "01.01.1900"); // Example of accessing properties - System.out.println("User Name: " + user.getName()); + System.out.println("User Name: " + user.getUserName()); System.out.println("User Password: " + user.getPassword()); + System.out.println("User Birthday: " + user.getBirthday()); + // Save user information to a JSON file user.saveToJsonFile("user.json"); diff --git a/user.json b/user.json new file mode 100644 index 0000000..b8726e5 --- /dev/null +++ b/user.json @@ -0,0 +1 @@ +{"userName":"Test User","password":"TestPasswort","birthday":"01.01.1900"} \ No newline at end of file From eea15e563eb3b145419ebd6d7b61b86a87f2b4da Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Tue, 6 Feb 2024 14:42:06 +0100 Subject: [PATCH 06/30] =?UTF-8?q?Added=20=C2=96Universally=20Unique=20Iden?= =?UTF-8?q?tifier=20for=20the=20user=20signing=20up?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/SignUp.java | 27 ++++++++++++++++++++------- user.json | 2 +- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main/java/SignUp.java b/src/main/java/SignUp.java index fe9ada6..79e32a8 100644 --- a/src/main/java/SignUp.java +++ b/src/main/java/SignUp.java @@ -1,25 +1,36 @@ import com.google.gson.Gson; import java.io.FileWriter; import java.io.IOException; +import java.util.UUID; public class SignUp { + private String id; private String userName; private String password; private String birthday; // Constructor - public SignUp(String name, String password, String birthday) { - this.userName = name; + public SignUp(String id, String name, String password, String birthday) { + this.id = id; + this.userName = name; this.password = password; this.birthday = birthday; } // Getters and Setters + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + public String getUserName() { return userName; } - public void setName(String userName) { + public void setUserName(String userName) { this.userName = userName; } @@ -40,7 +51,7 @@ public class SignUp { } // Function to create user with validation - public static SignUp createUser(String userName, String password, String birthday) { + public static SignUp createUser(String id, String userName, String password, String birthday) { if (userName == null || userName.isEmpty()) { throw new IllegalArgumentException("Username cannot be empty"); } @@ -49,7 +60,7 @@ public class SignUp { } if (password.length() < 6) { throw new IllegalArgumentException("Password must be at least 6 characters long"); - } return new SignUp(userName, password, birthday); + } return new SignUp(id, userName, password, birthday); } // Function to save to JSON file, replace with database call later @@ -65,10 +76,12 @@ public class SignUp { public static void main(String[] args) { try { - // Example usage - SignUp user = createUser("Test User", "TestPasswort", "01.01.1900"); + // Example usage + UUID randomUUID = UUID.randomUUID(); + SignUp user = createUser(randomUUID.toString(), "Test User", "TestPasswort", "01.01.1900"); // Example of accessing properties + System.out.println("UserID: " + user.getId()); System.out.println("User Name: " + user.getUserName()); System.out.println("User Password: " + user.getPassword()); System.out.println("User Birthday: " + user.getBirthday()); diff --git a/user.json b/user.json index b8726e5..5232e18 100644 --- a/user.json +++ b/user.json @@ -1 +1 @@ -{"userName":"Test User","password":"TestPasswort","birthday":"01.01.1900"} \ No newline at end of file +{"id":"48728bbb-b924-48ce-aac0-3e38d6c7878e","userName":"Test User","password":"TestPasswort","birthday":"01.01.1900"} \ No newline at end of file From 6df8acae097428e33e2b319bc0db7ff72281b30d Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Tue, 6 Feb 2024 15:15:42 +0100 Subject: [PATCH 07/30] changed it so the user data in user.json is appended and not overwritten --- src/main/java/SignUp.java | 37 ++++++++++++++++++++++++++++++++----- user.json | 27 ++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/src/main/java/SignUp.java b/src/main/java/SignUp.java index 79e32a8..964375b 100644 --- a/src/main/java/SignUp.java +++ b/src/main/java/SignUp.java @@ -1,9 +1,18 @@ import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + +import java.io.*; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + import java.io.FileWriter; import java.io.IOException; + import java.util.UUID; -public class SignUp { +class SignUp { private String id; private String userName; private String password; @@ -65,20 +74,38 @@ public class SignUp { // Function to save to JSON file, replace with database call later public void saveToJsonFile(String filename) { + List userList = readUserListFromJsonFile(filename); + userList.add(this); + try (FileWriter fileWriter = new FileWriter(filename)) { - Gson gson = new Gson(); - gson.toJson(this, fileWriter); - System.out.println("User information saved to " + filename); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + gson.toJson(userList, fileWriter); + System.out.println("User information appended to " + filename); } catch (IOException e) { System.out.println("Error occurred while saving user information to JSON file: " + e.getMessage()); } } + + // Function to read user information from a JSON file + public static List readUserListFromJsonFile(String filename) { + List userList = new ArrayList<>(); + try (Reader reader = new FileReader(filename)) { + Type userListType = new TypeToken>() {}.getType(); + Gson gson = new Gson(); + userList = gson.fromJson(reader, userListType); + } catch (FileNotFoundException e) { + // File does not exist yet, so return an empty list + } catch (IOException e) { + System.out.println("Error occurred while reading user information from JSON file: " + e.getMessage()); + } + return userList; + } public static void main(String[] args) { try { // Example usage UUID randomUUID = UUID.randomUUID(); - SignUp user = createUser(randomUUID.toString(), "Test User", "TestPasswort", "01.01.1900"); + SignUp user = createUser(randomUUID.toString(), "Another Test User", "TestPasswort123", "01.01.2000"); // Example of accessing properties System.out.println("UserID: " + user.getId()); diff --git a/user.json b/user.json index 5232e18..84627ce 100644 --- a/user.json +++ b/user.json @@ -1 +1,26 @@ -{"id":"48728bbb-b924-48ce-aac0-3e38d6c7878e","userName":"Test User","password":"TestPasswort","birthday":"01.01.1900"} \ No newline at end of file +[ + { + "id": "48728bbb-b924-48ce-aac0-3e38d6c7878e", + "userName": "Test User", + "password": "TestPasswort", + "birthday": "01.01.1900" + }, + { + "id": "bacd2bf9-9486-4cc3-92fe-9a24b5cf47a4", + "userName": "Test User", + "password": "TestPasswort", + "birthday": "01.01.1900" + }, + { + "id": "15474da8-c2cd-4c1c-ba57-cd1b8657140e", + "userName": "Test User", + "password": "TestPasswort", + "birthday": "01.01.1900" + }, + { + "id": "be83e49a-bb17-4be2-a50f-0b846d7de3ea", + "userName": "Another Test User", + "password": "TestPasswort123", + "birthday": "01.01.2000" + } +] \ No newline at end of file From 91d488fdb838334487c26aa129ae6fd0403eff24 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Tue, 6 Feb 2024 16:24:13 +0100 Subject: [PATCH 08/30] Added a file for a login GUI with basic GUI window --- .../java/{SignUp.java => CreateUser.java} | 19 +++++++------ src/main/java/SignUpGUI.java | 28 +++++++++++++++++++ user.json | 28 ++++++------------- 3 files changed, 46 insertions(+), 29 deletions(-) rename src/main/java/{SignUp.java => CreateUser.java} (83%) create mode 100644 src/main/java/SignUpGUI.java diff --git a/src/main/java/SignUp.java b/src/main/java/CreateUser.java similarity index 83% rename from src/main/java/SignUp.java rename to src/main/java/CreateUser.java index 964375b..8e8f15f 100644 --- a/src/main/java/SignUp.java +++ b/src/main/java/CreateUser.java @@ -12,14 +12,15 @@ import java.io.IOException; import java.util.UUID; -class SignUp { +class CreateUser { private String id; private String userName; private String password; private String birthday; + // Constructor - public SignUp(String id, String name, String password, String birthday) { + public CreateUser(String id, String name, String password, String birthday) { this.id = id; this.userName = name; this.password = password; @@ -60,7 +61,7 @@ class SignUp { } // Function to create user with validation - public static SignUp createUser(String id, String userName, String password, String birthday) { + public static CreateUser createUser(String id, String userName, String password, String birthday) { if (userName == null || userName.isEmpty()) { throw new IllegalArgumentException("Username cannot be empty"); } @@ -69,12 +70,12 @@ class SignUp { } if (password.length() < 6) { throw new IllegalArgumentException("Password must be at least 6 characters long"); - } return new SignUp(id, userName, password, birthday); + } return new CreateUser(id, userName, password, birthday); } // Function to save to JSON file, replace with database call later public void saveToJsonFile(String filename) { - List userList = readUserListFromJsonFile(filename); + List userList = readUserListFromJsonFile(filename); userList.add(this); try (FileWriter fileWriter = new FileWriter(filename)) { @@ -87,10 +88,10 @@ class SignUp { } // Function to read user information from a JSON file - public static List readUserListFromJsonFile(String filename) { - List userList = new ArrayList<>(); + public static List readUserListFromJsonFile(String filename) { + List userList = new ArrayList<>(); try (Reader reader = new FileReader(filename)) { - Type userListType = new TypeToken>() {}.getType(); + Type userListType = new TypeToken>() {}.getType(); Gson gson = new Gson(); userList = gson.fromJson(reader, userListType); } catch (FileNotFoundException e) { @@ -105,7 +106,7 @@ class SignUp { try { // Example usage UUID randomUUID = UUID.randomUUID(); - SignUp user = createUser(randomUUID.toString(), "Another Test User", "TestPasswort123", "01.01.2000"); + CreateUser user = createUser(randomUUID.toString(), "Another Test User", "TestPasswort123", "01.01.2000"); // Example of accessing properties System.out.println("UserID: " + user.getId()); diff --git a/src/main/java/SignUpGUI.java b/src/main/java/SignUpGUI.java new file mode 100644 index 0000000..ce58bc2 --- /dev/null +++ b/src/main/java/SignUpGUI.java @@ -0,0 +1,28 @@ +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.UUID; + +public class SignUpGUI extends JFrame implements ActionListener { + + + public SignUpGUI() { + setTitle("Sign Up"); + setSize(300, 200); + setDefaultCloseOperation(EXIT_ON_CLOSE); + setLayout(null); + + + } + + @Override + public void actionPerformed(ActionEvent e) { + } + + public static void main(String[] args) { + SwingUtilities.invokeLater(() -> { + SignUpGUI signUpGUI = new SignUpGUI(); + signUpGUI.setVisible(true); + }); + } +} \ No newline at end of file diff --git a/user.json b/user.json index 84627ce..7040154 100644 --- a/user.json +++ b/user.json @@ -1,26 +1,14 @@ [ { - "id": "48728bbb-b924-48ce-aac0-3e38d6c7878e", - "userName": "Test User", - "password": "TestPasswort", - "birthday": "01.01.1900" - }, - { - "id": "bacd2bf9-9486-4cc3-92fe-9a24b5cf47a4", - "userName": "Test User", - "password": "TestPasswort", - "birthday": "01.01.1900" - }, - { - "id": "15474da8-c2cd-4c1c-ba57-cd1b8657140e", - "userName": "Test User", - "password": "TestPasswort", - "birthday": "01.01.1900" + "id": "f9cd70c1-57cd-4943-a00b-0de521347aff", + "userName": "asd", + "password": "test1234", + "birthday": "01.01.2000" }, { - "id": "be83e49a-bb17-4be2-a50f-0b846d7de3ea", - "userName": "Another Test User", - "password": "TestPasswort123", - "birthday": "01.01.2000" + "id": "69e4b1d3-3089-4f98-936f-865dfe40e6a0", + "userName": "asd", + "password": "test1234", + "birthday": "01.01.2013" } ] \ No newline at end of file From ff5fbad1ad06092db34ef6b343ae135d34b64876 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Tue, 6 Feb 2024 16:27:17 +0100 Subject: [PATCH 09/30] added textfield for username to signup GUI --- src/main/java/SignUpGUI.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/SignUpGUI.java b/src/main/java/SignUpGUI.java index ce58bc2..1f50d14 100644 --- a/src/main/java/SignUpGUI.java +++ b/src/main/java/SignUpGUI.java @@ -4,7 +4,7 @@ import java.awt.event.ActionListener; import java.util.UUID; public class SignUpGUI extends JFrame implements ActionListener { - + private JTextField usernameField; public SignUpGUI() { setTitle("Sign Up"); @@ -12,7 +12,13 @@ public class SignUpGUI extends JFrame implements ActionListener { setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(null); - + JLabel usernameLabel = new JLabel("Username:"); + usernameLabel.setBounds(20, 20, 80, 25); + add(usernameLabel); + + usernameField = new JTextField(); + usernameField.setBounds(100, 20, 160, 25); + add(usernameField); } @Override From 6986de2c3de5b00b1035baf16c49405eb68dc062 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Tue, 6 Feb 2024 16:32:23 +0100 Subject: [PATCH 10/30] added a textfield for password to signup GUI --- src/main/java/SignUpGUI.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/SignUpGUI.java b/src/main/java/SignUpGUI.java index 1f50d14..1795445 100644 --- a/src/main/java/SignUpGUI.java +++ b/src/main/java/SignUpGUI.java @@ -4,7 +4,7 @@ import java.awt.event.ActionListener; import java.util.UUID; public class SignUpGUI extends JFrame implements ActionListener { - private JTextField usernameField; + private JTextField usernameField, passwordField; public SignUpGUI() { setTitle("Sign Up"); @@ -19,6 +19,14 @@ public class SignUpGUI extends JFrame implements ActionListener { usernameField = new JTextField(); usernameField.setBounds(100, 20, 160, 25); add(usernameField); + + JLabel passwordLabel = new JLabel("Password:"); + passwordLabel.setBounds(20, 50, 80, 25); + add(passwordLabel); + + passwordField = new JPasswordField(); + passwordField.setBounds(100, 50, 160, 25); + add(passwordField); } @Override From f34e5a8168ebc56552af9035cba7881a08f1b3ff Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Tue, 6 Feb 2024 16:33:48 +0100 Subject: [PATCH 11/30] added a textfield for birthday to signup GUI --- src/main/java/SignUpGUI.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/SignUpGUI.java b/src/main/java/SignUpGUI.java index 1795445..fdbb160 100644 --- a/src/main/java/SignUpGUI.java +++ b/src/main/java/SignUpGUI.java @@ -4,7 +4,7 @@ import java.awt.event.ActionListener; import java.util.UUID; public class SignUpGUI extends JFrame implements ActionListener { - private JTextField usernameField, passwordField; + private JTextField usernameField, passwordField, birthdayField; public SignUpGUI() { setTitle("Sign Up"); @@ -27,6 +27,15 @@ public class SignUpGUI extends JFrame implements ActionListener { passwordField = new JPasswordField(); passwordField.setBounds(100, 50, 160, 25); add(passwordField); + + JLabel birthdayLabel = new JLabel("Birthday:"); + birthdayLabel.setBounds(20, 80, 80, 25); + add(birthdayLabel); + + birthdayField = new JTextField(); + birthdayField.setBounds(100, 80, 160, 25); + add(birthdayField); + } @Override From 583188ac5a4ce6449b7e2d0e04cf3bb5ee37f6d3 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Tue, 6 Feb 2024 16:47:10 +0100 Subject: [PATCH 12/30] added functionality to the textfields, the input is now written to the user.json file --- src/main/java/SignUpGUI.java | 22 +++++++++++++++++++++- user.json | 6 ++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/SignUpGUI.java b/src/main/java/SignUpGUI.java index fdbb160..520adb1 100644 --- a/src/main/java/SignUpGUI.java +++ b/src/main/java/SignUpGUI.java @@ -5,7 +5,8 @@ import java.util.UUID; public class SignUpGUI extends JFrame implements ActionListener { private JTextField usernameField, passwordField, birthdayField; - + private JButton signUpButton; + public SignUpGUI() { setTitle("Sign Up"); setSize(300, 200); @@ -35,11 +36,30 @@ public class SignUpGUI extends JFrame implements ActionListener { birthdayField = new JTextField(); birthdayField.setBounds(100, 80, 160, 25); add(birthdayField); + + signUpButton = new JButton("Sign Up"); + signUpButton.setBounds(100, 120, 100, 25); + signUpButton.addActionListener(this); + add(signUpButton); } @Override public void actionPerformed(ActionEvent e) { + if (e.getSource() == signUpButton) { + String username = usernameField.getText(); + String password = passwordField.getText(); + String birthday = birthdayField.getText(); + + try { + UUID randomUUID = UUID.randomUUID(); + CreateUser user = CreateUser.createUser(randomUUID.toString(), username, password, birthday); + user.saveToJsonFile("user.json"); + JOptionPane.showMessageDialog(this, "User signed up successfully!"); + } catch (IllegalArgumentException ex) { + JOptionPane.showMessageDialog(this, "Error: " + ex.getMessage(), "Sign Up Error", JOptionPane.ERROR_MESSAGE); + } + } } public static void main(String[] args) { diff --git a/user.json b/user.json index 7040154..e407c0d 100644 --- a/user.json +++ b/user.json @@ -10,5 +10,11 @@ "userName": "asd", "password": "test1234", "birthday": "01.01.2013" + }, + { + "id": "4165bfe6-9851-480f-90e1-8229415fa44e", + "userName": "asdasdasd", + "password": "1231412512", + "birthday": "1111111" } ] \ No newline at end of file From 1ae51d1a1c4732b21f8ff08b680014240794f9b7 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Tue, 6 Feb 2024 17:07:07 +0100 Subject: [PATCH 13/30] the signup window now closes automatically after completion --- src/main/java/SignUpGUI.java | 1 + user.json | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/main/java/SignUpGUI.java b/src/main/java/SignUpGUI.java index 520adb1..babf30d 100644 --- a/src/main/java/SignUpGUI.java +++ b/src/main/java/SignUpGUI.java @@ -56,6 +56,7 @@ public class SignUpGUI extends JFrame implements ActionListener { CreateUser user = CreateUser.createUser(randomUUID.toString(), username, password, birthday); user.saveToJsonFile("user.json"); JOptionPane.showMessageDialog(this, "User signed up successfully!"); + dispose(); } catch (IllegalArgumentException ex) { JOptionPane.showMessageDialog(this, "Error: " + ex.getMessage(), "Sign Up Error", JOptionPane.ERROR_MESSAGE); } diff --git a/user.json b/user.json index e407c0d..5cd130f 100644 --- a/user.json +++ b/user.json @@ -16,5 +16,11 @@ "userName": "asdasdasd", "password": "1231412512", "birthday": "1111111" + }, + { + "id": "f2775f81-564b-4101-8e86-ce879a9e7737", + "userName": "asd", + "password": "asdasdasd", + "birthday": "asd" } ] \ No newline at end of file From f10b6457572bd526e5052c69cf4d7909aad74f53 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Tue, 6 Feb 2024 17:21:59 +0100 Subject: [PATCH 14/30] added a second password text field so the user has to input the same password twice --- src/main/java/SignUpGUI.java | 29 +++++++++++++++++++++-------- user.json | 6 ++++++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/main/java/SignUpGUI.java b/src/main/java/SignUpGUI.java index babf30d..6e3f306 100644 --- a/src/main/java/SignUpGUI.java +++ b/src/main/java/SignUpGUI.java @@ -4,12 +4,12 @@ import java.awt.event.ActionListener; import java.util.UUID; public class SignUpGUI extends JFrame implements ActionListener { - private JTextField usernameField, passwordField, birthdayField; + private JTextField usernameField, passwordField, confirmPasswordField, birthdayField; private JButton signUpButton; public SignUpGUI() { setTitle("Sign Up"); - setSize(300, 200); + setSize(300, 250); setDefaultCloseOperation(EXIT_ON_CLOSE); setLayout(null); @@ -20,7 +20,7 @@ public class SignUpGUI extends JFrame implements ActionListener { usernameField = new JTextField(); usernameField.setBounds(100, 20, 160, 25); add(usernameField); - + JLabel passwordLabel = new JLabel("Password:"); passwordLabel.setBounds(20, 50, 80, 25); add(passwordLabel); @@ -28,17 +28,25 @@ public class SignUpGUI extends JFrame implements ActionListener { passwordField = new JPasswordField(); passwordField.setBounds(100, 50, 160, 25); add(passwordField); - + + JLabel confirmPasswordLabel = new JLabel("Confirm Password:"); + confirmPasswordLabel.setBounds(20, 80, 120, 25); + add(confirmPasswordLabel); + + confirmPasswordField = new JPasswordField(); + confirmPasswordField.setBounds(140, 80, 120, 25); + add(confirmPasswordField); + JLabel birthdayLabel = new JLabel("Birthday:"); - birthdayLabel.setBounds(20, 80, 80, 25); + birthdayLabel.setBounds(20, 110, 80, 25); add(birthdayLabel); birthdayField = new JTextField(); - birthdayField.setBounds(100, 80, 160, 25); + birthdayField.setBounds(100, 110, 160, 25); add(birthdayField); - + signUpButton = new JButton("Sign Up"); - signUpButton.setBounds(100, 120, 100, 25); + signUpButton.setBounds(100, 150, 100, 25); signUpButton.addActionListener(this); add(signUpButton); @@ -49,8 +57,13 @@ public class SignUpGUI extends JFrame implements ActionListener { if (e.getSource() == signUpButton) { String username = usernameField.getText(); String password = passwordField.getText(); + String confirmPassword = confirmPasswordField.getText(); String birthday = birthdayField.getText(); + if (!password.equals(confirmPassword)) { + JOptionPane.showMessageDialog(this, "Passwords do not match!", "Sign Up Error", JOptionPane.ERROR_MESSAGE); + return; + } try { UUID randomUUID = UUID.randomUUID(); CreateUser user = CreateUser.createUser(randomUUID.toString(), username, password, birthday); diff --git a/user.json b/user.json index 5cd130f..01ececf 100644 --- a/user.json +++ b/user.json @@ -22,5 +22,11 @@ "userName": "asd", "password": "asdasdasd", "birthday": "asd" + }, + { + "id": "1e035bce-37b5-4f1e-894e-8136b8021c4d", + "userName": "asd", + "password": "123456", + "birthday": "1234" } ] \ No newline at end of file From 1e69815d996d797f112d60d4e508a64c02e9b810 Mon Sep 17 00:00:00 2001 From: Richard Schmidt Date: Tue, 6 Feb 2024 17:59:18 +0100 Subject: [PATCH 15/30] added functionality checking if a username already exists --- src/main/java/SignUpGUI.java | 18 ++++++++++++++++++ user.json | 30 ++++++------------------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/main/java/SignUpGUI.java b/src/main/java/SignUpGUI.java index 6e3f306..b19cf8e 100644 --- a/src/main/java/SignUpGUI.java +++ b/src/main/java/SignUpGUI.java @@ -1,6 +1,7 @@ import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.util.List; import java.util.UUID; public class SignUpGUI extends JFrame implements ActionListener { @@ -64,6 +65,11 @@ public class SignUpGUI extends JFrame implements ActionListener { JOptionPane.showMessageDialog(this, "Passwords do not match!", "Sign Up Error", JOptionPane.ERROR_MESSAGE); return; } + + if (!isUsernameAvailable("user.json", username)) { + JOptionPane.showMessageDialog(this, "Username already exists!", "Sign Up Error", JOptionPane.ERROR_MESSAGE); + return; + } try { UUID randomUUID = UUID.randomUUID(); CreateUser user = CreateUser.createUser(randomUUID.toString(), username, password, birthday); @@ -75,6 +81,18 @@ public class SignUpGUI extends JFrame implements ActionListener { } } } + // Function to check if the input username doesn't already exist in the JSON file + private boolean isUsernameAvailable(String filename, String username) { + List userList = CreateUser.readUserListFromJsonFile(filename); + if (userList != null) { + for (CreateUser user : userList) { + if (user.getUserName().equals(username)) { + return false; // Username already exists + } + } + } + return true; // Username is available + } public static void main(String[] args) { SwingUtilities.invokeLater(() -> { diff --git a/user.json b/user.json index 01ececf..0201a67 100644 --- a/user.json +++ b/user.json @@ -1,32 +1,14 @@ [ { - "id": "f9cd70c1-57cd-4943-a00b-0de521347aff", + "id": "961ca202-ecbd-4dfc-ac0b-28f367618aa1", "userName": "asd", - "password": "test1234", - "birthday": "01.01.2000" - }, - { - "id": "69e4b1d3-3089-4f98-936f-865dfe40e6a0", - "userName": "asd", - "password": "test1234", - "birthday": "01.01.2013" - }, - { - "id": "4165bfe6-9851-480f-90e1-8229415fa44e", - "userName": "asdasdasd", - "password": "1231412512", - "birthday": "1111111" - }, - { - "id": "f2775f81-564b-4101-8e86-ce879a9e7737", - "userName": "asd", - "password": "asdasdasd", - "birthday": "asd" + "password": "123456", + "birthday": "1" }, { - "id": "1e035bce-37b5-4f1e-894e-8136b8021c4d", - "userName": "asd", + "id": "d563a466-753b-4a5e-8b6c-e7e4756c7397", + "userName": "asd1", "password": "123456", - "birthday": "1234" + "birthday": "1" } ] \ No newline at end of file From 33a9aa7e469ab9546cda18fa9d6673a4f4f24f33 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Wed, 7 Feb 2024 00:13:02 +0100 Subject: [PATCH 16/30] Einbinden von ClientHandler --- src/main/java/ChatServer.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index 0fd0416..0327ad7 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -10,10 +10,12 @@ public class ChatServer { try { serverSocket = new ServerSocket(port); System.out.println("Started ChatServer on port " + port); - + + while(true) { Socket connectionToClient = serverSocket.accept(); - + ClientHandler client = new ClientHandler(this, connectionToClient); System.out.println("Accepted new Client"); + } } catch (IOException e) { e.printStackTrace(); } From 134ebf9a05f9e081c2f9e2520c07f0f7fc538031 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Wed, 7 Feb 2024 00:17:09 +0100 Subject: [PATCH 17/30] =?UTF-8?q?hinzuf=C3=BCgen=20der=20ClientList?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ChatServer.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index 0327ad7..e868615 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -2,9 +2,11 @@ import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; +import java.util.List; public class ChatServer { private ServerSocket serverSocket; + private List clients; public ChatServer(int port) { try { From 7970faab71c0df772809080ffeb61fd512707f7d Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Wed, 7 Feb 2024 00:19:38 +0100 Subject: [PATCH 18/30] copyOnWriteArrayList --- src/main/java/ChatServer.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index e868615..dc94664 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -3,12 +3,15 @@ import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; public class ChatServer { private ServerSocket serverSocket; private List clients; public ChatServer(int port) { + clients = new CopyOnWriteArrayList<>(); + try { serverSocket = new ServerSocket(port); System.out.println("Started ChatServer on port " + port); From 18b9ff3b033db7d1f5c443e5e9ab146fb2e0ea96 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Wed, 7 Feb 2024 00:23:31 +0100 Subject: [PATCH 19/30] clients in CopyOnWriteList --- src/main/java/ChatServer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index dc94664..fdf1007 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -19,6 +19,7 @@ public class ChatServer { while(true) { Socket connectionToClient = serverSocket.accept(); ClientHandler client = new ClientHandler(this, connectionToClient); + clients.add(client); System.out.println("Accepted new Client"); } } catch (IOException e) { From 9c2454a8d027057981a5c2e99beac8844b75ed31 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Wed, 7 Feb 2024 00:25:37 +0100 Subject: [PATCH 20/30] =?UTF-8?q?zus=C3=A4tzliche=20Ausgabenachricht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ChatServer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index fdf1007..c359642 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -17,6 +17,7 @@ public class ChatServer { System.out.println("Started ChatServer on port " + port); while(true) { + System.out.println("waiting for new Client..."); Socket connectionToClient = serverSocket.accept(); ClientHandler client = new ClientHandler(this, connectionToClient); clients.add(client); From 5adf67da98d69bf15023f9980ac742ca0cf397a3 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Wed, 7 Feb 2024 00:28:20 +0100 Subject: [PATCH 21/30] =?UTF-8?q?refactoring:=20Einr=C3=BCcken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ChatServer.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index c359642..c647fe6 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -11,17 +11,17 @@ public class ChatServer { public ChatServer(int port) { clients = new CopyOnWriteArrayList<>(); - + try { serverSocket = new ServerSocket(port); System.out.println("Started ChatServer on port " + port); - - while(true) { + + while (true) { System.out.println("waiting for new Client..."); - Socket connectionToClient = serverSocket.accept(); - ClientHandler client = new ClientHandler(this, connectionToClient); - clients.add(client); - System.out.println("Accepted new Client"); + Socket connectionToClient = serverSocket.accept(); + ClientHandler client = new ClientHandler(this, connectionToClient); + clients.add(client); + System.out.println("Accepted new Client"); } } catch (IOException e) { e.printStackTrace(); From c15ed63353828500275e90e7eac60d5780599576 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Wed, 7 Feb 2024 00:33:20 +0100 Subject: [PATCH 22/30] Einbinden von sendMessage in server --- src/main/java/ChatServer.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index c647fe6..3ece54e 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -29,7 +29,10 @@ public class ChatServer { } - public void broadcastMessage(String s) { + public void broadcastMessage(String message) { + for (ClientHandler client : clients) { + client.sendMessage(message); + } } From 0398b37b8ff71e1c1af72a03e4b325f28d48afed Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Wed, 7 Feb 2024 00:34:45 +0100 Subject: [PATCH 23/30] Message ausgeben --- src/main/java/ChatServer.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index 3ece54e..8a65b1a 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -30,6 +30,7 @@ public class ChatServer { } public void broadcastMessage(String message) { + System.out.println(message); for (ClientHandler client : clients) { client.sendMessage(message); } From d90c8f75605e8279ba587b31f6206e2496a614ae Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Wed, 7 Feb 2024 00:41:02 +0100 Subject: [PATCH 24/30] Abfrage ob Nachricht nicht leer ist --- src/main/java/ChatServer.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index 8a65b1a..70929e7 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -31,9 +31,11 @@ public class ChatServer { public void broadcastMessage(String message) { System.out.println(message); + if (message != null) { for (ClientHandler client : clients) { client.sendMessage(message); } + } } From 0957069b71314f6de4b8211d81c2446b08c80864 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Wed, 7 Feb 2024 00:46:21 +0100 Subject: [PATCH 25/30] =?UTF-8?q?finally=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/ChatServer.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index 70929e7..33d2860 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -25,6 +25,13 @@ public class ChatServer { } } catch (IOException e) { e.printStackTrace(); + } finally { + try { + serverSocket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } From 18400eb14b49b0f675e3b15e7d6f6b7541a20fd2 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Wed, 7 Feb 2024 00:49:32 +0100 Subject: [PATCH 26/30] fehlendes if-statement --- src/main/java/ChatServer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index 33d2860..84d84af 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -26,11 +26,12 @@ public class ChatServer { } catch (IOException e) { e.printStackTrace(); } finally { + if (serverSocket != null) { try { serverSocket.close(); } catch (IOException e) { e.printStackTrace(); - } + }} } From b70c89951dd2f6245b26c8f7c2b7778061171ab2 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Wed, 7 Feb 2024 00:50:29 +0100 Subject: [PATCH 27/30] refactoring: Formatierung --- src/main/java/ChatServer.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index 84d84af..68eafeb 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -27,12 +27,13 @@ public class ChatServer { e.printStackTrace(); } finally { if (serverSocket != null) { - try { - serverSocket.close(); - } catch (IOException e) { - e.printStackTrace(); - }} - + try { + serverSocket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } } @@ -40,9 +41,9 @@ public class ChatServer { public void broadcastMessage(String message) { System.out.println(message); if (message != null) { - for (ClientHandler client : clients) { - client.sendMessage(message); - } + for (ClientHandler client : clients) { + client.sendMessage(message); + } } } From 97d94c3057de574b1d60491c8a3f0cdff5673b70 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Wed, 7 Feb 2024 01:05:26 +0100 Subject: [PATCH 28/30] remove-Methode --- src/main/java/ChatServer.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index 68eafeb..92a4497 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -52,5 +52,9 @@ public class ChatServer { new ChatServer(3141); } + + public void removeClient(ClientHandler client) { + clients.remove(client); + } } \ No newline at end of file From 0dd61cb78c1df560314072d1846f79edb11dcc49 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Wed, 7 Feb 2024 01:11:08 +0100 Subject: [PATCH 29/30] refactoring: Kommentare --- src/main/java/ChatServer.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index 92a4497..b118b63 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -7,10 +7,10 @@ import java.util.concurrent.CopyOnWriteArrayList; public class ChatServer { private ServerSocket serverSocket; - private List clients; + private List clients; // Liste, um alle verbundenen Clients zu verwalten public ChatServer(int port) { - clients = new CopyOnWriteArrayList<>(); + clients = new CopyOnWriteArrayList<>(); // Verwende CopyOnWriteArrayList für die Thread-Sicherheit try { serverSocket = new ServerSocket(port); @@ -18,9 +18,9 @@ public class ChatServer { while (true) { System.out.println("waiting for new Client..."); - Socket connectionToClient = serverSocket.accept(); + Socket connectionToClient = serverSocket.accept(); // Auf Verbindungen von Clients warten ClientHandler client = new ClientHandler(this, connectionToClient); - clients.add(client); + clients.add(client); // Neuen Client zur Liste hinzufügen System.out.println("Accepted new Client"); } } catch (IOException e) { From 1ca86de8689d6b2702c23dbf46abdc27def1c83b Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Wed, 7 Feb 2024 01:13:32 +0100 Subject: [PATCH 30/30] refactoring: Kommentare --- src/main/java/ChatServer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index b118b63..0c60774 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -37,22 +37,22 @@ public class ChatServer { } } - - public void broadcastMessage(String message) { + // Methode, um eine Nachricht an alle verbundenen Clients zu senden + public void broadcastMessage(String message) { System.out.println(message); if (message != null) { for (ClientHandler client : clients) { - client.sendMessage(message); + client.sendMessage(message); // Nachricht an jeden Client senden } } } public static void main(String[] args) { - new ChatServer(3141); + new ChatServer(3141); // ChatServer auf Port 3141 starten (eventuell den Port flexibler noch wählen? falls belegt) } - + // Methode, um einen Client aus der Liste der verbundenen Clients zu entfernen public void removeClient(ClientHandler client) { clients.remove(client); }