mirror of
https://github.com/ViaVersion/ViaProxy.git
synced 2024-12-22 16:38:04 +01:00
Added config file support, improved GUI error handling, deprecated CLI arguments
This commit is contained in:
parent
43daa63246
commit
0cb34ed553
@ -6,7 +6,7 @@ plugins {
|
||||
id "maven-publish"
|
||||
id "idea"
|
||||
id "net.raphimc.class-token-replacer" version "1.0.0"
|
||||
id "net.raphimc.java-downgrader" version "1.1.1"
|
||||
id "net.raphimc.java-downgrader" version "1.1.2"
|
||||
}
|
||||
|
||||
base {
|
||||
|
@ -44,19 +44,21 @@ import net.raphimc.viaproxy.plugins.events.ProxyStartEvent;
|
||||
import net.raphimc.viaproxy.plugins.events.ProxyStopEvent;
|
||||
import net.raphimc.viaproxy.plugins.events.ViaProxyLoadedEvent;
|
||||
import net.raphimc.viaproxy.protocoltranslator.ProtocolTranslator;
|
||||
import net.raphimc.viaproxy.protocoltranslator.viaproxy.ViaProxyConfig;
|
||||
import net.raphimc.viaproxy.proxy.client2proxy.Client2ProxyChannelInitializer;
|
||||
import net.raphimc.viaproxy.proxy.client2proxy.Client2ProxyHandler;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
import net.raphimc.viaproxy.saves.SaveManager;
|
||||
import net.raphimc.viaproxy.tasks.UpdateCheckTask;
|
||||
import net.raphimc.viaproxy.ui.SplashScreen;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyUI;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyWindow;
|
||||
import net.raphimc.viaproxy.util.AddressUtil;
|
||||
import net.raphimc.viaproxy.util.ClassLoaderPriorityUtil;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.instrument.Instrumentation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -69,13 +71,15 @@ public class ViaProxy {
|
||||
public static final String IMPL_VERSION = "${impl_version}";
|
||||
|
||||
public static final LambdaManager EVENT_MANAGER = LambdaManager.threadSafe(new LambdaMetaFactoryGenerator(JavaBypass.TRUSTED_LOOKUP));
|
||||
private static /*final*/ SaveManager SAVE_MANAGER;
|
||||
private static /*final*/ PluginManager PLUGIN_MANAGER;
|
||||
private static /*final*/ SaveManager SAVE_MANAGER;
|
||||
private static /*final*/ ViaProxyConfig CONFIG;
|
||||
private static /*final*/ ChannelGroup CLIENT_CHANNELS;
|
||||
|
||||
private static Instrumentation instrumentation;
|
||||
private static NetServer currentProxyServer;
|
||||
private static ViaProxyUI ui;
|
||||
private static ViaProxyWindow viaProxyWindow;
|
||||
private static JFrame foregroundWindow;
|
||||
|
||||
public static void agentmain(final String args, final Instrumentation instrumentation) {
|
||||
ViaProxy.instrumentation = instrumentation;
|
||||
@ -105,15 +109,20 @@ public class ViaProxy {
|
||||
|
||||
public static void injectedMain(final String injectionMethod, final String[] args) throws InterruptedException, IOException, InvocationTargetException {
|
||||
final boolean hasUI = args.length == 0 && !GraphicsEnvironment.isHeadless();
|
||||
final boolean legacyCLI = args.length > 0 && args[0].startsWith("-");
|
||||
final SplashScreen splashScreen;
|
||||
final Consumer<String> progressConsumer;
|
||||
if (hasUI) {
|
||||
final float progressStep = 1F / 6F;
|
||||
splashScreen = new SplashScreen();
|
||||
final float progressStep = 1F / 7F;
|
||||
foregroundWindow = splashScreen = new SplashScreen();
|
||||
progressConsumer = (text) -> {
|
||||
splashScreen.setProgress(splashScreen.getProgress() + progressStep);
|
||||
splashScreen.setText(text);
|
||||
};
|
||||
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
|
||||
ViaProxyWindow.showException(e);
|
||||
System.exit(1);
|
||||
});
|
||||
} else {
|
||||
splashScreen = null;
|
||||
progressConsumer = text -> {
|
||||
@ -154,18 +163,29 @@ public class ViaProxy {
|
||||
ViaProxy.loadNetty();
|
||||
ClassLoaderPriorityUtil.loadOverridingJars();
|
||||
|
||||
final File viaProxyConfigFile;
|
||||
if (!hasUI && !legacyCLI) {
|
||||
viaProxyConfigFile = new File(args[0]);
|
||||
} else {
|
||||
viaProxyConfigFile = new File("viaproxy.yml");
|
||||
}
|
||||
final boolean firstStart = !viaProxyConfigFile.exists();
|
||||
|
||||
progressConsumer.accept("Loading Plugins");
|
||||
PLUGIN_MANAGER = new PluginManager();
|
||||
progressConsumer.accept("Loading Protocol Translators");
|
||||
ProtocolTranslator.init();
|
||||
progressConsumer.accept("Loading Saves");
|
||||
SAVE_MANAGER = new SaveManager();
|
||||
progressConsumer.accept("Loading Config");
|
||||
CONFIG = new ViaProxyConfig(viaProxyConfigFile);
|
||||
CONFIG.reload();
|
||||
|
||||
if (hasUI) {
|
||||
progressConsumer.accept("Loading GUI");
|
||||
SwingUtilities.invokeAndWait(() -> {
|
||||
try {
|
||||
ui = new ViaProxyUI();
|
||||
foregroundWindow = viaProxyWindow = new ViaProxyWindow();
|
||||
progressConsumer.accept("Done");
|
||||
splashScreen.dispose();
|
||||
} catch (Throwable e) {
|
||||
@ -179,7 +199,12 @@ public class ViaProxy {
|
||||
EVENT_MANAGER.call(new ViaProxyLoadedEvent());
|
||||
Logger.LOGGER.info("ViaProxy started successfully!");
|
||||
} else {
|
||||
Options.parse(args);
|
||||
if (legacyCLI) {
|
||||
Options.parse(args);
|
||||
} else if (firstStart) {
|
||||
Logger.LOGGER.info("This is the first start of ViaProxy. Please configure the settings in the " + viaProxyConfigFile.getName() + " file and restart ViaProxy.");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
if (System.getProperty("skipUpdateCheck") == null) {
|
||||
CompletableFuture.runAsync(new UpdateCheckTask(false));
|
||||
@ -202,8 +227,8 @@ public class ViaProxy {
|
||||
Logger.LOGGER.info("Starting proxy server");
|
||||
currentProxyServer = new NetServer(() -> EVENT_MANAGER.call(new Client2ProxyHandlerCreationEvent(new Client2ProxyHandler(), false)).getHandler(), Client2ProxyChannelInitializer::new);
|
||||
EVENT_MANAGER.call(new ProxyStartEvent());
|
||||
Logger.LOGGER.info("Binding proxy server to " + AddressUtil.toString(Options.BIND_ADDRESS));
|
||||
currentProxyServer.bind(Options.BIND_ADDRESS, false);
|
||||
Logger.LOGGER.info("Binding proxy server to " + AddressUtil.toString(CONFIG.getBindAddress()));
|
||||
currentProxyServer.bind(CONFIG.getBindAddress(), false);
|
||||
} catch (Throwable e) {
|
||||
currentProxyServer = null;
|
||||
throw e;
|
||||
@ -236,12 +261,16 @@ public class ViaProxy {
|
||||
CLIENT_CHANNELS = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
|
||||
}
|
||||
|
||||
public static PluginManager getPluginManager() {
|
||||
return PLUGIN_MANAGER;
|
||||
}
|
||||
|
||||
public static SaveManager getSaveManager() {
|
||||
return SAVE_MANAGER;
|
||||
}
|
||||
|
||||
public static PluginManager getPluginManager() {
|
||||
return PLUGIN_MANAGER;
|
||||
public static ViaProxyConfig getConfig() {
|
||||
return CONFIG;
|
||||
}
|
||||
|
||||
public static ChannelGroup getConnectedClients() {
|
||||
@ -252,8 +281,12 @@ public class ViaProxy {
|
||||
return currentProxyServer;
|
||||
}
|
||||
|
||||
public static ViaProxyUI getUI() {
|
||||
return ui;
|
||||
public static ViaProxyWindow getViaProxyWindow() {
|
||||
return viaProxyWindow;
|
||||
}
|
||||
|
||||
public static JFrame getForegroundWindow() {
|
||||
return foregroundWindow;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import joptsimple.OptionDescriptor;
|
||||
import joptsimple.internal.Classes;
|
||||
import joptsimple.internal.Strings;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public class BetterHelpFormatter extends BuiltinHelpFormatter {
|
||||
|
||||
public BetterHelpFormatter() {
|
||||
|
@ -25,6 +25,7 @@ import joptsimple.OptionSpec;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.plugins.events.PostOptionsParseEvent;
|
||||
import net.raphimc.viaproxy.plugins.events.PreOptionsParseEvent;
|
||||
import net.raphimc.viaproxy.protocoltranslator.viaproxy.ViaProxyConfig;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.Account;
|
||||
import net.raphimc.viaproxy.util.AddressUtil;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
@ -37,33 +38,37 @@ import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public class Options {
|
||||
|
||||
public static SocketAddress BIND_ADDRESS;
|
||||
public static SocketAddress CONNECT_ADDRESS;
|
||||
public static ProtocolVersion PROTOCOL_VERSION;
|
||||
public static boolean ONLINE_MODE;
|
||||
public static boolean OPENAUTHMOD_AUTH;
|
||||
public static boolean BETACRAFT_AUTH;
|
||||
public static Account MC_ACCOUNT;
|
||||
public static URI PROXY_URL; // Example: type://address:port or type://username:password@address:port
|
||||
public static URI PROXY_URL;
|
||||
public static boolean IGNORE_PACKET_TRANSLATION_ERRORS;
|
||||
public static boolean ALLOW_BETA_PINGING;
|
||||
|
||||
// GUI only config options
|
||||
public static String CLASSIC_MP_PASS;
|
||||
public static Boolean LEGACY_SKIN_LOADING;
|
||||
public static boolean CHAT_SIGNING;
|
||||
|
||||
// CLI only config options
|
||||
public static int COMPRESSION_THRESHOLD = 256;
|
||||
public static boolean SRV_MODE; // Example: lenni0451.net_25565_1.8.x.viaproxy.127.0.0.1.nip.io
|
||||
public static boolean INTERNAL_SRV_MODE; // Example: ip:port\7version\7mppass
|
||||
public static String RESOURCE_PACK_URL; // Example: http://example.com/resourcepack.zip
|
||||
public static boolean SRV_MODE;
|
||||
public static String RESOURCE_PACK_URL;
|
||||
public static boolean SERVER_HAPROXY_PROTOCOL;
|
||||
public static boolean LEGACY_CLIENT_PASSTHROUGH;
|
||||
|
||||
public static void parse(final String[] args) throws IOException {
|
||||
Logger.LOGGER.fatal("===============================================================================================================");
|
||||
Logger.LOGGER.fatal("ViaProxy CLI is deprecated and will be removed in the future. Please use the config file instead. See the ViaProxy README on GitHub for more information.");
|
||||
Logger.LOGGER.fatal("Waiting 10 seconds before continuing...");
|
||||
Logger.LOGGER.fatal("===============================================================================================================");
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
final OptionParser parser = new OptionParser();
|
||||
final OptionSpec<Void> help = parser.acceptsAll(asList("help", "h", "?"), "Get a list of all arguments").forHelp();
|
||||
|
||||
@ -71,7 +76,6 @@ public class Options {
|
||||
final OptionSpec<String> connectAddress = parser.acceptsAll(asList("connect_address", "target_ip", "ca", "a"), "The address of the target server").withRequiredArg().ofType(String.class).required();
|
||||
final OptionSpec<ProtocolVersion> version = parser.acceptsAll(asList("version", "v"), "The version of the target server").withRequiredArg().withValuesConvertedBy(new ProtocolVersionConverter()).required();
|
||||
final OptionSpec<Void> srvMode = parser.acceptsAll(asList("srv_mode", "srv", "s"), "Enable srv mode");
|
||||
final OptionSpec<Void> iSrvMode = parser.acceptsAll(asList("internal_srv_mode", "isrv"), "Enable internal srv mode").availableUnless(srvMode);
|
||||
final OptionSpec<Void> proxyOnlineMode = parser.acceptsAll(asList("online_mode", "om", "o"), "Enable proxy online mode");
|
||||
final OptionSpec<Integer> compressionThreshold = parser.acceptsAll(asList("compression_threshold", "ct", "c"), "The threshold for packet compression").withRequiredArg().ofType(Integer.class).defaultsTo(COMPRESSION_THRESHOLD);
|
||||
final OptionSpec<Void> openAuthModAuth = parser.acceptsAll(asList("openauthmod_auth", "oam_auth"), "Use OpenAuthMod for joining online mode servers");
|
||||
@ -99,10 +103,8 @@ public class Options {
|
||||
BIND_ADDRESS = AddressUtil.parse(options.valueOf(bindAddress), null);
|
||||
CONNECT_ADDRESS = AddressUtil.parse(options.valueOf(connectAddress), PROTOCOL_VERSION);
|
||||
SRV_MODE = options.has(srvMode);
|
||||
INTERNAL_SRV_MODE = options.has(iSrvMode);
|
||||
ONLINE_MODE = options.has(proxyOnlineMode);
|
||||
COMPRESSION_THRESHOLD = options.valueOf(compressionThreshold);
|
||||
OPENAUTHMOD_AUTH = options.has(openAuthModAuth);
|
||||
if (options.has(guiAccountIndex)) {
|
||||
final List<Account> accounts = ViaProxy.getSaveManager().accountsSave.getAccounts();
|
||||
final int index = options.valueOf(guiAccountIndex);
|
||||
@ -141,6 +143,7 @@ public class Options {
|
||||
IGNORE_PACKET_TRANSLATION_ERRORS = options.has(ignorePacketTranslationErrors);
|
||||
ALLOW_BETA_PINGING = options.has(allowBetaPinging);
|
||||
ViaProxy.EVENT_MANAGER.call(new PostOptionsParseEvent(options));
|
||||
putToConfig(ViaProxy.getConfig());
|
||||
} catch (OptionException e) {
|
||||
Logger.LOGGER.error("Error parsing options: " + e.getMessage());
|
||||
parser.formatHelpWith(new BetterHelpFormatter());
|
||||
@ -149,4 +152,40 @@ public class Options {
|
||||
}
|
||||
}
|
||||
|
||||
public static void putToConfig(final ViaProxyConfig config) {
|
||||
config.setBindAddress(BIND_ADDRESS);
|
||||
config.setTargetAddress(CONNECT_ADDRESS);
|
||||
config.setTargetVersion(PROTOCOL_VERSION);
|
||||
config.setProxyOnlineMode(ONLINE_MODE);
|
||||
config.setBetacraftAuth(BETACRAFT_AUTH);
|
||||
config.setAccount(MC_ACCOUNT);
|
||||
config.setBackendProxyUrl(PROXY_URL);
|
||||
config.setBackendHaProxy(SERVER_HAPROXY_PROTOCOL);
|
||||
config.setChatSigning(CHAT_SIGNING);
|
||||
config.setCompressionThreshold(COMPRESSION_THRESHOLD);
|
||||
config.setResourcePackUrl(RESOURCE_PACK_URL);
|
||||
config.setSrvMode(SRV_MODE);
|
||||
config.setAllowBetaPinging(ALLOW_BETA_PINGING);
|
||||
config.setIgnoreProtocolTranslationErrors(IGNORE_PACKET_TRANSLATION_ERRORS);
|
||||
config.setAllowLegacyClientPassthrough(LEGACY_CLIENT_PASSTHROUGH);
|
||||
}
|
||||
|
||||
public static void loadFromConfig(final ViaProxyConfig config) {
|
||||
BIND_ADDRESS = config.getBindAddress();
|
||||
CONNECT_ADDRESS = config.getTargetAddress();
|
||||
PROTOCOL_VERSION = config.getTargetVersion();
|
||||
ONLINE_MODE = config.isProxyOnlineMode();
|
||||
BETACRAFT_AUTH = config.useBetacraftAuth();
|
||||
MC_ACCOUNT = config.getAccount();
|
||||
PROXY_URL = config.getBackendProxyUrl();
|
||||
SERVER_HAPROXY_PROTOCOL = config.useBackendHaProxy();
|
||||
CHAT_SIGNING = config.shouldSignChat();
|
||||
COMPRESSION_THRESHOLD = config.getCompressionThreshold();
|
||||
ALLOW_BETA_PINGING = config.shouldAllowBetaPinging();
|
||||
IGNORE_PACKET_TRANSLATION_ERRORS = config.shouldIgnoreProtocolTranslationErrors();
|
||||
LEGACY_CLIENT_PASSTHROUGH = config.shouldAllowLegacyClientPassthrough();
|
||||
RESOURCE_PACK_URL = config.getResourcePackUrl();
|
||||
SRV_MODE = config.isSrvMode();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import joptsimple.ValueConversionException;
|
||||
import joptsimple.ValueConverter;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public class ProtocolVersionConverter implements ValueConverter<ProtocolVersion> {
|
||||
|
||||
@Override
|
||||
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2024 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.injection.mixins;
|
||||
|
||||
import com.viaversion.viaversion.util.Config;
|
||||
import net.raphimc.viaproxy.protocoltranslator.ConfigPatcher;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(Config.class)
|
||||
public abstract class MixinConfig {
|
||||
|
||||
@Redirect(method = "loadConfig(Ljava/io/File;Lcom/viaversion/viaversion/util/InputStreamSupplier;)Ljava/util/Map;", at = @At(value = "INVOKE", target = "Ljava/util/Map;containsKey(Ljava/lang/Object;)Z"))
|
||||
private boolean allowConfigPatching(final Map<String, Object> map, final Object key) {
|
||||
if (((Object) this) instanceof ConfigPatcher) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return map.containsKey(key);
|
||||
}
|
||||
|
||||
}
|
@ -18,7 +18,7 @@
|
||||
package net.raphimc.viaproxy.injection.mixins;
|
||||
|
||||
import net.raphimc.vialegacy.ViaLegacyConfig;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
@ -29,15 +29,15 @@ public abstract class MixinViaLegacyConfig {
|
||||
|
||||
@Inject(method = "isLegacySkinLoading", at = @At("HEAD"), cancellable = true)
|
||||
private void makeGUIConfigurable1(final CallbackInfoReturnable<Boolean> cir) {
|
||||
if (Options.LEGACY_SKIN_LOADING != null) {
|
||||
cir.setReturnValue(Options.LEGACY_SKIN_LOADING);
|
||||
if (ViaProxy.getViaProxyWindow() != null) {
|
||||
cir.setReturnValue(ViaProxy.getViaProxyWindow().advancedTab.legacySkinLoading.isSelected());
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "isLegacySkullLoading", at = @At("HEAD"), cancellable = true)
|
||||
private void makeGUIConfigurable2(final CallbackInfoReturnable<Boolean> cir) {
|
||||
if (Options.LEGACY_SKIN_LOADING != null) {
|
||||
cir.setReturnValue(Options.LEGACY_SKIN_LOADING);
|
||||
if (ViaProxy.getViaProxyWindow() != null) {
|
||||
cir.setReturnValue(ViaProxy.getViaProxyWindow().advancedTab.legacySkinLoading.isSelected());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import joptsimple.OptionSet;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public class PostOptionsParseEvent {
|
||||
|
||||
private final OptionSet options;
|
||||
|
@ -19,6 +19,7 @@ package net.raphimc.viaproxy.plugins.events;
|
||||
|
||||
import joptsimple.OptionParser;
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public class PreOptionsParseEvent {
|
||||
|
||||
private final OptionParser parser;
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2024 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.protocoltranslator;
|
||||
|
||||
import com.viaversion.viaversion.util.Config;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConfigPatcher extends Config {
|
||||
|
||||
private final Map<String, Object> patches;
|
||||
|
||||
public ConfigPatcher(final File configFile, final Map<String, Object> patches) {
|
||||
super(configFile);
|
||||
|
||||
this.patches = patches;
|
||||
this.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getDefaultConfigURL() {
|
||||
return ConfigPatcher.class.getClassLoader().getResource("assets/viaproxy/dummy.yml");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleConfig(Map<String, Object> config) {
|
||||
for (final Map.Entry<String, Object> entry : this.patches.entrySet()) {
|
||||
if (!config.containsKey(entry.getKey())) {
|
||||
config.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUnsupportedOptions() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
}
|
@ -31,9 +31,10 @@ import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyViaLegacyPlatformImp
|
||||
import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyViaVersionPlatformImpl;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.FileAlreadyExistsException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ProtocolTranslator {
|
||||
@ -67,25 +68,41 @@ public class ProtocolTranslator {
|
||||
|
||||
private static void patchConfigs() {
|
||||
final File configFolder = new File("ViaLoader");
|
||||
configFolder.mkdirs();
|
||||
|
||||
final File viaVersionConfig = new File(configFolder, "viaversion.yml");
|
||||
final Map<String, Object> viaVersionPatches = new HashMap<>();
|
||||
viaVersionPatches.put("1_13-tab-complete-delay", 5);
|
||||
viaVersionPatches.put("no-delay-shield-blocking", true);
|
||||
viaVersionPatches.put("chunk-border-fix", true);
|
||||
new ConfigPatcher(viaVersionConfig, viaVersionPatches);
|
||||
try {
|
||||
final File viaVersionConfig = new File(configFolder, "viaversion.yml");
|
||||
Files.writeString(viaVersionConfig.toPath(), """
|
||||
1_13-tab-complete-delay: 5
|
||||
no-delay-shield-blocking: true
|
||||
chunk-border-fix: true
|
||||
""", StandardOpenOption.CREATE_NEW);
|
||||
} catch (FileAlreadyExistsException ignored) {
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Failed to patch ViaVersion config", e);
|
||||
}
|
||||
|
||||
final File viaBackwardsConfig = new File(configFolder, "viabackwards.yml");
|
||||
final Map<String, Object> viaBackwardsPatches = new HashMap<>();
|
||||
viaBackwardsPatches.put("fix-1_13-face-player", true);
|
||||
viaBackwardsPatches.put("handle-pings-as-inv-acknowledgements", true);
|
||||
new ConfigPatcher(viaBackwardsConfig, viaBackwardsPatches);
|
||||
try {
|
||||
final File viaBackwardsConfig = new File(configFolder, "viabackwards.yml");
|
||||
Files.writeString(viaBackwardsConfig.toPath(), """
|
||||
fix-1_13-face-player: 5
|
||||
handle-pings-as-inv-acknowledgements: true
|
||||
""", StandardOpenOption.CREATE_NEW);
|
||||
} catch (FileAlreadyExistsException ignored) {
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Failed to patch ViaBackwards config", e);
|
||||
}
|
||||
|
||||
final File viaRewindConfig = new File(configFolder, "viarewind.yml");
|
||||
final Map<String, Object> viaRewindPatches = new HashMap<>();
|
||||
viaRewindPatches.put("replace-adventure", true);
|
||||
viaRewindPatches.put("replace-particles", true);
|
||||
new ConfigPatcher(viaRewindConfig, viaRewindPatches);
|
||||
try {
|
||||
final File viaRewindConfig = new File(configFolder, "viarewind.yml");
|
||||
Files.writeString(viaRewindConfig.toPath(), """
|
||||
replace-adventure: true
|
||||
replace-particles: true
|
||||
""", StandardOpenOption.CREATE_NEW);
|
||||
} catch (FileAlreadyExistsException ignored) {
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Failed to patch ViaRewind config", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ package net.raphimc.viaproxy.protocoltranslator.impl;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import net.raphimc.vialoader.netty.ViaCodec;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
|
||||
public class ViaProxyViaCodec extends ViaCodec {
|
||||
@ -31,7 +31,7 @@ public class ViaProxyViaCodec extends ViaCodec {
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
if (Options.IGNORE_PACKET_TRANSLATION_ERRORS) {
|
||||
if (ViaProxy.getConfig().shouldIgnoreProtocolTranslationErrors()) {
|
||||
try {
|
||||
super.channelRead(ctx, msg);
|
||||
} catch (Throwable e) {
|
||||
|
@ -24,7 +24,7 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicMPPassProvider;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.providers.OldAuthProvider;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.HandshakeStorage;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
|
||||
import java.net.InetAddress;
|
||||
@ -39,7 +39,7 @@ public class ViaProxyClassicMPPassProvider extends ClassicMPPassProvider {
|
||||
final String mppass = ProxyConnection.fromUserConnection(user).getUserOptions().classicMpPass();
|
||||
if (mppass != null && !mppass.isEmpty() && !mppass.equals("0")) {
|
||||
return mppass;
|
||||
} else if (Options.BETACRAFT_AUTH) {
|
||||
} else if (ViaProxy.getConfig().useBetacraftAuth()) {
|
||||
final HandshakeStorage handshakeStorage = user.get(HandshakeStorage.class);
|
||||
return getBetacraftMpPass(user, user.getProtocolInfo().getUsername(), handshakeStorage.getHostname(), handshakeStorage.getPort());
|
||||
} else {
|
||||
|
@ -0,0 +1,314 @@
|
||||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2024 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.protocoltranslator.viaproxy;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.util.Config;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
import net.raphimc.viaproxy.protocoltranslator.ProtocolTranslator;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.Account;
|
||||
import net.raphimc.viaproxy.util.AddressUtil;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class ViaProxyConfig extends Config implements com.viaversion.viaversion.api.configuration.Config {
|
||||
|
||||
private SocketAddress bindAddress;
|
||||
private SocketAddress targetAddress;
|
||||
private ProtocolVersion targetVersion;
|
||||
private boolean proxyOnlineMode;
|
||||
private AuthMethod authMethod;
|
||||
private Account account;
|
||||
private boolean betacraftAuth;
|
||||
private URI backendProxyUrl;
|
||||
private boolean backendHaProxy;
|
||||
private boolean chatSigning;
|
||||
private int compressionThreshold;
|
||||
private boolean allowBetaPinging;
|
||||
private boolean ignoreProtocolTranslationErrors;
|
||||
private boolean allowLegacyClientPassthrough;
|
||||
private String resourcePackUrl;
|
||||
private boolean srvMode;
|
||||
|
||||
public ViaProxyConfig(final File configFile) {
|
||||
super(configFile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
super.reload();
|
||||
this.loadFields();
|
||||
}
|
||||
|
||||
private void loadFields() {
|
||||
this.bindAddress = AddressUtil.parse(this.getString("bind-address", "0.0.0.0:25568"), null);
|
||||
this.targetVersion = ProtocolVersion.getClosest(this.getString("target-version", ProtocolTranslator.AUTO_DETECT_PROTOCOL.getName()));
|
||||
if (this.targetVersion == null) {
|
||||
this.targetVersion = ProtocolTranslator.AUTO_DETECT_PROTOCOL;
|
||||
Logger.LOGGER.info("Invalid target version: " + this.getString("target-version", "") + ". Defaulting to auto detect.");
|
||||
Logger.LOGGER.info("=== Supported Protocol Versions ===");
|
||||
for (ProtocolVersion version : ProtocolVersion.getProtocols()) {
|
||||
Logger.LOGGER.info(version.getName());
|
||||
}
|
||||
Logger.LOGGER.info("===================================");
|
||||
}
|
||||
this.targetAddress = AddressUtil.parse(this.getString("target-address", "127.0.0.1:25565"), this.targetVersion);
|
||||
this.proxyOnlineMode = this.getBoolean("proxy-online-mode", false);
|
||||
this.authMethod = AuthMethod.byName(this.getString("auth-method", "none"));
|
||||
final List<Account> accounts = ViaProxy.getSaveManager().accountsSave.getAccounts();
|
||||
final int accountIndex = this.getInt("minecraft-account-index", 0);
|
||||
if (this.authMethod == AuthMethod.ACCOUNT && accountIndex >= 0 && accountIndex < accounts.size()) {
|
||||
this.account = accounts.get(accountIndex);
|
||||
} else {
|
||||
this.account = null;
|
||||
}
|
||||
this.betacraftAuth = this.getBoolean("betacraft-auth", false);
|
||||
final String proxyUrl = this.getString("backend-proxy-url", "");
|
||||
if (!proxyUrl.isBlank()) {
|
||||
try {
|
||||
this.backendProxyUrl = new URI(proxyUrl);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException("Invalid proxy url: " + proxyUrl + ". Proxy url format: type://address:port or type://username:password@address:port");
|
||||
}
|
||||
}
|
||||
this.backendHaProxy = this.getBoolean("backend-haproxy", false);
|
||||
this.chatSigning = this.getBoolean("chat-signing", true);
|
||||
this.compressionThreshold = this.getInt("compression-threshold", 256);
|
||||
this.allowBetaPinging = this.getBoolean("allow-beta-pinging", false);
|
||||
this.ignoreProtocolTranslationErrors = this.getBoolean("ignore-protocol-translation-errors", false);
|
||||
this.allowLegacyClientPassthrough = this.getBoolean("allow-legacy-client-passthrough", false);
|
||||
this.resourcePackUrl = this.getString("resource-pack-url", "");
|
||||
this.srvMode = this.getBoolean("srv-mode", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getDefaultConfigURL() {
|
||||
return this.getClass().getClassLoader().getResource("assets/viaproxy/viaproxy.yml");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleConfig(Map<String, Object> map) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getUnsupportedOptions() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(String path, Object value) {
|
||||
super.set(path, value);
|
||||
Options.loadFromConfig(this);
|
||||
}
|
||||
|
||||
public SocketAddress getBindAddress() {
|
||||
return this.bindAddress;
|
||||
}
|
||||
|
||||
public void setBindAddress(final SocketAddress bindAddress) {
|
||||
this.bindAddress = bindAddress;
|
||||
this.set("bind-address", AddressUtil.toString(bindAddress));
|
||||
}
|
||||
|
||||
public SocketAddress getTargetAddress() {
|
||||
return this.targetAddress;
|
||||
}
|
||||
|
||||
public void setTargetAddress(final SocketAddress targetAddress) {
|
||||
this.targetAddress = targetAddress;
|
||||
this.set("target-address", AddressUtil.toString(targetAddress));
|
||||
}
|
||||
|
||||
public ProtocolVersion getTargetVersion() {
|
||||
return this.targetVersion;
|
||||
}
|
||||
|
||||
public void setTargetVersion(final ProtocolVersion targetVersion) {
|
||||
this.targetVersion = targetVersion;
|
||||
this.set("target-version", targetVersion.getName());
|
||||
}
|
||||
|
||||
public boolean isProxyOnlineMode() {
|
||||
return this.proxyOnlineMode;
|
||||
}
|
||||
|
||||
public void setProxyOnlineMode(final boolean proxyOnlineMode) {
|
||||
this.proxyOnlineMode = proxyOnlineMode;
|
||||
this.set("proxy-online-mode", proxyOnlineMode);
|
||||
}
|
||||
|
||||
public AuthMethod getAuthMethod() {
|
||||
return this.authMethod;
|
||||
}
|
||||
|
||||
public void setAuthMethod(final AuthMethod authMethod) {
|
||||
this.authMethod = authMethod;
|
||||
this.set("auth-method", authMethod.name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
public Account getAccount() {
|
||||
return this.account;
|
||||
}
|
||||
|
||||
public void setAccount(final Account account) {
|
||||
this.account = account;
|
||||
this.set("minecraft-account-index", ViaProxy.getSaveManager().accountsSave.getAccounts().indexOf(account));
|
||||
}
|
||||
|
||||
public boolean useBetacraftAuth() {
|
||||
return this.betacraftAuth;
|
||||
}
|
||||
|
||||
public void setBetacraftAuth(final boolean betacraftAuth) {
|
||||
this.betacraftAuth = betacraftAuth;
|
||||
this.set("betacraft-auth", betacraftAuth);
|
||||
}
|
||||
|
||||
public URI getBackendProxyUrl() {
|
||||
return this.backendProxyUrl;
|
||||
}
|
||||
|
||||
public void setBackendProxyUrl(final URI backendProxyUrl) {
|
||||
this.backendProxyUrl = backendProxyUrl;
|
||||
if (backendProxyUrl != null) {
|
||||
this.set("backend-proxy-url", backendProxyUrl.toString());
|
||||
} else {
|
||||
this.set("backend-proxy-url", "");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean useBackendHaProxy() {
|
||||
return this.backendHaProxy;
|
||||
}
|
||||
|
||||
public void setBackendHaProxy(final boolean backendHaProxy) {
|
||||
this.backendHaProxy = backendHaProxy;
|
||||
this.set("backend-haproxy", backendHaProxy);
|
||||
}
|
||||
|
||||
public boolean shouldSignChat() {
|
||||
return this.chatSigning;
|
||||
}
|
||||
|
||||
public void setChatSigning(final boolean chatSigning) {
|
||||
this.chatSigning = chatSigning;
|
||||
this.set("chat-signing", chatSigning);
|
||||
}
|
||||
|
||||
public int getCompressionThreshold() {
|
||||
return this.compressionThreshold;
|
||||
}
|
||||
|
||||
public void setCompressionThreshold(final int compressionThreshold) {
|
||||
this.compressionThreshold = compressionThreshold;
|
||||
this.set("compression-threshold", compressionThreshold);
|
||||
}
|
||||
|
||||
public boolean shouldAllowBetaPinging() {
|
||||
return this.allowBetaPinging;
|
||||
}
|
||||
|
||||
public void setAllowBetaPinging(final boolean allowBetaPinging) {
|
||||
this.allowBetaPinging = allowBetaPinging;
|
||||
this.set("allow-beta-pinging", allowBetaPinging);
|
||||
}
|
||||
|
||||
public boolean shouldIgnoreProtocolTranslationErrors() {
|
||||
return this.ignoreProtocolTranslationErrors;
|
||||
}
|
||||
|
||||
public void setIgnoreProtocolTranslationErrors(final boolean ignoreProtocolTranslationErrors) {
|
||||
this.ignoreProtocolTranslationErrors = ignoreProtocolTranslationErrors;
|
||||
this.set("ignore-protocol-translation-errors", ignoreProtocolTranslationErrors);
|
||||
}
|
||||
|
||||
public boolean shouldAllowLegacyClientPassthrough() {
|
||||
return this.allowLegacyClientPassthrough;
|
||||
}
|
||||
|
||||
public void setAllowLegacyClientPassthrough(final boolean allowLegacyClientPassthrough) {
|
||||
this.allowLegacyClientPassthrough = allowLegacyClientPassthrough;
|
||||
this.set("allow-legacy-client-passthrough", allowLegacyClientPassthrough);
|
||||
}
|
||||
|
||||
public String getResourcePackUrl() {
|
||||
return this.resourcePackUrl;
|
||||
}
|
||||
|
||||
public void setResourcePackUrl(final String resourcePackUrl) {
|
||||
this.resourcePackUrl = resourcePackUrl;
|
||||
this.set("resource-pack-url", resourcePackUrl);
|
||||
}
|
||||
|
||||
public boolean isSrvMode() {
|
||||
return this.srvMode;
|
||||
}
|
||||
|
||||
public void setSrvMode(final boolean srvMode) {
|
||||
this.srvMode = srvMode;
|
||||
this.set("srv-mode", srvMode);
|
||||
}
|
||||
|
||||
public enum AuthMethod {
|
||||
|
||||
/**
|
||||
* Use an account for joining the target server (Has to be configured in ViaProxy GUI)
|
||||
*/
|
||||
ACCOUNT("tab.general.minecraft_account.option_select_account"),
|
||||
/**
|
||||
* No authentication (Offline mode)
|
||||
*/
|
||||
NONE("tab.general.minecraft_account.option_no_account"),
|
||||
/**
|
||||
* Requires the OpenAuthMod client mod (https://modrinth.com/mod/openauthmod)
|
||||
*/
|
||||
OPENAUTHMOD("tab.general.minecraft_account.option_openauthmod");
|
||||
|
||||
private final String guiTranslationKey;
|
||||
|
||||
AuthMethod(String guiTranslationKey) {
|
||||
this.guiTranslationKey = guiTranslationKey;
|
||||
}
|
||||
|
||||
public static AuthMethod byName(String name) {
|
||||
for (AuthMethod mode : values()) {
|
||||
if (mode.name().equalsIgnoreCase(name)) {
|
||||
return mode;
|
||||
}
|
||||
}
|
||||
|
||||
return NONE;
|
||||
}
|
||||
|
||||
public String getGuiTranslationKey() {
|
||||
return this.guiTranslationKey;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -23,7 +23,6 @@ import net.raphimc.netminecraft.constants.MCPipeline;
|
||||
import net.raphimc.netminecraft.netty.connection.MinecraftChannelInitializer;
|
||||
import net.raphimc.netminecraft.packet.registry.PacketRegistryUtil;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
import net.raphimc.viaproxy.plugins.events.Client2ProxyChannelInitializeEvent;
|
||||
import net.raphimc.viaproxy.plugins.events.types.ITyped;
|
||||
import net.raphimc.viaproxy.proxy.client2proxy.passthrough.LegacyPassthroughInitialHandler;
|
||||
@ -45,7 +44,7 @@ public class Client2ProxyChannelInitializer extends MinecraftChannelInitializer
|
||||
return;
|
||||
}
|
||||
|
||||
if (Options.LEGACY_CLIENT_PASSTHROUGH) {
|
||||
if (ViaProxy.getConfig().shouldAllowLegacyClientPassthrough()) {
|
||||
channel.pipeline().addLast(LEGACY_PASSTHROUGH_INITIAL_HANDLER_NAME, new LegacyPassthroughInitialHandler());
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,6 @@ import net.raphimc.netminecraft.packet.impl.handshake.C2SHandshakePacket;
|
||||
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
|
||||
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
import net.raphimc.viaproxy.plugins.events.ConnectEvent;
|
||||
import net.raphimc.viaproxy.plugins.events.PreConnectEvent;
|
||||
import net.raphimc.viaproxy.plugins.events.Proxy2ServerHandlerCreationEvent;
|
||||
@ -44,6 +43,7 @@ import net.raphimc.viaproxy.proxy.session.DummyProxyConnection;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
import net.raphimc.viaproxy.proxy.session.UserOptions;
|
||||
import net.raphimc.viaproxy.proxy.util.*;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.ClassicAccount;
|
||||
import net.raphimc.viaproxy.util.AddressUtil;
|
||||
import net.raphimc.viaproxy.util.ArrayHelper;
|
||||
import net.raphimc.viaproxy.util.ProtocolVersionDetector;
|
||||
@ -121,20 +121,11 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
|
||||
|
||||
final String[] handshakeParts = packet.address.split("\0");
|
||||
|
||||
SocketAddress serverAddress = Options.CONNECT_ADDRESS;
|
||||
ProtocolVersion serverVersion = Options.PROTOCOL_VERSION;
|
||||
String classicMpPass = Options.CLASSIC_MP_PASS;
|
||||
SocketAddress serverAddress = ViaProxy.getConfig().getTargetAddress();
|
||||
ProtocolVersion serverVersion = ViaProxy.getConfig().getTargetVersion();
|
||||
String classicMpPass = ViaProxy.getConfig().getAccount() instanceof ClassicAccount classicAccount ? classicAccount.getMppass() : null;
|
||||
|
||||
if (Options.INTERNAL_SRV_MODE) {
|
||||
final ArrayHelper arrayHelper = ArrayHelper.instanceOf(handshakeParts[0].split("\7"));
|
||||
final String versionString = arrayHelper.get(1);
|
||||
serverVersion = ProtocolVersion.getClosest(versionString);
|
||||
if (serverVersion == null) throw CloseAndReturn.INSTANCE;
|
||||
serverAddress = AddressUtil.parse(arrayHelper.get(0), serverVersion);
|
||||
if (arrayHelper.isIndexValid(2)) {
|
||||
classicMpPass = arrayHelper.getString(2);
|
||||
}
|
||||
} else if (Options.SRV_MODE) {
|
||||
if (ViaProxy.getConfig().isSrvMode()) {
|
||||
try {
|
||||
if (handshakeParts[0].toLowerCase().contains(".viaproxy.")) {
|
||||
handshakeParts[0] = handshakeParts[0].substring(0, handshakeParts[0].toLowerCase().lastIndexOf(".viaproxy."));
|
||||
@ -159,7 +150,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
|
||||
}
|
||||
}
|
||||
|
||||
if (packet.intendedState.getConnectionState() == ConnectionState.STATUS && !Options.ALLOW_BETA_PINGING && serverVersion.olderThanOrEqualTo(LegacyProtocolVersion.b1_7tob1_7_3)) {
|
||||
if (packet.intendedState.getConnectionState() == ConnectionState.STATUS && !ViaProxy.getConfig().shouldAllowBetaPinging() && serverVersion.olderThanOrEqualTo(LegacyProtocolVersion.b1_7tob1_7_3)) {
|
||||
this.proxyConnection.kickClient("§7ViaProxy is working!\n§7Connect to join the configured server");
|
||||
}
|
||||
|
||||
@ -174,7 +165,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
|
||||
serverAddress = preConnectEvent.getServerAddress();
|
||||
serverVersion = preConnectEvent.getServerVersion();
|
||||
|
||||
final UserOptions userOptions = new UserOptions(classicMpPass, Options.MC_ACCOUNT);
|
||||
final UserOptions userOptions = new UserOptions(classicMpPass, ViaProxy.getConfig().getAccount());
|
||||
ChannelUtil.disableAutoRead(this.proxyConnection.getC2P());
|
||||
|
||||
if (packet.intendedState.getConnectionState() == ConnectionState.LOGIN && serverVersion.equals(ProtocolTranslator.AUTO_DETECT_PROTOCOL)) {
|
||||
@ -233,7 +224,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
|
||||
this.proxyConnection.connectToServer(serverAddress, serverVersion).addListeners((ThrowingChannelFutureListener) f -> {
|
||||
if (f.isSuccess()) {
|
||||
f.channel().eventLoop().submit(() -> { // Reschedule so the packets get sent after the channel is fully initialized and active
|
||||
if (Options.SERVER_HAPROXY_PROTOCOL) {
|
||||
if (ViaProxy.getConfig().useBackendHaProxy()) {
|
||||
this.proxyConnection.getChannel().writeAndFlush(HAProxyUtil.createMessage(this.proxyConnection.getC2P(), this.proxyConnection.getChannel(), clientVersion)).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,6 @@ package net.raphimc.viaproxy.proxy.client2proxy.passthrough;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.*;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
import net.raphimc.viaproxy.plugins.events.Proxy2ServerHandlerCreationEvent;
|
||||
import net.raphimc.viaproxy.plugins.events.ProxySessionCreationEvent;
|
||||
import net.raphimc.viaproxy.proxy.proxy2server.passthrough.PassthroughProxy2ServerChannelInitializer;
|
||||
@ -86,7 +85,7 @@ public class PassthroughClient2ProxyHandler extends SimpleChannelInboundHandler<
|
||||
this.proxyConnection.connect(serverAddress).addListeners((ThrowingChannelFutureListener) f -> {
|
||||
if (f.isSuccess()) {
|
||||
f.channel().eventLoop().submit(() -> { // Reschedule so the packets get sent after the channel is fully initialized and active
|
||||
if (Options.SERVER_HAPROXY_PROTOCOL) {
|
||||
if (ViaProxy.getConfig().useBackendHaProxy()) {
|
||||
this.proxyConnection.getChannel().writeAndFlush(HAProxyUtil.createMessage(this.proxyConnection.getC2P(), this.proxyConnection.getChannel(), null)).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
|
||||
}
|
||||
|
||||
@ -103,7 +102,7 @@ public class PassthroughClient2ProxyHandler extends SimpleChannelInboundHandler<
|
||||
}
|
||||
|
||||
protected SocketAddress getServerAddress() {
|
||||
return Options.CONNECT_ADDRESS;
|
||||
return ViaProxy.getConfig().getTargetAddress();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ import net.raphimc.netminecraft.packet.impl.login.C2SLoginKeyPacket1_19;
|
||||
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
|
||||
import net.raphimc.viabedrock.protocol.storage.AuthChainData;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
import net.raphimc.viaproxy.plugins.events.FillPlayerDataEvent;
|
||||
import net.raphimc.viaproxy.protocoltranslator.viaproxy.ViaProxyConfig;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.Account;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.BedrockAccount;
|
||||
@ -65,7 +65,7 @@ public class ExternalInterface {
|
||||
proxyConnection.setGameProfile(account.getGameProfile());
|
||||
final UserConnection user = proxyConnection.getUserConnection();
|
||||
|
||||
if (Options.CHAT_SIGNING && proxyConnection.getServerVersion().newerThanOrEqualTo(ProtocolVersion.v1_19) && account instanceof MicrosoftAccount microsoftAccount) {
|
||||
if (ViaProxy.getConfig().shouldSignChat() && proxyConnection.getServerVersion().newerThanOrEqualTo(ProtocolVersion.v1_19) && account instanceof MicrosoftAccount microsoftAccount) {
|
||||
final StepPlayerCertificates.PlayerCertificates playerCertificates = microsoftAccount.getPlayerCertificates();
|
||||
final Instant expiresAt = Instant.ofEpochMilli(playerCertificates.getExpireTimeMs());
|
||||
final long expiresAtMillis = playerCertificates.getExpireTimeMs();
|
||||
@ -107,7 +107,7 @@ public class ExternalInterface {
|
||||
|
||||
public static void joinServer(final String serverIdHash, final ProxyConnection proxyConnection) throws InterruptedException, ExecutionException {
|
||||
Logger.u_info("auth", proxyConnection.getC2P().remoteAddress(), proxyConnection.getGameProfile(), "Trying to join online mode server");
|
||||
if (Options.OPENAUTHMOD_AUTH) {
|
||||
if (ViaProxy.getConfig().getAuthMethod() == ViaProxyConfig.AuthMethod.OPENAUTHMOD) {
|
||||
try {
|
||||
final ByteBuf response = proxyConnection.sendCustomPayload(OpenAuthModConstants.JOIN_CHANNEL, PacketTypes.writeString(Unpooled.buffer(), serverIdHash)).get(6, TimeUnit.SECONDS);
|
||||
if (response == null) throw new TimeoutException();
|
||||
@ -130,7 +130,7 @@ public class ExternalInterface {
|
||||
Logger.u_info("auth", proxyConnection.getC2P().remoteAddress(), proxyConnection.getGameProfile(), "Requesting nonce signature");
|
||||
final UserConnection user = proxyConnection.getUserConnection();
|
||||
|
||||
if (Options.OPENAUTHMOD_AUTH) {
|
||||
if (ViaProxy.getConfig().getAuthMethod() == ViaProxyConfig.AuthMethod.OPENAUTHMOD) {
|
||||
try {
|
||||
final ByteBuf response = proxyConnection.sendCustomPayload(OpenAuthModConstants.SIGN_NONCE_CHANNEL, PacketTypes.writeByteArray(Unpooled.buffer(), nonce)).get(5, TimeUnit.SECONDS);
|
||||
if (response == null) throw new TimeoutException();
|
||||
|
@ -29,7 +29,7 @@ import net.raphimc.netminecraft.packet.PacketTypes;
|
||||
import net.raphimc.netminecraft.packet.UnknownPacket;
|
||||
import net.raphimc.netminecraft.packet.impl.login.S2CLoginCompressionPacket;
|
||||
import net.raphimc.netminecraft.packet.impl.login.S2CLoginSuccessPacket1_7;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
import net.raphimc.viaproxy.proxy.util.ChannelUtil;
|
||||
|
||||
@ -58,11 +58,11 @@ public class CompressionPacketHandler extends PacketHandler {
|
||||
}
|
||||
} else if (packet instanceof S2CLoginSuccessPacket1_7) {
|
||||
if (this.proxyConnection.getClientVersion().newerThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
if (Options.COMPRESSION_THRESHOLD > -1 && this.proxyConnection.getC2P().attr(MCPipeline.COMPRESSION_THRESHOLD_ATTRIBUTE_KEY).get() == -1) {
|
||||
if (ViaProxy.getConfig().getCompressionThreshold() > -1 && this.proxyConnection.getC2P().attr(MCPipeline.COMPRESSION_THRESHOLD_ATTRIBUTE_KEY).get() == -1) {
|
||||
ChannelUtil.disableAutoRead(this.proxyConnection.getChannel());
|
||||
this.proxyConnection.getC2P().writeAndFlush(new S2CLoginCompressionPacket(Options.COMPRESSION_THRESHOLD)).addListeners(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE, (ChannelFutureListener) f -> {
|
||||
this.proxyConnection.getC2P().writeAndFlush(new S2CLoginCompressionPacket(ViaProxy.getConfig().getCompressionThreshold())).addListeners(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE, (ChannelFutureListener) f -> {
|
||||
if (f.isSuccess()) {
|
||||
this.proxyConnection.getC2P().attr(MCPipeline.COMPRESSION_THRESHOLD_ATTRIBUTE_KEY).set(Options.COMPRESSION_THRESHOLD);
|
||||
this.proxyConnection.getC2P().attr(MCPipeline.COMPRESSION_THRESHOLD_ATTRIBUTE_KEY).set(ViaProxy.getConfig().getCompressionThreshold());
|
||||
ChannelUtil.restoreAutoRead(this.proxyConnection.getChannel());
|
||||
}
|
||||
});
|
||||
|
@ -30,7 +30,6 @@ import net.raphimc.vialegacy.api.LegacyProtocolVersion;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ProtocolMetadataStorage;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.cli.ConsoleFormatter;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
import net.raphimc.viaproxy.plugins.events.ClientLoggedInEvent;
|
||||
import net.raphimc.viaproxy.plugins.events.ShouldVerifyOnlineModeEvent;
|
||||
import net.raphimc.viaproxy.proxy.LoginState;
|
||||
@ -85,7 +84,7 @@ public class LoginPacketHandler extends PacketHandler {
|
||||
proxyConnection.setGameProfile(new GameProfile(null, loginHelloPacket.name));
|
||||
}
|
||||
|
||||
if (Options.ONLINE_MODE && !ViaProxy.EVENT_MANAGER.call(new ShouldVerifyOnlineModeEvent(this.proxyConnection)).isCancelled()) {
|
||||
if (ViaProxy.getConfig().isProxyOnlineMode() && !ViaProxy.EVENT_MANAGER.call(new ShouldVerifyOnlineModeEvent(this.proxyConnection)).isCancelled()) {
|
||||
this.proxyConnection.getC2P().writeAndFlush(new S2CLoginKeyPacket1_8("", KEY_PAIR.getPublic().getEncoded(), this.verifyToken)).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
|
||||
} else {
|
||||
ViaProxy.EVENT_MANAGER.call(new ClientLoggedInEvent(proxyConnection));
|
||||
|
@ -28,7 +28,7 @@ import net.raphimc.netminecraft.constants.MCPackets;
|
||||
import net.raphimc.netminecraft.packet.IPacket;
|
||||
import net.raphimc.netminecraft.packet.PacketTypes;
|
||||
import net.raphimc.netminecraft.packet.UnknownPacket;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -61,12 +61,12 @@ public class ResourcePackPacketHandler extends PacketHandler {
|
||||
}
|
||||
|
||||
private void sendResourcePack() {
|
||||
if (Options.RESOURCE_PACK_URL != null) {
|
||||
if (!ViaProxy.getConfig().getResourcePackUrl().isBlank()) {
|
||||
this.proxyConnection.getChannel().eventLoop().schedule(() -> {
|
||||
if (this.proxyConnection.getClientVersion().newerThanOrEqualTo(ProtocolVersion.v1_8)) {
|
||||
final ByteBuf resourcePackPacket = Unpooled.buffer();
|
||||
PacketTypes.writeVarInt(resourcePackPacket, MCPackets.S2C_RESOURCE_PACK.getId(this.proxyConnection.getClientVersion().getVersion()));
|
||||
PacketTypes.writeString(resourcePackPacket, Options.RESOURCE_PACK_URL); // url
|
||||
PacketTypes.writeString(resourcePackPacket, ViaProxy.getConfig().getResourcePackUrl()); // url
|
||||
PacketTypes.writeString(resourcePackPacket, ""); // hash
|
||||
if (this.proxyConnection.getClientVersion().newerThanOrEqualTo(ProtocolVersion.v1_17)) {
|
||||
resourcePackPacket.writeBoolean(Via.getConfig().isForcedUse1_17ResourcePack()); // required
|
||||
@ -80,7 +80,7 @@ public class ResourcePackPacketHandler extends PacketHandler {
|
||||
}
|
||||
this.proxyConnection.getC2P().writeAndFlush(resourcePackPacket).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
|
||||
} else if (this.proxyConnection.getClientVersion().newerThanOrEqualTo(ProtocolVersion.v1_7_2)) {
|
||||
final byte[] data = Options.RESOURCE_PACK_URL.getBytes(StandardCharsets.UTF_8);
|
||||
final byte[] data = ViaProxy.getConfig().getResourcePackUrl().getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
final ByteBuf customPayloadPacket = Unpooled.buffer();
|
||||
PacketTypes.writeVarInt(customPayloadPacket, MCPackets.S2C_PLUGIN_MESSAGE.getId(this.proxyConnection.getClientVersion().getVersion()));
|
||||
|
@ -34,7 +34,6 @@ import net.raphimc.netminecraft.packet.registry.PacketRegistryUtil;
|
||||
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
|
||||
import net.raphimc.vialoader.netty.VLPipeline;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
import net.raphimc.viaproxy.plugins.events.Proxy2ServerChannelInitializeEvent;
|
||||
import net.raphimc.viaproxy.plugins.events.types.ITyped;
|
||||
import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyVLPipeline;
|
||||
@ -67,10 +66,10 @@ public class Proxy2ServerChannelInitializer extends MinecraftChannelInitializer
|
||||
new ProtocolPipelineImpl(user);
|
||||
proxyConnection.setUserConnection(user);
|
||||
|
||||
if (Options.PROXY_URL != null && !proxyConnection.getServerVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
|
||||
if (ViaProxy.getConfig().getBackendProxyUrl() != null && !proxyConnection.getServerVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
|
||||
channel.pipeline().addLast(VIAPROXY_PROXY_HANDLER_NAME, this.getProxyHandler());
|
||||
}
|
||||
if (Options.SERVER_HAPROXY_PROTOCOL) {
|
||||
if (ViaProxy.getConfig().useBackendHaProxy()) {
|
||||
channel.pipeline().addLast(VIAPROXY_HAPROXY_ENCODER_NAME, HAProxyMessageEncoder.INSTANCE);
|
||||
}
|
||||
|
||||
@ -90,7 +89,7 @@ public class Proxy2ServerChannelInitializer extends MinecraftChannelInitializer
|
||||
}
|
||||
|
||||
protected ProxyHandler getProxyHandler() {
|
||||
final URI proxyUrl = Options.PROXY_URL;
|
||||
final URI proxyUrl = ViaProxy.getConfig().getBackendProxyUrl();
|
||||
final InetSocketAddress proxyAddress = new InetSocketAddress(proxyUrl.getHost(), proxyUrl.getPort());
|
||||
final String username = proxyUrl.getUserInfo() != null ? proxyUrl.getUserInfo().split(":")[0] : null;
|
||||
final String password = proxyUrl.getUserInfo() != null && proxyUrl.getUserInfo().contains(":") ? proxyUrl.getUserInfo().split(":")[1] : null;
|
||||
|
@ -22,7 +22,6 @@ import io.netty.channel.ChannelHandler;
|
||||
import io.netty.handler.codec.haproxy.HAProxyMessageEncoder;
|
||||
import net.raphimc.netminecraft.constants.MCPipeline;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
import net.raphimc.viaproxy.plugins.events.Proxy2ServerChannelInitializeEvent;
|
||||
import net.raphimc.viaproxy.plugins.events.types.ITyped;
|
||||
import net.raphimc.viaproxy.proxy.proxy2server.Proxy2ServerChannelInitializer;
|
||||
@ -42,10 +41,10 @@ public class PassthroughProxy2ServerChannelInitializer extends Proxy2ServerChann
|
||||
return;
|
||||
}
|
||||
|
||||
if (Options.PROXY_URL != null) {
|
||||
if (ViaProxy.getConfig().getBackendProxyUrl() != null) {
|
||||
channel.pipeline().addLast(VIAPROXY_PROXY_HANDLER_NAME, this.getProxyHandler());
|
||||
}
|
||||
if (Options.SERVER_HAPROXY_PROTOCOL) {
|
||||
if (ViaProxy.getConfig().useBackendHaProxy()) {
|
||||
channel.pipeline().addLast(VIAPROXY_HAPROXY_ENCODER_NAME, HAProxyMessageEncoder.INSTANCE);
|
||||
}
|
||||
|
||||
|
@ -61,8 +61,8 @@ public class ExceptionUtil {
|
||||
|
||||
public static String prettyPrint(Throwable t) {
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
if (t instanceof EncoderException) t = t.getCause();
|
||||
if (t instanceof DecoderException) t = t.getCause();
|
||||
if (t instanceof EncoderException && t.getCause() != null) t = t.getCause();
|
||||
if (t instanceof DecoderException && t.getCause() != null) t = t.getCause();
|
||||
while (t != null) {
|
||||
msg.append("\n");
|
||||
msg.append("§c").append(t.getClass().getSimpleName()).append("§7: §f").append(t.getMessage());
|
||||
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is part of ViaProxy - https://github.com/RaphiMC/ViaProxy
|
||||
* Copyright (C) 2021-2024 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.saves.impl.accounts;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class ClassicAccount extends OfflineAccount {
|
||||
|
||||
private final String mppass;
|
||||
|
||||
public ClassicAccount(JsonObject jsonObject) {
|
||||
super(jsonObject);
|
||||
this.mppass = jsonObject.get("mppass").getAsString();
|
||||
}
|
||||
|
||||
public ClassicAccount(final String name, final String mppass) {
|
||||
super(name);
|
||||
this.mppass = mppass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject toJson() {
|
||||
final JsonObject jsonObject = super.toJson();
|
||||
jsonObject.addProperty("mppass", this.mppass);
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
public String getMppass() {
|
||||
return this.mppass;
|
||||
}
|
||||
|
||||
}
|
@ -24,6 +24,7 @@ import com.google.gson.JsonParser;
|
||||
import com.vdurmont.semver4j.Semver;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.ui.I18n;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyWindow;
|
||||
import net.raphimc.viaproxy.ui.popups.DownloadPopup;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
|
||||
@ -45,6 +46,7 @@ public class UpdateCheckTask implements Runnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("UnreachableCode")
|
||||
public void run() {
|
||||
if (VERSION.startsWith("$")) return; // Dev env check
|
||||
try {
|
||||
@ -95,26 +97,26 @@ public class UpdateCheckTask implements Runnable {
|
||||
}
|
||||
|
||||
private void showUpdateWarning(final String latestVersion) {
|
||||
JOptionPane.showMessageDialog(ViaProxy.getUI(), I18n.get("popup.update.info", VERSION, latestVersion), "ViaProxy", JOptionPane.WARNING_MESSAGE);
|
||||
JOptionPane.showMessageDialog(ViaProxy.getForegroundWindow(), I18n.get("popup.update.info", VERSION, latestVersion), "ViaProxy", JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
|
||||
private void showUpdateQuestion(final String name, final String downloadUrl, final String latestVersion) {
|
||||
int chosen = JOptionPane.showConfirmDialog(ViaProxy.getUI(), I18n.get("popup.update.info", VERSION, latestVersion) + "\n\n" + I18n.get("popup.update.question"), "ViaProxy", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||
int chosen = JOptionPane.showConfirmDialog(ViaProxy.getForegroundWindow(), I18n.get("popup.update.info", VERSION, latestVersion) + "\n\n" + I18n.get("popup.update.question"), "ViaProxy", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||
if (chosen == JOptionPane.YES_OPTION) {
|
||||
File f = new File(name);
|
||||
new DownloadPopup(ViaProxy.getUI(), downloadUrl, f, () -> SwingUtilities.invokeLater(() -> {
|
||||
JOptionPane.showMessageDialog(ViaProxy.getUI(), I18n.get("popup.update.success"), "ViaProxy", JOptionPane.INFORMATION_MESSAGE);
|
||||
new DownloadPopup(ViaProxy.getForegroundWindow(), downloadUrl, f, () -> SwingUtilities.invokeLater(() -> {
|
||||
JOptionPane.showMessageDialog(ViaProxy.getForegroundWindow(), I18n.get("popup.update.success"), "ViaProxy", JOptionPane.INFORMATION_MESSAGE);
|
||||
try {
|
||||
Runtime.getRuntime().exec(new String[]{System.getProperty("java.home") + "/bin/java", "-jar", f.getAbsolutePath()});
|
||||
System.exit(0);
|
||||
} catch (IOException e) {
|
||||
Logger.LOGGER.error("Could not start the new ViaProxy jar", e);
|
||||
ViaProxy.getUI().showException(e);
|
||||
ViaProxyWindow.showException(e);
|
||||
}
|
||||
}), t -> {
|
||||
if (t != null) {
|
||||
Logger.LOGGER.error("Could not download the latest version of ViaProxy", t);
|
||||
ViaProxy.getUI().showException(t);
|
||||
ViaProxyWindow.showException(t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -19,14 +19,14 @@ package net.raphimc.viaproxy.ui;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public abstract class AUITab {
|
||||
public abstract class UITab {
|
||||
|
||||
protected final ViaProxyUI frame;
|
||||
protected final ViaProxyWindow viaProxyWindow;
|
||||
private final String name;
|
||||
protected final JPanel contentPane;
|
||||
|
||||
public AUITab(final ViaProxyUI frame, final String name) {
|
||||
this.frame = frame;
|
||||
public UITab(final ViaProxyWindow viaProxyWindow, final String name) {
|
||||
this.viaProxyWindow = viaProxyWindow;
|
||||
this.name = I18n.get("tab." + name + ".name");
|
||||
this.contentPane = new JPanel();
|
||||
|
@ -37,7 +37,7 @@ import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ViaProxyUI extends JFrame {
|
||||
public class ViaProxyWindow extends JFrame {
|
||||
|
||||
public final LambdaManager eventManager = LambdaManager.threadSafe(new LambdaMetaFactoryGenerator(JavaBypass.TRUSTED_LOOKUP));
|
||||
|
||||
@ -45,7 +45,7 @@ public class ViaProxyUI extends JFrame {
|
||||
public static final int BODY_BLOCK_PADDING = 10;
|
||||
|
||||
public final JTabbedPane contentPane = new JTabbedPane();
|
||||
private final List<AUITab> tabs = new ArrayList<>();
|
||||
private final List<UITab> tabs = new ArrayList<>();
|
||||
|
||||
public final GeneralTab generalTab = new GeneralTab(this);
|
||||
public final AdvancedTab advancedTab = new AdvancedTab(this);
|
||||
@ -55,8 +55,8 @@ public class ViaProxyUI extends JFrame {
|
||||
|
||||
private ImageIcon icon;
|
||||
|
||||
public ViaProxyUI() {
|
||||
Thread.setDefaultUncaughtExceptionHandler((t, e) -> this.showException(e));
|
||||
public ViaProxyWindow() {
|
||||
Thread.setDefaultUncaughtExceptionHandler((t, e) -> showException(e));
|
||||
this.eventManager.register(this);
|
||||
|
||||
this.setLookAndFeel();
|
||||
@ -94,7 +94,9 @@ public class ViaProxyUI extends JFrame {
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
ViaProxyUI.this.eventManager.call(new UICloseEvent());
|
||||
ViaProxyWindow.this.eventManager.call(new UICloseEvent());
|
||||
ViaProxy.getConfig().save();
|
||||
ViaProxy.getSaveManager().save();
|
||||
}
|
||||
});
|
||||
this.setSize(500, 360);
|
||||
@ -107,49 +109,49 @@ public class ViaProxyUI extends JFrame {
|
||||
RStream
|
||||
.of(this)
|
||||
.fields()
|
||||
.filter(field -> AUITab.class.isAssignableFrom(field.type()))
|
||||
.filter(field -> UITab.class.isAssignableFrom(field.type()))
|
||||
.forEach(field -> {
|
||||
final AUITab tab = field.get();
|
||||
final UITab tab = field.get();
|
||||
this.tabs.add(field.get());
|
||||
tab.add(this.contentPane);
|
||||
this.eventManager.register(tab);
|
||||
});
|
||||
this.contentPane.addChangeListener(e -> {
|
||||
int selectedIndex = contentPane.getSelectedIndex();
|
||||
if (selectedIndex >= 0 && selectedIndex < ViaProxyUI.this.tabs.size()) ViaProxyUI.this.tabs.get(selectedIndex).onTabOpened();
|
||||
if (selectedIndex >= 0 && selectedIndex < ViaProxyWindow.this.tabs.size()) ViaProxyWindow.this.tabs.get(selectedIndex).onTabOpened();
|
||||
});
|
||||
}
|
||||
|
||||
public void openURL(final String url) {
|
||||
public static void openURL(final String url) {
|
||||
try {
|
||||
Desktop.getDesktop().browse(new URI(url));
|
||||
} catch (Throwable t) {
|
||||
this.showInfo(I18n.get("generic.could_not_open_url", url));
|
||||
showInfo(I18n.get("generic.could_not_open_url", url));
|
||||
}
|
||||
}
|
||||
|
||||
public void showException(final Throwable t) {
|
||||
public static void showException(final Throwable t) {
|
||||
Logger.LOGGER.error("Caught exception in thread " + Thread.currentThread().getName(), t);
|
||||
StringBuilder builder = new StringBuilder("An error occurred:\n");
|
||||
builder.append("[").append(t.getClass().getSimpleName()).append("] ").append(t.getMessage()).append("\n");
|
||||
for (StackTraceElement element : t.getStackTrace()) builder.append(element.toString()).append("\n");
|
||||
this.showError(builder.toString());
|
||||
showError(builder.toString());
|
||||
}
|
||||
|
||||
public void showInfo(final String message) {
|
||||
this.showNotification(message, JOptionPane.INFORMATION_MESSAGE);
|
||||
public static void showInfo(final String message) {
|
||||
showNotification(message, JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
public void showWarning(final String message) {
|
||||
this.showNotification(message, JOptionPane.WARNING_MESSAGE);
|
||||
public static void showWarning(final String message) {
|
||||
showNotification(message, JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
|
||||
public void showError(final String message) {
|
||||
this.showNotification(message, JOptionPane.ERROR_MESSAGE);
|
||||
public static void showError(final String message) {
|
||||
showNotification(message, JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
public void showNotification(final String message, final int type) {
|
||||
JOptionPane.showMessageDialog(this, message, "ViaProxy", type);
|
||||
public static void showNotification(final String message, final int type) {
|
||||
JOptionPane.showMessageDialog(ViaProxy.getForegroundWindow(), message, "ViaProxy", type);
|
||||
}
|
||||
|
||||
}
|
@ -21,13 +21,12 @@ import net.lenni0451.commons.swing.GBC;
|
||||
import net.raphimc.minecraftauth.MinecraftAuth;
|
||||
import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.Account;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.BedrockAccount;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.MicrosoftAccount;
|
||||
import net.raphimc.viaproxy.ui.AUITab;
|
||||
import net.raphimc.viaproxy.ui.I18n;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyUI;
|
||||
import net.raphimc.viaproxy.ui.UITab;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyWindow;
|
||||
import net.raphimc.viaproxy.ui.popups.AddAccountPopup;
|
||||
import net.raphimc.viaproxy.util.TFunction;
|
||||
|
||||
@ -40,10 +39,10 @@ import java.awt.event.MouseEvent;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyUI.BODY_BLOCK_PADDING;
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyUI.BORDER_PADDING;
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyWindow.BODY_BLOCK_PADDING;
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyWindow.BORDER_PADDING;
|
||||
|
||||
public class AccountsTab extends AUITab {
|
||||
public class AccountsTab extends UITab {
|
||||
|
||||
private JList<Account> accountsList;
|
||||
private JButton addMicrosoftAccountButton;
|
||||
@ -52,7 +51,7 @@ public class AccountsTab extends AUITab {
|
||||
private AddAccountPopup addAccountPopup;
|
||||
private Thread addThread;
|
||||
|
||||
public AccountsTab(final ViaProxyUI frame) {
|
||||
public AccountsTab(final ViaProxyWindow frame) {
|
||||
super(frame, "accounts");
|
||||
}
|
||||
|
||||
@ -100,7 +99,7 @@ public class AccountsTab extends AUITab {
|
||||
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
DefaultListCellRenderer component = (DefaultListCellRenderer) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
Account account = (Account) value;
|
||||
if (Options.MC_ACCOUNT == account) {
|
||||
if (ViaProxy.getConfig().getAccount() == account) {
|
||||
component.setText("<html><span style=\"color:rgb(0, 180, 0)\"><b>" + account.getDisplayString() + "</b></span></html>");
|
||||
} else {
|
||||
component.setText(account.getDisplayString());
|
||||
@ -126,7 +125,7 @@ public class AccountsTab extends AUITab {
|
||||
Account removed = model.remove(index);
|
||||
ViaProxy.getSaveManager().accountsSave.removeAccount(removed);
|
||||
ViaProxy.getSaveManager().save();
|
||||
if (Options.MC_ACCOUNT == removed) {
|
||||
if (ViaProxy.getConfig().getAccount() == removed) {
|
||||
if (model.isEmpty()) this.markSelected(-1);
|
||||
else this.markSelected(0);
|
||||
}
|
||||
@ -162,7 +161,7 @@ public class AccountsTab extends AUITab {
|
||||
{
|
||||
JButton addOfflineAccountButton = new JButton(I18n.get("tab.accounts.add_offline.label"));
|
||||
addOfflineAccountButton.addActionListener(event -> {
|
||||
String username = JOptionPane.showInputDialog(this.frame, I18n.get("tab.accounts.add_offline.enter_username"), I18n.get("tab.accounts.add.title"), JOptionPane.PLAIN_MESSAGE);
|
||||
String username = JOptionPane.showInputDialog(this.viaProxyWindow, I18n.get("tab.accounts.add_offline.enter_username"), I18n.get("tab.accounts.add.title"), JOptionPane.PLAIN_MESSAGE);
|
||||
if (username != null && !username.trim().isEmpty()) {
|
||||
Account account = ViaProxy.getSaveManager().accountsSave.addAccount(username);
|
||||
ViaProxy.getSaveManager().save();
|
||||
@ -226,11 +225,11 @@ public class AccountsTab extends AUITab {
|
||||
|
||||
public void markSelected(final int index) {
|
||||
if (index < 0 || index >= this.accountsList.getModel().getSize()) {
|
||||
Options.MC_ACCOUNT = null;
|
||||
ViaProxy.getConfig().setAccount(null);
|
||||
return;
|
||||
}
|
||||
|
||||
Options.MC_ACCOUNT = ViaProxy.getSaveManager().accountsSave.getAccounts().get(index);
|
||||
ViaProxy.getConfig().setAccount(ViaProxy.getSaveManager().accountsSave.getAccounts().get(index));
|
||||
this.accountsList.repaint();
|
||||
}
|
||||
|
||||
@ -265,7 +264,7 @@ public class AccountsTab extends AUITab {
|
||||
private void handleLogin(final TFunction<Consumer<StepMsaDeviceCode.MsaDeviceCode>, Account> requestHandler) {
|
||||
this.addThread = new Thread(() -> {
|
||||
try {
|
||||
final Account account = requestHandler.apply(msaDeviceCode -> SwingUtilities.invokeLater(() -> new AddAccountPopup(this.frame, msaDeviceCode, popup -> this.addAccountPopup = popup, () -> {
|
||||
final Account account = requestHandler.apply(msaDeviceCode -> SwingUtilities.invokeLater(() -> new AddAccountPopup(this.viaProxyWindow, msaDeviceCode, popup -> this.addAccountPopup = popup, () -> {
|
||||
this.closePopup();
|
||||
this.addThread.interrupt();
|
||||
})));
|
||||
@ -274,18 +273,18 @@ public class AccountsTab extends AUITab {
|
||||
ViaProxy.getSaveManager().accountsSave.addAccount(account);
|
||||
ViaProxy.getSaveManager().save();
|
||||
this.addAccount(account);
|
||||
this.frame.showInfo(I18n.get("tab.accounts.add.success", account.getName()));
|
||||
ViaProxyWindow.showInfo(I18n.get("tab.accounts.add.success", account.getName()));
|
||||
});
|
||||
} catch (InterruptedException ignored) {
|
||||
} catch (TimeoutException e) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
this.closePopup();
|
||||
this.frame.showError(I18n.get("tab.accounts.add.timeout", "60"));
|
||||
ViaProxyWindow.showError(I18n.get("tab.accounts.add.timeout", "60"));
|
||||
});
|
||||
} catch (Throwable t) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
this.closePopup();
|
||||
this.frame.showException(t);
|
||||
ViaProxyWindow.showException(t);
|
||||
});
|
||||
}
|
||||
}, "Add Account Thread");
|
||||
|
@ -23,10 +23,9 @@ import gs.mclo.api.response.UploadLogResponse;
|
||||
import net.lenni0451.commons.swing.GBC;
|
||||
import net.lenni0451.lambdaevents.EventHandler;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.saves.impl.UISave;
|
||||
import net.raphimc.viaproxy.ui.AUITab;
|
||||
import net.raphimc.viaproxy.ui.I18n;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyUI;
|
||||
import net.raphimc.viaproxy.ui.UITab;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyWindow;
|
||||
import net.raphimc.viaproxy.ui.events.UICloseEvent;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@ -38,22 +37,22 @@ import java.awt.datatransfer.StringSelection;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyUI.BODY_BLOCK_PADDING;
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyUI.BORDER_PADDING;
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyWindow.BODY_BLOCK_PADDING;
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyWindow.BORDER_PADDING;
|
||||
|
||||
public class AdvancedTab extends AUITab {
|
||||
public class AdvancedTab extends UITab {
|
||||
|
||||
JSpinner bindPort;
|
||||
JTextField bindAddress;
|
||||
JTextField proxy;
|
||||
JCheckBox proxyOnlineMode;
|
||||
JCheckBox legacySkinLoading;
|
||||
public JCheckBox legacySkinLoading;
|
||||
JCheckBox chatSigning;
|
||||
JCheckBox ignorePacketTranslationErrors;
|
||||
JCheckBox allowBetaPinging;
|
||||
JButton viaVersionDumpButton;
|
||||
JButton uploadLogsButton;
|
||||
|
||||
public AdvancedTab(final ViaProxyUI frame) {
|
||||
public AdvancedTab(final ViaProxyWindow frame) {
|
||||
super(frame, "advanced");
|
||||
}
|
||||
|
||||
@ -71,14 +70,15 @@ public class AdvancedTab extends AUITab {
|
||||
|
||||
int gridy = 0;
|
||||
{
|
||||
JLabel bindPortLabel = new JLabel(I18n.get("tab.advanced.bind_port.label"));
|
||||
bindPortLabel.setToolTipText(I18n.get("tab.advanced.bind_port.tooltip"));
|
||||
JLabel bindPortLabel = new JLabel(I18n.get("tab.advanced.bind_address.label"));
|
||||
bindPortLabel.setToolTipText(I18n.get("tab.advanced.bind_address.tooltip"));
|
||||
GBC.create(body).grid(0, gridy++).insets(BORDER_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(bindPortLabel);
|
||||
|
||||
this.bindPort = new JSpinner(new SpinnerNumberModel(25568, 1, 65535, 1));
|
||||
this.bindPort.setToolTipText(I18n.get("tab.advanced.bind_port.tooltip"));
|
||||
ViaProxy.getSaveManager().uiSave.loadSpinner("bind_port", this.bindPort);
|
||||
GBC.create(body).grid(0, gridy++).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(this.bindPort);
|
||||
this.bindAddress = new JTextField();
|
||||
this.bindAddress.setToolTipText(I18n.get("tab.advanced.bind_address.tooltip"));
|
||||
this.bindAddress.setText("0.0.0.0:25568");
|
||||
ViaProxy.getSaveManager().uiSave.loadTextField("bind_address", this.bindAddress);
|
||||
GBC.create(body).grid(0, gridy++).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(this.bindAddress);
|
||||
}
|
||||
{
|
||||
JLabel proxyLabel = new JLabel(I18n.get("tab.advanced.proxy_url.label"));
|
||||
@ -93,7 +93,7 @@ public class AdvancedTab extends AUITab {
|
||||
{
|
||||
this.proxyOnlineMode = new JCheckBox(I18n.get("tab.advanced.proxy_online_mode.label"));
|
||||
this.proxyOnlineMode.setToolTipText(I18n.get("tab.advanced.proxy_online_mode.tooltip"));
|
||||
ViaProxy.getSaveManager().uiSave.loadCheckBox("proxy_online_mode", this.proxyOnlineMode);
|
||||
this.proxyOnlineMode.setSelected(ViaProxy.getConfig().isProxyOnlineMode());
|
||||
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(this.proxyOnlineMode);
|
||||
}
|
||||
{
|
||||
@ -105,22 +105,21 @@ public class AdvancedTab extends AUITab {
|
||||
{
|
||||
this.chatSigning = new JCheckBox(I18n.get("tab.advanced.chat_signing.label"));
|
||||
this.chatSigning.setToolTipText(I18n.get("tab.advanced.chat_signing.tooltip"));
|
||||
this.chatSigning.setSelected(true);
|
||||
ViaProxy.getSaveManager().uiSave.loadCheckBox("chat_signing", this.chatSigning);
|
||||
this.chatSigning.setSelected(ViaProxy.getConfig().shouldSignChat());
|
||||
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(this.chatSigning);
|
||||
}
|
||||
{
|
||||
this.ignorePacketTranslationErrors = new JCheckBox(I18n.get("tab.advanced.ignore_packet_translation_errors.label"));
|
||||
this.ignorePacketTranslationErrors.setToolTipText(I18n.get("tab.advanced.ignore_packet_translation_errors.tooltip"));
|
||||
this.ignorePacketTranslationErrors.setSelected(false);
|
||||
ViaProxy.getSaveManager().uiSave.loadCheckBox("ignore_packet_translation_errors", this.ignorePacketTranslationErrors);
|
||||
this.ignorePacketTranslationErrors.setSelected(ViaProxy.getConfig().shouldIgnoreProtocolTranslationErrors());
|
||||
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(this.ignorePacketTranslationErrors);
|
||||
}
|
||||
{
|
||||
this.allowBetaPinging = new JCheckBox(I18n.get("tab.advanced.allow_beta_pinging.label"));
|
||||
this.allowBetaPinging.setToolTipText(I18n.get("tab.advanced.allow_beta_pinging.tooltip"));
|
||||
this.allowBetaPinging.setSelected(false);
|
||||
ViaProxy.getSaveManager().uiSave.loadCheckBox("allow_beta_pinging", this.allowBetaPinging);
|
||||
this.allowBetaPinging.setSelected(ViaProxy.getConfig().shouldAllowBetaPinging());
|
||||
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(this.allowBetaPinging);
|
||||
}
|
||||
|
||||
@ -138,12 +137,12 @@ public class AdvancedTab extends AUITab {
|
||||
DumpUtil.postDump(null).whenComplete((url, e) -> {
|
||||
if (e != null) {
|
||||
Logger.LOGGER.error("Failed to create ViaVersion dump", e);
|
||||
SwingUtilities.invokeLater(() -> ViaProxy.getUI().showError(e.getMessage()));
|
||||
SwingUtilities.invokeLater(() -> ViaProxyWindow.showError(e.getMessage()));
|
||||
} else {
|
||||
ViaProxy.getUI().openURL(url);
|
||||
ViaProxyWindow.openURL(url);
|
||||
final StringSelection stringSelection = new StringSelection(url);
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, stringSelection);
|
||||
SwingUtilities.invokeLater(() -> ViaProxy.getUI().showInfo(I18n.get("tab.advanced.create_viaversion_dump.success")));
|
||||
SwingUtilities.invokeLater(() -> ViaProxyWindow.showInfo(I18n.get("tab.advanced.create_viaversion_dump.success")));
|
||||
}
|
||||
SwingUtilities.invokeLater(() -> this.viaVersionDumpButton.setEnabled(true));
|
||||
});
|
||||
@ -163,18 +162,18 @@ public class AdvancedTab extends AUITab {
|
||||
final MclogsClient mclogsClient = new MclogsClient("ViaProxy", ViaProxy.VERSION);
|
||||
final UploadLogResponse apiResponse = mclogsClient.uploadLog(logFile.toPath());
|
||||
if (apiResponse.isSuccess()) {
|
||||
ViaProxy.getUI().openURL(apiResponse.getUrl());
|
||||
ViaProxyWindow.openURL(apiResponse.getUrl());
|
||||
final StringSelection selection = new StringSelection(apiResponse.getUrl());
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection);
|
||||
ViaProxy.getUI().showInfo("<html>" + I18n.get("tab.advanced.upload_latest_log.success", "<a href=\"\">" + apiResponse.getUrl() + "</a>") + "</html>");
|
||||
ViaProxyWindow.showInfo("<html>" + I18n.get("tab.advanced.upload_latest_log.success", "<a href=\"\">" + apiResponse.getUrl() + "</a>") + "</html>");
|
||||
} else {
|
||||
ViaProxy.getUI().showError(I18n.get("tab.advanced.upload_latest_log.error_generic", apiResponse.getError()));
|
||||
ViaProxyWindow.showError(I18n.get("tab.advanced.upload_latest_log.error_generic", apiResponse.getError()));
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
ViaProxy.getUI().showError(I18n.get("tab.advanced.upload_latest_log.error_not_found"));
|
||||
ViaProxyWindow.showError(I18n.get("tab.advanced.upload_latest_log.error_not_found"));
|
||||
} catch (Throwable e) {
|
||||
Logger.LOGGER.error("Failed to upload log file", e);
|
||||
ViaProxy.getUI().showError(I18n.get("tab.advanced.upload_latest_log.error_generic", e.getMessage()));
|
||||
ViaProxyWindow.showError(I18n.get("tab.advanced.upload_latest_log.error_generic", e.getMessage()));
|
||||
} finally {
|
||||
this.uploadLogsButton.setEnabled(true);
|
||||
}
|
||||
@ -189,17 +188,15 @@ public class AdvancedTab extends AUITab {
|
||||
container.add(padding, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onClose(final UICloseEvent event) {
|
||||
UISave save = ViaProxy.getSaveManager().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()));
|
||||
save.put("legacy_skin_loading", String.valueOf(this.legacySkinLoading.isSelected()));
|
||||
save.put("chat_signing", String.valueOf(this.chatSigning.isSelected()));
|
||||
save.put("ignore_packet_translation_errors", String.valueOf(this.ignorePacketTranslationErrors.isSelected()));
|
||||
save.put("allow_beta_pinging", String.valueOf(this.allowBetaPinging.isSelected()));
|
||||
ViaProxy.getSaveManager().save();
|
||||
@EventHandler(events = UICloseEvent.class)
|
||||
void applyGuiState() {
|
||||
ViaProxy.getSaveManager().uiSave.put("bind_address", this.bindAddress.getText());
|
||||
ViaProxy.getSaveManager().uiSave.put("proxy", this.proxy.getText());
|
||||
ViaProxy.getConfig().setProxyOnlineMode(this.proxyOnlineMode.isSelected());
|
||||
ViaProxy.getSaveManager().uiSave.put("legacy_skin_loading", String.valueOf(this.legacySkinLoading.isSelected()));
|
||||
ViaProxy.getConfig().setChatSigning(this.chatSigning.isSelected());
|
||||
ViaProxy.getConfig().setIgnoreProtocolTranslationErrors(this.ignorePacketTranslationErrors.isSelected());
|
||||
ViaProxy.getConfig().setAllowBetaPinging(this.allowBetaPinging.isSelected());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,12 +25,11 @@ import net.raphimc.viabedrock.api.BedrockProtocolVersion;
|
||||
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
|
||||
import net.raphimc.vialoader.util.ProtocolVersionList;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
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.protocoltranslator.viaproxy.ViaProxyConfig;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.ClassicAccount;
|
||||
import net.raphimc.viaproxy.ui.I18n;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyUI;
|
||||
import net.raphimc.viaproxy.ui.UITab;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyWindow;
|
||||
import net.raphimc.viaproxy.ui.events.UICloseEvent;
|
||||
import net.raphimc.viaproxy.util.AddressUtil;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
@ -45,19 +44,19 @@ import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyUI.BODY_BLOCK_PADDING;
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyUI.BORDER_PADDING;
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyWindow.BODY_BLOCK_PADDING;
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyWindow.BORDER_PADDING;
|
||||
|
||||
public class GeneralTab extends AUITab {
|
||||
public class GeneralTab extends UITab {
|
||||
|
||||
JTextField serverAddress;
|
||||
JComboBox<ProtocolVersion> serverVersion;
|
||||
JComboBox<String> authMethod;
|
||||
private JCheckBox betaCraftAuth;
|
||||
private JLabel stateLabel;
|
||||
JComboBox<ViaProxyConfig.AuthMethod> authMethod;
|
||||
JCheckBox betaCraftAuth;
|
||||
JLabel stateLabel;
|
||||
JButton stateButton;
|
||||
|
||||
public GeneralTab(final ViaProxyUI frame) {
|
||||
public GeneralTab(final ViaProxyWindow frame) {
|
||||
super(frame, "general");
|
||||
}
|
||||
|
||||
@ -82,7 +81,7 @@ public class GeneralTab extends AUITab {
|
||||
discord.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
frame.openURL("https://discord.gg/viaversion");
|
||||
ViaProxyWindow.openURL("https://discord.gg/viaversion");
|
||||
}
|
||||
});
|
||||
discord.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
@ -137,21 +136,30 @@ public class GeneralTab extends AUITab {
|
||||
this.betaCraftAuth.setSelected(false);
|
||||
}
|
||||
});
|
||||
ViaProxy.getSaveManager().uiSave.loadComboBoxProtocolVersion("server_version", this.serverVersion);
|
||||
this.serverVersion.setSelectedItem(ViaProxy.getConfig().getTargetVersion());
|
||||
GBC.create(body).grid(0, gridy++).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(this.serverVersion);
|
||||
}
|
||||
{
|
||||
JLabel minecraftAccountLabel = new JLabel(I18n.get("tab.general.minecraft_account.label"));
|
||||
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(minecraftAccountLabel);
|
||||
|
||||
this.authMethod = new JComboBox<>(new String[]{I18n.get("tab.general.minecraft_account.option_select_account"), I18n.get("tab.general.minecraft_account.option_no_account"), I18n.get("tab.general.minecraft_account.option_openauthmod")});
|
||||
ViaProxy.getSaveManager().uiSave.loadComboBox("auth_method", this.authMethod);
|
||||
this.authMethod = new JComboBox<>(ViaProxyConfig.AuthMethod.values());
|
||||
this.authMethod.setRenderer(new DefaultListCellRenderer() {
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
if (value instanceof ViaProxyConfig.AuthMethod authMethod) {
|
||||
value = I18n.get(authMethod.getGuiTranslationKey());
|
||||
}
|
||||
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
||||
}
|
||||
});
|
||||
this.authMethod.setSelectedItem(ViaProxy.getConfig().getAuthMethod());
|
||||
GBC.create(body).grid(0, gridy++).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(this.authMethod);
|
||||
}
|
||||
{
|
||||
this.betaCraftAuth = new JCheckBox(I18n.get("tab.general.betacraft_auth.label"));
|
||||
this.betaCraftAuth.setToolTipText(I18n.get("tab.general.betacraft_auth.tooltip"));
|
||||
ViaProxy.getSaveManager().uiSave.loadCheckBox("betacraft_auth", this.betaCraftAuth);
|
||||
this.betaCraftAuth.setSelected(ViaProxy.getConfig().useBetacraftAuth());
|
||||
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(this.betaCraftAuth);
|
||||
// Simulate user action on serverVersion to update betaCraftAuth
|
||||
final ActionEvent fakeAction = new ActionEvent(this.serverVersion, ActionEvent.ACTION_PERFORMED, "");
|
||||
@ -192,35 +200,27 @@ public class GeneralTab extends AUITab {
|
||||
timer.start();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
private void onClose(final UICloseEvent event) {
|
||||
UISave save = ViaProxy.getSaveManager().uiSave;
|
||||
save.put("server_address", this.serverAddress.getText());
|
||||
if (this.serverVersion.getSelectedItem() instanceof ProtocolVersion version) {
|
||||
save.put("server_version", version.getName());
|
||||
}
|
||||
save.put("auth_method", String.valueOf(this.authMethod.getSelectedIndex()));
|
||||
save.put("betacraft_auth", String.valueOf(this.betaCraftAuth.isSelected()));
|
||||
ViaProxy.getSaveManager().save();
|
||||
}
|
||||
|
||||
private void setComponentsEnabled(final boolean state) {
|
||||
this.serverAddress.setEnabled(state);
|
||||
this.serverVersion.setEnabled(state);
|
||||
ViaProxy.getUI().advancedTab.bindPort.setEnabled(state);
|
||||
this.viaProxyWindow.advancedTab.bindAddress.setEnabled(state);
|
||||
this.authMethod.setEnabled(state);
|
||||
this.betaCraftAuth.setEnabled(state);
|
||||
ViaProxy.getUI().advancedTab.proxyOnlineMode.setEnabled(state);
|
||||
ViaProxy.getUI().advancedTab.proxy.setEnabled(state);
|
||||
ViaProxy.getUI().advancedTab.legacySkinLoading.setEnabled(state);
|
||||
ViaProxy.getUI().advancedTab.chatSigning.setEnabled(state);
|
||||
ViaProxy.getUI().advancedTab.ignorePacketTranslationErrors.setEnabled(state);
|
||||
ViaProxy.getUI().advancedTab.allowBetaPinging.setEnabled(state);
|
||||
this.viaProxyWindow.advancedTab.proxyOnlineMode.setEnabled(state);
|
||||
this.viaProxyWindow.advancedTab.proxy.setEnabled(state);
|
||||
this.viaProxyWindow.advancedTab.legacySkinLoading.setEnabled(state);
|
||||
this.viaProxyWindow.advancedTab.chatSigning.setEnabled(state);
|
||||
this.viaProxyWindow.advancedTab.ignorePacketTranslationErrors.setEnabled(state);
|
||||
this.viaProxyWindow.advancedTab.allowBetaPinging.setEnabled(state);
|
||||
if (state) this.serverVersion.getActionListeners()[0].actionPerformed(null);
|
||||
}
|
||||
|
||||
private void updateStateLabel() {
|
||||
this.stateLabel.setText(I18n.get("tab.general.state.running", "1.7+", "127.0.0.1:" + ViaProxy.getUI().advancedTab.bindPort.getValue()));
|
||||
if (ViaProxy.getConfig().getBindAddress() instanceof InetSocketAddress inetSocketAddress) {
|
||||
this.stateLabel.setText(I18n.get("tab.general.state.running", "1.7+", "127.0.0.1:" + inetSocketAddress.getPort()));
|
||||
} else {
|
||||
this.stateLabel.setText(I18n.get("tab.general.state.running", "1.7+", AddressUtil.toString(ViaProxy.getConfig().getBindAddress())));
|
||||
}
|
||||
this.stateLabel.setForeground(Color.GREEN);
|
||||
this.stateLabel.setVisible(true);
|
||||
}
|
||||
@ -228,20 +228,20 @@ public class GeneralTab extends AUITab {
|
||||
private void start() {
|
||||
final Object selectedVersion = this.serverVersion.getSelectedItem();
|
||||
if (!(selectedVersion instanceof ProtocolVersion)) {
|
||||
this.frame.showError(I18n.get("tab.general.error.no_server_version_selected"));
|
||||
ViaProxyWindow.showError(I18n.get("tab.general.error.no_server_version_selected"));
|
||||
return;
|
||||
}
|
||||
if (ViaProxy.getSaveManager().uiSave.get("notice.ban_warning") == null) {
|
||||
ViaProxy.getSaveManager().uiSave.put("notice.ban_warning", "true");
|
||||
ViaProxy.getSaveManager().save();
|
||||
|
||||
this.frame.showWarning("<html><div style='text-align: center;'>" + I18n.get("tab.general.warning.ban_warning.line1") + "<br><b>" + I18n.get("tab.general.warning.risk") + "</b></div></html>");
|
||||
ViaProxyWindow.showWarning("<html><div style='text-align: center;'>" + I18n.get("tab.general.warning.ban_warning.line1") + "<br><b>" + I18n.get("tab.general.warning.risk") + "</b></div></html>");
|
||||
}
|
||||
if (selectedVersion.equals(BedrockProtocolVersion.bedrockLatest) && ViaProxy.getSaveManager().uiSave.get("notice.bedrock_warning") == null) {
|
||||
ViaProxy.getSaveManager().uiSave.put("notice.bedrock_warning", "true");
|
||||
ViaProxy.getSaveManager().save();
|
||||
|
||||
this.frame.showWarning("<html><div style='text-align: center;'>" + I18n.get("tab.general.warning.bedrock_warning.line1") + "<br><b>" + I18n.get("tab.general.warning.risk") + "</b></div></html>");
|
||||
ViaProxyWindow.showWarning("<html><div style='text-align: center;'>" + I18n.get("tab.general.warning.bedrock_warning.line1") + "<br><b>" + I18n.get("tab.general.warning.risk") + "</b></div></html>");
|
||||
}
|
||||
|
||||
this.setComponentsEnabled(false);
|
||||
@ -249,17 +249,11 @@ public class GeneralTab extends AUITab {
|
||||
this.stateButton.setText(I18n.get("tab.general.state.starting"));
|
||||
|
||||
new Thread(() -> {
|
||||
String serverAddress = this.serverAddress.getText().trim();
|
||||
final String serverAddress = this.serverAddress.getText().trim();
|
||||
final ProtocolVersion serverVersion = (ProtocolVersion) this.serverVersion.getSelectedItem();
|
||||
final int bindPort = (int) ViaProxy.getUI().advancedTab.bindPort.getValue();
|
||||
final int authMethod = this.authMethod.getSelectedIndex();
|
||||
final boolean betaCraftAuth = this.betaCraftAuth.isSelected();
|
||||
final boolean proxyOnlineMode = ViaProxy.getUI().advancedTab.proxyOnlineMode.isSelected();
|
||||
final boolean legacySkinLoading = ViaProxy.getUI().advancedTab.legacySkinLoading.isSelected();
|
||||
final String proxyUrl = ViaProxy.getUI().advancedTab.proxy.getText().trim();
|
||||
final boolean chatSigning = ViaProxy.getUI().advancedTab.chatSigning.isSelected();
|
||||
final boolean ignorePacketTranslationErrors = ViaProxy.getUI().advancedTab.ignorePacketTranslationErrors.isSelected();
|
||||
final boolean allowBetaPinging = ViaProxy.getUI().advancedTab.allowBetaPinging.isSelected();
|
||||
final String bindAddress = this.viaProxyWindow.advancedTab.bindAddress.getText().trim();
|
||||
final ViaProxyConfig.AuthMethod authMethod = (ViaProxyConfig.AuthMethod) this.authMethod.getSelectedItem();
|
||||
final String proxyUrl = this.viaProxyWindow.advancedTab.proxy.getText().trim();
|
||||
|
||||
try {
|
||||
try {
|
||||
@ -271,52 +265,50 @@ public class GeneralTab extends AUITab {
|
||||
throw new IllegalArgumentException(I18n.get("tab.general.error.invalid_classicube_url"));
|
||||
}
|
||||
|
||||
Options.CONNECT_ADDRESS = new InetSocketAddress(uri.getHost(), uri.getPort());
|
||||
Options.MC_ACCOUNT = new OfflineAccount(path[0]);
|
||||
Options.CLASSIC_MP_PASS = path[1];
|
||||
ViaProxy.getConfig().setTargetAddress(new InetSocketAddress(uri.getHost(), uri.getPort()));
|
||||
ViaProxy.getConfig().setAccount(new ClassicAccount(path[0], path[1]));
|
||||
} else {
|
||||
try {
|
||||
Options.CONNECT_ADDRESS = AddressUtil.parse(serverAddress, serverVersion);
|
||||
ViaProxy.getConfig().setTargetAddress(AddressUtil.parse(serverAddress, serverVersion));
|
||||
} catch (Throwable t) {
|
||||
throw new IllegalArgumentException(I18n.get("tab.general.error.invalid_server_address"));
|
||||
}
|
||||
|
||||
if (authMethod != 0) {
|
||||
Options.MC_ACCOUNT = null;
|
||||
} else if (Options.MC_ACCOUNT == null) {
|
||||
this.frame.accountsTab.markSelected(0);
|
||||
if (authMethod == ViaProxyConfig.AuthMethod.ACCOUNT) {
|
||||
if (ViaProxy.getConfig().getAccount() == null) {
|
||||
this.viaProxyWindow.accountsTab.markSelected(0);
|
||||
}
|
||||
} else {
|
||||
ViaProxy.getConfig().setAccount(null);
|
||||
}
|
||||
Options.CLASSIC_MP_PASS = null;
|
||||
}
|
||||
|
||||
Options.BIND_ADDRESS = new InetSocketAddress("0.0.0.0", bindPort);
|
||||
Options.ONLINE_MODE = proxyOnlineMode;
|
||||
Options.PROTOCOL_VERSION = serverVersion;
|
||||
Options.BETACRAFT_AUTH = betaCraftAuth;
|
||||
Options.LEGACY_SKIN_LOADING = legacySkinLoading;
|
||||
Options.OPENAUTHMOD_AUTH = authMethod == 2;
|
||||
Options.CHAT_SIGNING = chatSigning;
|
||||
Options.IGNORE_PACKET_TRANSLATION_ERRORS = ignorePacketTranslationErrors;
|
||||
Options.ALLOW_BETA_PINGING = allowBetaPinging;
|
||||
|
||||
if (!proxyUrl.isEmpty()) {
|
||||
try {
|
||||
ViaProxy.getConfig().setBindAddress(AddressUtil.parse(bindAddress, null));
|
||||
} catch (Throwable t) {
|
||||
throw new IllegalArgumentException(I18n.get("tab.general.error.invalid_bind_address"));
|
||||
}
|
||||
if (!proxyUrl.isBlank()) {
|
||||
try {
|
||||
Options.PROXY_URL = new URI(proxyUrl);
|
||||
ViaProxy.getConfig().setBackendProxyUrl(new URI(proxyUrl));
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException(I18n.get("tab.general.error.invalid_proxy_url"));
|
||||
}
|
||||
} else {
|
||||
Options.PROXY_URL = null;
|
||||
ViaProxy.getConfig().setBackendProxyUrl(null);
|
||||
}
|
||||
this.applyGuiState();
|
||||
this.viaProxyWindow.advancedTab.applyGuiState();
|
||||
ViaProxy.getConfig().save();
|
||||
ViaProxy.getSaveManager().save();
|
||||
} catch (Throwable t) {
|
||||
SwingUtilities.invokeLater(() -> this.frame.showError(t.getMessage()));
|
||||
SwingUtilities.invokeLater(() -> ViaProxyWindow.showError(t.getMessage()));
|
||||
throw t;
|
||||
}
|
||||
|
||||
try {
|
||||
ViaProxy.startProxy();
|
||||
} catch (Throwable e) {
|
||||
SwingUtilities.invokeLater(() -> this.frame.showError(I18n.get("tab.general.error.failed_to_start")));
|
||||
SwingUtilities.invokeLater(() -> ViaProxyWindow.showError(I18n.get("tab.general.error.failed_to_start")));
|
||||
throw e;
|
||||
}
|
||||
|
||||
@ -345,4 +337,16 @@ public class GeneralTab extends AUITab {
|
||||
this.setComponentsEnabled(true);
|
||||
}
|
||||
|
||||
@EventHandler(events = UICloseEvent.class)
|
||||
void applyGuiState() {
|
||||
ViaProxy.getSaveManager().uiSave.put("server_address", this.serverAddress.getText());
|
||||
if (this.serverVersion.getSelectedItem() instanceof ProtocolVersion version) {
|
||||
ViaProxy.getConfig().setTargetVersion(version);
|
||||
}
|
||||
if (this.authMethod.getSelectedItem() instanceof ViaProxyConfig.AuthMethod authMethod) {
|
||||
ViaProxy.getConfig().setAuthMethod(authMethod);
|
||||
}
|
||||
ViaProxy.getConfig().setBetacraftAuth(this.betaCraftAuth.isSelected());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,13 +31,12 @@ import net.raphimc.minecraftauth.service.realms.model.RealmsWorld;
|
||||
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
|
||||
import net.raphimc.viabedrock.protocol.data.ProtocolConstants;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.cli.options.Options;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.Account;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.BedrockAccount;
|
||||
import net.raphimc.viaproxy.saves.impl.accounts.MicrosoftAccount;
|
||||
import net.raphimc.viaproxy.ui.AUITab;
|
||||
import net.raphimc.viaproxy.ui.I18n;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyUI;
|
||||
import net.raphimc.viaproxy.ui.UITab;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyWindow;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
@ -45,7 +44,7 @@ import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class RealmsTab extends AUITab {
|
||||
public class RealmsTab extends UITab {
|
||||
|
||||
private static final ProtocolVersion LATEST_JAVA_RELEASE;
|
||||
private static final ProtocolVersion LATEST_JAVA_SNAPSHOT;
|
||||
@ -72,14 +71,14 @@ public class RealmsTab extends AUITab {
|
||||
private Account currentAccount = null;
|
||||
private ProtocolVersion currentSelectedJavaVersion = LATEST_JAVA_RELEASE;
|
||||
|
||||
public RealmsTab(final ViaProxyUI frame) {
|
||||
public RealmsTab(final ViaProxyWindow frame) {
|
||||
super(frame, "realms");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTabOpened() {
|
||||
if (Options.MC_ACCOUNT != this.currentAccount) {
|
||||
this.currentAccount = Options.MC_ACCOUNT;
|
||||
if (ViaProxy.getConfig().getAccount() != this.currentAccount) {
|
||||
this.currentAccount = ViaProxy.getConfig().getAccount();
|
||||
this.reinit();
|
||||
}
|
||||
}
|
||||
@ -121,7 +120,7 @@ public class RealmsTab extends AUITab {
|
||||
});
|
||||
} catch (Throwable e) {
|
||||
Logger.LOGGER.error("Failed to refresh account", e);
|
||||
ViaProxy.getUI().showError(I18n.get("tab.realms.error_account", e.getMessage()));
|
||||
ViaProxyWindow.showError(I18n.get("tab.realms.error_account", e.getMessage()));
|
||||
SwingUtilities.invokeLater(() -> statusLabel.setText(I18n.get("tab.realms.error_account_label")));
|
||||
}
|
||||
});
|
||||
@ -158,7 +157,7 @@ public class RealmsTab extends AUITab {
|
||||
})).exceptionally(e -> {
|
||||
final Throwable cause = e.getCause();
|
||||
Logger.LOGGER.error("Failed to get realms worlds", cause);
|
||||
ViaProxy.getUI().showError(I18n.get("tab.realms.error_generic", cause.getMessage()));
|
||||
ViaProxyWindow.showError(I18n.get("tab.realms.error_generic", cause.getMessage()));
|
||||
SwingUtilities.invokeLater(() -> statusLabel.setText(I18n.get("tab.realms.error_generic_label")));
|
||||
return null;
|
||||
});
|
||||
@ -168,7 +167,7 @@ public class RealmsTab extends AUITab {
|
||||
}).exceptionally(e -> {
|
||||
final Throwable cause = e.getCause();
|
||||
Logger.LOGGER.error("Failed to check realms availability", cause);
|
||||
ViaProxy.getUI().showError(I18n.get("tab.realms.error_generic", cause.getMessage()));
|
||||
ViaProxyWindow.showError(I18n.get("tab.realms.error_generic", cause.getMessage()));
|
||||
SwingUtilities.invokeLater(() -> statusLabel.setText(I18n.get("tab.realms.error_generic_label")));
|
||||
return null;
|
||||
});
|
||||
@ -234,14 +233,14 @@ public class RealmsTab extends AUITab {
|
||||
join.setEnabled(true);
|
||||
join.setText(I18n.get("tab.realms.join"));
|
||||
if (realmsService instanceof JavaRealmsService javaRealmsService && cause instanceof RealmsRequestException realmsRequestException && realmsRequestException.getErrorCode() == RealmsRequestException.TOS_NOT_ACCEPTED) {
|
||||
final int chosen = JOptionPane.showConfirmDialog(ViaProxy.getUI(), I18n.get("tab.realms.accept_tos", "https://aka.ms/MinecraftRealmsTerms"), "ViaProxy", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||
final int chosen = JOptionPane.showConfirmDialog(this.viaProxyWindow, I18n.get("tab.realms.accept_tos", "https://aka.ms/MinecraftRealmsTerms"), "ViaProxy", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||
if (chosen == JOptionPane.YES_OPTION) {
|
||||
javaRealmsService.acceptTos();
|
||||
join.doClick();
|
||||
}
|
||||
} else {
|
||||
Logger.LOGGER.error("Failed to join realm", cause);
|
||||
ViaProxy.getUI().showError(I18n.get("tab.realms.error_generic", cause.getMessage()));
|
||||
ViaProxyWindow.showError(I18n.get("tab.realms.error_generic", cause.getMessage()));
|
||||
}
|
||||
});
|
||||
return null;
|
||||
@ -253,7 +252,7 @@ public class RealmsTab extends AUITab {
|
||||
}
|
||||
|
||||
private void setServerAddressAndStartViaProxy(final String address, final ProtocolVersion version) {
|
||||
final GeneralTab generalTab = ViaProxy.getUI().generalTab;
|
||||
final GeneralTab generalTab = this.viaProxyWindow.generalTab;
|
||||
if (generalTab.stateButton.isEnabled()) {
|
||||
if (!generalTab.stateButton.getText().equals(I18n.get("tab.general.state.start"))) {
|
||||
generalTab.stateButton.doClick(); // Stop the running proxy
|
||||
@ -262,7 +261,7 @@ public class RealmsTab extends AUITab {
|
||||
generalTab.serverVersion.setSelectedItem(version);
|
||||
generalTab.authMethod.setSelectedIndex(0);
|
||||
generalTab.stateButton.doClick();
|
||||
ViaProxy.getUI().contentPane.setSelectedIndex(0);
|
||||
this.viaProxyWindow.contentPane.setSelectedIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,9 +19,9 @@ package net.raphimc.viaproxy.ui.impl;
|
||||
|
||||
import net.lenni0451.commons.swing.GBC;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.ui.AUITab;
|
||||
import net.raphimc.viaproxy.ui.I18n;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyUI;
|
||||
import net.raphimc.viaproxy.ui.UITab;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyWindow;
|
||||
import net.raphimc.viaproxy.util.logging.Logger;
|
||||
|
||||
import javax.swing.*;
|
||||
@ -30,11 +30,11 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyUI.BORDER_PADDING;
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyWindow.BORDER_PADDING;
|
||||
|
||||
public class UISettingsTab extends AUITab {
|
||||
public class UISettingsTab extends UITab {
|
||||
|
||||
public UISettingsTab(final ViaProxyUI frame) {
|
||||
public UISettingsTab(final ViaProxyWindow frame) {
|
||||
super(frame, "ui_settings");
|
||||
}
|
||||
|
||||
@ -63,14 +63,14 @@ public class UISettingsTab extends AUITab {
|
||||
if (!(language.getSelectedItem() instanceof String locale)) return;
|
||||
if (locale.equals(I18n.getCurrentLocale())) return;
|
||||
I18n.setLocale(locale);
|
||||
ViaProxy.getUI().showInfo(I18n.get("tab.ui_settings.language.success", I18n.get("language.name"), locale));
|
||||
ViaProxyWindow.showInfo(I18n.get("tab.ui_settings.language.success", I18n.get("language.name"), locale));
|
||||
try {
|
||||
final File f = new File(ViaProxy.class.getProtectionDomain().getCodeSource().getLocation().toURI());
|
||||
Runtime.getRuntime().exec(new String[]{System.getProperty("java.home") + "/bin/java", "-jar", f.getAbsolutePath()});
|
||||
System.exit(0);
|
||||
} catch (URISyntaxException | IOException e) {
|
||||
Logger.LOGGER.error("Could not start the ViaProxy jar", e);
|
||||
ViaProxy.getUI().showException(e);
|
||||
ViaProxyWindow.showException(e);
|
||||
System.exit(1);
|
||||
}
|
||||
});
|
||||
|
@ -20,7 +20,7 @@ package net.raphimc.viaproxy.ui.popups;
|
||||
import net.lenni0451.commons.swing.GBC;
|
||||
import net.raphimc.minecraftauth.step.msa.StepMsaDeviceCode;
|
||||
import net.raphimc.viaproxy.ui.I18n;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyUI;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyWindow;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@ -30,16 +30,16 @@ import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyUI.BODY_BLOCK_PADDING;
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyUI.BORDER_PADDING;
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyWindow.BODY_BLOCK_PADDING;
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyWindow.BORDER_PADDING;
|
||||
|
||||
public class AddAccountPopup extends JDialog {
|
||||
|
||||
private final ViaProxyUI parent;
|
||||
private final ViaProxyWindow parent;
|
||||
private final StepMsaDeviceCode.MsaDeviceCode deviceCode;
|
||||
private boolean externalClose;
|
||||
|
||||
public AddAccountPopup(final ViaProxyUI parent, final StepMsaDeviceCode.MsaDeviceCode deviceCode, final Consumer<AddAccountPopup> popupConsumer, final Runnable closeListener) {
|
||||
public AddAccountPopup(final ViaProxyWindow parent, final StepMsaDeviceCode.MsaDeviceCode deviceCode, final Consumer<AddAccountPopup> popupConsumer, final Runnable closeListener) {
|
||||
super(parent, true);
|
||||
this.parent = parent;
|
||||
this.deviceCode = deviceCode;
|
||||
@ -76,7 +76,7 @@ public class AddAccountPopup extends JDialog {
|
||||
urlLabel.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
AddAccountPopup.this.parent.openURL(AddAccountPopup.this.deviceCode.getDirectVerificationUri());
|
||||
ViaProxyWindow.openURL(AddAccountPopup.this.deviceCode.getDirectVerificationUri());
|
||||
}
|
||||
});
|
||||
GBC.create(contentPane).grid(0, 1).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(urlLabel);
|
||||
|
@ -20,7 +20,6 @@ package net.raphimc.viaproxy.ui.popups;
|
||||
import net.lenni0451.commons.swing.GBC;
|
||||
import net.raphimc.viaproxy.ViaProxy;
|
||||
import net.raphimc.viaproxy.ui.I18n;
|
||||
import net.raphimc.viaproxy.ui.ViaProxyUI;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@ -35,11 +34,11 @@ import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyUI.BORDER_PADDING;
|
||||
import static net.raphimc.viaproxy.ui.ViaProxyWindow.BORDER_PADDING;
|
||||
|
||||
public class DownloadPopup extends JDialog {
|
||||
|
||||
private final ViaProxyUI parent;
|
||||
private final JFrame parent;
|
||||
private final String url;
|
||||
private final File file;
|
||||
private final Runnable finishListener;
|
||||
@ -48,7 +47,7 @@ public class DownloadPopup extends JDialog {
|
||||
private JProgressBar progressBar;
|
||||
private Thread downloadThread;
|
||||
|
||||
public DownloadPopup(final ViaProxyUI parent, final String url, final File file, final Runnable finishListener, final Consumer<Throwable> stopConsumer) {
|
||||
public DownloadPopup(final JFrame parent, final String url, final File file, final Runnable finishListener, final Consumer<Throwable> stopConsumer) {
|
||||
super(parent, true);
|
||||
this.parent = parent;
|
||||
this.url = url;
|
||||
|
@ -41,8 +41,6 @@ tab.general.error.invalid_proxy_url=Neplatná proxy URL!
|
||||
tab.general.error.failed_to_start=Nebylo možné spustit ViaProxy! Ujistěte se že vybraný port není používaný a zkuste to znovu.
|
||||
|
||||
tab.advanced.name=Pokročilé
|
||||
tab.advanced.bind_port.label=Bind Port:
|
||||
tab.advanced.bind_port.tooltip=Port na kterém by se měla ViaProxy spustit.
|
||||
tab.advanced.proxy_url.label=Proxy URL:
|
||||
tab.advanced.proxy_url.tooltip=URL SOCKS(4/5)/HTTP(S) proxy, která bude používána pro TCP připojení.\nPodporované formáty:\n- typ://addresa:port\n- typ://uzivatelske_jmeno:heslo@addresa:port
|
||||
tab.advanced.proxy_online_mode.label=Proxy Online Mód
|
||||
|
@ -37,12 +37,13 @@ tab.general.warning.risk=Verwendung auf eigene Gefahr!
|
||||
tab.general.error.no_server_version_selected=Bitte wähle eine Server Version aus!
|
||||
tab.general.error.invalid_classicube_url=Ungültige ClassiCube Direct URL!
|
||||
tab.general.error.invalid_server_address=Ungültige Server Adresse!
|
||||
tab.general.error.invalid_bind_address=Ungültige Lokale Adresse!
|
||||
tab.general.error.invalid_proxy_url=Ungültige proxy URL!
|
||||
tab.general.error.failed_to_start=ViaProxy konnte nicht starten! Sorge dafür, dass der lokale Port nicht bereits belegt ist und versuche es nochmal.
|
||||
|
||||
tab.advanced.name=Erweitert
|
||||
tab.advanced.bind_port.label=Lokaler Port:
|
||||
tab.advanced.bind_port.tooltip=Der lokale Port, auf dem ViaProxy Verbindungen entgegen nehmen soll.
|
||||
tab.advanced.bind_address.label=Lokale Adresse:
|
||||
tab.advanced.bind_address.tooltip=Die lokale Adresse, auf der ViaProxy Verbindungen entgegen nehmen soll.
|
||||
tab.advanced.proxy_url.label=Proxy URL:
|
||||
tab.advanced.proxy_url.tooltip=URL von einem SOCKS(4/5)/HTTP(S) Proxy der für TCP Verbindungen verwendet werden soll.\nUnterstützte Formate:\n- Typ://Adresse:Port\n- Typ://Benutzername:Passwort@Adresse:Port
|
||||
tab.advanced.proxy_online_mode.label=Proxy Online Mode
|
||||
|
@ -25,7 +25,7 @@ tab.general.minecraft_account.option_no_account=Use no account
|
||||
tab.general.minecraft_account.option_select_account=Use selected account
|
||||
tab.general.minecraft_account.option_openauthmod=Use OpenAuthMod
|
||||
tab.general.betacraft_auth.label=BetaCraft Auth (Classic)
|
||||
tab.general.betacraft_auth.tooltip=Enabling BetaCraft Auth allows you to join Classic servers which have online mode enabled.
|
||||
tab.general.betacraft_auth.tooltip=Enabling BetaCraft Auth allows you to join classic servers which have online mode enabled.
|
||||
tab.general.state.loading=Loading ViaProxy...
|
||||
tab.general.state.start=Start
|
||||
tab.general.state.starting=Starting...
|
||||
@ -37,12 +37,13 @@ tab.general.warning.risk=Use at your own risk!
|
||||
tab.general.error.no_server_version_selected=Please select a server version!
|
||||
tab.general.error.invalid_classicube_url=Invalid ClassiCube Direct URL!
|
||||
tab.general.error.invalid_server_address=Invalid server address!
|
||||
tab.general.error.invalid_bind_address=Invalid bind address!
|
||||
tab.general.error.invalid_proxy_url=Invalid proxy URL!
|
||||
tab.general.error.failed_to_start=Failed to start ViaProxy! Ensure that the local port is not already in use and try again.
|
||||
|
||||
tab.advanced.name=Advanced
|
||||
tab.advanced.bind_port.label=Bind Port:
|
||||
tab.advanced.bind_port.tooltip=The port ViaProxy should bind to.
|
||||
tab.advanced.bind_address.label=Bind Address:
|
||||
tab.advanced.bind_address.tooltip=The address ViaProxy should accept incoming connections on.
|
||||
tab.advanced.proxy_url.label=Proxy URL:
|
||||
tab.advanced.proxy_url.tooltip=URL of a SOCKS(4/5)/HTTP(S) proxy which will be used for TCP connections.\nSupported formats:\n- type://address:port\n- type://username:password@address:port
|
||||
tab.advanced.proxy_online_mode.label=Proxy Online Mode
|
||||
|
@ -41,8 +41,6 @@ tab.general.error.invalid_proxy_url=Nieprawidłowy adres serwera proxy.
|
||||
tab.general.error.failed_to_start=Nie można uruchomić ViaProxy! Upewnij się że port nie jest już zajęty i spróbuj ponownie.
|
||||
|
||||
tab.advanced.name=Zaawansowane
|
||||
tab.advanced.bind_port.label=Port:
|
||||
tab.advanced.bind_port.tooltip=Port na którym ViaProxy będzie działać.
|
||||
tab.advanced.proxy_url.label=Adres Proxy:
|
||||
tab.advanced.proxy_url.tooltip=Adres SOCKS(4/5)/HTTP(S) proxy.\nFormat:\n- typ://adres:port\n- typ://użytkownik:hasło@adres:port
|
||||
tab.advanced.proxy_online_mode.label=Tryb Online
|
||||
|
@ -41,8 +41,6 @@ tab.general.error.invalid_proxy_url=Неверный proxy URL!
|
||||
tab.general.error.failed_to_start=Не удалось запустить ViaProxy! Убедитесь, что локальный порт не используется и попробуйте снова.
|
||||
|
||||
tab.advanced.name=Дополнительное
|
||||
tab.advanced.bind_port.label=Привязываемый порт:
|
||||
tab.advanced.bind_port.tooltip=Порт, к которому привязывается ViaProxy.
|
||||
tab.advanced.proxy_url.label=Proxy URL:
|
||||
tab.advanced.proxy_url.tooltip=URL SOCKS(4/5)/HTTP(S) proxy, который будет использован при TCP подключении.\nПоддерживаемые форматы:\n- type://address:port\n- type://username:password@address:port
|
||||
tab.advanced.proxy_online_mode.label=Online Mode Proxy
|
||||
|
@ -41,8 +41,6 @@ tab.general.error.invalid_proxy_url=无效的代理URL!
|
||||
tab.general.error.failed_to_start=无法启动ViaProxy!请在确保本地端口未被使用后重试。
|
||||
|
||||
tab.advanced.name=高级
|
||||
tab.advanced.bind_port.label=绑定端口:
|
||||
tab.advanced.bind_port.tooltip=ViaProxy应绑定到的端口。
|
||||
tab.advanced.proxy_url.label=代理URL:
|
||||
tab.advanced.proxy_url.tooltip=用于TCP连接的SOCKS(4/5)/HTTP(S)代理的URL。\n支持的格式:\n- type://address:port\n- type://username:password@address:port
|
||||
tab.advanced.proxy_online_mode.label=代理在线模式
|
||||
|
@ -1,2 +0,0 @@
|
||||
#Dummy config
|
||||
this_is_a_dummy_config: true
|
64
src/main/resources/assets/viaproxy/viaproxy.yml
Normal file
64
src/main/resources/assets/viaproxy/viaproxy.yml
Normal file
@ -0,0 +1,64 @@
|
||||
# ViaProxy configuration file
|
||||
|
||||
#
|
||||
# The address ViaProxy should listen for connections.
|
||||
bind-address: "0.0.0.0:25568"
|
||||
#
|
||||
# The address of the server ViaProxy should connect to.
|
||||
target-address: "127.0.0.1:25565"
|
||||
#
|
||||
# The version ViaProxy should translate to. (See ViaProxy GUI for a list of versions)
|
||||
target-version: "Auto Detect (1.7+ servers)"
|
||||
#
|
||||
# Proxy Online Mode allows you to see skins on online mode servers and use the signed chat features.
|
||||
# Enabling Proxy Online Mode requires your client to have a valid minecraft account.
|
||||
proxy-online-mode: false
|
||||
#
|
||||
# The authentication method to use for joining the target server.
|
||||
# none: No authentication (Offline mode)
|
||||
# openauthmod: Requires the OpenAuthMod client mod (https://modrinth.com/mod/openauthmod)
|
||||
# account: Use an account for joining the target server. (Has to be configured in ViaProxy GUI)
|
||||
auth-method: "none"
|
||||
#
|
||||
# The GUI account list index (0 indexed) of the account if the auth method is set to account.
|
||||
minecraft-account-index: 0
|
||||
#
|
||||
# Use BetaCraft authentication for classic servers.
|
||||
# Enabling BetaCraft Auth allows you to join classic servers which have online mode enabled.
|
||||
betacraft-auth: false
|
||||
#
|
||||
# URL of a SOCKS(4/5)/HTTP(S) proxy which will be used for backend server connections. Leave empty to connect directly.
|
||||
# Supported formats:
|
||||
# - type://address:port
|
||||
# - type://username:password@address:port
|
||||
backend-proxy-url: ""
|
||||
#
|
||||
# Send HAProxy protocol messages to the target server.
|
||||
backend-haproxy: false
|
||||
#
|
||||
# Enables sending signed chat messages on >= 1.19 servers.
|
||||
chat-signing: true
|
||||
#
|
||||
# The threshold for packet compression. Packets larger than this size will be compressed. (-1 to disable)
|
||||
compression-threshold: 256
|
||||
#
|
||||
# Enabling this will allow you to ping <= b1.7.3 servers. This may cause issues with servers that block too frequent connections.
|
||||
allow-beta-pinging: false
|
||||
#
|
||||
# Enabling this will prevent getting disconnected from the server when a packet translation error occurs and instead only print the error in the console.
|
||||
# This may cause issues depending on the type of packet which failed to translate.
|
||||
ignore-protocol-translation-errors: false
|
||||
#
|
||||
# Allow <= 1.6.4 clients to connect through ViaProxy to the target server. (No protocol translation or packet handling)
|
||||
allow-legacy-client-passthrough: false
|
||||
#
|
||||
# URL of a resource pack which clients can optionally download when connecting to the server. Leave empty to disable.
|
||||
# Example: http://example.com/resourcepack.zip
|
||||
resource-pack-url: ""
|
||||
#
|
||||
# Allows players to specify the target server address and protocol in their client.
|
||||
# Example: viaversion.com_25565_1.8.x.viaproxy.127.0.0.1.nip.io
|
||||
srv-mode: false
|
||||
#
|
||||
# Configuration version. Do not change this.
|
||||
config-version: 1
|
Loading…
Reference in New Issue
Block a user