mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 02:55:17 +00:00
Support IPv6 address compression for logged IPs
This commit is contained in:
1 parent
301e7252b0
commit
7006fe4f29
5 files changed
+50
-12
No files matched your search
@@ -130,6 +130,7 @@ public class ForgeConfig {
|
||||
|
||||
public final BooleanValue useCombinedDepthStencilAttachment;
|
||||
|
||||
@Deprecated(since = "1.20.1", forRemoval = true) // Config option ignored.
|
||||
public final BooleanValue compressLanIPv6Addresses;
|
||||
|
||||
Client(ForgeConfigSpec.Builder builder) {
|
||||
@@ -159,7 +160,7 @@ public class ForgeConfig {
|
||||
.define("useCombinedDepthStencilAttachment", false);
|
||||
|
||||
compressLanIPv6Addresses = builder
|
||||
.comment("When enabled, Forge will convert discovered 'Open to LAN' IPv6 addresses to their more compact, compressed representation")
|
||||
.comment("[DEPRECATED] [NOW IN COMMON CONFIG] When enabled, Forge will convert discovered 'Open to LAN' IPv6 addresses to their more compact, compressed representation")
|
||||
.translation("forge.configgui.compressLanIPv6Addresses")
|
||||
.define("compressLanIPv6Addresses", true);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package net.minecraftforge.network;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
import com.google.common.net.InetAddresses;
|
||||
import net.minecraft.client.multiplayer.resolver.ResolvedServerAddress;
|
||||
import net.minecraft.client.multiplayer.resolver.ServerAddress;
|
||||
import net.minecraft.client.multiplayer.resolver.ServerNameResolver;
|
||||
@@ -15,6 +16,10 @@ import org.slf4j.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.net.Inet4Address;
|
||||
import net.minecraftforge.common.ForgeConfig;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.net.SocketAddress;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -150,4 +155,26 @@ public class DualStackUtils
|
||||
LOGGER.debug("Initial IPv4 stack preference: " + INITIAL_PREFER_IPv4_STACK);
|
||||
LOGGER.debug("Initial IPv6 addresses preference: " + INITIAL_PREFER_IPv6_ADDRESSES);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link SocketAddress#toString()} but with IPv6 address compression support
|
||||
*/
|
||||
public static String getAddressString(final SocketAddress address) {
|
||||
if (address instanceof final InetSocketAddress inetAddress) {
|
||||
String formatted;
|
||||
if (inetAddress.isUnresolved()) {
|
||||
formatted = inetAddress.getHostName() + "/<unresolved>";
|
||||
} else {
|
||||
formatted = InetAddresses.toAddrString(inetAddress.getAddress());
|
||||
if (inetAddress.getAddress() instanceof Inet6Address)
|
||||
formatted = '[' + formatted + ']';
|
||||
|
||||
formatted = '/' + formatted;
|
||||
}
|
||||
|
||||
return formatted + ':' + inetAddress.getPort();
|
||||
}
|
||||
|
||||
return address.toString();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user