From 931e34bcaa17da8a2f1149f1a594b43a3d76ea69 Mon Sep 17 00:00:00 2001 From: Ziedelth Date: Fri, 7 Jan 2022 11:38:15 +0100 Subject: [PATCH] Fix stupid bug --- src/fr/univ/lyon1/client/Client.java | 7 ++++--- src/fr/univ/lyon1/gui/MainGui.java | 2 ++ .../lyon1/gui/controller/ConnectGuiController.java | 10 ++++++++-- src/fr/univ/lyon1/gui/controller/Dialog.java | 5 +++++ src/fr/univ/lyon1/gui/handlers/MainHandler.java | 6 ++++++ src/module-info.java | 2 +- 6 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/fr/univ/lyon1/client/Client.java b/src/fr/univ/lyon1/client/Client.java index 36b4b73..0174ac1 100644 --- a/src/fr/univ/lyon1/client/Client.java +++ b/src/fr/univ/lyon1/client/Client.java @@ -30,22 +30,23 @@ public class Client { private List channels = new ArrayList<>(); protected boolean started = false; - public Client(String address, int port, String username, String password) throws IOException { this.address = address; this.port = port; this.username = username; this.password = password; + System.out.println("Init SSL..."); socket = initSSL(); + System.out.println("Set output stream..."); out = new ObjectOutputStream(socket.getOutputStream()); + System.out.println("Get In..."); getIn(); + System.out.println("Client ok"); } private Socket initSSL() throws IOException { SSLContext ctx = ChatSSL.getSSLContext(); - SocketFactory factory = ctx.getSocketFactory(); - Socket connection = factory.createSocket(address, port); ((SSLSocket) connection).setEnabledProtocols(new String[] {ChatSSL.tlsVersion}); SSLParameters sslParams = new SSLParameters(); diff --git a/src/fr/univ/lyon1/gui/MainGui.java b/src/fr/univ/lyon1/gui/MainGui.java index 36281f9..cdf6c45 100644 --- a/src/fr/univ/lyon1/gui/MainGui.java +++ b/src/fr/univ/lyon1/gui/MainGui.java @@ -14,6 +14,8 @@ public class MainGui extends Application { try { new MainHandler().launch(stage); } catch (IOException e) { + System.out.println(e.getMessage()); + // Launch server configuration try { new ServerConfigurationHandler().launch(stage); diff --git a/src/fr/univ/lyon1/gui/controller/ConnectGuiController.java b/src/fr/univ/lyon1/gui/controller/ConnectGuiController.java index 2016191..5995936 100644 --- a/src/fr/univ/lyon1/gui/controller/ConnectGuiController.java +++ b/src/fr/univ/lyon1/gui/controller/ConnectGuiController.java @@ -44,13 +44,17 @@ public class ConnectGuiController { try { // Save server configuration new ServerConfiguration(address, iPort).save(); - Dialog.showSuccessDialog("Connecté", "Vous êtes bien connecté au serveur"); +// Dialog.showSuccessDialog("Connecté", "Vous êtes bien connecté au serveur"); System.out.println("File saved, next step..."); + System.out.println("Get scene..."); @NotNull final Stage stage = (Stage) this.connectButton.getScene().getWindow(); + System.out.println("Scene : " + stage.toString()); new MainHandler().launch(stage); } catch (IOException e) { + System.out.println(e.getMessage()); + Dialog.showErrorDialog("Erreur", "Impossible de sauvegarder les informations de connexion au serveur"); this.connectButton.setDisable(false); System.out.println("Failed to save file, error: " + e.getMessage()); @@ -84,8 +88,10 @@ public class ConnectGuiController { @NotNull final Socket socket = new Socket(address, port); socket.setSoTimeout(5 * 1000); + boolean connected = socket.isConnected(); + socket.close(); - return true; + return connected; } catch (IOException exception) { return false; } diff --git a/src/fr/univ/lyon1/gui/controller/Dialog.java b/src/fr/univ/lyon1/gui/controller/Dialog.java index 6623ab8..b148506 100644 --- a/src/fr/univ/lyon1/gui/controller/Dialog.java +++ b/src/fr/univ/lyon1/gui/controller/Dialog.java @@ -11,14 +11,19 @@ public class Dialog { } public static void showSuccessDialog(String title, String description) { + System.out.println("Create success dialog..."); @NotNull final Alert alert = new Alert(Alert.AlertType.INFORMATION); + System.out.println("Extracting..."); extracted(title, description, alert); } private static void extracted(String title, String description, @NotNull Alert alert) { + System.out.println("Set title"); alert.setTitle(title); + System.out.println("Set description"); alert.setContentText(description); + System.out.println("Show"); alert.show(); } } diff --git a/src/fr/univ/lyon1/gui/handlers/MainHandler.java b/src/fr/univ/lyon1/gui/handlers/MainHandler.java index be9a06f..795b206 100644 --- a/src/fr/univ/lyon1/gui/handlers/MainHandler.java +++ b/src/fr/univ/lyon1/gui/handlers/MainHandler.java @@ -18,22 +18,28 @@ public class MainHandler implements Handler { @Override public void launch(Stage stage) throws IOException { + System.out.println("New..."); @NotNull final ServerConfiguration serverConfiguration = ServerConfiguration.load(); + System.out.println("Launch Client GUI..."); this.client = new ClientGUI(this, serverConfiguration.getAddress(), serverConfiguration.getPort()); + System.out.println("Set..."); stage.setTitle("Chat client"); stage.setWidth(440); + System.out.println("Set panel..."); this.clientPanel = new ClientPanel(this); Group root = new Group(); root.getChildren().add(this.clientPanel); Scene scene = new Scene(root, 600, 500); + System.out.println("Set scene..."); stage.setScene(scene); stage.show(); if (this.client != null) { + System.out.println("Run..."); this.client.run(); } } diff --git a/src/module-info.java b/src/module-info.java index 998ef49..e8047f3 100644 --- a/src/module-info.java +++ b/src/module-info.java @@ -1,4 +1,4 @@ -module fr.univ.lyon { +module fr.univ.lyon1 { requires javafx.controls; requires javafx.fxml;