mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2025-01-02 18:17:36 +01:00
fix #144 getting native server version, update address parser
This commit is contained in:
parent
b1e5645a2c
commit
84c3421d38
@ -0,0 +1,83 @@
|
||||
package com.viaversion.fabric.common;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
// Based on VIAaaS parser
|
||||
public class AddressParser {
|
||||
public Integer protocol;
|
||||
public String viaSuffix;
|
||||
public String serverAddress;
|
||||
public String viaOptions;
|
||||
|
||||
public AddressParser parse(String address) {
|
||||
return parse(address, ".viafabric");
|
||||
}
|
||||
|
||||
public AddressParser parse(String address, String viaHostName) {
|
||||
address = StringUtils.removeEnd(address, ".");
|
||||
String suffixRemoved = StringUtils.removeEnd(address, viaHostName);
|
||||
|
||||
if (suffixRemoved.equals(address)) {
|
||||
serverAddress = address;
|
||||
return this;
|
||||
}
|
||||
|
||||
boolean stopOptions = false;
|
||||
List<String> optionsParts = new ArrayList<>();
|
||||
List<String> serverParts = new ArrayList<>();
|
||||
|
||||
for (String part : Lists.reverse(Arrays.asList(suffixRemoved.split(Pattern.quote("."))))) {
|
||||
if (!stopOptions && parseOption(part)) {
|
||||
optionsParts.add(part);
|
||||
continue;
|
||||
}
|
||||
stopOptions = true;
|
||||
serverParts.add(part);
|
||||
}
|
||||
|
||||
serverAddress = String.join(".", Lists.reverse(serverParts));
|
||||
viaOptions = String.join(".", Lists.reverse(optionsParts));
|
||||
viaSuffix = viaHostName;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean parseOption(String part) {
|
||||
String option;
|
||||
if (part.length() < 2) {
|
||||
return false;
|
||||
} else if (part.startsWith("_")) {
|
||||
option = String.valueOf(part.charAt(1));
|
||||
} else if (part.charAt(1) == '_') {
|
||||
option = String.valueOf(part.charAt(0));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
String arg = part.substring(2);
|
||||
switch (option) {
|
||||
case "v": {
|
||||
parseProtocol(arg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void parseProtocol(String arg) {
|
||||
protocol = Ints.tryParse(arg);
|
||||
if (protocol == null) {
|
||||
ProtocolVersion ver = ProtocolVersion.getClosest(arg.replace("_", "."));
|
||||
if (ver != null) protocol = ver.getVersion();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
package com.viaversion.fabric.common;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class VFAddressParser {
|
||||
public int protocol = 0;
|
||||
public String viaSuffix = null;
|
||||
public String realAddress = null;
|
||||
|
||||
public VFAddressParser parse(String address) {
|
||||
if (address == null) return null;
|
||||
String[] parts = address.split("\\.");
|
||||
|
||||
boolean foundDomain = false;
|
||||
boolean foundOptions = false;
|
||||
|
||||
StringBuilder ourParts = new StringBuilder();
|
||||
StringBuilder realAddrBuilder = new StringBuilder();
|
||||
|
||||
for (int i = parts.length - 1; i >= 0; i--) {
|
||||
String part = parts[i];
|
||||
boolean realAddrPart = false;
|
||||
if (foundDomain) {
|
||||
if (!foundOptions) {
|
||||
if (part.startsWith("_")) {
|
||||
String arg = part.substring(2);
|
||||
if (part.toLowerCase(Locale.ROOT).startsWith("_v")) {
|
||||
try {
|
||||
protocol = Integer.parseInt(arg);
|
||||
} catch (NumberFormatException e) {
|
||||
ProtocolVersion closest = ProtocolVersion.getClosest(arg.replace("_", "."));
|
||||
if (closest != null) {
|
||||
protocol = closest.getVersion();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foundOptions = true;
|
||||
}
|
||||
}
|
||||
if (foundOptions) {
|
||||
realAddrPart = true;
|
||||
}
|
||||
} else if (part.equalsIgnoreCase("viafabric")) {
|
||||
foundDomain = true;
|
||||
}
|
||||
if (realAddrPart) {
|
||||
realAddrBuilder.insert(0, part + ".");
|
||||
} else {
|
||||
ourParts.insert(0, part + ".");
|
||||
}
|
||||
}
|
||||
|
||||
String realAddr = realAddrBuilder.toString().replaceAll("\\.$", "");
|
||||
String suffix = ourParts.toString().replaceAll("\\.$", "");
|
||||
|
||||
if (realAddr.isEmpty()) {
|
||||
this.realAddress = address;
|
||||
} else {
|
||||
this.realAddress = realAddr;
|
||||
this.viaSuffix = suffix;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ViaFabricAddress{" +
|
||||
"protocol=" + protocol +
|
||||
", viaSuffix='" + viaSuffix + '\'' +
|
||||
", realAddress='" + realAddress + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package com.viaversion.fabric.common.platform;
|
||||
|
||||
import com.viaversion.viaversion.api.platform.providers.Provider;
|
||||
|
||||
public interface NativeVersionProvider extends Provider {
|
||||
int getServerProtocolVersion();
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.common.protocol;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
|
||||
@ -20,7 +20,7 @@ public class HostnameParserProtocol extends AbstractSimpleProtocol {
|
||||
map(Type.STRING, new ValueTransformer<String, String>(Type.STRING) {
|
||||
@Override
|
||||
public String transform(PacketWrapper packetWrapper, String s) {
|
||||
return new VFAddressParser().parse(s).realAddress;
|
||||
return new AddressParser().parse(s).serverAddress;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ package com.viaversion.fabric.common.provider;
|
||||
|
||||
import com.viaversion.fabric.common.platform.FabricViaAPI;
|
||||
import com.viaversion.fabric.common.platform.FabricViaConfig;
|
||||
import com.viaversion.fabric.common.platform.NativeVersionProvider;
|
||||
import com.viaversion.fabric.common.util.JLoggerToLog4j;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.ViaAPI;
|
||||
import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
|
||||
import com.viaversion.viaversion.api.configuration.ViaVersionConfig;
|
||||
@ -110,7 +112,9 @@ public abstract class AbstractFabricPlatform implements ViaPlatform<UUID> {
|
||||
JsonObject contact = new JsonObject();
|
||||
it.getContact().asMap().entrySet().stream()
|
||||
.forEach(c -> contact.addProperty(c.getKey(), c.getValue()));
|
||||
info.add("contact", contact);
|
||||
if (contact.size() != 0) {
|
||||
info.add("contact", contact);
|
||||
}
|
||||
info.addProperty("name", it.getName());
|
||||
|
||||
return info;
|
||||
@ -121,6 +125,10 @@ public abstract class AbstractFabricPlatform implements ViaPlatform<UUID> {
|
||||
}).forEach(mods::add);
|
||||
|
||||
platformSpecific.add("mods", mods);
|
||||
NativeVersionProvider ver = Via.getManager().getProviders().get(NativeVersionProvider.class);
|
||||
if (ver != null) {
|
||||
platformSpecific.addProperty("native version", ver.getServerProtocolVersion());
|
||||
}
|
||||
return platformSpecific;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.viaversion.fabric.common.provider;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import com.viaversion.fabric.common.config.VFConfig;
|
||||
import com.viaversion.fabric.common.platform.NativeVersionProvider;
|
||||
import com.viaversion.fabric.common.util.ProtocolUtils;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.ProtocolInfo;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
@ -66,16 +68,14 @@ public abstract class AbstractFabricVersionProvider extends BaseVersionProvider
|
||||
if (connection.isClientSide()) {
|
||||
ProtocolInfo info = Objects.requireNonNull(connection.getProtocolInfo());
|
||||
|
||||
if (!getConfig().isClientSideEnabled()) {
|
||||
return info.getProtocolVersion();
|
||||
}
|
||||
if (!getConfig().isClientSideEnabled()) return info.getProtocolVersion();
|
||||
|
||||
int serverVer = getConfig().getClientSideVersion();
|
||||
SocketAddress addr = connection.getChannel().remoteAddress();
|
||||
|
||||
if (addr instanceof InetSocketAddress) {
|
||||
int addrVersion = new VFAddressParser().parse(((InetSocketAddress) addr).getHostName()).protocol;
|
||||
if (addrVersion != 0) serverVer = addrVersion;
|
||||
Integer addrVersion = new AddressParser().parse(((InetSocketAddress) addr).getHostName()).protocol;
|
||||
if (addrVersion != null) serverVer = addrVersion;
|
||||
|
||||
try {
|
||||
if (serverVer == -2) {
|
||||
@ -100,6 +100,10 @@ public abstract class AbstractFabricVersionProvider extends BaseVersionProvider
|
||||
|
||||
return serverVer;
|
||||
}
|
||||
NativeVersionProvider natProvider = Via.getManager().getProviders().get(NativeVersionProvider.class);
|
||||
if (natProvider != null) {
|
||||
return natProvider.getServerProtocolVersion();
|
||||
}
|
||||
return super.getClosestServerProtocol(connection);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.mc114.mixin.address.client;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
@ -13,12 +13,12 @@ public class MixinConnectScreenThread {
|
||||
@Redirect(method = "run()V", at = @At(value = "INVOKE",
|
||||
target = "Ljava/net/InetAddress;getByName(Ljava/lang/String;)Ljava/net/InetAddress;"))
|
||||
private InetAddress resolveViaFabricAddr(String address) throws UnknownHostException {
|
||||
VFAddressParser viaAddr = new VFAddressParser().parse(address);
|
||||
AddressParser viaAddr = new AddressParser().parse(address);
|
||||
if (viaAddr.viaSuffix == null) {
|
||||
return InetAddress.getByName(address);
|
||||
}
|
||||
|
||||
InetAddress resolved = InetAddress.getByName(viaAddr.realAddress);
|
||||
InetAddress resolved = InetAddress.getByName(viaAddr.serverAddress);
|
||||
return InetAddress.getByAddress(resolved.getHostName() + "." + viaAddr.viaSuffix, resolved.getAddress());
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.mc114.mixin.address.client;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import net.minecraft.network.ServerAddress;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@ -16,12 +16,12 @@ public abstract class MixinServerAddress {
|
||||
|
||||
@Redirect(method = "parse", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ServerAddress;resolveSrv(Ljava/lang/String;)[Ljava/lang/String;"))
|
||||
private static String[] modifySrvAddr(String address) {
|
||||
VFAddressParser viaAddr = new VFAddressParser().parse(address);
|
||||
AddressParser viaAddr = new AddressParser().parse(address);
|
||||
if (viaAddr.viaSuffix == null) {
|
||||
return resolveSrv(address);
|
||||
}
|
||||
|
||||
String[] resolvedSrv = resolveSrv(viaAddr.realAddress);
|
||||
String[] resolvedSrv = resolveSrv(viaAddr.serverAddress);
|
||||
resolvedSrv[0] = resolvedSrv[0].replaceAll("\\.$", "") + "." + viaAddr.viaSuffix;
|
||||
|
||||
return resolvedSrv;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.mc114.mixin.address.client;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import net.minecraft.client.network.MultiplayerServerListPinger;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@ -14,12 +14,12 @@ public class MixinServerPinger {
|
||||
@Redirect(method = "add", at = @At(value = "INVOKE",
|
||||
target = "Ljava/net/InetAddress;getByName(Ljava/lang/String;)Ljava/net/InetAddress;"))
|
||||
private InetAddress resolveViaFabricAddr(String address) throws UnknownHostException {
|
||||
VFAddressParser viaAddr = new VFAddressParser().parse(address);
|
||||
AddressParser viaAddr = new AddressParser().parse(address);
|
||||
if (viaAddr.viaSuffix == null) {
|
||||
return InetAddress.getByName(address);
|
||||
}
|
||||
|
||||
InetAddress resolved = InetAddress.getByName(viaAddr.realAddress);
|
||||
InetAddress resolved = InetAddress.getByName(viaAddr.serverAddress);
|
||||
return InetAddress.getByAddress(resolved.getHostName() + "." + viaAddr.viaSuffix, resolved.getAddress());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.viaversion.fabric.mc114.platform;
|
||||
|
||||
import com.viaversion.fabric.common.platform.NativeVersionProvider;
|
||||
import net.minecraft.SharedConstants;
|
||||
|
||||
public class FabricNativeVersionProvider implements NativeVersionProvider {
|
||||
@Override
|
||||
public int getServerProtocolVersion() {
|
||||
return SharedConstants.getGameVersion().getProtocolVersion();
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.viaversion.fabric.mc114.platform;
|
||||
|
||||
import com.viaversion.fabric.common.platform.NativeVersionProvider;
|
||||
import com.viaversion.fabric.mc114.providers.VRHandItemProvider;
|
||||
import com.viaversion.fabric.mc114.providers.FabricVersionProvider;
|
||||
import net.fabricmc.api.EnvType;
|
||||
@ -14,6 +15,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTr
|
||||
public class VFLoader implements ViaPlatformLoader {
|
||||
@Override
|
||||
public void load() {
|
||||
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
|
||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
|
||||
Via.getManager().getProviders().use(VersionProvider.class, new FabricVersionProvider());
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.mc114.service;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import com.viaversion.fabric.mc114.ViaFabric;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
@ -114,7 +114,7 @@ public class ProtocolAutoDetector {
|
||||
public static CompletableFuture<ProtocolVersion> detectVersion(InetSocketAddress address) {
|
||||
try {
|
||||
InetSocketAddress real = new InetSocketAddress(InetAddress.getByAddress
|
||||
(new VFAddressParser().parse(address.getHostString()).realAddress,
|
||||
(new AddressParser().parse(address.getHostString()).serverAddress,
|
||||
address.getAddress().getAddress()), address.getPort());
|
||||
return SERVER_VER.get(real);
|
||||
} catch (UnknownHostException | ExecutionException e) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.mc115.mixin.address.client;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
@ -13,12 +13,12 @@ public class MixinConnectScreenThread {
|
||||
@Redirect(method = "run()V", at = @At(value = "INVOKE",
|
||||
target = "Ljava/net/InetAddress;getByName(Ljava/lang/String;)Ljava/net/InetAddress;"))
|
||||
private InetAddress resolveViaFabricAddr(String address) throws UnknownHostException {
|
||||
VFAddressParser viaAddr = new VFAddressParser().parse(address);
|
||||
AddressParser viaAddr = new AddressParser().parse(address);
|
||||
if (viaAddr.viaSuffix == null) {
|
||||
return InetAddress.getByName(address);
|
||||
}
|
||||
|
||||
InetAddress resolved = InetAddress.getByName(viaAddr.realAddress);
|
||||
InetAddress resolved = InetAddress.getByName(viaAddr.serverAddress);
|
||||
return InetAddress.getByAddress(resolved.getHostName() + "." + viaAddr.viaSuffix, resolved.getAddress());
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.mc115.mixin.address.client;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import net.minecraft.network.ServerAddress;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@ -16,12 +16,12 @@ public abstract class MixinServerAddress {
|
||||
|
||||
@Redirect(method = "parse", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ServerAddress;resolveSrv(Ljava/lang/String;)[Ljava/lang/String;"))
|
||||
private static String[] modifySrvAddr(String address) {
|
||||
VFAddressParser viaAddr = new VFAddressParser().parse(address);
|
||||
AddressParser viaAddr = new AddressParser().parse(address);
|
||||
if (viaAddr.viaSuffix == null) {
|
||||
return resolveSrv(address);
|
||||
}
|
||||
|
||||
String[] resolvedSrv = resolveSrv(viaAddr.realAddress);
|
||||
String[] resolvedSrv = resolveSrv(viaAddr.serverAddress);
|
||||
resolvedSrv[0] = resolvedSrv[0].replaceAll("\\.$", "") + "." + viaAddr.viaSuffix;
|
||||
|
||||
return resolvedSrv;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.mc115.mixin.address.client;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import net.minecraft.client.network.MultiplayerServerListPinger;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@ -14,12 +14,12 @@ public class MixinServerPinger {
|
||||
@Redirect(method = "add", at = @At(value = "INVOKE",
|
||||
target = "Ljava/net/InetAddress;getByName(Ljava/lang/String;)Ljava/net/InetAddress;"))
|
||||
private InetAddress resolveViaFabricAddr(String address) throws UnknownHostException {
|
||||
VFAddressParser viaAddr = new VFAddressParser().parse(address);
|
||||
AddressParser viaAddr = new AddressParser().parse(address);
|
||||
if (viaAddr.viaSuffix == null) {
|
||||
return InetAddress.getByName(address);
|
||||
}
|
||||
|
||||
InetAddress resolved = InetAddress.getByName(viaAddr.realAddress);
|
||||
InetAddress resolved = InetAddress.getByName(viaAddr.serverAddress);
|
||||
return InetAddress.getByAddress(resolved.getHostName() + "." + viaAddr.viaSuffix, resolved.getAddress());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.viaversion.fabric.mc115.platform;
|
||||
|
||||
import com.viaversion.fabric.common.platform.NativeVersionProvider;
|
||||
import net.minecraft.SharedConstants;
|
||||
|
||||
public class FabricNativeVersionProvider implements NativeVersionProvider {
|
||||
@Override
|
||||
public int getServerProtocolVersion() {
|
||||
return SharedConstants.getGameVersion().getProtocolVersion();
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.viaversion.fabric.mc115.platform;
|
||||
|
||||
import com.viaversion.fabric.common.platform.NativeVersionProvider;
|
||||
import com.viaversion.fabric.mc115.providers.VRHandItemProvider;
|
||||
import com.viaversion.fabric.mc115.providers.FabricVersionProvider;
|
||||
import net.fabricmc.api.EnvType;
|
||||
@ -14,6 +15,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTr
|
||||
public class VFLoader implements ViaPlatformLoader {
|
||||
@Override
|
||||
public void load() {
|
||||
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
|
||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
|
||||
Via.getManager().getProviders().use(VersionProvider.class, new FabricVersionProvider());
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.mc115.service;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import com.viaversion.fabric.mc115.ViaFabric;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
@ -114,7 +114,7 @@ public class ProtocolAutoDetector {
|
||||
public static CompletableFuture<ProtocolVersion> detectVersion(InetSocketAddress address) {
|
||||
try {
|
||||
InetSocketAddress real = new InetSocketAddress(InetAddress.getByAddress
|
||||
(new VFAddressParser().parse(address.getHostString()).realAddress,
|
||||
(new AddressParser().parse(address.getHostString()).serverAddress,
|
||||
address.getAddress().getAddress()), address.getPort());
|
||||
return SERVER_VER.get(real);
|
||||
} catch (UnknownHostException | ExecutionException e) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.mc116.mixin.address.client;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
@ -13,12 +13,12 @@ public class MixinConnectScreenThread {
|
||||
@Redirect(method = "run()V", at = @At(value = "INVOKE",
|
||||
target = "Ljava/net/InetAddress;getByName(Ljava/lang/String;)Ljava/net/InetAddress;"))
|
||||
private InetAddress resolveViaFabricAddr(String address) throws UnknownHostException {
|
||||
VFAddressParser viaAddr = new VFAddressParser().parse(address);
|
||||
AddressParser viaAddr = new AddressParser().parse(address);
|
||||
if (viaAddr.viaSuffix == null) {
|
||||
return InetAddress.getByName(address);
|
||||
}
|
||||
|
||||
InetAddress resolved = InetAddress.getByName(viaAddr.realAddress);
|
||||
InetAddress resolved = InetAddress.getByName(viaAddr.serverAddress);
|
||||
return InetAddress.getByAddress(resolved.getHostName() + "." + viaAddr.viaSuffix, resolved.getAddress());
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package com.viaversion.fabric.mc116.mixin.address.client;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import net.minecraft.network.ServerAddress;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@ -17,11 +17,11 @@ public abstract class MixinServerAddress {
|
||||
|
||||
@Redirect(method = "parse", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ServerAddress;resolveServer(Ljava/lang/String;)Lcom/mojang/datafixers/util/Pair;"))
|
||||
private static Pair<String, Integer> modifySrvAddr(String address) {
|
||||
VFAddressParser viaAddr = new VFAddressParser().parse(address);
|
||||
AddressParser viaAddr = new AddressParser().parse(address);
|
||||
if (viaAddr.viaSuffix == null) {
|
||||
return resolveServer(address);
|
||||
}
|
||||
|
||||
return resolveServer(viaAddr.realAddress).mapFirst(it -> it.replaceAll("\\.$", "") + "." + viaAddr.viaSuffix);
|
||||
return resolveServer(viaAddr.serverAddress).mapFirst(it -> it.replaceAll("\\.$", "") + "." + viaAddr.viaSuffix);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.mc116.mixin.address.client;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import net.minecraft.client.network.MultiplayerServerListPinger;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@ -14,12 +14,12 @@ public class MixinServerPinger {
|
||||
@Redirect(method = "add", at = @At(value = "INVOKE",
|
||||
target = "Ljava/net/InetAddress;getByName(Ljava/lang/String;)Ljava/net/InetAddress;"))
|
||||
private InetAddress resolveViaFabricAddr(String address) throws UnknownHostException {
|
||||
VFAddressParser viaAddr = new VFAddressParser().parse(address);
|
||||
AddressParser viaAddr = new AddressParser().parse(address);
|
||||
if (viaAddr.viaSuffix == null) {
|
||||
return InetAddress.getByName(address);
|
||||
}
|
||||
|
||||
InetAddress resolved = InetAddress.getByName(viaAddr.realAddress);
|
||||
InetAddress resolved = InetAddress.getByName(viaAddr.serverAddress);
|
||||
return InetAddress.getByAddress(resolved.getHostName() + "." + viaAddr.viaSuffix, resolved.getAddress());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.viaversion.fabric.mc116.platform;
|
||||
|
||||
import com.viaversion.fabric.common.platform.NativeVersionProvider;
|
||||
import net.minecraft.SharedConstants;
|
||||
|
||||
public class FabricNativeVersionProvider implements NativeVersionProvider {
|
||||
@Override
|
||||
public int getServerProtocolVersion() {
|
||||
return SharedConstants.getGameVersion().getProtocolVersion();
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.viaversion.fabric.mc116.platform;
|
||||
|
||||
import com.viaversion.fabric.common.platform.NativeVersionProvider;
|
||||
import com.viaversion.fabric.mc116.providers.VRHandItemProvider;
|
||||
import com.viaversion.fabric.mc116.providers.FabricVersionProvider;
|
||||
import net.fabricmc.api.EnvType;
|
||||
@ -14,6 +15,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTr
|
||||
public class VFLoader implements ViaPlatformLoader {
|
||||
@Override
|
||||
public void load() {
|
||||
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
|
||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
|
||||
Via.getManager().getProviders().use(VersionProvider.class, new FabricVersionProvider());
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.mc116.service;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import com.viaversion.fabric.mc116.ViaFabric;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
@ -114,7 +114,7 @@ public class ProtocolAutoDetector {
|
||||
public static CompletableFuture<ProtocolVersion> detectVersion(InetSocketAddress address) {
|
||||
try {
|
||||
InetSocketAddress real = new InetSocketAddress(InetAddress.getByAddress
|
||||
(new VFAddressParser().parse(address.getHostString()).realAddress,
|
||||
(new AddressParser().parse(address.getHostString()).serverAddress,
|
||||
address.getAddress().getAddress()), address.getPort());
|
||||
return SERVER_VER.get(real);
|
||||
} catch (UnknownHostException | ExecutionException e) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.mc117.mixin.address.client;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import net.minecraft.client.network.Address;
|
||||
import net.minecraft.client.network.AllowedAddressResolver;
|
||||
import net.minecraft.client.network.ServerAddress;
|
||||
@ -22,12 +22,12 @@ public abstract class MixinAllowedAddressResolver {
|
||||
|
||||
@Inject(method = "resolve", at = @At(value = "HEAD"), cancellable = true)
|
||||
private void resolveVF(ServerAddress address, CallbackInfoReturnable<Optional<Address>> cir) {
|
||||
VFAddressParser viaAddr = new VFAddressParser().parse(address.getAddress());
|
||||
AddressParser viaAddr = new AddressParser().parse(address.getAddress());
|
||||
if (viaAddr.viaSuffix == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ServerAddress realAddress = new ServerAddress(viaAddr.realAddress, address.getPort());
|
||||
ServerAddress realAddress = new ServerAddress(viaAddr.serverAddress, address.getPort());
|
||||
|
||||
cir.setReturnValue(resolve(realAddress).map(it -> viaFabricAddSuffix(it, viaAddr.viaSuffix)));
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.viaversion.fabric.mc117.platform;
|
||||
|
||||
import com.viaversion.fabric.common.platform.NativeVersionProvider;
|
||||
import net.minecraft.SharedConstants;
|
||||
|
||||
public class FabricNativeVersionProvider implements NativeVersionProvider {
|
||||
@Override
|
||||
public int getServerProtocolVersion() {
|
||||
return SharedConstants.getGameVersion().getProtocolVersion();
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.viaversion.fabric.mc117.platform;
|
||||
|
||||
import com.viaversion.fabric.common.platform.NativeVersionProvider;
|
||||
import com.viaversion.fabric.mc117.providers.VRHandItemProvider;
|
||||
import com.viaversion.fabric.mc117.providers.FabricVersionProvider;
|
||||
import net.fabricmc.api.EnvType;
|
||||
@ -14,6 +15,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTr
|
||||
public class VFLoader implements ViaPlatformLoader {
|
||||
@Override
|
||||
public void load() {
|
||||
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
|
||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
|
||||
Via.getManager().getProviders().use(VersionProvider.class, new FabricVersionProvider());
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.mc117.service;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import com.viaversion.fabric.mc117.ViaFabric;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
@ -114,7 +114,7 @@ public class ProtocolAutoDetector {
|
||||
public static CompletableFuture<ProtocolVersion> detectVersion(InetSocketAddress address) {
|
||||
try {
|
||||
InetSocketAddress real = new InetSocketAddress(InetAddress.getByAddress
|
||||
(new VFAddressParser().parse(address.getHostString()).realAddress,
|
||||
(new AddressParser().parse(address.getHostString()).serverAddress,
|
||||
address.getAddress().getAddress()), address.getPort());
|
||||
return SERVER_VER.get(real);
|
||||
} catch (UnknownHostException | ExecutionException e) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.mc18.mixin.address.client;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
@ -13,12 +13,12 @@ public class MixinConnectScreenThread {
|
||||
@Redirect(method = "run()V", at = @At(value = "INVOKE",
|
||||
target = "Ljava/net/InetAddress;getByName(Ljava/lang/String;)Ljava/net/InetAddress;"))
|
||||
private InetAddress resolveViaFabricAddr(String address) throws UnknownHostException {
|
||||
VFAddressParser viaAddr = new VFAddressParser().parse(address);
|
||||
AddressParser viaAddr = new AddressParser().parse(address);
|
||||
if (viaAddr.viaSuffix == null) {
|
||||
return InetAddress.getByName(address);
|
||||
}
|
||||
|
||||
InetAddress resolved = InetAddress.getByName(viaAddr.realAddress);
|
||||
InetAddress resolved = InetAddress.getByName(viaAddr.serverAddress);
|
||||
return InetAddress.getByAddress(resolved.getHostName() + "." + viaAddr.viaSuffix, resolved.getAddress());
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.mc18.mixin.address.client;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import net.minecraft.network.ServerAddress;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
@ -16,12 +16,12 @@ public abstract class MixinServerAddress {
|
||||
|
||||
@Redirect(method = "parse", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ServerAddress;resolveSrv(Ljava/lang/String;)[Ljava/lang/String;"))
|
||||
private static String[] modifySrvAddr(String address) {
|
||||
VFAddressParser viaAddr = new VFAddressParser().parse(address);
|
||||
AddressParser viaAddr = new AddressParser().parse(address);
|
||||
if (viaAddr.viaSuffix == null) {
|
||||
return resolveSrv(address);
|
||||
}
|
||||
|
||||
String[] resolvedSrv = resolveSrv(viaAddr.realAddress);
|
||||
String[] resolvedSrv = resolveSrv(viaAddr.serverAddress);
|
||||
resolvedSrv[0] = resolvedSrv[0].replaceAll("\\.$", "") + "." + viaAddr.viaSuffix;
|
||||
|
||||
return resolvedSrv;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.viaversion.fabric.mc18.mixin.address.client;
|
||||
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import net.minecraft.client.network.MultiplayerServerListPinger;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@ -14,12 +14,12 @@ public class MixinServerPinger {
|
||||
@Redirect(method = "add", at = @At(value = "INVOKE",
|
||||
target = "Ljava/net/InetAddress;getByName(Ljava/lang/String;)Ljava/net/InetAddress;"))
|
||||
private InetAddress resolveViaFabricAddr(String address) throws UnknownHostException {
|
||||
VFAddressParser viaAddr = new VFAddressParser().parse(address);
|
||||
AddressParser viaAddr = new AddressParser().parse(address);
|
||||
if (viaAddr.viaSuffix == null) {
|
||||
return InetAddress.getByName(address);
|
||||
}
|
||||
|
||||
InetAddress resolved = InetAddress.getByName(viaAddr.realAddress);
|
||||
InetAddress resolved = InetAddress.getByName(viaAddr.serverAddress);
|
||||
return InetAddress.getByAddress(resolved.getHostName() + "." + viaAddr.viaSuffix, resolved.getAddress());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
package com.viaversion.fabric.mc18.platform;
|
||||
|
||||
import com.viaversion.fabric.common.platform.NativeVersionProvider;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.minecraft.realms.RealmsSharedConstants;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
public class FabricNativeVersionProvider implements NativeVersionProvider {
|
||||
@Override
|
||||
public int getServerProtocolVersion() {
|
||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
|
||||
return getClientProtocol();
|
||||
}
|
||||
return MinecraftServer.getServer().getServerMetadata().getVersion().getProtocolVersion();
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private int getClientProtocol() {
|
||||
try {
|
||||
return RealmsSharedConstants.class.getField("NETWORK_PROTOCOL_VERSION").getInt(null);
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ProtocolVersion.v1_8.getVersion(); // fallback
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.viaversion.fabric.mc18.platform;
|
||||
|
||||
import com.viaversion.fabric.common.platform.NativeVersionProvider;
|
||||
import com.viaversion.fabric.mc18.providers.VRHandItemProvider;
|
||||
import com.viaversion.fabric.mc18.providers.FabricVersionProvider;
|
||||
import net.fabricmc.api.EnvType;
|
||||
@ -14,6 +15,7 @@ import com.viaversion.viaversion.protocols.protocol1_9to1_8.providers.MovementTr
|
||||
public class VFLoader implements ViaPlatformLoader {
|
||||
@Override
|
||||
public void load() {
|
||||
Via.getManager().getProviders().use(NativeVersionProvider.class, new FabricNativeVersionProvider());
|
||||
Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
|
||||
Via.getManager().getProviders().use(VersionProvider.class, new FabricVersionProvider());
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.viaversion.fabric.mc18.service;
|
||||
|
||||
import com.viaversion.fabric.mc18.ViaFabric;
|
||||
import com.viaversion.fabric.common.VFAddressParser;
|
||||
import com.viaversion.fabric.common.AddressParser;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
@ -109,7 +109,7 @@ public class ProtocolAutoDetector {
|
||||
public static CompletableFuture<ProtocolVersion> detectVersion(InetSocketAddress address) {
|
||||
try {
|
||||
InetSocketAddress real = new InetSocketAddress(InetAddress.getByAddress
|
||||
(new VFAddressParser().parse(address.getHostString()).realAddress,
|
||||
(new AddressParser().parse(address.getHostString()).serverAddress,
|
||||
address.getAddress().getAddress()), address.getPort());
|
||||
return SERVER_VER.get(real);
|
||||
} catch (UnknownHostException | ExecutionException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user