From 1289ac8ad58e4b1bbcce1bfab9375add7c93d368 Mon Sep 17 00:00:00 2001 From: Ziedelth Date: Wed, 19 Jan 2022 11:53:36 +0100 Subject: [PATCH] Fix invalid connection exception --- .../gui/controller/ApplicationController.java | 22 ++++++++++++++++--- src/fr/univ/lyon1/server/ConnectedClient.java | 3 ++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/fr/univ/lyon1/gui/controller/ApplicationController.java b/src/fr/univ/lyon1/gui/controller/ApplicationController.java index dd3a3cb..337f1e9 100644 --- a/src/fr/univ/lyon1/gui/controller/ApplicationController.java +++ b/src/fr/univ/lyon1/gui/controller/ApplicationController.java @@ -7,7 +7,9 @@ import fr.univ.lyon1.common.ServerConfiguration; import fr.univ.lyon1.common.command.Command; import fr.univ.lyon1.common.command.CommandType; import fr.univ.lyon1.common.exception.ChatException; +import fr.univ.lyon1.common.exception.LoginInvalid; import fr.univ.lyon1.common.exception.UnknownCommand; +import fr.univ.lyon1.gui.handlers.ServerConfigurationHandler; import javafx.application.Platform; import javafx.fxml.FXML; import javafx.scene.control.TextArea; @@ -17,6 +19,7 @@ import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.scene.text.TextFlow; +import javafx.stage.Stage; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -135,10 +138,25 @@ public class ApplicationController { } } } + } else if (object instanceof LoginInvalid) { + // TODO: Invalid login + Platform.runLater(() -> { + try { + this.closeSocket(); + + @NotNull + final Stage stage = (Stage) this.vboxChannelsList.getScene().getWindow(); + new ServerConfigurationHandler().launch(stage); + } catch (IOException e) { + e.printStackTrace(); + } + }); } else if (object instanceof ChatException) { + System.out.println("?"); ((ChatException) object).printStackTrace(); - } else + } else { this.sendObject(new UnknownCommand()); + } } else { try { this.closeSocket(); @@ -156,8 +174,6 @@ public class ApplicationController { ex.printStackTrace(); } } - - e.printStackTrace(); } } }); diff --git a/src/fr/univ/lyon1/server/ConnectedClient.java b/src/fr/univ/lyon1/server/ConnectedClient.java index 09f98c6..20200a7 100644 --- a/src/fr/univ/lyon1/server/ConnectedClient.java +++ b/src/fr/univ/lyon1/server/ConnectedClient.java @@ -122,7 +122,8 @@ public class ConnectedClient implements Runnable { actionCommand((Command) data); else throw new UnknownCommand(); - } catch (ChatException e) { + } catch (IOException | ChatException e) { + System.out.println("Error server " + e.getLocalizedMessage()); out.writeObject(e); out.flush(); }