Verified Commit 392c53a0 authored by Bixilon's avatar Bixilon

debugUi: disconnect handling

parent 10d2cfe2
......@@ -46,4 +46,8 @@ public class DebugWindow {
public DebugUIHandler getUIHandler() {
return handler;
}
public void disconnect() {
DebugMainWindow.disconnect();
}
}
......@@ -58,6 +58,11 @@ public class DebugMainWindow extends Application {
}
private static void showCloseConfirmation() {
if (!connection.isConnected()) {
// already disconnected
stage.close();
return;
}
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle("Disconnect?");
alert.setHeaderText("Do you want to disconnect from the server?");
......@@ -84,6 +89,20 @@ public class DebugMainWindow extends Application {
// else return
}
public static void disconnect() {
Platform.runLater(() -> {
// disable all gui parts (interactable nodes)
Text statusBarServerAddress = (Text) stage.getScene().lookup("#statusBarServerAddress");
statusBarServerAddress.setText("Disconnected");
statusBarServerAddress.setDisable(true);
TextField chatToSend = ((TextField) stage.getScene().lookup("#chatToSend"));
chatToSend.setDisable(true);
});
}
@Override
public void start(Stage stage) throws IOException {
......
......@@ -14,11 +14,10 @@
package de.bixilon.minosoft.debug.handling;
import de.bixilon.minosoft.debug.DebugWindow;
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketChatMessage;
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketDestroyEntity;
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketSpawnMob;
import de.bixilon.minosoft.protocol.packets.clientbound.play.PacketSpawnObject;
import de.bixilon.minosoft.protocol.packets.clientbound.play.*;
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
import javafx.application.Platform;
import javafx.scene.control.Alert;
public class DebugUIPacketHandler extends PacketHandler {
DebugWindow window;
......@@ -47,4 +46,15 @@ public class DebugUIPacketHandler extends PacketHandler {
window.getUIHandler().removeEntities(pkg.getEntityIds());
}
@Override
public void handle(PacketDisconnect pkg) {
Platform.runLater(() -> {
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.setTitle("Disconnected!");
alert.setHeaderText("You have been disconnected from the server");
alert.setContentText(pkg.getReason().getRawMessage());
alert.show();
});
}
}
......@@ -115,6 +115,10 @@ public class Connection {
debugWindow.run();
}
break;
case DISCONNECTED:
if (Minosoft.getConfig().getBoolean(GameConfiguration.DEBUG_UI)) {
debugWindow.disconnect();
}
}
}
......@@ -183,4 +187,8 @@ public class Connection {
public void addHandler(PacketHandler handler) {
handlers.add(handler);
}
public boolean isConnected() {
return network.isConnected();
}
}
......@@ -41,6 +41,7 @@ public class Network {
private Cipher cipherEncrypt;
private Cipher cipherDecrypt;
private Thread packetThread;
private boolean connected;
public Network(Connection c) {
this.connection = c;
......@@ -60,6 +61,7 @@ public class Network {
Thread socketThread = new Thread(() -> {
try {
socket = new Socket(connection.getHost(), connection.getPort());
connected = true;
connection.setConnectionState(ConnectionState.HANDSHAKING);
socket.setKeepAlive(true);
DataOutputStream dOut = new DataOutputStream(socket.getOutputStream());
......@@ -106,6 +108,7 @@ public class Network {
}
socket.close();
connected = false;
connection.setConnectionState(ConnectionState.DISCONNECTED);
} catch (IOException e) {
// Could not connect
......@@ -168,10 +171,10 @@ public class Network {
Log.protocol(String.format("[IN] Packet %s did not used all bytes sent", ((p != null) ? p.name() : "UNKNOWN")));
}
if (packet instanceof PacketLoginSuccess) {
// login was okay, setting play status to avoid miss timing issues
connection.setConnectionState(ConnectionState.PLAY);
}
if (packet instanceof PacketLoginSuccess) {
// login was okay, setting play status to avoid miss timing issues
connection.setConnectionState(ConnectionState.PLAY);
}
connection.handle(packet);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
// safety first, but will not occur
......@@ -207,4 +210,8 @@ public class Network {
encryptionEnabled = true;
Log.debug("Encryption enabled!");
}
public boolean isConnected() {
return connected;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment