Added support for joining ClassiCube servers

This commit is contained in:
RaphiMC 2023-03-26 21:02:53 +02:00
parent c612d79a81
commit f3f3bf67a9
6 changed files with 37 additions and 11 deletions

View File

@ -44,7 +44,7 @@ import net.raphimc.viaproxy.proxy.client2proxy.Client2ProxyHandler;
import net.raphimc.viaproxy.saves.SaveManager;
import net.raphimc.viaproxy.tasks.AccountRefreshTask;
import net.raphimc.viaproxy.tasks.LoaderTask;
import net.raphimc.viaproxy.tasks.UpdatedCheckTask;
import net.raphimc.viaproxy.tasks.UpdateCheckTask;
import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.util.logging.Logger;
@ -100,7 +100,7 @@ public class ViaProxy {
Thread loaderThread = new Thread(new LoaderTask(), "ViaProtocolHack-Loader");
Thread accountRefreshThread = new Thread(new AccountRefreshTask(saveManager), "AccountRefresh");
Thread updateCheckThread = new Thread(new UpdatedCheckTask(hasUI), "UpdateCheck");
Thread updateCheckThread = new Thread(new UpdateCheckTask(hasUI), "UpdateCheck");
if (hasUI) {
loaderThread.start();

View File

@ -47,6 +47,7 @@ public class Options {
// GUI only config options
public static Account MC_ACCOUNT;
public static String CLASSIC_MP_PASS;
// CLI only config options
public static int COMPRESSION_THRESHOLD = 256;

View File

@ -39,6 +39,8 @@ public class ViaProxyClassicMPPassProvider extends ClassicMPPassProvider {
final String mppass = ProxyConnection.fromUserConnection(user).getClassicMpPass();
if (mppass != null && !mppass.isEmpty() && !mppass.equals("0")) {
return mppass;
} else if (Options.CLASSIC_MP_PASS != null) {
return Options.CLASSIC_MP_PASS;
} else if (Options.BETACRAFT_AUTH) {
final HandshakeStorage handshakeStorage = user.get(HandshakeStorage.class);
return getBetacraftMpPass(user, user.getProtocolInfo().getUsername(), handshakeStorage.getHostname(), handshakeStorage.getPort());

View File

@ -35,11 +35,11 @@ import java.net.URL;
import static net.raphimc.viaproxy.ViaProxy.VERSION;
public class UpdatedCheckTask implements Runnable {
public class UpdateCheckTask implements Runnable {
private final boolean hasUI;
public UpdatedCheckTask(final boolean hasUI) {
public UpdateCheckTask(final boolean hasUI) {
this.hasUI = hasUI;
}

View File

@ -36,6 +36,7 @@ public class ViaProxyUI extends JFrame {
private final JTabbedPane contentPane = new JTabbedPane();
private final List<AUITab> tabs = new ArrayList<>();
public final GeneralTab generalTab = new GeneralTab(this);
public final AccountsTab accountsTab = new AccountsTab(this);
@ -49,6 +50,8 @@ public class ViaProxyUI extends JFrame {
this.initWindow();
this.initTabs();
ToolTipManager.sharedInstance().setInitialDelay(100);
ToolTipManager.sharedInstance().setDismissDelay(10_000);
SwingUtilities.updateComponentTreeUI(this);
this.setVisible(true);
}

View File

@ -24,6 +24,7 @@ import net.raphimc.viaproxy.cli.options.Options;
import net.raphimc.viaproxy.plugins.PluginManager;
import net.raphimc.viaproxy.plugins.events.GetDefaultPortEvent;
import net.raphimc.viaproxy.saves.impl.UISave;
import net.raphimc.viaproxy.saves.impl.accounts.OfflineAccount;
import net.raphimc.viaproxy.ui.AUITab;
import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.util.logging.Logger;
@ -32,6 +33,7 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.net.URI;
public class GeneralTab extends AUITab {
@ -80,6 +82,10 @@ public class GeneralTab extends AUITab {
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");
ViaProxy.saveManager.uiSave.loadTextField("server_address", this.serverAddress);
contentPane.add(this.serverAddress);
}
@ -126,6 +132,7 @@ public class GeneralTab extends AUITab {
{
this.betaCraftAuth = new JCheckBox("BetaCraft Auth (Classic)");
this.betaCraftAuth.setBounds(10, 250, 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);
}
@ -194,7 +201,7 @@ public class GeneralTab extends AUITab {
this.stateButton.setText("Starting...");
new Thread(() -> {
final String serverAddress = this.serverAddress.getText().trim();
String serverAddress = this.serverAddress.getText().trim();
final VersionEnum serverVersion = (VersionEnum) this.serverVersion.getSelectedItem();
final int bindPort = (int) this.bindPort.getValue();
final int authMethod = this.authMethod.getSelectedIndex();
@ -203,6 +210,25 @@ public class GeneralTab extends AUITab {
try {
try {
if (serverAddress.startsWith("mc://")) { // ClassiCube Direct URL
final URI uri = new URI(serverAddress);
serverAddress = uri.getHost() + ":" + uri.getPort();
final String[] path = uri.getPath().substring(1).split("/");
if (path.length < 2) {
throw new IllegalArgumentException("Invalid ClassiCube Direct URL");
}
Options.MC_ACCOUNT = new OfflineAccount(path[0]);
Options.CLASSIC_MP_PASS = path[1];
} else { // Normal address
if (authMethod != 1) {
Options.MC_ACCOUNT = null;
} else if (Options.MC_ACCOUNT == null) {
this.frame.accountsTab.markSelected(0);
}
}
final HostAndPort hostAndPort = HostAndPort.fromString(serverAddress);
Options.BIND_PORT = bindPort;
@ -212,12 +238,6 @@ public class GeneralTab extends AUITab {
Options.CONNECT_PORT = hostAndPort.getPortOrDefault(PluginManager.EVENT_MANAGER.call(new GetDefaultPortEvent(serverVersion, 25565)).getDefaultPort());
Options.BETACRAFT_AUTH = betaCraftAuth;
if (authMethod != 1) {
Options.MC_ACCOUNT = null;
} else if (Options.MC_ACCOUNT == null) {
this.frame.accountsTab.markSelected(0);
}
if (authMethod == 2) {
Options.OPENAUTHMOD_AUTH = true;
}