mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +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
@@ -9,21 +9,13 @@
|
||||
this.f_120088_.setSoTimeout(5000);
|
||||
this.f_120088_.joinGroup(this.f_120087_);
|
||||
}
|
||||
@@ -87,7 +_,19 @@
|
||||
@@ -87,7 +_,11 @@
|
||||
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;
|
||||
+ s1 = "[" + com.google.common.net.InetAddresses.toAddrString(p_120098_) + "]:" + s1;
|
||||
+ } else {
|
||||
+ s1 = p_120098_.getHostAddress() + ":" + s1;
|
||||
+ }
|
||||
|
||||
+10
@@ -15,6 +15,16 @@
|
||||
this.m_10055_();
|
||||
} else if (this.f_10019_ == ServerLoginPacketListenerImpl.State.DELAY_ACCEPT) {
|
||||
ServerPlayer serverplayer = this.f_10018_.m_6846_().m_11259_(this.f_10021_.getId());
|
||||
@@ -138,7 +_,8 @@
|
||||
}
|
||||
|
||||
public String m_10056_() {
|
||||
- return this.f_10021_ != null ? this.f_10021_ + " (" + this.f_10013_.m_129523_() + ")" : String.valueOf((Object)this.f_10013_.m_129523_());
|
||||
+ final String addressString = net.minecraftforge.network.DualStackUtils.getAddressString(this.f_10013_.m_129523_());
|
||||
+ return this.f_10021_ != null ? this.f_10021_ + " (" + addressString + ")" : addressString;
|
||||
}
|
||||
|
||||
public void m_5990_(ServerboundHelloPacket p_10047_) {
|
||||
@@ -147,14 +_,14 @@
|
||||
GameProfile gameprofile = this.f_10018_.m_236731_();
|
||||
if (gameprofile != null && p_10047_.f_238040_().equalsIgnoreCase(gameprofile.getName())) {
|
||||
|
||||
@@ -8,7 +8,15 @@
|
||||
|
||||
public PlayerList(MinecraftServer p_203842_, LayeredRegistryAccess<RegistryLayer> p_251844_, PlayerDataStorage p_203844_, int p_203845_) {
|
||||
this.f_11195_ = p_203842_;
|
||||
@@ -168,6 +_,7 @@
|
||||
@@ -161,13 +_,14 @@
|
||||
p_11263_.m_143425_(serverlevel1);
|
||||
String s1 = "local";
|
||||
if (p_11262_.m_129523_() != null) {
|
||||
- s1 = p_11262_.m_129523_().toString();
|
||||
+ s1 = net.minecraftforge.network.DualStackUtils.getAddressString(p_11262_.m_129523_());
|
||||
}
|
||||
|
||||
f_11188_.info("{}[{}] logged in with entity id {} at ({}, {}, {})", p_11263_.m_7755_().getString(), s1, p_11263_.m_19879_(), p_11263_.m_20185_(), p_11263_.m_20186_(), p_11263_.m_20189_());
|
||||
LevelData leveldata = serverlevel1.m_6106_();
|
||||
p_11263_.m_143427_(compoundtag);
|
||||
ServerGamePacketListenerImpl servergamepacketlistenerimpl = new ServerGamePacketListenerImpl(this.f_11195_, p_11262_, p_11263_);
|
||||
|
||||
@@ -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