Added advanced options to ui

This commit is contained in:
Lenni0451 2023-03-29 21:29:40 +02:00
parent f0599ca775
commit e9b16fec4f
5 changed files with 151 additions and 48 deletions

View File

@ -34,6 +34,10 @@ public abstract class AUITab {
this.init(this.contentPane);
}
public String getName() {
return this.name;
}
public void add(final JTabbedPane tabbedPane) {
tabbedPane.addTab(this.name, this.contentPane);
}

View File

@ -21,6 +21,7 @@ import com.formdev.flatlaf.FlatDarkLaf;
import net.lenni0451.reflect.stream.RStream;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.ui.impl.AccountsTab;
import net.raphimc.viaproxy.ui.impl.AdvancedTab;
import net.raphimc.viaproxy.ui.impl.GeneralTab;
import net.raphimc.viaproxy.util.logging.Logger;
@ -38,6 +39,7 @@ public class ViaProxyUI extends JFrame {
private final List<AUITab> tabs = new ArrayList<>();
public final GeneralTab generalTab = new GeneralTab(this);
public final AdvancedTab advancedTab = new AdvancedTab(this);
public final AccountsTab accountsTab = new AccountsTab(this);
private ImageIcon icon;
@ -78,7 +80,7 @@ public class ViaProxyUI extends JFrame {
for (AUITab tab : tabs) tab.onClose();
}
});
this.setSize(500, 403);
this.setSize(500, 353);
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setContentPane(this.contentPane);
@ -95,7 +97,7 @@ public class ViaProxyUI extends JFrame {
tab.add(this.contentPane);
});
this.contentPane.setEnabledAt(1, false);
this.contentPane.setEnabledAt(this.contentPane.indexOfTab(this.accountsTab.getName()), false);
}

View File

@ -82,7 +82,7 @@ public class AccountsTab extends AUITab {
}
{
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(10, 105, 465, 185);
scrollPane.setBounds(10, 105, 465, 135);
contentPane.add(scrollPane);
DefaultListModel<String> model = new DefaultListModel<>();
@ -167,7 +167,7 @@ public class AccountsTab extends AUITab {
}
{
JButton addOfflineAccountButton = new JButton("Add Offline Account");
addOfflineAccountButton.setBounds(10, 300, 153, 20);
addOfflineAccountButton.setBounds(10, 250, 153, 20);
addOfflineAccountButton.addActionListener(event -> {
String username = JOptionPane.showInputDialog(this.frame, "Enter your offline mode Username:", "Add Offline Account", JOptionPane.PLAIN_MESSAGE);
if (username != null && !username.trim().isEmpty()) {
@ -180,7 +180,7 @@ public class AccountsTab extends AUITab {
}
{
this.addMicrosoftAccountButton = new JButton("Add Microsoft Account");
this.addMicrosoftAccountButton.setBounds(168, 300, 153, 20);
this.addMicrosoftAccountButton.setBounds(168, 250, 153, 20);
this.addMicrosoftAccountButton.addActionListener(event -> {
this.addMicrosoftAccountButton.setEnabled(false);
this.handleLogin(MinecraftAuth::requestJavaLogin, profile -> ViaProxy.saveManager.accountsSave.addAccount(profile));
@ -189,7 +189,7 @@ public class AccountsTab extends AUITab {
}
{
this.addBedrockAccountButton = new JButton("Add Bedrock Account");
this.addBedrockAccountButton.setBounds(326, 300, 149, 20);
this.addBedrockAccountButton.setBounds(326, 250, 149, 20);
this.addBedrockAccountButton.addActionListener(event -> {
this.addBedrockAccountButton.setEnabled(false);
this.handleLogin(MinecraftAuth::requestBedrockLogin, chain -> ViaProxy.saveManager.accountsSave.addAccount(chain));

View File

@ -0,0 +1,90 @@
/*
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
* Copyright (C) 2023 RK_01/RaphiMC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.raphimc.viaproxy.ui.impl;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.saves.impl.UISave;
import net.raphimc.viaproxy.ui.AUITab;
import net.raphimc.viaproxy.ui.ViaProxyUI;
import javax.swing.*;
public class AdvancedTab extends AUITab {
JSpinner bindPort;
JTextField proxy;
JCheckBox proxyOnlineMode;
public AdvancedTab(final ViaProxyUI frame) {
super(frame, "Advanced");
}
@Override
protected void init(JPanel contentPane) {
{
String toolTipText = "The port the proxy should bind to.";
JLabel bindPortLabel = new JLabel("Bind Port:");
bindPortLabel.setBounds(10, 10, 100, 20);
bindPortLabel.setToolTipText(toolTipText);
contentPane.add(bindPortLabel);
this.bindPort = new JSpinner(new SpinnerNumberModel(25568, 1, 65535, 1));
this.bindPort.setBounds(10, 30, 465, 20);
this.bindPort.setToolTipText(toolTipText);
ViaProxy.saveManager.uiSave.loadSpinner("bind_port", this.bindPort);
contentPane.add(this.bindPort);
}
{
String toolTipText = "URL of a SOCKS(4/5)/HTTP(S) proxy which will be used for TCP connections.\n" +
"Supported formats:\n" +
"- type://address:port\n" +
"- type://username:password@address:port";
JLabel proxyLabel = new JLabel("Proxy URL:");
proxyLabel.setBounds(10, 60, 100, 20);
proxyLabel.setToolTipText(toolTipText);
contentPane.add(proxyLabel);
this.proxy = new JTextField();
this.proxy.setBounds(10, 80, 465, 20);
this.proxy.setToolTipText(toolTipText);
ViaProxy.saveManager.uiSave.loadTextField("proxy", this.proxy);
contentPane.add(this.proxy);
}
{
this.proxyOnlineMode = new JCheckBox("Proxy Online Mode");
this.proxyOnlineMode.setBounds(10, 110, 465, 20);
this.proxyOnlineMode.setToolTipText("Enabling Proxy Online Mode requires your client to have a valid account.\n" +
"Proxy Online Mode allows your client to see skins on online mode servers and use the signed chat features.");
ViaProxy.saveManager.uiSave.loadCheckBox("proxy_online_mode", this.proxyOnlineMode);
contentPane.add(this.proxyOnlineMode);
}
}
@Override
public void onClose() {
UISave save = ViaProxy.saveManager.uiSave;
save.put("bind_port", String.valueOf(this.bindPort.getValue()));
save.put("proxy", this.proxy.getText());
save.put("proxy_online_mode", String.valueOf(this.proxyOnlineMode.isSelected()));
ViaProxy.saveManager.save();
}
}

View File

@ -34,15 +34,14 @@ import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.net.URI;
import java.net.URISyntaxException;
public class GeneralTab extends AUITab {
private JTextField serverAddress;
private JComboBox<VersionEnum> serverVersion;
private JSpinner bindPort;
private JComboBox<String> authMethod;
private JCheckBox betaCraftAuth;
private JCheckBox proxyOnlineMode;
private JLabel stateLabel;
private JButton stateButton;
@ -76,16 +75,19 @@ public class GeneralTab extends AUITab {
contentPane.add(discordLabel);
}
{
String toolTipText = "Supported formats:\n" +
"- address\n" +
"- address:port\n" +
"- ClassiCube Direct URL";
JLabel addressLabel = new JLabel("Server Address:");
addressLabel.setBounds(10, 50, 100, 20);
addressLabel.setToolTipText(toolTipText);
contentPane.add(addressLabel);
this.serverAddress = new JTextField();
this.serverAddress.setBounds(10, 70, 465, 20);
this.serverAddress.setToolTipText("Supported formats:\n" +
"- hostname\n" +
"- hostname:port\n" +
"- ClassiCube Direct URL");
this.serverAddress.setToolTipText(toolTipText);
ViaProxy.saveManager.uiSave.loadTextField("server_address", this.serverAddress);
contentPane.add(this.serverAddress);
}
@ -106,52 +108,45 @@ public class GeneralTab extends AUITab {
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
this.serverVersion.addActionListener(e -> {
if (!(this.serverVersion.getSelectedItem() instanceof VersionEnum)) return;
if (((VersionEnum) this.serverVersion.getSelectedItem()).isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
this.betaCraftAuth.setEnabled(true);
} else {
this.betaCraftAuth.setEnabled(false);
this.betaCraftAuth.setSelected(false);
}
});
ViaProxy.saveManager.uiSave.loadComboBox("server_version", this.serverVersion);
contentPane.add(this.serverVersion);
}
{
JLabel bindPortLabel = new JLabel("Local Port:");
bindPortLabel.setBounds(10, 150, 100, 20);
contentPane.add(bindPortLabel);
this.bindPort = new JSpinner(new SpinnerNumberModel(25568, 1, 65535, 1));
this.bindPort.setBounds(10, 170, 465, 20);
ViaProxy.saveManager.uiSave.loadSpinner("bind_port", this.bindPort);
contentPane.add(this.bindPort);
}
{
JLabel authMethodLabel = new JLabel("Minecraft Account:");
authMethodLabel.setBounds(10, 200, 400, 20);
authMethodLabel.setBounds(10, 150, 400, 20);
contentPane.add(authMethodLabel);
this.authMethod = new JComboBox<>(new String[]{"Use no account", "Use selected account", "Use OpenAuthMod"});
this.authMethod.setBounds(10, 220, 465, 20);
this.authMethod.setBounds(10, 170, 465, 20);
ViaProxy.saveManager.uiSave.loadComboBox("auth_method", this.authMethod);
contentPane.add(this.authMethod);
}
{
this.betaCraftAuth = new JCheckBox("BetaCraft Auth (Classic)");
this.betaCraftAuth.setBounds(10, 250, 250, 20);
this.betaCraftAuth.setBounds(10, 200, 250, 20);
this.betaCraftAuth.setToolTipText("Enabling BetaCraft Auth allows you to join Classic servers which have online mode enabled.");
ViaProxy.saveManager.uiSave.loadCheckBox("betacraft_auth", this.betaCraftAuth);
contentPane.add(this.betaCraftAuth);
}
{
this.proxyOnlineMode = new JCheckBox("Proxy Online Mode");
this.proxyOnlineMode.setBounds(350, 250, 465, 20);
this.proxyOnlineMode.setToolTipText("Enabling Proxy Online Mode requires your client to have a valid account.\nProxy Online Mode allows your client to see skins on online mode servers and use the signed chat features.");
ViaProxy.saveManager.uiSave.loadCheckBox("proxy_online_mode", this.proxyOnlineMode);
contentPane.add(this.proxyOnlineMode);
this.serverVersion.actionPerformed(null);
}
{
this.stateLabel = new JLabel();
this.stateLabel.setBounds(14, 280, 465, 20);
this.stateLabel.setBounds(14, 230, 465, 20);
this.stateLabel.setVisible(false);
contentPane.add(this.stateLabel);
}
{
this.stateButton = new JButton("Loading ViaProxy...");
this.stateButton.setBounds(10, 300, 465, 20);
this.stateButton.setBounds(10, 250, 465, 20);
this.stateButton.addActionListener(e -> {
if (this.stateButton.getText().equalsIgnoreCase("Start")) this.start();
else if (this.stateButton.getText().equalsIgnoreCase("Stop")) this.stop();
@ -174,24 +169,24 @@ public class GeneralTab extends AUITab {
UISave save = ViaProxy.saveManager.uiSave;
save.put("server_address", this.serverAddress.getText());
save.put("server_version", String.valueOf(this.serverVersion.getSelectedIndex()));
save.put("bind_port", String.valueOf(this.bindPort.getValue()));
save.put("auth_method", String.valueOf(this.authMethod.getSelectedIndex()));
save.put("betacraft_auth", String.valueOf(this.betaCraftAuth.isSelected()));
save.put("proxy_online_mode", String.valueOf(this.proxyOnlineMode.isSelected()));
ViaProxy.saveManager.save();
}
private void setComponentsEnabled(final boolean state) {
this.serverAddress.setEnabled(state);
this.serverVersion.setEnabled(state);
this.bindPort.setEnabled(state);
ViaProxy.ui.advancedTab.bindPort.setEnabled(state);
this.authMethod.setEnabled(state);
this.betaCraftAuth.setEnabled(state);
this.proxyOnlineMode.setEnabled(state);
ViaProxy.ui.advancedTab.proxyOnlineMode.setEnabled(state);
ViaProxy.ui.advancedTab.proxy.setEnabled(state);
if (state) this.serverVersion.actionPerformed(null);
}
private void updateStateLabel() {
this.stateLabel.setText("ViaProxy is running! Connect with Minecraft 1.7+ to 127.0.0.1:" + this.bindPort.getValue());
this.stateLabel.setText("ViaProxy is running! Connect with Minecraft 1.7+ to 127.0.0.1:" + ViaProxy.ui.advancedTab.bindPort.getValue());
this.stateLabel.setVisible(true);
}
@ -203,10 +198,11 @@ public class GeneralTab extends AUITab {
new Thread(() -> {
String serverAddress = this.serverAddress.getText().trim();
final VersionEnum serverVersion = (VersionEnum) this.serverVersion.getSelectedItem();
final int bindPort = (int) this.bindPort.getValue();
final int bindPort = (int) ViaProxy.ui.advancedTab.bindPort.getValue();
final int authMethod = this.authMethod.getSelectedIndex();
final boolean betaCraftAuth = this.betaCraftAuth.isSelected();
final boolean proxyOnlineMode = this.proxyOnlineMode.isSelected();
final boolean proxyOnlineMode = ViaProxy.ui.advancedTab.proxyOnlineMode.isSelected();
final String proxyUrl = ViaProxy.ui.advancedTab.proxy.getText();
try {
try {
@ -216,7 +212,7 @@ public class GeneralTab extends AUITab {
final String[] path = uri.getPath().substring(1).split("/");
if (path.length < 2) {
throw new IllegalArgumentException("Invalid ClassiCube Direct URL");
throw new IllegalArgumentException("Invalid ClassiCube Direct URL!");
}
Options.MC_ACCOUNT = new OfflineAccount(path[0]);
@ -230,23 +226,34 @@ public class GeneralTab extends AUITab {
Options.CLASSIC_MP_PASS = null;
}
final HostAndPort hostAndPort = HostAndPort.fromString(serverAddress);
try {
HostAndPort hostAndPort = HostAndPort.fromString(serverAddress);
Options.CONNECT_ADDRESS = hostAndPort.getHost();
Options.CONNECT_PORT = hostAndPort.getPortOrDefault(PluginManager.EVENT_MANAGER.call(new GetDefaultPortEvent(serverVersion, 25565)).getDefaultPort());
} catch (Throwable t) {
throw new IllegalArgumentException("Invalid server address!");
}
Options.BIND_PORT = bindPort;
Options.ONLINE_MODE = proxyOnlineMode;
Options.CONNECT_ADDRESS = hostAndPort.getHost();
Options.PROTOCOL_VERSION = serverVersion;
Options.CONNECT_PORT = hostAndPort.getPortOrDefault(PluginManager.EVENT_MANAGER.call(new GetDefaultPortEvent(serverVersion, 25565)).getDefaultPort());
Options.BETACRAFT_AUTH = betaCraftAuth;
if (authMethod == 2) {
Options.OPENAUTHMOD_AUTH = true;
}
} catch (Throwable e) {
if (!proxyUrl.isEmpty()) {
try {
Options.PROXY_URL = new URI(proxyUrl);
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Invalid proxy URL!");
}
}
} catch (Throwable t) {
SwingUtilities.invokeLater(() -> {
this.frame.showError("Invalid server address!");
this.frame.showError(t.getMessage());
});
throw e;
throw t;
}
try {