forked from MinecraftForge/MinecraftForge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement full support for IPv6 (MinecraftForge#8742)
- Loading branch information
1 parent
bb03b1a
commit c2225ab
Showing
16 changed files
with
198 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
patches/minecraft/net/minecraft/client/server/LanServerDetection.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- a/net/minecraft/client/server/LanServerDetection.java | ||
+++ b/net/minecraft/client/server/LanServerDetection.java | ||
@@ -33,7 +_,7 @@ | ||
this.setDaemon(true); | ||
this.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LanServerDetection.f_120082_)); | ||
this.f_120088_ = new MulticastSocket(4445); | ||
- this.f_120087_ = InetAddress.getByName("224.0.2.60"); | ||
+ this.f_120087_ = InetAddress.getByName(LanServerPinger.f_174974_); | ||
this.f_120088_.setSoTimeout(5000); | ||
this.f_120088_.joinGroup(this.f_120087_); | ||
} | ||
@@ -88,7 +_,19 @@ | ||
String s = LanServerPinger.m_120111_(p_120097_); | ||
String s1 = LanServerPinger.m_120116_(p_120097_); | ||
if (s1 != null) { | ||
- s1 = p_120098_.getHostAddress() + ":" + s1; | ||
+ if (net.minecraftforge.network.DualStackUtils.checkIPv6(p_120098_)) { | ||
+ final String ip; | ||
+ | ||
+ // compress to short form if enabled in config | ||
+ if (net.minecraftforge.common.ForgeConfig.CLIENT.compressLanIPv6Addresses.get()) | ||
+ ip = com.google.common.net.InetAddresses.toAddrString(p_120098_); | ||
+ else | ||
+ ip = p_120098_.getHostAddress(); | ||
+ | ||
+ s1 = "[" + ip + "]:" + s1; | ||
+ } else { | ||
+ s1 = p_120098_.getHostAddress() + ":" + s1; | ||
+ } | ||
boolean flag = false; | ||
|
||
for(LanServer lanserver : this.f_120092_) { |
20 changes: 20 additions & 0 deletions
20
patches/minecraft/net/minecraft/client/server/LanServerPinger.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- a/net/minecraft/client/server/LanServerPinger.java | ||
+++ b/net/minecraft/client/server/LanServerPinger.java | ||
@@ -16,7 +_,7 @@ | ||
public class LanServerPinger extends Thread { | ||
private static final AtomicInteger f_120101_ = new AtomicInteger(0); | ||
private static final Logger f_120102_ = LogUtils.getLogger(); | ||
- public static final String f_174974_ = "224.0.2.60"; | ||
+ public static final String f_174974_ = net.minecraftforge.network.DualStackUtils.getMulticastGroup(); | ||
public static final int f_174975_ = 4445; | ||
private static final long f_174976_ = 1500L; | ||
private final String f_120103_; | ||
@@ -39,7 +_,7 @@ | ||
|
||
while(!this.isInterrupted() && this.f_120105_) { | ||
try { | ||
- InetAddress inetaddress = InetAddress.getByName("224.0.2.60"); | ||
+ InetAddress inetaddress = InetAddress.getByName(f_174974_); | ||
DatagramPacket datagrampacket = new DatagramPacket(abyte, abyte.length, inetaddress, 4445); | ||
this.f_120104_.send(datagrampacket); | ||
} catch (IOException ioexception) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/net/minecraftforge/client/IFluidTypeRenderProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/net/minecraftforge/common/extensions/IForgeBoat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/net/minecraftforge/common/extensions/IForgeLivingEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/net/minecraftforge/fluids/FluidInteractionRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/main/java/net/minecraftforge/network/DualStackUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (c) Forge Development LLC and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.minecraftforge.network; | ||
|
||
import net.minecraft.client.multiplayer.resolver.ResolvedServerAddress; | ||
import net.minecraft.client.multiplayer.resolver.ServerAddress; | ||
import net.minecraft.client.multiplayer.resolver.ServerNameResolver; | ||
import net.minecraft.util.HttpUtil; | ||
|
||
import javax.annotation.Nullable; | ||
import java.net.Inet6Address; | ||
import java.net.InetAddress; | ||
import java.net.InetSocketAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.Optional; | ||
|
||
public class DualStackUtils | ||
{ | ||
/** | ||
* Resolve the address and see if Java and the OS return an IPv6 or IPv4 one, then let Netty know | ||
* accordingly (it doesn't understand the {@code java.net.preferIPv6Addresses=system} property). | ||
* | ||
* @param hostAddress The address you want to check | ||
* @return true if IPv6, false if IPv4 | ||
*/ | ||
public static boolean checkIPv6(final String hostAddress) | ||
{ | ||
final Optional<InetSocketAddress> hostAddr = | ||
ServerNameResolver.DEFAULT | ||
.resolveAddress(ServerAddress.parseString(hostAddress)) | ||
.map(ResolvedServerAddress::asInetSocketAddress); | ||
|
||
if (hostAddr.isPresent()) return checkIPv6(hostAddr.get().getAddress()); | ||
else return false; | ||
} | ||
|
||
/** | ||
* Checks if an address is an IPv6 one or an IPv4 one, lets Netty know accordingly and returns the result. | ||
* | ||
* @param inetAddress The address you want to check | ||
* @return true if IPv6, false if IPv4 | ||
*/ | ||
public static boolean checkIPv6(final InetAddress inetAddress) | ||
{ | ||
if (inetAddress instanceof Inet6Address) | ||
{ | ||
System.setProperty("java.net.preferIPv4Stack", "false"); | ||
System.setProperty("java.net.preferIPv6Addresses", "true"); | ||
return true; | ||
} | ||
else | ||
{ | ||
System.setProperty("java.net.preferIPv4Stack", "true"); | ||
System.setProperty("java.net.preferIPv6Addresses", "false"); | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Get the device's local IP address, taking into account scenarios where the client's network adapter | ||
* supports IPv6 and has it enabled but the router's LAN does not. | ||
* | ||
* @return the client's local IP address or {@code null} if unable to determine it | ||
*/ | ||
@Nullable | ||
public static InetAddress getLocalAddress() | ||
{ | ||
final InetAddress localAddr = new InetSocketAddress(HttpUtil.getAvailablePort()).getAddress(); | ||
if (localAddr.isAnyLocalAddress()) return localAddr; | ||
|
||
try | ||
{ | ||
return InetAddress.getByName("localhost"); | ||
} | ||
catch (final UnknownHostException e) | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
public static String getMulticastGroup() { | ||
if (checkIPv6(getLocalAddress())) return "FF75:230::60"; | ||
else return "224.0.2.60"; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/test/java/net/minecraftforge/debug/fluid/FluidTypeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters