Updated Via API (#180)

* Updated Via API usage

* Added 24w07a client and server support

* Updated Via API usage

* Updated Via API usage

* Fixed Via load position

* Updated MixinProtocolVersion

* Moved auto detect to bottom of protocol list

* Fixed remaining errors

* Renamed ProtocolHack -> ProtocolTranslator
This commit is contained in:
RK_01 2024-02-14 23:46:35 +01:00 committed by GitHub
parent 6d91e44719
commit 0c23bd42ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
53 changed files with 220 additions and 372 deletions

View file

@ -54,8 +54,8 @@ repositories {
}
dependencies {
include "com.viaversion:viaversion-common:4.10.0-24w06a-SNAPSHOT"
include "com.viaversion:viabackwards-common:4.10.0-24w06a-SNAPSHOT"
include "com.viaversion:viaversion-common:4.10.0-24w07a-SNAPSHOT"
include "com.viaversion:viabackwards-common:4.10.0-24w07a-SNAPSHOT"
include "com.viaversion:viarewind-common:3.0.6-SNAPSHOT"
include "net.raphimc:ViaLegacy:2.2.22-SNAPSHOT"
include "net.raphimc:ViaAprilFools:2.0.11-SNAPSHOT"

View file

@ -4,4 +4,4 @@ org.gradle.configureondemand=true
maven_group=net.raphimc
maven_name=ViaProxy
maven_version=3.1.1-SNAPSHOT
maven_version=3.2.0-SNAPSHOT

View file

@ -38,17 +38,16 @@ import net.raphimc.netminecraft.constants.MCPipeline;
import net.raphimc.netminecraft.netty.connection.NetServer;
import net.raphimc.viaproxy.cli.ConsoleHandler;
import net.raphimc.viaproxy.cli.options.Options;
import net.raphimc.viaproxy.injection.VersionEnumExtension;
import net.raphimc.viaproxy.plugins.PluginManager;
import net.raphimc.viaproxy.plugins.events.Client2ProxyHandlerCreationEvent;
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.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.LoaderTask;
import net.raphimc.viaproxy.tasks.UpdateCheckTask;
import net.raphimc.viaproxy.ui.ViaProxyUI;
import net.raphimc.viaproxy.ui.events.UIInitEvent;
@ -60,6 +59,7 @@ import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.lang.instrument.Instrumentation;
import java.lang.reflect.InvocationTargetException;
public class ViaProxy {
@ -101,7 +101,7 @@ public class ViaProxy {
injectedMain("Runtime Agent", args);
}
public static void injectedMain(final String injectionMethod, final String[] args) throws InterruptedException, IOException {
public static void injectedMain(final String injectionMethod, final String[] args) throws InterruptedException, IOException, InvocationTargetException {
Logger.setup();
final boolean hasUI = args.length == 0 && !GraphicsEnvironment.isHeadless();
@ -136,17 +136,15 @@ public class ViaProxy {
ConsoleHandler.hookConsole();
ClassLoaderPriorityUtil.loadOverridingJars();
ViaProxy.loadNetty();
VersionEnumExtension.init();
ProtocolTranslator.init();
SAVE_MANAGER = new SaveManager();
PLUGIN_MANAGER = new PluginManager();
final Thread loaderThread = new Thread(new LoaderTask(), "ViaLoader");
final Thread updateCheckThread = new Thread(new UpdateCheckTask(hasUI), "UpdateCheck");
if (hasUI) {
loaderThread.start();
SwingUtilities.invokeLater(() -> {
SwingUtilities.invokeAndWait(() -> {
try {
ui = new ViaProxyUI();
} catch (Throwable e) {
@ -157,11 +155,6 @@ public class ViaProxy {
if (System.getProperty("skipUpdateCheck") == null) {
updateCheckThread.start();
}
loaderThread.join();
while (ui == null) {
Logger.LOGGER.info("Waiting for UI to be initialized...");
Thread.sleep(1000);
}
ui.eventManager.call(new UIInitEvent());
EVENT_MANAGER.call(new ViaProxyLoadedEvent());
Logger.LOGGER.info("ViaProxy started successfully!");
@ -171,8 +164,6 @@ public class ViaProxy {
if (System.getProperty("skipUpdateCheck") == null) {
updateCheckThread.start();
}
loaderThread.start();
loaderThread.join();
EVENT_MANAGER.call(new ViaProxyLoadedEvent());
Logger.LOGGER.info("ViaProxy started successfully!");
startProxy();

View file

@ -20,7 +20,7 @@ package net.raphimc.viaproxy.cli;
import com.viaversion.viaversion.api.Via;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.plugins.events.ConsoleCommandEvent;
import net.raphimc.viaproxy.protocolhack.viaproxy.ConsoleCommandSender;
import net.raphimc.viaproxy.protocoltranslator.viaproxy.ConsoleCommandSender;
import net.raphimc.viaproxy.util.ArrayHelper;
import net.raphimc.viaproxy.util.logging.Logger;

View file

@ -17,11 +17,11 @@
*/
package net.raphimc.viaproxy.cli.options;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import joptsimple.OptionException;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.plugins.events.PostOptionsParseEvent;
import net.raphimc.viaproxy.plugins.events.PreOptionsParseEvent;
@ -41,7 +41,7 @@ public class Options {
public static SocketAddress BIND_ADDRESS;
public static SocketAddress CONNECT_ADDRESS;
public static VersionEnum PROTOCOL_VERSION;
public static ProtocolVersion PROTOCOL_VERSION;
public static boolean ONLINE_MODE;
public static boolean OPENAUTHMOD_AUTH;
public static boolean BETACRAFT_AUTH;
@ -68,7 +68,7 @@ public class Options {
final OptionSpec<String> bindAddress = parser.acceptsAll(asList("bind_address", "bind_ip", "ba"), "The address the proxy should bind to").withRequiredArg().ofType(String.class).defaultsTo("0.0.0.0:25568");
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<VersionEnum> version = parser.acceptsAll(asList("version", "v"), "The version of the target server").withRequiredArg().withValuesConvertedBy(new VersionEnumConverter()).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");

View file

@ -17,16 +17,16 @@
*/
package net.raphimc.viaproxy.cli.options;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import joptsimple.ValueConversionException;
import joptsimple.ValueConverter;
import net.raphimc.vialoader.util.VersionEnum;
public class VersionEnumConverter implements ValueConverter<VersionEnum> {
public class ProtocolVersionConverter implements ValueConverter<ProtocolVersion> {
@Override
public VersionEnum convert(String s) {
final VersionEnum version = VersionEnum.fromProtocolName(s);
if (version == VersionEnum.UNKNOWN) {
public ProtocolVersion convert(String s) {
final ProtocolVersion version = ProtocolVersion.getClosest(s);
if (version == null) {
throw new ValueConversionException("Unable to find version '" + s + "'");
}
@ -34,14 +34,14 @@ public class VersionEnumConverter implements ValueConverter<VersionEnum> {
}
@Override
public Class<VersionEnum> valueType() {
return VersionEnum.class;
public Class<ProtocolVersion> valueType() {
return ProtocolVersion.class;
}
@Override
public String valuePattern() {
StringBuilder s = new StringBuilder();
for (VersionEnum version : VersionEnum.getAllVersions()) {
for (ProtocolVersion version : ProtocolVersion.getProtocols()) {
s.append((s.isEmpty()) ? "" : ", ").append(version.getName());
}
return "[" + s + "]";

View file

@ -29,10 +29,10 @@ import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag;
import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.model.ClassicLevel;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicWorldHeightProvider;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.storage.ClassicLevelStorage;
import net.raphimc.vialoader.util.VersionEnum;
import java.util.ArrayList;
import java.util.BitSet;
@ -45,7 +45,7 @@ public class ClassicWorldHeightInjection {
parentHandler.handle(wrapper);
if (wrapper.isCancelled()) return;
if (VersionEnum.fromUserConnection(wrapper.user()).isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
if (wrapper.user().getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
for (Tag dimension : wrapper.get(Type.NAMED_COMPOUND_TAG, 0).<CompoundTag>get("minecraft:dimension_type").<ListTag>get("value")) {
changeDimensionTagHeight(wrapper.user(), ((CompoundTag) dimension).get("element"));
}
@ -59,7 +59,7 @@ public class ClassicWorldHeightInjection {
parentHandler.handle(wrapper);
if (wrapper.isCancelled()) return;
if (VersionEnum.fromUserConnection(wrapper.user()).isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
if (wrapper.user().getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
changeDimensionTagHeight(wrapper.user(), wrapper.get(Type.NAMED_COMPOUND_TAG, 0));
}
};
@ -70,7 +70,7 @@ public class ClassicWorldHeightInjection {
parentHandler.handle(wrapper);
if (wrapper.isCancelled()) return;
if (VersionEnum.fromUserConnection(wrapper.user()).isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
if (wrapper.user().getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
wrapper.resetReader();
final Chunk chunk = wrapper.read(new ChunkType1_17(16));
wrapper.write(new ChunkType1_17(chunk.getSections().length), chunk);
@ -160,7 +160,7 @@ public class ClassicWorldHeightInjection {
};
return wrapper -> {
if (VersionEnum.fromUserConnection(wrapper.user()).isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
if (wrapper.user().getProtocolInfo().serverProtocolVersion().olderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
classicLightHandler.handle(wrapper);
} else {
parentHandler.handle(wrapper);

View file

@ -1,42 +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;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.lenni0451.reflect.Enums;
import net.lenni0451.reflect.stream.RStream;
import net.raphimc.vialoader.util.VersionEnum;
import java.util.Map;
public class VersionEnumExtension {
private static final ProtocolVersion autoDetect = ProtocolVersion.register(-2, "Auto Detect (1.7+ servers)");
public static final VersionEnum AUTO_DETECT = Enums.newInstance(VersionEnum.class, "AUTO_DETECT", VersionEnum.UNKNOWN.ordinal(), new Class<?>[]{ProtocolVersion.class}, new Object[]{autoDetect});
static {
Enums.addEnumInstance(VersionEnum.class, AUTO_DETECT);
RStream.of(VersionEnum.class).fields().by("VERSION_REGISTRY").<Map<ProtocolVersion, VersionEnum>>get().put(autoDetect, AUTO_DETECT);
VersionEnum.SORTED_VERSIONS.add(AUTO_DETECT);
}
public static void init() {
// calls static initializer
}
}

View file

@ -1,53 +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.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockFace;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.AbstractFenceConnectionHandler;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
@Mixin(value = AbstractFenceConnectionHandler.class, remap = false)
public abstract class MixinAbstractFenceConnectionHandler {
@Shadow
protected abstract boolean connects(BlockFace side, int blockState, boolean pre1_12);
@Shadow
public abstract int getBlockData(UserConnection user, Position position);
/**
* @author RK_01
* @reason Fixes version comparisons
*/
@Overwrite
public byte getStates(UserConnection user, Position position, int blockState) {
byte states = 0;
boolean pre1_12 = VersionEnum.fromUserConnection(user).isOlderThan(VersionEnum.r1_12);
if (this.connects(BlockFace.EAST, this.getBlockData(user, position.getRelative(BlockFace.EAST)), pre1_12)) states |= 1;
if (this.connects(BlockFace.NORTH, this.getBlockData(user, position.getRelative(BlockFace.NORTH)), pre1_12)) states |= 2;
if (this.connects(BlockFace.SOUTH, this.getBlockData(user, position.getRelative(BlockFace.SOUTH)), pre1_12)) states |= 4;
if (this.connects(BlockFace.WEST, this.getBlockData(user, position.getRelative(BlockFace.WEST)), pre1_12)) states |= 8;
return states;
}
}

View file

@ -18,7 +18,7 @@
package net.raphimc.viaproxy.injection.mixins;
import com.viaversion.viaversion.util.Config;
import net.raphimc.viaproxy.protocolhack.ConfigPatcher;
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;

View file

@ -1,49 +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.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.AbstractFenceConnectionHandler;
import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.GlassConnectionHandler;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
@Mixin(value = GlassConnectionHandler.class, remap = false)
public abstract class MixinGlassConnectionHandler extends AbstractFenceConnectionHandler {
protected MixinGlassConnectionHandler(String blockConnections) {
super(blockConnections);
}
/**
* @author RK_01
* @reason Fixes version comparisons
*/
@Overwrite
public byte getStates(UserConnection user, Position position, int blockState) {
byte states = super.getStates(user, position, blockState);
if (states != 0) return states;
ProtocolInfo protocolInfo = user.getProtocolInfo();
return VersionEnum.fromUserConnection(user).isOlderThanOrEqualTo(VersionEnum.r1_8) && protocolInfo.getServerProtocolVersion() != -1 ? 0xF : states;
}
}

View file

@ -24,7 +24,7 @@ import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17;
import com.viaversion.viaversion.protocols.protocol1_18_2to1_18.Protocol1_18_2To1_18;
import com.viaversion.viaversion.protocols.protocol1_18to1_17_1.ClientboundPackets1_18;
import net.raphimc.viaproxy.protocolhack.viaproxy.loading_terrain_fix.SpawnPositionTracker;
import net.raphimc.viaproxy.protocoltranslator.viaproxy.loading_terrain_fix.SpawnPositionTracker;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;

View file

@ -17,9 +17,8 @@
*/
package net.raphimc.viaproxy.injection.mixins;
import com.google.common.collect.ImmutableSet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.VersionRange;
import com.viaversion.viaversion.api.protocol.version.SubVersionRange;
import com.viaversion.viaversion.util.Pair;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
@ -30,35 +29,29 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@Mixin(value = ProtocolVersion.class, remap = false)
public abstract class MixinProtocolVersion {
@Unique
private static Set<String> skips;
@Unique
private static Map<String, Pair<String, VersionRange>> remaps;
private static Map<String, Pair<String, SubVersionRange>> remaps;
@Inject(method = "<clinit>", at = @At("HEAD"))
private static void initMaps(CallbackInfo ci) {
skips = ImmutableSet.of("1.4.6/7", "1.5.1", "1.5.2", "1.6.1", "1.6.2", "1.6.3", "1.6.4");
remaps = new HashMap<>();
remaps.put("1.9.3/4", new Pair<>("1.9.3-1.9.4", null));
remaps.put("1.11.1/2", new Pair<>("1.11.1-1.11.2", null));
remaps.put("1.16.4/5", new Pair<>("1.16.4-1.16.5", null));
remaps.put("1.9.3/1.9.4", new Pair<>("1.9.3-1.9.4", null));
remaps.put("1.11.1/1.11.2", new Pair<>("1.11.1-1.11.2", null));
remaps.put("1.16.4/1.16.5", new Pair<>("1.16.4-1.16.5", null));
remaps.put("1.18/1.18.1", new Pair<>("1.18-1.18.1", null));
remaps.put("1.19.1/2", new Pair<>("1.19.1-1.19.2", null));
remaps.put("1.19.1/1.19.2", new Pair<>("1.19.1-1.19.2", null));
remaps.put("1.20/1.20.1", new Pair<>("1.20-1.20.1", null));
remaps.put("1.20.3/1.20.4", new Pair<>("1.20.3-1.20.4", null));
remaps.put("1.20.5", new Pair<>("24w06a", null));
remaps.put("1.20.5", new Pair<>("24w07a", null));
}
@Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;register(ILjava/lang/String;)Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;"))
private static ProtocolVersion unregisterAndRenameVersions(int version, String name) {
if (skips.contains(name)) return null;
final Pair<String, VersionRange> remapEntry = remaps.get(name);
final Pair<String, SubVersionRange> remapEntry = remaps.get(name);
if (remapEntry != null) {
if (remapEntry.key() != null) name = remapEntry.key();
if (remapEntry.value() != null) {
@ -72,8 +65,7 @@ public abstract class MixinProtocolVersion {
@SuppressWarnings({"UnresolvedMixinReference", "MixinAnnotationTarget", "InvalidInjectorMethodSignature"}) // Optional injection
@Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;register(IILjava/lang/String;)Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;"), require = 0)
private static ProtocolVersion unregisterAndRenameVersions(int version, int snapshotVersion, String name) {
if (skips.contains(name)) return null;
final Pair<String, VersionRange> remapEntry = remaps.get(name);
final Pair<String, SubVersionRange> remapEntry = remaps.get(name);
if (remapEntry != null) {
if (remapEntry.key() != null) name = remapEntry.key();
}
@ -81,10 +73,9 @@ public abstract class MixinProtocolVersion {
return ProtocolVersion.register(version, snapshotVersion, name);
}
@Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;register(ILjava/lang/String;Lcom/viaversion/viaversion/api/protocol/version/VersionRange;)Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;"))
private static ProtocolVersion unregisterAndRenameVersions(int version, String name, VersionRange versionRange) {
if (skips.contains(name)) return null;
final Pair<String, VersionRange> remapEntry = remaps.get(name);
@Redirect(method = "<clinit>", at = @At(value = "INVOKE", target = "Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;register(ILjava/lang/String;Lcom/viaversion/viaversion/api/protocol/version/SubVersionRange;)Lcom/viaversion/viaversion/api/protocol/version/ProtocolVersion;"))
private static ProtocolVersion unregisterAndRenameVersions(int version, String name, SubVersionRange versionRange) {
final Pair<String, SubVersionRange> remapEntry = remaps.get(name);
if (remapEntry != null) {
if (remapEntry.key() != null) name = remapEntry.key();
if (remapEntry.value() != null) versionRange = remapEntry.value();

View file

@ -112,7 +112,7 @@ public class PluginManager {
if (!ViaProxyPlugin.class.isAssignableFrom(mainClass)) {
throw new IllegalStateException("Class '" + mainClass.getName() + "' from '" + file.getName() + "' does not extend ViaProxyPlugin");
}
final Object instance = mainClass.newInstance();
final Object instance = mainClass.getDeclaredConstructor().newInstance();
final ViaProxyPlugin plugin = (ViaProxyPlugin) instance;
plugin.init(loader, yaml);

View file

@ -17,8 +17,8 @@
*/
package net.raphimc.viaproxy.plugins.events;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.channel.Channel;
import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.viaproxy.plugins.events.types.EventCancellable;
import java.net.SocketAddress;
@ -26,13 +26,13 @@ import java.net.SocketAddress;
public class PreConnectEvent extends EventCancellable {
private SocketAddress serverAddress;
private VersionEnum serverVersion;
private final VersionEnum clientVersion;
private ProtocolVersion serverVersion;
private final ProtocolVersion clientVersion;
private final Channel clientChannel;
private String cancelMessage = "§cCould not connect to the backend server! (Server is blacklisted)";
public PreConnectEvent(final SocketAddress serverAddress, final VersionEnum serverVersion, final VersionEnum clientVersion, final Channel clientChannel) {
public PreConnectEvent(final SocketAddress serverAddress, final ProtocolVersion serverVersion, final ProtocolVersion clientVersion, final Channel clientChannel) {
this.serverAddress = serverAddress;
this.serverVersion = serverVersion;
this.clientVersion = clientVersion;
@ -47,15 +47,15 @@ public class PreConnectEvent extends EventCancellable {
this.serverAddress = serverAddress;
}
public VersionEnum getServerVersion() {
public ProtocolVersion getServerVersion() {
return this.serverVersion;
}
public void setServerVersion(final VersionEnum serverVersion) {
public void setServerVersion(final ProtocolVersion serverVersion) {
this.serverVersion = serverVersion;
}
public VersionEnum getClientVersion() {
public ProtocolVersion getClientVersion() {
return this.clientVersion;
}

View file

@ -21,11 +21,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
public class ProtocolHackInitEvent {
public class ProtocolTranslatorInitEvent {
private final List<Supplier<?>> additionalPlatformSuppliers = new ArrayList<>();
public ProtocolHackInitEvent(final Supplier<?>... additionalPlatformSuppliers) {
public ProtocolTranslatorInitEvent(final Supplier<?>... additionalPlatformSuppliers) {
for (final Supplier<?> platformSupplier : additionalPlatformSuppliers) {
this.registerPlatform(platformSupplier);
}

View file

@ -15,7 +15,7 @@
* 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.protocolhack;
package net.raphimc.viaproxy.protocoltranslator;
import com.viaversion.viaversion.util.Config;

View file

@ -15,30 +15,54 @@
* 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.protocolhack;
package net.raphimc.viaproxy.protocoltranslator;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.VersionType;
import net.raphimc.vialoader.ViaLoader;
import net.raphimc.vialoader.impl.platform.ViaAprilFoolsPlatformImpl;
import net.raphimc.vialoader.impl.platform.ViaBackwardsPlatformImpl;
import net.raphimc.vialoader.impl.platform.ViaBedrockPlatformImpl;
import net.raphimc.vialoader.impl.platform.ViaRewindPlatformImpl;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.plugins.events.ProtocolHackInitEvent;
import net.raphimc.viaproxy.protocolhack.impl.ViaProxyVLLoader;
import net.raphimc.viaproxy.protocolhack.impl.ViaProxyViaLegacyPlatformImpl;
import net.raphimc.viaproxy.protocolhack.impl.ViaProxyViaVersionPlatformImpl;
import net.raphimc.viaproxy.plugins.events.ProtocolTranslatorInitEvent;
import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyVLLoader;
import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyViaLegacyPlatformImpl;
import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyViaVersionPlatformImpl;
import java.io.File;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
public class ProtocolHack {
public class ProtocolTranslator {
public static final ProtocolVersion AUTO_DETECT_PROTOCOL = new ProtocolVersion(VersionType.SPECIAL, -2, -1, "Auto Detect (1.7+ servers)", null) {
@Override
protected Comparator<ProtocolVersion> customComparator() {
return (o1, o2) -> {
if (o1 == AUTO_DETECT_PROTOCOL) {
return -1;
} else if (o2 == AUTO_DETECT_PROTOCOL) {
return 1;
} else {
return 0;
}
};
}
@Override
public boolean isKnown() {
return false;
}
};
public static void init() {
patchConfigs();
final Supplier<?>[] platformSuppliers = ViaProxy.EVENT_MANAGER.call(new ProtocolHackInitEvent(ViaBackwardsPlatformImpl::new, ViaRewindPlatformImpl::new, ViaProxyViaLegacyPlatformImpl::new, ViaAprilFoolsPlatformImpl::new, ViaBedrockPlatformImpl::new)).getPlatformSuppliers().toArray(new Supplier[0]);
final Supplier<?>[] platformSuppliers = ViaProxy.EVENT_MANAGER.call(new ProtocolTranslatorInitEvent(ViaBackwardsPlatformImpl::new, ViaRewindPlatformImpl::new, ViaProxyViaLegacyPlatformImpl::new, ViaAprilFoolsPlatformImpl::new, ViaBedrockPlatformImpl::new)).getPlatformSuppliers().toArray(new Supplier[0]);
ViaLoader.init(new ViaProxyViaVersionPlatformImpl(), new ViaProxyVLLoader(), null, null, platformSuppliers);
ProtocolVersion.register(AUTO_DETECT_PROTOCOL);
}
private static void patchConfigs() {

View file

@ -15,7 +15,7 @@
* 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.protocolhack.impl;
package net.raphimc.viaproxy.protocoltranslator.impl;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.version.VersionProvider;
@ -32,7 +32,7 @@ import net.raphimc.vialegacy.protocols.release.protocol1_8to1_7_6_10.providers.G
import net.raphimc.vialoader.impl.viaversion.VLLoader;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.plugins.events.ViaLoadingEvent;
import net.raphimc.viaproxy.protocolhack.providers.*;
import net.raphimc.viaproxy.protocoltranslator.providers.*;
public class ViaProxyVLLoader extends VLLoader {

View file

@ -15,17 +15,17 @@
* 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.protocolhack.impl;
package net.raphimc.viaproxy.protocoltranslator.impl;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.channel.ChannelHandler;
import net.raphimc.netminecraft.constants.MCPipeline;
import net.raphimc.vialoader.netty.VLPipeline;
import net.raphimc.vialoader.util.VersionEnum;
public class ViaProxyVLPipeline extends VLPipeline {
public ViaProxyVLPipeline(UserConnection user, VersionEnum version) {
public ViaProxyVLPipeline(UserConnection user, ProtocolVersion version) {
super(user, version);
}

View file

@ -15,7 +15,7 @@
* 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.protocolhack.impl;
package net.raphimc.viaproxy.protocoltranslator.impl;
import com.viaversion.viaversion.api.connection.UserConnection;
import io.netty.channel.ChannelHandlerContext;
@ -35,7 +35,7 @@ public class ViaProxyViaCodec extends ViaCodec {
try {
super.channelRead(ctx, msg);
} catch (Throwable e) {
Logger.LOGGER.error("ProtocolHack packet translation error occurred", e);
Logger.LOGGER.error("ProtocolTranslator packet translation error occurred", e);
}
} else {
super.channelRead(ctx, msg);

View file

@ -15,7 +15,7 @@
* 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.protocolhack.impl;
package net.raphimc.viaproxy.protocoltranslator.impl;
import net.raphimc.vialoader.impl.platform.ViaLegacyPlatformImpl;
import net.raphimc.viaproxy.ViaProxy;

View file

@ -15,7 +15,7 @@
* 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.protocolhack.impl;
package net.raphimc.viaproxy.protocoltranslator.impl;
import com.viaversion.viaversion.libs.gson.JsonArray;
import com.viaversion.viaversion.libs.gson.JsonObject;

View file

@ -15,7 +15,7 @@
* 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.protocolhack.providers;
package net.raphimc.viaproxy.protocoltranslator.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import net.raphimc.vialegacy.ViaLegacy;

View file

@ -15,7 +15,7 @@
* 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.protocolhack.providers;
package net.raphimc.viaproxy.protocoltranslator.providers;
import com.google.common.hash.Hashing;
import com.google.common.io.Resources;

View file

@ -15,18 +15,17 @@
* 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.protocolhack.providers;
package net.raphimc.viaproxy.protocoltranslator.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.providers.ClassicWorldHeightProvider;
import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
public class ViaProxyClassicWorldHeightProvider extends ClassicWorldHeightProvider {
@Override
public short getMaxChunkSectionCount(UserConnection user) {
if (ProxyConnection.fromUserConnection(user).getClientVersion().isNewerThanOrEqualTo(VersionEnum.r1_17)) {
if (user.getProtocolInfo().protocolVersion().newerThanOrEqualTo(ProtocolVersion.v1_17)) {
return 64;
}
return 16;

View file

@ -15,7 +15,7 @@
* 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.protocolhack.providers;
package net.raphimc.viaproxy.protocoltranslator.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.CompressionProvider;

View file

@ -15,7 +15,7 @@
* 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.protocolhack.providers;
package net.raphimc.viaproxy.protocoltranslator.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.providers.EncryptionProvider;

View file

@ -15,7 +15,7 @@
* 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.protocolhack.providers;
package net.raphimc.viaproxy.protocoltranslator.providers;
import com.mojang.authlib.Agent;
import com.mojang.authlib.ProfileLookupCallback;

View file

@ -15,7 +15,7 @@
* 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.protocolhack.providers;
package net.raphimc.viaproxy.protocoltranslator.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.item.Item;

View file

@ -15,7 +15,7 @@
* 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.protocolhack.providers;
package net.raphimc.viaproxy.protocoltranslator.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import io.netty.channel.Channel;

View file

@ -15,7 +15,7 @@
* 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.protocolhack.providers;
package net.raphimc.viaproxy.protocoltranslator.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.providers.OldAuthProvider;

View file

@ -15,7 +15,7 @@
* 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.protocolhack.providers;
package net.raphimc.viaproxy.protocoltranslator.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import net.raphimc.viabedrock.protocol.providers.TransferProvider;

View file

@ -15,18 +15,22 @@
* 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.protocolhack.providers;
package net.raphimc.viaproxy.protocoltranslator.providers;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.protocols.base.BaseVersionProvider;
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
public class ViaProxyVersionProvider extends BaseVersionProvider {
@Override
public int getClosestServerProtocol(UserConnection connection) throws Exception {
if (connection.isClientSide()) return ProxyConnection.fromUserConnection(connection).getServerVersion().getVersion();
return super.getClosestServerProtocol(connection);
public ProtocolVersion getClosestServerProtocol(UserConnection connection) throws Exception {
if (connection.isClientSide()) {
return ProxyConnection.fromUserConnection(connection).getServerVersion();
} else {
return super.getClosestServerProtocol(connection);
}
}
}

View file

@ -15,7 +15,7 @@
* 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.protocolhack.viaproxy;
package net.raphimc.viaproxy.protocoltranslator.viaproxy;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.command.ViaCommandSender;

View file

@ -15,7 +15,7 @@
* 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.protocolhack.viaproxy.loading_terrain_fix;
package net.raphimc.viaproxy.protocoltranslator.viaproxy.loading_terrain_fix;
import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;

View file

@ -27,14 +27,14 @@ import net.raphimc.netminecraft.constants.ConnectionState;
import net.raphimc.netminecraft.constants.IntendedState;
import net.raphimc.netminecraft.packet.IPacket;
import net.raphimc.netminecraft.packet.impl.handshake.C2SHandshakePacket;
import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.cli.options.Options;
import net.raphimc.viaproxy.injection.VersionEnumExtension;
import net.raphimc.viaproxy.plugins.events.ConnectEvent;
import net.raphimc.viaproxy.plugins.events.PreConnectEvent;
import net.raphimc.viaproxy.plugins.events.Proxy2ServerHandlerCreationEvent;
import net.raphimc.viaproxy.plugins.events.ProxySessionCreationEvent;
import net.raphimc.viaproxy.protocoltranslator.ProtocolTranslator;
import net.raphimc.viaproxy.proxy.packethandler.*;
import net.raphimc.viaproxy.proxy.proxy2server.Proxy2ServerChannelInitializer;
import net.raphimc.viaproxy.proxy.proxy2server.Proxy2ServerHandler;
@ -105,7 +105,7 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
}
private void handleHandshake(final C2SHandshakePacket packet) {
final VersionEnum clientVersion = VersionEnum.fromProtocolVersion(ProtocolVersion.getProtocol(packet.protocolVersion));
final ProtocolVersion clientVersion = ProtocolVersion.getProtocol(packet.protocolVersion);
if (packet.intendedState == null) {
throw CloseAndReturn.INSTANCE;
@ -114,21 +114,21 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
this.proxyConnection.setClientVersion(clientVersion);
this.proxyConnection.setC2pConnectionState(packet.intendedState.getConnectionState());
if (clientVersion == VersionEnum.UNKNOWN || !VersionEnum.OFFICIAL_SUPPORTED_PROTOCOLS.contains(clientVersion)) {
if (!clientVersion.isKnown()) {
this.proxyConnection.kickClient("§cYour client version is not supported by ViaProxy!");
}
final String[] handshakeParts = packet.address.split("\0");
SocketAddress serverAddress = Options.CONNECT_ADDRESS;
VersionEnum serverVersion = Options.PROTOCOL_VERSION;
ProtocolVersion serverVersion = Options.PROTOCOL_VERSION;
String classicMpPass = Options.CLASSIC_MP_PASS;
if (Options.INTERNAL_SRV_MODE) {
final ArrayHelper arrayHelper = ArrayHelper.instanceOf(handshakeParts[0].split("\7"));
final String versionString = arrayHelper.get(1);
serverVersion = VersionEnum.fromProtocolName(versionString);
if (serverVersion == VersionEnum.UNKNOWN) throw CloseAndReturn.INSTANCE;
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);
@ -145,11 +145,11 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
throw CloseAndReturn.INSTANCE;
}
final String versionString = arrayHelper.get(arrayHelper.getLength() - 1);
serverVersion = VersionEnum.fromProtocolName(versionString);
if (serverVersion == VersionEnum.UNKNOWN) {
serverVersion = VersionEnum.fromProtocolName(versionString.replace("-", " "));
serverVersion = ProtocolVersion.getClosest(versionString);
if (serverVersion == null) {
serverVersion = ProtocolVersion.getClosest(versionString.replace("-", " "));
}
if (serverVersion == VersionEnum.UNKNOWN) throw CloseAndReturn.INSTANCE;
if (serverVersion == null) throw CloseAndReturn.INSTANCE;
final String connectIP = arrayHelper.getAsString(0, arrayHelper.getLength() - 3, "_");
final int connectPort = arrayHelper.getInteger(arrayHelper.getLength() - 2);
serverAddress = AddressUtil.parse(connectIP + ":" + connectPort, serverVersion);
@ -172,10 +172,10 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
final UserOptions userOptions = new UserOptions(classicMpPass, Options.MC_ACCOUNT);
ChannelUtil.disableAutoRead(this.proxyConnection.getC2P());
if (packet.intendedState.getConnectionState() == ConnectionState.LOGIN && serverVersion.equals(VersionEnumExtension.AUTO_DETECT)) {
if (packet.intendedState.getConnectionState() == ConnectionState.LOGIN && serverVersion.equals(ProtocolTranslator.AUTO_DETECT_PROTOCOL)) {
SocketAddress finalServerAddress = serverAddress;
CompletableFuture.runAsync(() -> {
final VersionEnum detectedVersion = ProtocolVersionDetector.get(finalServerAddress, clientVersion);
final ProtocolVersion detectedVersion = ProtocolVersionDetector.get(finalServerAddress, clientVersion);
this.connect(finalServerAddress, detectedVersion, clientVersion, packet.intendedState, userOptions, handshakeParts);
}).exceptionally(t -> {
if (t instanceof ConnectException || t instanceof UnresolvedAddressException) {
@ -190,10 +190,10 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
}
}
private void connect(final SocketAddress serverAddress, final VersionEnum serverVersion, final VersionEnum clientVersion, final IntendedState intendedState, final UserOptions userOptions, final String[] handshakeParts) {
private void connect(final SocketAddress serverAddress, final ProtocolVersion serverVersion, final ProtocolVersion clientVersion, final IntendedState intendedState, final UserOptions userOptions, final String[] handshakeParts) {
final Supplier<ChannelHandler> handlerSupplier = () -> ViaProxy.EVENT_MANAGER.call(new Proxy2ServerHandlerCreationEvent(new Proxy2ServerHandler(), false)).getHandler();
final ProxyConnection proxyConnection;
if (serverVersion.equals(VersionEnum.bedrockLatest)) {
if (serverVersion.equals(BedrockProtocolVersion.bedrockLatest)) {
proxyConnection = new BedrockProxyConnection(handlerSupplier, Proxy2ServerChannelInitializer::new, this.proxyConnection.getC2P());
} else {
proxyConnection = new ProxyConnection(handlerSupplier, Proxy2ServerChannelInitializer::new, this.proxyConnection.getC2P());
@ -207,13 +207,13 @@ public class Client2ProxyHandler extends SimpleChannelInboundHandler<IPacket> {
this.proxyConnection.getPacketHandlers().add(new CustomPayloadPacketHandler(this.proxyConnection));
this.proxyConnection.getPacketHandlers().add(new CompressionPacketHandler(this.proxyConnection));
this.proxyConnection.getPacketHandlers().add(new LoginPacketHandler(this.proxyConnection));
if (clientVersion.isNewerThanOrEqualTo(VersionEnum.r1_20_5)) {
if (clientVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_5)) {
this.proxyConnection.getPacketHandlers().add(new TransferPacketHandler(this.proxyConnection));
}
if (clientVersion.isNewerThanOrEqualTo(VersionEnum.r1_20_2) || serverVersion.isNewerThanOrEqualTo(VersionEnum.r1_20_2)) {
if (clientVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_2) || serverVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_2)) {
this.proxyConnection.getPacketHandlers().add(new ConfigurationPacketHandler(this.proxyConnection));
}
if (clientVersion.isNewerThanOrEqualTo(VersionEnum.r1_19_3) && serverVersion.isNewerThanOrEqualTo(VersionEnum.r1_19_3)) {
if (clientVersion.newerThanOrEqualTo(ProtocolVersion.v1_19_3) && serverVersion.newerThanOrEqualTo(ProtocolVersion.v1_19_3)) {
this.proxyConnection.getPacketHandlers().add(new ChatSignaturePacketHandler(this.proxyConnection));
}
this.proxyConnection.getPacketHandlers().add(new ResourcePackPacketHandler(this.proxyConnection));

View file

@ -23,6 +23,7 @@ import com.viaversion.viaversion.api.minecraft.ProfileKey;
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_0;
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_1;
import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19_3;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.raphimc.minecraftauth.step.bedrock.StepMCChain;
@ -31,8 +32,8 @@ import net.raphimc.netminecraft.packet.PacketTypes;
import net.raphimc.netminecraft.packet.impl.login.C2SLoginHelloPacket1_19_3;
import net.raphimc.netminecraft.packet.impl.login.C2SLoginHelloPacket1_20_2;
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.vialoader.util.VersionEnum;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.cli.options.Options;
import net.raphimc.viaproxy.plugins.events.FillPlayerDataEvent;
@ -64,7 +65,7 @@ public class ExternalInterface {
proxyConnection.setGameProfile(account.getGameProfile());
final UserConnection user = proxyConnection.getUserConnection();
if (Options.CHAT_SIGNING && proxyConnection.getServerVersion().isNewerThanOrEqualTo(VersionEnum.r1_19) && account instanceof MicrosoftAccount microsoftAccount) {
if (Options.CHAT_SIGNING && 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();
@ -75,7 +76,7 @@ public class ExternalInterface {
final UUID uuid = proxyConnection.getGameProfile().getId();
byte[] loginHelloKeySignature = keySignature;
if (proxyConnection.getClientVersion().equals(VersionEnum.r1_19)) {
if (proxyConnection.getClientVersion().equals(ProtocolVersion.v1_19)) {
loginHelloKeySignature = playerCertificates.getLegacyPublicKeySignature();
}
proxyConnection.setLoginHelloPacket(new C2SLoginHelloPacket1_20_2(proxyConnection.getGameProfile().getName(), expiresAt, publicKey, loginHelloKeySignature, proxyConnection.getGameProfile().getId()));
@ -83,7 +84,7 @@ public class ExternalInterface {
user.put(new ChatSession1_19_0(uuid, privateKey, new ProfileKey(expiresAtMillis, publicKeyBytes, playerCertificates.getLegacyPublicKeySignature())));
user.put(new ChatSession1_19_1(uuid, privateKey, new ProfileKey(expiresAtMillis, publicKeyBytes, keySignature)));
user.put(new ChatSession1_19_3(uuid, privateKey, new ProfileKey(expiresAtMillis, publicKeyBytes, keySignature)));
} else if (proxyConnection.getServerVersion().equals(VersionEnum.bedrockLatest) && account instanceof BedrockAccount bedrockAccount) {
} else if (proxyConnection.getServerVersion().equals(BedrockProtocolVersion.bedrockLatest) && account instanceof BedrockAccount bedrockAccount) {
final StepMCChain.MCChain mcChain = bedrockAccount.getMcChain();
final UUID deviceId = mcChain.getXblXsts().getInitialXblSession().getXblDeviceToken().getId();

View file

@ -17,6 +17,7 @@
*/
package net.raphimc.viaproxy.proxy.packethandler;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
@ -28,7 +29,6 @@ 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.vialoader.util.VersionEnum;
import net.raphimc.viaproxy.cli.options.Options;
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
import net.raphimc.viaproxy.proxy.util.ChannelUtil;
@ -57,7 +57,7 @@ public class CompressionPacketHandler extends PacketHandler {
return false;
}
} else if (packet instanceof S2CLoginSuccessPacket1_7) {
if (this.proxyConnection.getClientVersion().isNewerThanOrEqualTo(VersionEnum.r1_8)) {
if (this.proxyConnection.getClientVersion().newerThanOrEqualTo(ProtocolVersion.v1_8)) {
if (Options.COMPRESSION_THRESHOLD > -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 -> {

View file

@ -17,6 +17,7 @@
*/
package net.raphimc.viaproxy.proxy.packethandler;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelFutureListener;
@ -27,7 +28,6 @@ import net.raphimc.netminecraft.packet.PacketTypes;
import net.raphimc.netminecraft.packet.UnknownPacket;
import net.raphimc.netminecraft.packet.impl.login.C2SLoginCustomPayloadPacket;
import net.raphimc.netminecraft.packet.impl.login.C2SLoginKeyPacket1_7;
import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.viaproxy.proxy.external_interface.OpenAuthModConstants;
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
@ -59,7 +59,7 @@ public class CustomPayloadPacketHandler extends PacketHandler {
return false;
}
} else if (packet instanceof C2SLoginKeyPacket1_7 loginKeyPacket) {
if (this.proxyConnection.getClientVersion().isOlderThanOrEqualTo(VersionEnum.r1_12_2) && new String(loginKeyPacket.encryptedNonce, StandardCharsets.UTF_8).equals(OpenAuthModConstants.DATA_CHANNEL)) { // 1.8-1.12.2 OpenAuthMod response handling
if (this.proxyConnection.getClientVersion().olderThanOrEqualTo(ProtocolVersion.v1_12_2) && new String(loginKeyPacket.encryptedNonce, StandardCharsets.UTF_8).equals(OpenAuthModConstants.DATA_CHANNEL)) { // 1.8-1.12.2 OpenAuthMod response handling
final ByteBuf byteBuf = Unpooled.wrappedBuffer(loginKeyPacket.encryptedSecretKey);
this.proxyConnection.handleCustomPayload(PacketTypes.readVarInt(byteBuf), byteBuf);
return false;

View file

@ -18,6 +18,7 @@
package net.raphimc.viaproxy.proxy.packethandler;
import com.mojang.authlib.GameProfile;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.channel.ChannelFutureListener;
import net.raphimc.netminecraft.constants.ConnectionState;
import net.raphimc.netminecraft.constants.MCPipeline;
@ -25,8 +26,8 @@ import net.raphimc.netminecraft.netty.crypto.AESEncryption;
import net.raphimc.netminecraft.netty.crypto.CryptUtil;
import net.raphimc.netminecraft.packet.IPacket;
import net.raphimc.netminecraft.packet.impl.login.*;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.vialegacy.protocols.release.protocol1_7_2_5to1_6_4.storage.ProtocolMetadataStorage;
import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.cli.ConsoleFormatter;
import net.raphimc.viaproxy.cli.options.Options;
@ -149,7 +150,7 @@ public class LoginPacketHandler extends PacketHandler {
final String serverHash = new BigInteger(CryptUtil.computeServerIdHash(loginKeyPacket.serverId, publicKey, secretKey)).toString(16);
boolean auth = true;
if (this.proxyConnection.getServerVersion().isOlderThanOrEqualTo(VersionEnum.r1_6_4)) {
if (this.proxyConnection.getServerVersion().olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)) {
auth = this.proxyConnection.getUserConnection().get(ProtocolMetadataStorage.class).authenticate;
}
if (auth) {
@ -160,12 +161,12 @@ public class LoginPacketHandler extends PacketHandler {
final byte[] encryptedNonce = CryptUtil.encryptData(publicKey, loginKeyPacket.nonce);
final C2SLoginKeyPacket1_19_3 loginKey = new C2SLoginKeyPacket1_19_3(encryptedSecretKey, encryptedNonce);
if (this.proxyConnection.getServerVersion().isNewerThanOrEqualTo(VersionEnum.r1_19) && this.proxyConnection.getLoginHelloPacket() instanceof C2SLoginHelloPacket1_19 && ((C2SLoginHelloPacket1_19) this.proxyConnection.getLoginHelloPacket()).key != null) {
if (this.proxyConnection.getServerVersion().newerThanOrEqualTo(ProtocolVersion.v1_19) && this.proxyConnection.getLoginHelloPacket() instanceof C2SLoginHelloPacket1_19 && ((C2SLoginHelloPacket1_19) this.proxyConnection.getLoginHelloPacket()).key != null) {
ExternalInterface.signNonce(loginKeyPacket.nonce, loginKey, this.proxyConnection);
}
this.proxyConnection.getChannel().writeAndFlush(loginKey).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
if (this.proxyConnection.getServerVersion().isNewerThanOrEqualTo(VersionEnum.r1_7_2tor1_7_5)) {
if (this.proxyConnection.getServerVersion().newerThanOrEqualTo(ProtocolVersion.v1_7_2)) {
this.proxyConnection.getChannel().attr(MCPipeline.ENCRYPTION_ATTRIBUTE_KEY).set(new AESEncryption(secretKey));
} else {
this.proxyConnection.setKeyForPreNettyEncryption(secretKey);
@ -173,7 +174,7 @@ public class LoginPacketHandler extends PacketHandler {
return false;
} else if (packet instanceof S2CLoginSuccessPacket1_7 loginSuccessPacket) {
final ConnectionState nextState = this.proxyConnection.getClientVersion().isNewerThanOrEqualTo(VersionEnum.r1_20_2) ? ConnectionState.CONFIGURATION : ConnectionState.PLAY;
final ConnectionState nextState = this.proxyConnection.getClientVersion().newerThanOrEqualTo(ProtocolVersion.v1_20_2) ? ConnectionState.CONFIGURATION : ConnectionState.PLAY;
this.proxyConnection.setGameProfile(new GameProfile(loginSuccessPacket.uuid, loginSuccessPacket.name));
Logger.u_info("session", this.proxyConnection.getC2P().remoteAddress(), this.proxyConnection.getGameProfile(), "Connected successfully! Switching to " + nextState + " state");

View file

@ -18,6 +18,7 @@
package net.raphimc.viaproxy.proxy.packethandler;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.libs.gson.JsonElement;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@ -27,7 +28,6 @@ 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.vialoader.util.VersionEnum;
import net.raphimc.viaproxy.cli.options.Options;
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
@ -63,12 +63,12 @@ public class ResourcePackPacketHandler extends PacketHandler {
private void sendResourcePack() {
if (Options.RESOURCE_PACK_URL != null) {
this.proxyConnection.getChannel().eventLoop().schedule(() -> {
if (this.proxyConnection.getClientVersion().isNewerThanOrEqualTo(VersionEnum.r1_8)) {
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, ""); // hash
if (this.proxyConnection.getClientVersion().isNewerThanOrEqualTo(VersionEnum.r1_17)) {
if (this.proxyConnection.getClientVersion().newerThanOrEqualTo(ProtocolVersion.v1_17)) {
resourcePackPacket.writeBoolean(Via.getConfig().isForcedUse1_17ResourcePack()); // required
final JsonElement promptMessage = Via.getConfig().get1_17ResourcePackPrompt();
if (promptMessage != null) {
@ -79,7 +79,7 @@ public class ResourcePackPacketHandler extends PacketHandler {
}
}
this.proxyConnection.getC2P().writeAndFlush(resourcePackPacket).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
} else if (this.proxyConnection.getClientVersion().isNewerThanOrEqualTo(VersionEnum.r1_7_2tor1_7_5)) {
} else if (this.proxyConnection.getClientVersion().newerThanOrEqualTo(ProtocolVersion.v1_7_2)) {
final byte[] data = Options.RESOURCE_PACK_URL.getBytes(StandardCharsets.UTF_8);
final ByteBuf customPayloadPacket = Unpooled.buffer();

View file

@ -31,13 +31,13 @@ import net.raphimc.netminecraft.constants.MCPipeline;
import net.raphimc.netminecraft.netty.codec.NoReadFlowControlHandler;
import net.raphimc.netminecraft.netty.connection.MinecraftChannelInitializer;
import net.raphimc.netminecraft.packet.registry.PacketRegistryUtil;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import net.raphimc.vialoader.netty.VLPipeline;
import net.raphimc.vialoader.util.VersionEnum;
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.protocolhack.impl.ViaProxyVLPipeline;
import net.raphimc.viaproxy.protocoltranslator.impl.ViaProxyVLPipeline;
import net.raphimc.viaproxy.proxy.session.ProxyConnection;
import java.net.InetSocketAddress;
@ -67,7 +67,7 @@ public class Proxy2ServerChannelInitializer extends MinecraftChannelInitializer
new ProtocolPipelineImpl(user);
proxyConnection.setUserConnection(user);
if (Options.PROXY_URL != null && !proxyConnection.getServerVersion().equals(VersionEnum.bedrockLatest)) {
if (Options.PROXY_URL != null && !proxyConnection.getServerVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
channel.pipeline().addLast(VIAPROXY_PROXY_HANDLER_NAME, this.getProxyHandler());
}
if (Options.SERVER_HAPROXY_PROTOCOL) {
@ -79,7 +79,7 @@ public class Proxy2ServerChannelInitializer extends MinecraftChannelInitializer
channel.pipeline().addLast(new ViaProxyVLPipeline(user, proxyConnection.getServerVersion()));
channel.pipeline().addAfter(VLPipeline.VIA_CODEC_NAME, "via-" + MCPipeline.FLOW_CONTROL_HANDLER_NAME, new NoReadFlowControlHandler());
if (proxyConnection.getServerVersion().equals(VersionEnum.bedrockLatest)) {
if (proxyConnection.getServerVersion().equals(BedrockProtocolVersion.bedrockLatest)) {
channel.pipeline().remove(MCPipeline.COMPRESSION_HANDLER_NAME);
channel.pipeline().remove(MCPipeline.ENCRYPTION_HANDLER_NAME);
}

View file

@ -17,6 +17,7 @@
*/
package net.raphimc.viaproxy.proxy.session;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.*;
import io.netty.channel.socket.DatagramChannel;
@ -27,7 +28,6 @@ import net.raphimc.netminecraft.util.ChannelType;
import net.raphimc.viabedrock.protocol.data.ProtocolConstants;
import net.raphimc.vialoader.netty.VLPipeline;
import net.raphimc.vialoader.netty.viabedrock.PingEncapsulationCodec;
import net.raphimc.vialoader.util.VersionEnum;
import org.cloudburstmc.netty.channel.raknet.RakChannelFactory;
import org.cloudburstmc.netty.channel.raknet.config.RakChannelOption;
@ -66,7 +66,7 @@ public class BedrockProxyConnection extends ProxyConnection {
}
@Override
public ChannelFuture connectToServer(final SocketAddress serverAddress, final VersionEnum targetVersion) {
public ChannelFuture connectToServer(final SocketAddress serverAddress, final ProtocolVersion targetVersion) {
if (!(serverAddress instanceof InetSocketAddress)) {
throw new IllegalArgumentException("Server address must be an InetSocketAddress");
}

View file

@ -19,6 +19,7 @@ package net.raphimc.viaproxy.proxy.session;
import com.mojang.authlib.GameProfile;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
@ -26,7 +27,6 @@ import io.netty.channel.ChannelFuture;
import net.raphimc.netminecraft.constants.ConnectionState;
import net.raphimc.netminecraft.packet.impl.login.C2SLoginHelloPacket1_7;
import net.raphimc.netminecraft.util.ChannelType;
import net.raphimc.vialoader.util.VersionEnum;
import java.net.SocketAddress;
import java.security.Key;
@ -44,7 +44,7 @@ public class DummyProxyConnection extends ProxyConnection {
}
@Override
public ChannelFuture connectToServer(SocketAddress serverAddress, VersionEnum targetVersion) {
public ChannelFuture connectToServer(SocketAddress serverAddress, ProtocolVersion targetVersion) {
throw new UnsupportedOperationException();
}
@ -54,7 +54,7 @@ public class DummyProxyConnection extends ProxyConnection {
}
@Override
public VersionEnum getServerVersion() {
public ProtocolVersion getServerVersion() {
throw new UnsupportedOperationException();
}

View file

@ -19,6 +19,7 @@ package net.raphimc.viaproxy.proxy.session;
import com.mojang.authlib.GameProfile;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.libs.gson.JsonObject;
import com.viaversion.viaversion.libs.gson.JsonPrimitive;
import io.netty.bootstrap.Bootstrap;
@ -43,7 +44,6 @@ import net.raphimc.netminecraft.packet.impl.login.S2CLoginDisconnectPacket1_20_3
import net.raphimc.netminecraft.packet.impl.status.S2CStatusResponsePacket;
import net.raphimc.netminecraft.packet.registry.PacketRegistryUtil;
import net.raphimc.netminecraft.util.ChannelType;
import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.viaproxy.cli.ConsoleFormatter;
import net.raphimc.viaproxy.proxy.external_interface.OpenAuthModConstants;
import net.raphimc.viaproxy.proxy.packethandler.PacketHandler;
@ -75,8 +75,8 @@ public class ProxyConnection extends NetClient {
private SocketAddress serverAddress;
private VersionEnum serverVersion;
private VersionEnum clientVersion;
private ProtocolVersion serverVersion;
private ProtocolVersion clientVersion;
private GameProfile gameProfile;
private C2SLoginHelloPacket1_7 loginHelloPacket;
@ -114,7 +114,7 @@ public class ProxyConnection extends NetClient {
super.initialize(channelType, bootstrap);
}
public ChannelFuture connectToServer(final SocketAddress serverAddress, final VersionEnum targetVersion) {
public ChannelFuture connectToServer(final SocketAddress serverAddress, final ProtocolVersion targetVersion) {
this.serverAddress = serverAddress;
this.serverVersion = targetVersion;
return super.connect(serverAddress);
@ -132,15 +132,15 @@ public class ProxyConnection extends NetClient {
return this.serverAddress;
}
public VersionEnum getServerVersion() {
public ProtocolVersion getServerVersion() {
return this.serverVersion;
}
public VersionEnum getClientVersion() {
public ProtocolVersion getClientVersion() {
return this.clientVersion;
}
public void setClientVersion(final VersionEnum clientVersion) {
public void setClientVersion(final ProtocolVersion clientVersion) {
this.clientVersion = clientVersion;
}
@ -246,7 +246,7 @@ public class ProxyConnection extends NetClient {
switch (this.c2pConnectionState) {
case LOGIN:
if (this.clientVersion.isNewerThanOrEqualTo(VersionEnum.r1_13)) {
if (this.clientVersion.newerThanOrEqualTo(ProtocolVersion.v1_13)) {
this.c2p.writeAndFlush(new S2CLoginCustomPayloadPacket(id, channel, PacketTypes.readReadableBytes(data))).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
} else {
final ByteBuf disconnectPacketData = Unpooled.buffer();
@ -291,7 +291,7 @@ public class ProxyConnection extends NetClient {
} else if (this.c2pConnectionState == ConnectionState.CONFIGURATION) {
final ByteBuf disconnectPacket = Unpooled.buffer();
PacketTypes.writeVarInt(disconnectPacket, MCPackets.S2C_CONFIG_DISCONNECT.getId(this.clientVersion.getVersion()));
if (this.clientVersion.isOlderThanOrEqualTo(VersionEnum.r1_20_2)) {
if (this.clientVersion.olderThanOrEqualTo(ProtocolVersion.v1_20_2)) {
PacketTypes.writeString(disconnectPacket, messageToJson(message));
} else {
PacketTypes.writeUnnamedTag(disconnectPacket, messageToNbt(message));
@ -300,7 +300,7 @@ public class ProxyConnection extends NetClient {
} else if (this.c2pConnectionState == ConnectionState.PLAY) {
final ByteBuf disconnectPacket = Unpooled.buffer();
PacketTypes.writeVarInt(disconnectPacket, MCPackets.S2C_DISCONNECT.getId(this.clientVersion.getVersion()));
if (this.clientVersion.isOlderThanOrEqualTo(VersionEnum.r1_20_2)) {
if (this.clientVersion.olderThanOrEqualTo(ProtocolVersion.v1_20_2)) {
PacketTypes.writeString(disconnectPacket, messageToJson(message));
} else {
PacketTypes.writeUnnamedTag(disconnectPacket, messageToNbt(message));

View file

@ -17,11 +17,11 @@
*/
package net.raphimc.viaproxy.proxy.util;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.unix.DomainSocketAddress;
import io.netty.handler.codec.haproxy.*;
import net.raphimc.vialoader.util.VersionEnum;
import java.net.*;
import java.util.ArrayList;
@ -29,7 +29,7 @@ import java.util.List;
public class HAProxyUtil {
public static HAProxyMessage createMessage(final Channel sourceChannel, final Channel targetChannel, final VersionEnum clientVersion) {
public static HAProxyMessage createMessage(final Channel sourceChannel, final Channel targetChannel, final ProtocolVersion clientVersion) {
final List<HAProxyTLV> tlvs = new ArrayList<>();
if (clientVersion != null) {
tlvs.add(new HAProxyTLV((byte) 0xE0, Unpooled.buffer().writeInt(clientVersion.getOriginalVersion())));

View file

@ -19,7 +19,7 @@ package net.raphimc.viaproxy.saves.impl;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import net.raphimc.vialoader.util.VersionEnum;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.raphimc.viaproxy.saves.AbstractSave;
import javax.swing.*;
@ -77,12 +77,14 @@ public class UISave extends AbstractSave {
}
}
public void loadComboBoxVersionEnum(final String key, final JComboBox<VersionEnum> comboBox) {
public void loadComboBoxProtocolVersion(final String key, final JComboBox<ProtocolVersion> comboBox) {
if (this.values.containsKey(key)) {
try {
String value = String.valueOf(this.values.get(key));
VersionEnum version = VersionEnum.valueOf(value);
comboBox.setSelectedItem(version);
String value = this.values.get(key);
ProtocolVersion version = ProtocolVersion.getClosest(value);
if (version != null) {
comboBox.setSelectedItem(version);
}
} catch (Throwable ignored) {
}
}

View file

@ -1,29 +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.tasks;
import net.raphimc.viaproxy.protocolhack.ProtocolHack;
public class LoaderTask implements Runnable {
@Override
public void run() {
ProtocolHack.init();
}
}

View file

@ -17,9 +17,12 @@
*/
package net.raphimc.viaproxy.ui.impl;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.lenni0451.commons.swing.GBC;
import net.lenni0451.lambdaevents.EventHandler;
import net.raphimc.vialoader.util.VersionEnum;
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;
@ -48,7 +51,7 @@ import static net.raphimc.viaproxy.ui.ViaProxyUI.BORDER_PADDING;
public class GeneralTab extends AUITab {
JTextField serverAddress;
JComboBox<VersionEnum> serverVersion;
JComboBox<ProtocolVersion> serverVersion;
JComboBox<String> authMethod;
private JCheckBox betaCraftAuth;
private JLabel stateLabel;
@ -114,11 +117,11 @@ public class GeneralTab extends AUITab {
JLabel serverVersionLabel = new JLabel(I18n.get("tab.general.server_version.label"));
GBC.create(body).grid(0, gridy++).insets(BODY_BLOCK_PADDING, BORDER_PADDING, 0, 0).anchor(GBC.NORTHWEST).add(serverVersionLabel);
this.serverVersion = new JComboBox<>(VersionEnum.SORTED_VERSIONS.toArray(new VersionEnum[0]));
this.serverVersion = new JComboBox<>(ProtocolVersionList.getProtocolsNewToOld().toArray(new ProtocolVersion[0]));
this.serverVersion.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value instanceof VersionEnum version) {
if (value instanceof ProtocolVersion version) {
value = version.getName();
}
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
@ -126,15 +129,15 @@ public class GeneralTab extends AUITab {
});
this.serverVersion.addActionListener(event -> {
if (this.betaCraftAuth == null) return; // This is called when the JComboBox is created (before betaCraftAuth is set)
if (!(this.serverVersion.getSelectedItem() instanceof VersionEnum selectedVersion)) return;
if (selectedVersion.isOlderThanOrEqualTo(VersionEnum.c0_28toc0_30)) {
if (!(this.serverVersion.getSelectedItem() instanceof ProtocolVersion selectedVersion)) return;
if (selectedVersion.olderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
this.betaCraftAuth.setEnabled(true);
} else {
this.betaCraftAuth.setEnabled(false);
this.betaCraftAuth.setSelected(false);
}
});
ViaProxy.getSaveManager().uiSave.loadComboBoxVersionEnum("server_version", this.serverVersion);
ViaProxy.getSaveManager().uiSave.loadComboBoxProtocolVersion("server_version", this.serverVersion);
GBC.create(body).grid(0, gridy++).weightx(1).insets(0, BORDER_PADDING, 0, BORDER_PADDING).fill(GBC.HORIZONTAL).add(this.serverVersion);
}
{
@ -191,8 +194,8 @@ public class GeneralTab extends AUITab {
private void onClose(final UICloseEvent event) {
UISave save = ViaProxy.getSaveManager().uiSave;
save.put("server_address", this.serverAddress.getText());
if (this.serverVersion.getSelectedItem() instanceof VersionEnum version) {
save.put("server_version", version.name());
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()));
@ -221,7 +224,7 @@ public class GeneralTab extends AUITab {
private void start() {
final Object selectedVersion = this.serverVersion.getSelectedItem();
if (!(selectedVersion instanceof VersionEnum)) {
if (!(selectedVersion instanceof ProtocolVersion)) {
this.frame.showError(I18n.get("tab.general.error.no_server_version_selected"));
return;
}
@ -231,7 +234,7 @@ public class GeneralTab extends AUITab {
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>");
}
if (VersionEnum.bedrockLatest.equals(selectedVersion) && ViaProxy.getSaveManager().uiSave.get("notice.bedrock_warning") == null) {
if (selectedVersion.equals(BedrockProtocolVersion.bedrockLatest) && ViaProxy.getSaveManager().uiSave.get("notice.bedrock_warning") == null) {
ViaProxy.getSaveManager().uiSave.put("notice.bedrock_warning", "true");
ViaProxy.getSaveManager().save();
@ -244,7 +247,7 @@ public class GeneralTab extends AUITab {
new Thread(() -> {
String serverAddress = this.serverAddress.getText().trim();
final VersionEnum serverVersion = (VersionEnum) this.serverVersion.getSelectedItem();
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();

View file

@ -18,6 +18,8 @@
package net.raphimc.viaproxy.ui.impl;
import com.google.common.collect.Iterables;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.protocol.version.VersionType;
import net.lenni0451.commons.swing.GBC;
import net.lenni0451.commons.swing.layouts.VerticalLayout;
import net.raphimc.minecraftauth.MinecraftAuth;
@ -26,8 +28,8 @@ import net.raphimc.minecraftauth.service.realms.AbstractRealmsService;
import net.raphimc.minecraftauth.service.realms.BedrockRealmsService;
import net.raphimc.minecraftauth.service.realms.JavaRealmsService;
import net.raphimc.minecraftauth.service.realms.model.RealmsWorld;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import net.raphimc.viabedrock.protocol.data.ProtocolConstants;
import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.viaproxy.ViaProxy;
import net.raphimc.viaproxy.cli.options.Options;
import net.raphimc.viaproxy.saves.impl.accounts.Account;
@ -45,17 +47,19 @@ import java.util.concurrent.CompletableFuture;
public class RealmsTab extends AUITab {
private static final VersionEnum LATEST_JAVA_RELEASE;
private static final VersionEnum LATEST_JAVA_SNAPSHOT;
private static final ProtocolVersion LATEST_JAVA_RELEASE;
private static final ProtocolVersion LATEST_JAVA_SNAPSHOT;
static {
VersionEnum latestVersion = null;
VersionEnum latestSnapshotVersion = null;
for (int i = VersionEnum.OFFICIAL_SUPPORTED_PROTOCOLS.size() - 1; i >= 0; i--) {
VersionEnum version = VersionEnum.OFFICIAL_SUPPORTED_PROTOCOLS.get(i);
if (version.getProtocol().isSnapshot() && latestSnapshotVersion == null) {
ProtocolVersion latestVersion = null;
ProtocolVersion latestSnapshotVersion = null;
final List<ProtocolVersion> supportedVersions = ProtocolVersion.getProtocols();
for (int i = supportedVersions.size() - 1; i >= 0; i--) {
final ProtocolVersion version = supportedVersions.get(i);
if (version.getVersionType() != VersionType.RELEASE) continue;
if (version.isSnapshot() && latestSnapshotVersion == null) {
latestSnapshotVersion = version;
} else if (!version.getProtocol().isSnapshot()) {
} else if (!version.isSnapshot()) {
latestVersion = version;
break;
}
@ -66,7 +70,7 @@ public class RealmsTab extends AUITab {
}
private Account currentAccount = Options.MC_ACCOUNT;
private VersionEnum currentSelectedJavaVersion = LATEST_JAVA_RELEASE;
private ProtocolVersion currentSelectedJavaVersion = LATEST_JAVA_RELEASE;
public RealmsTab(final ViaProxyUI frame) {
super(frame, "realms");
@ -106,7 +110,7 @@ public class RealmsTab extends AUITab {
ViaProxy.getSaveManager().accountsSave.ensureRefreshed(this.currentAccount);
SwingUtilities.invokeLater(() -> {
if (this.currentAccount instanceof MicrosoftAccount account) {
final JavaRealmsService realmsService = new JavaRealmsService(MinecraftAuth.createHttpClient(), Iterables.getLast(this.currentSelectedJavaVersion.getProtocol().getIncludedVersions()), account.getMcProfile());
final JavaRealmsService realmsService = new JavaRealmsService(MinecraftAuth.createHttpClient(), Iterables.getLast(this.currentSelectedJavaVersion.getIncludedVersions()), account.getMcProfile());
this.loadRealms(realmsService, body, statusLabel);
} else if (this.currentAccount instanceof BedrockAccount account) {
final BedrockRealmsService realmsService = new BedrockRealmsService(MinecraftAuth.createHttpClient(), ProtocolConstants.BEDROCK_VERSION_NAME, account.getRealmsXsts());
@ -176,9 +180,9 @@ public class RealmsTab extends AUITab {
JComboBox<String> type = new JComboBox<>();
type.addItem(I18n.get("tab.realms.release"));
type.addItem(I18n.get("tab.realms.snapshot"));
type.setSelectedIndex(this.currentSelectedJavaVersion.getProtocol().isSnapshot() ? 1 : 0);
type.setSelectedIndex(this.currentSelectedJavaVersion.isSnapshot() ? 1 : 0);
type.addActionListener(e -> {
VersionEnum selected = type.getSelectedIndex() == 0 ? LATEST_JAVA_RELEASE : LATEST_JAVA_SNAPSHOT;
ProtocolVersion selected = type.getSelectedIndex() == 0 ? LATEST_JAVA_RELEASE : LATEST_JAVA_SNAPSHOT;
if (selected != this.currentSelectedJavaVersion) {
this.currentSelectedJavaVersion = selected;
this.reinit();
@ -223,7 +227,7 @@ public class RealmsTab extends AUITab {
realmsService.joinWorld(world).thenAccept(address -> SwingUtilities.invokeLater(() -> {
join.setEnabled(true);
join.setText(I18n.get("tab.realms.join"));
this.setServerAddressAndStartViaProxy(address, realmsService instanceof JavaRealmsService ? this.currentSelectedJavaVersion : VersionEnum.bedrockLatest);
this.setServerAddressAndStartViaProxy(address, realmsService instanceof JavaRealmsService ? this.currentSelectedJavaVersion : BedrockProtocolVersion.bedrockLatest);
})).exceptionally(e -> {
final Throwable cause = e.getCause();
SwingUtilities.invokeLater(() -> {
@ -248,7 +252,7 @@ public class RealmsTab extends AUITab {
}
}
private void setServerAddressAndStartViaProxy(final String address, final VersionEnum version) {
private void setServerAddressAndStartViaProxy(final String address, final ProtocolVersion version) {
final GeneralTab generalTab = ViaProxy.getUI().generalTab;
if (generalTab.stateButton.isEnabled()) {
if (!generalTab.stateButton.getText().equals(I18n.get("tab.general.state.start"))) {

View file

@ -18,17 +18,19 @@
package net.raphimc.viaproxy.util;
import com.google.common.net.HostAndPort;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.channel.unix.DomainSocketAddress;
import net.lenni0451.reflect.stream.RStream;
import net.raphimc.netminecraft.util.MinecraftServerAddress;
import net.raphimc.vialoader.util.VersionEnum;
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
public class AddressUtil {
public static SocketAddress parse(final String serverAddress, final VersionEnum version) {
public static SocketAddress parse(final String serverAddress, final ProtocolVersion version) {
if (serverAddress.startsWith("file:///") || serverAddress.startsWith("unix:///")) { // Unix Socket
final String filePath = serverAddress.substring(7);
@ -42,7 +44,7 @@ public class AddressUtil {
port = hostAndPort.getPort();
}
if (version == null || version.isOlderThan(VersionEnum.r1_3_1tor1_3_2) || version.equals(VersionEnum.bedrockLatest)) {
if (version == null || version.olderThan(LegacyProtocolVersion.r1_3_1tor1_3_2) || version.equals(BedrockProtocolVersion.bedrockLatest)) {
return new InetSocketAddress(hostAndPort.getHost(), port);
} else {
return MinecraftServerAddress.ofResolved(hostAndPort.getHost(), port);
@ -60,8 +62,8 @@ public class AddressUtil {
}
}
public static int getDefaultPort(final VersionEnum version) {
if (VersionEnum.bedrockLatest.equals(version)) {
public static int getDefaultPort(final ProtocolVersion version) {
if (version.equals(BedrockProtocolVersion.bedrockLatest)) {
return 19132;
}

View file

@ -21,7 +21,6 @@ import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.lenni0451.mcping.MCPing;
import net.lenni0451.mcping.pings.sockets.impl.factories.SocketChannelSocketFactory;
import net.lenni0451.mcping.responses.MCPingResponse;
import net.raphimc.vialoader.util.VersionEnum;
import java.net.SocketAddress;
@ -29,7 +28,7 @@ public class ProtocolVersionDetector {
private static final int TIMEOUT = 3000;
public static VersionEnum get(final SocketAddress serverAddress, final VersionEnum clientVersion) {
public static ProtocolVersion get(final SocketAddress serverAddress, final ProtocolVersion clientVersion) {
MCPingResponse response = MCPing
.pingModern(clientVersion.getOriginalVersion())
.tcpSocketFactory(new SocketChannelSocketFactory())
@ -50,7 +49,7 @@ public class ProtocolVersionDetector {
.getSync();
if (ProtocolVersion.isRegistered(response.version.protocol)) { // If the protocol is registered, we can use it
return VersionEnum.fromProtocolId(response.version.protocol);
return ProtocolVersion.getProtocol(response.version.protocol);
} else {
throw new RuntimeException("Unsupported protocol version: " + response.version.protocol);
}