Search in sources :

Example 1 with AddressParser

use of com.viaversion.fabric.common.AddressParser in project ViaFabric by ViaVersion.

the class MixinAllowedAddressResolver method resolveVF.

@Inject(method = "resolve", at = @At(value = "HEAD"), cancellable = true)
private void resolveVF(ServerAddress address, CallbackInfoReturnable<Optional<Address>> cir) {
    AddressParser viaAddr = new AddressParser().parse(address.getAddress());
    if (viaAddr.viaSuffix == null) {
        return;
    }
    ServerAddress realAddress = new ServerAddress(viaAddr.serverAddress, address.getPort());
    cir.setReturnValue(resolve(realAddress).map(it -> viaFabricAddSuffix(it, viaAddr.getSuffixWithOptions())));
}
Also used : Address(net.minecraft.client.network.Address) Inject(org.spongepowered.asm.mixin.injection.Inject) AddressParser(com.viaversion.fabric.common.AddressParser) InetSocketAddress(java.net.InetSocketAddress) UnknownHostException(java.net.UnknownHostException) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) InetAddress(java.net.InetAddress) Mixin(org.spongepowered.asm.mixin.Mixin) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) ServerAddress(net.minecraft.client.network.ServerAddress) AllowedAddressResolver(net.minecraft.client.network.AllowedAddressResolver) At(org.spongepowered.asm.mixin.injection.At) AddressParser(com.viaversion.fabric.common.AddressParser) ServerAddress(net.minecraft.client.network.ServerAddress) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with AddressParser

use of com.viaversion.fabric.common.AddressParser in project ViaFabric by ViaVersion.

the class MixinAllowedAddressResolver method resolveVF.

@Inject(method = "resolve", at = @At(value = "HEAD"), cancellable = true)
private void resolveVF(ServerAddress address, CallbackInfoReturnable<Optional<Address>> cir) {
    AddressParser viaAddr = new AddressParser().parse(address.getAddress());
    if (viaAddr.viaSuffix == null) {
        return;
    }
    ServerAddress realAddress = new ServerAddress(viaAddr.serverAddress, address.getPort());
    cir.setReturnValue(resolve(realAddress).map(it -> viaFabricAddSuffix(it, viaAddr.getSuffixWithOptions())));
}
Also used : Address(net.minecraft.client.network.Address) Inject(org.spongepowered.asm.mixin.injection.Inject) AddressParser(com.viaversion.fabric.common.AddressParser) InetSocketAddress(java.net.InetSocketAddress) UnknownHostException(java.net.UnknownHostException) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) InetAddress(java.net.InetAddress) Mixin(org.spongepowered.asm.mixin.Mixin) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) ServerAddress(net.minecraft.client.network.ServerAddress) AllowedAddressResolver(net.minecraft.client.network.AllowedAddressResolver) At(org.spongepowered.asm.mixin.injection.At) AddressParser(com.viaversion.fabric.common.AddressParser) ServerAddress(net.minecraft.client.network.ServerAddress) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with AddressParser

use of com.viaversion.fabric.common.AddressParser in project ViaFabric by ViaVersion.

the class MixinAllowedAddressResolver method resolveVF.

@Inject(method = "resolve", at = @At(value = "HEAD"), cancellable = true)
private void resolveVF(ServerAddress address, CallbackInfoReturnable<Optional<Address>> cir) {
    AddressParser viaAddr = new AddressParser().parse(address.getAddress());
    if (viaAddr.viaSuffix == null) {
        return;
    }
    ServerAddress realAddress = new ServerAddress(viaAddr.serverAddress, address.getPort());
    cir.setReturnValue(resolve(realAddress).map(it -> viaFabricAddSuffix(it, viaAddr.getSuffixWithOptions())));
}
Also used : Address(net.minecraft.client.network.Address) Inject(org.spongepowered.asm.mixin.injection.Inject) AddressParser(com.viaversion.fabric.common.AddressParser) InetSocketAddress(java.net.InetSocketAddress) UnknownHostException(java.net.UnknownHostException) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) InetAddress(java.net.InetAddress) Mixin(org.spongepowered.asm.mixin.Mixin) Shadow(org.spongepowered.asm.mixin.Shadow) Optional(java.util.Optional) ServerAddress(net.minecraft.client.network.ServerAddress) AllowedAddressResolver(net.minecraft.client.network.AllowedAddressResolver) At(org.spongepowered.asm.mixin.injection.At) AddressParser(com.viaversion.fabric.common.AddressParser) ServerAddress(net.minecraft.client.network.ServerAddress) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with AddressParser

use of com.viaversion.fabric.common.AddressParser in project ViaFabric by ViaVersion.

the class MixinServerAddress method modifySrvAddr.

@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) {
    AddressParser viaAddr = new AddressParser().parse(address);
    if (viaAddr.viaSuffix == null) {
        return resolveSrv(address);
    }
    String[] resolvedSrv = resolveSrv(viaAddr.serverAddress);
    resolvedSrv[0] = resolvedSrv[0].replaceAll("\\.$", "") + "." + viaAddr.getSuffixWithOptions();
    return resolvedSrv;
}
Also used : AddressParser(com.viaversion.fabric.common.AddressParser) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 5 with AddressParser

use of com.viaversion.fabric.common.AddressParser in project ViaFabric by ViaVersion.

the class MixinServerPinger method resolveViaFabricAddr.

@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 {
    AddressParser viaAddr = new AddressParser().parse(address);
    if (viaAddr.viaSuffix == null) {
        return InetAddress.getByName(address);
    }
    InetAddress resolved = InetAddress.getByName(viaAddr.serverAddress);
    return InetAddress.getByAddress(resolved.getHostName() + "." + viaAddr.getSuffixWithOptions(), resolved.getAddress());
}
Also used : AddressParser(com.viaversion.fabric.common.AddressParser) InetAddress(java.net.InetAddress) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

AddressParser (com.viaversion.fabric.common.AddressParser)15 InetAddress (java.net.InetAddress)11 Redirect (org.spongepowered.asm.mixin.injection.Redirect)11 InetSocketAddress (java.net.InetSocketAddress)4 UnknownHostException (java.net.UnknownHostException)3 Optional (java.util.Optional)3 Address (net.minecraft.client.network.Address)3 AllowedAddressResolver (net.minecraft.client.network.AllowedAddressResolver)3 ServerAddress (net.minecraft.client.network.ServerAddress)3 Mixin (org.spongepowered.asm.mixin.Mixin)3 Shadow (org.spongepowered.asm.mixin.Shadow)3 At (org.spongepowered.asm.mixin.injection.At)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 CallbackInfoReturnable (org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable)3 NativeVersionProvider (com.viaversion.fabric.common.platform.NativeVersionProvider)1 ProtocolInfo (com.viaversion.viaversion.api.connection.ProtocolInfo)1 ProtocolVersion (com.viaversion.viaversion.api.protocol.version.ProtocolVersion)1 CancelException (com.viaversion.viaversion.exception.CancelException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SocketAddress (java.net.SocketAddress)1