Skip to content

Commit

Permalink
Simplified UI connection tab
Browse files Browse the repository at this point in the history
  • Loading branch information
mircokroon committed Jul 5, 2023
1 parent 4fe4207 commit 2cda9e5
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 88 deletions.
6 changes: 1 addition & 5 deletions src/main/java/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void settingsComplete() {
isStarted = true;

versionHandler = ProtocolVersionHandler.getInstance();
connectionDetails = new ConnectionDetails(server, portRemote, portLocal, !disableSrvLookup);
connectionDetails = new ConnectionDetails(server, portLocal, !disableSrvLookup);

if (!disableGui) {
GuiManager.loadSceneMap();
Expand Down Expand Up @@ -354,10 +354,6 @@ public static PacketInjector getPacketInjector() {
usage = "Your Minecraft username.")
public transient String username;

@Option(name = "--port", aliases = "-p",
usage = "The port on which the remote server runs.")
public int portRemote = 25565;

@Option(name = "--local-port", aliases = "-l",
usage = "The port on which the world downloader's server will run.")
public int portLocal = 25565;
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/gui/AuthTabController.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,8 @@ private void clearAuthenticationStatus() {
}

public void checkButtonPressed(ActionEvent actionEvent) {
try {
AuthenticationMethod method = Config.getAuthMethod();
AuthDetails details = AuthDetailsManager.loadAuthDetails();
AuthDetailsManager.validateAuthStatus(this::setStatusText, this::setStatusError);

boolean isValid = details.isValid();
if (isValid) {
setStatusText("Valid session found! \n\nUsername: " + details.getUsername());
} else {
setStatusError(method.getErrorMessage());
}
} catch (IOException e) {
setStatusError("Exception occurred: " + e.getMessage());
}
clearAuthenticationStatus();
}

Expand Down
45 changes: 15 additions & 30 deletions src/main/java/gui/GuiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

public class GuiSettings {
public TextField server;
public DefaultIntField portRemote;
public DefaultIntField portLocal;

public TextField worldOutputDir;
Expand All @@ -52,20 +51,20 @@ public class GuiSettings {
public Tab errTab;
public TabPane tabPane;
public TextArea errOutput;
public Label authDetailsVerifyLabel;
public Tooltip authTooltip;
public CheckBox disableWorldGen;
public Label portVerifyLabel;
public Slider extendedDistance;
public IntField extendedDistanceText;
public Hyperlink openWorldDir;
public Hyperlink verifyAuthLink;
public CheckBox renderOtherPlayers;
public CheckBox enableInfoMessages;
public Tab realmsTab;
public Tab authTab;
public RealmsTabController realmsController;
public AuthTabController authController;
public CheckBox enableDrawExtendedChunks;

Config config;
private boolean portInUse;

Expand All @@ -82,7 +81,6 @@ void initialize() {

// connection tab
server.setText(config.server);
portRemote.setText("" + config.portRemote);
portLocal.setText("" + config.portLocal);

// output tab
Expand Down Expand Up @@ -115,10 +113,8 @@ void initialize() {
}
});
}
disableWhenRunning(Arrays.asList(server, portRemote, portLocal, centerX, centerZ, worldOutputDir));
disableWhenRunning(Arrays.asList(server, portLocal, centerX, centerZ, worldOutputDir));

authTooltip = new Tooltip("");
GuiManager.bindTooltip(authDetailsVerifyLabel, authTooltip);
GuiManager.bindTooltip(portVerifyLabel, new Tooltip("Is the downloader already running?"));

openWorldDir.setOnAction(e -> attemptQuiet(() -> {
Expand All @@ -131,16 +127,17 @@ void initialize() {
}
}));

// accessToken.textProperty().addListener((ov, oldV, newV) -> {
// // trim invalid characters, remove accessToken at front in case they copied the entire line
// accessToken.setText(newV.trim()
// .replaceAll("[^A-Za-z0-9\\-_.]*", "")
// .replaceFirst("accessToken", ""));
// });
verifyAuthLink.setOnAction(e -> tabPane.getSelectionModel().select(authTab));

handleDataValidation();
handleErrorTab();
handleResizing();

validateAuthentication();
}

private void validateAuthentication() {

}

private void handleDataValidation() {
Expand Down Expand Up @@ -279,7 +276,6 @@ public void saveSettings(ActionEvent actionEvent) {
private void save() {
// connection tab
config.server = server.getText();
config.portRemote = Math.abs(portRemote.getAsInt());
config.portLocal = Math.abs(portLocal.getAsInt());

// output tab
Expand Down Expand Up @@ -310,22 +306,11 @@ public boolean portInUse(int port) {
}
}

public void setSelectedIp(String address) throws URISyntaxException, MalformedURLException {
// address needs to start with a scheme, so we just prefix https
URI uri = new URI("https://" + address);

String host = uri.getHost();
int port = uri.getPort();

// if the port is the default, maybe it is not actually reported(?), so just in case...
if (port < 0) { port = 25565; }

if (host == null) {
throw new MalformedURLException("No host present in " + address);
}

this.portRemote.setValue(port);
this.server.setText(host);
/**
* Set the IP address given by the realms tab
*/
public void setSelectedIp(String address) {
this.server.setText(address);

tabPane.getSelectionModel().selectFirst();
this.saveButton.requestFocus();
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/proxy/ConnectionDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,17 @@ public class ConnectionDetails {
private int portRemote;
private int portLocal;

public ConnectionDetails(String host, int portRemote, int portLocal, boolean performSrvLookup) {
this.host = host;
this.portRemote = portRemote;
public ConnectionDetails(String host, int portLocal, boolean performSrvLookup) {
this.portRemote = DEFAULT_PORT;

if (host.contains(":")) {
String[] hostParts = host.split(":");
this.host = hostParts[0];

attempt(() -> this.portRemote = Integer.parseInt(hostParts[1]));
} else {
this.host = host;
}
this.portLocal = portLocal;

if (performSrvLookup) {
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/proxy/auth/AuthDetailsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import gui.GuiManager;
import java.io.IOException;
import java.util.function.Consumer;

/**
* Class to handle retrieving authentication details from either user input, or the relevant launcher files.
Expand Down Expand Up @@ -44,6 +45,22 @@ public static AuthDetails loadAuthDetails() throws IOException {
};
}

public static void validateAuthStatus(Consumer<String> onSuccess, Consumer<String> onError) {
try {
AuthDetails details = loadAuthDetails();

boolean isValid = details.isValid();
if (isValid) {
onSuccess.accept("Valid session found! \n\nUsername: " + details.getUsername());
} else {
AuthenticationMethod method = Config.getAuthMethod();
onError.accept(method.getErrorMessage());
}
} catch (IOException e) {
onError.accept("Exception occurred: " + e.getMessage());
}
}

public AuthDetails getAuthDetails() throws IOException {
if (this.details == null) {
this.details = loadAuthDetails();
Expand Down
71 changes: 34 additions & 37 deletions src/main/resources/ui/Settings.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,39 @@
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane prefHeight="265.0" prefWidth="620.0" stylesheets="/ui/dark.css" xmlns="http://javafx.com/javafx/" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gui.GuiSettings">
<Button fx:id="saveButton" layoutX="491.0" layoutY="225.0" mnemonicParsing="false" onAction="#saveSettings" prefHeight="27.0" prefWidth="101.0" text="Start" />
<TabPane fx:id="tabPane" prefHeight="225.0" prefWidth="620.0" tabClosingPolicy="UNAVAILABLE">
<AnchorPane prefHeight="265.0" prefWidth="620.0" stylesheets="/ui/dark.css" xmlns="http://javafx.com/javafx/1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="gui.GuiSettings">
<TabPane fx:id="tabPane" prefHeight="233.0" prefWidth="620.0" tabClosingPolicy="UNAVAILABLE">
<Tab text="Connection">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="254.0" prefWidth="600.0">
<GridPane layoutX="14.0" layoutY="6.0" prefHeight="187.0" prefWidth="579.0">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="215.0" prefWidth="620.0">
<GridPane layoutX="19.0" layoutY="35.0" prefHeight="108.0" prefWidth="574.0">
<columnConstraints>
<ColumnConstraints prefWidth="120.0" />
<ColumnConstraints prefWidth="300.0" />
<ColumnConstraints prefWidth="150.0" />
<ColumnConstraints maxWidth="121.0" minWidth="19.0" prefWidth="121.0" />
<ColumnConstraints maxWidth="345.0" minWidth="159.0" prefWidth="235.0" />
<ColumnConstraints maxWidth="136.0" minWidth="10.0" prefWidth="101.0" />
<ColumnConstraints maxWidth="170.0" minWidth="105.0" prefWidth="105.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints prefHeight="32.0" />
<RowConstraints prefHeight="32.0" />
<RowConstraints prefHeight="32.0" />
<RowConstraints prefHeight="32.0" />
<RowConstraints prefHeight="32.0" />
<RowConstraints prefHeight="32.0" />
<RowConstraints minHeight="10.0" prefHeight="32.0" />
<RowConstraints minHeight="10.0" prefHeight="32.0" />
</rowConstraints>
<TextField fx:id="server" prefHeight="25.0" prefWidth="93.0" styleClass="field-nonempty" GridPane.columnIndex="1" />
<DefaultIntField fx:id="portRemote" defaultVal="25565" layoutX="10.0" layoutY="98.0" prefHeight="25.0" prefWidth="93.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label text="Server address" />
<Label text="Server port" GridPane.rowIndex="1" />
<Label text="Local port" GridPane.rowIndex="2">
<tooltip><QuickTooltip text="Port on which the downloader's proxy server will run" /></tooltip>
<TextField fx:id="server" prefHeight="25.0" prefWidth="93.0" styleClass="field-nonempty" GridPane.columnIndex="1" GridPane.columnSpan="2" />
<Label text="Server address" GridPane.columnSpan="2">
<tooltip><QuickTooltip text="Server address. E.g. 'example.com' or '192.168.0.1:25565'" /></tooltip>
</Label>
<DefaultIntField fx:id="portLocal" defaultVal="25565" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="2" GridPane.rowIndex="4">
<Label fx:id="authDetailsVerifyLabel" layoutX="22.0" layoutY="6.0" prefHeight="17.0" prefWidth="90.0" textAlignment="CENTER" AnchorPane.leftAnchor="20.0" />
</AnchorPane>
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="2" GridPane.rowIndex="2">
<Label fx:id="portVerifyLabel" layoutX="22.0" layoutY="6.0" prefHeight="17.0" prefWidth="90.0" styleClass="label-err" textAlignment="CENTER" AnchorPane.leftAnchor="20.0" />
</AnchorPane>
<Hyperlink fx:id="verifyAuthLink" text="Verify authentication" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</GridPane>
</AnchorPane>
</Tab>
<Tab text="General">
<AnchorPane>
<GridPane layoutX="14.0" layoutY="6.0" prefHeight="183.0" prefWidth="500.0">
<AnchorPane prefHeight="238.0" prefWidth="620.0">
<GridPane layoutX="14.0" layoutY="6.0" prefHeight="202.0" prefWidth="500.0">
<columnConstraints>
<ColumnConstraints prefWidth="160.0" />
<ColumnConstraints maxWidth="262.0" minWidth="28.0" prefWidth="77.0" />
<ColumnConstraints maxWidth="306.0" minWidth="10.0" prefWidth="235.0" />
<ColumnConstraints prefWidth="40.0" />
<ColumnConstraints maxWidth="262.0" minWidth="28.0" prefWidth="79.0" />
<ColumnConstraints maxWidth="306.0" minWidth="10.0" prefWidth="23.0" />
<ColumnConstraints maxWidth="306.0" minWidth="10.0" prefWidth="259.0" />
<ColumnConstraints maxWidth="39.0" minWidth="33.0" prefWidth="39.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints prefHeight="32.0" />
Expand All @@ -57,18 +46,18 @@
<RowConstraints prefHeight="32.0" />
<RowConstraints prefHeight="32.0" />
</rowConstraints>
<Label text="Extended render distance" GridPane.rowIndex="0" >
<Label text="Extended render distance" GridPane.rowIndex="0">
<tooltip><QuickTooltip text="Render distance in chunks. If greater than the server's render distance, send previously downloaded chunks back to the game." /></tooltip>
</Label>
<Slider fx:id="extendedDistance" blockIncrement="1" layoutX="10.0" layoutY="98.0" majorTickUnit="1.0" max="32" minorTickCount="0" prefHeight="25.0" prefWidth="93.0" showTickLabels="true" snapToTicks="true" GridPane.columnIndex="1" GridPane.columnSpan="2" />
<AnchorPane GridPane.columnIndex="3">
<Slider fx:id="extendedDistance" blockIncrement="1" layoutX="10.0" layoutY="98.0" majorTickUnit="1.0" max="32" minorTickCount="0" prefHeight="25.0" prefWidth="93.0" showTickLabels="true" snapToTicks="true" GridPane.columnIndex="1" GridPane.columnSpan="3" />
<AnchorPane GridPane.columnIndex="4">
<IntField fx:id="extendedDistanceText" prefWidth="40" AnchorPane.leftAnchor="10" />
</AnchorPane>
<CheckBox fx:id="markUnsaved" prefHeight="25.0" prefWidth="93.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label text="Mark unsaved chunks" GridPane.rowIndex="2">
<tooltip><QuickTooltip text="Colour chunks that haven't been saved to disk in red" /></tooltip>
</Label>
<CheckBox fx:id="markOld" prefHeight="25.0" prefWidth="93.0" GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<CheckBox fx:id="markOld" prefHeight="25.0" prefWidth="93.0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label text="Grey out old chunks" GridPane.rowIndex="3">
<tooltip><QuickTooltip text="Darken chunks downloaded in a previous session." /></tooltip>
</Label>
Expand All @@ -77,7 +66,7 @@
<tooltip><QuickTooltip text="Show other players on the overview map" /></tooltip>
</Label>

<AnchorPane prefWidth="200.0" GridPane.columnIndex="2" GridPane.rowIndex="2" GridPane.rowSpan="4">
<AnchorPane prefWidth="200.0" GridPane.columnIndex="3" GridPane.rowIndex="2" GridPane.rowSpan="4">
<TitledPane animated="false" expanded="false" prefHeight="97.0" prefWidth="219.0" text="Advanced">
<AnchorPane layoutY="-20" prefHeight="64.0" prefWidth="217.0" style="-fx-padding: 6">
<GridPane layoutX="26.0" prefWidth="200.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="-3.0">
Expand All @@ -102,6 +91,13 @@
</AnchorPane>
</TitledPane>
</AnchorPane>
<Label text="Downloader port" GridPane.rowIndex="5">
<tooltip>
<QuickTooltip text="Port on which the downloader's proxy server will run" />
</tooltip>
</Label>
<DefaultIntField fx:id="portLocal" defaultVal="25565" prefHeight="53.0" prefWidth="336.0" text="default" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<Label fx:id="portVerifyLabel" prefHeight="17.0" prefWidth="90.0" styleClass="label-err" textAlignment="CENTER" GridPane.columnIndex="3" GridPane.rowIndex="5" />
</GridPane>
</AnchorPane>
</Tab>
Expand Down Expand Up @@ -177,7 +173,8 @@
<fx:include fx:id="realms" source="RealmsTab.fxml" />
</Tab>
<Tab fx:id="errTab" text="Error log">
<TextArea fx:id="errOutput" prefHeight="174.0" prefWidth="600.0" />
<TextArea fx:id="errOutput" prefHeight="189.0" prefWidth="620.0" />
</Tab>
</TabPane>
<Button fx:id="saveButton" layoutX="505.0" layoutY="224.0" mnemonicParsing="false" onAction="#saveSettings" prefHeight="27.0" prefWidth="101.0" text="Start" />
</AnchorPane>
3 changes: 2 additions & 1 deletion src/main/resources/ui/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@
-fx-font-weight: bold;
}
.field-nonempty:empty {
-fx-background-color: #ffbaba;
-fx-background-color: #fbcece;
-fx-prompt-text-fill: #828282;
}

.titled-pane > .title {
Expand Down

0 comments on commit 2cda9e5

Please sign in to comment.