diff --git a/common/cpw/mods/fml/common/network/FMLNetworkHandler.java b/common/cpw/mods/fml/common/network/FMLNetworkHandler.java index f4595b8a79..b9e0b74264 100644 --- a/common/cpw/mods/fml/common/network/FMLNetworkHandler.java +++ b/common/cpw/mods/fml/common/network/FMLNetworkHandler.java @@ -2,7 +2,12 @@ package cpw.mods.fml.common.network; import static cpw.mods.fml.common.network.FMLPacket.Type.MOD_LIST_REQUEST; +import java.io.IOException; +import java.net.InetAddress; +import java.net.NetworkInterface; import java.net.SocketAddress; +import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.Set; @@ -22,6 +27,7 @@ import net.minecraft.src.ServerConfigurationManager; import net.minecraft.src.World; import net.minecraft.src.WorldType; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.hash.Hashing; @@ -349,4 +355,39 @@ public class FMLNetworkHandler player.field_71135_a.func_72567_b(pkt); } + + public static InetAddress computeLocalHost() throws IOException + { + InetAddress add = null; + List addresses = Lists.newArrayList(); + InetAddress localHost = InetAddress.getLocalHost(); + for (NetworkInterface ni : Collections.list(NetworkInterface.getNetworkInterfaces())) + { + if (!ni.isLoopback() && ni.isUp()) + { + addresses.addAll(Collections.list(ni.getInetAddresses())); + if (addresses.contains(localHost)) + { + add = localHost; + break; + } + } + } + if (add == null && !addresses.isEmpty()) + { + for (InetAddress addr: addresses) + { + if (addr.getAddress().length == 4) + { + add = addr; + break; + } + } + } + if (add == null) + { + add = localHost; + } + return add; + } } \ No newline at end of file diff --git a/patches/minecraft/net/minecraft/src/IntegratedServerListenThread.java.patch b/patches/minecraft/net/minecraft/src/IntegratedServerListenThread.java.patch index 4d909ffab8..c130e9e801 100644 --- a/patches/minecraft/net/minecraft/src/IntegratedServerListenThread.java.patch +++ b/patches/minecraft/net/minecraft/src/IntegratedServerListenThread.java.patch @@ -1,11 +1,17 @@ --- ../src-base/minecraft/net/minecraft/src/IntegratedServerListenThread.java +++ ../src-work/minecraft/net/minecraft/src/IntegratedServerListenThread.java -@@ -4,6 +4,12 @@ +@@ -2,8 +2,18 @@ + + import cpw.mods.fml.common.Side; import cpw.mods.fml.common.asm.SideOnly; ++import cpw.mods.fml.common.network.FMLNetworkHandler; ++ import java.io.IOException; import java.net.InetAddress; +import java.net.NetworkInterface; ++import java.util.Arrays; +import java.util.Collections; ++import java.util.List; + +import com.google.common.collect.Iterators; +import com.google.common.collect.Lists; @@ -13,37 +19,21 @@ import net.minecraft.server.MinecraftServer; @SideOnly(Side.CLIENT) -@@ -48,7 +54,32 @@ +@@ -48,7 +58,7 @@ try { - this.field_71757_g = new ServerListenThread(this, InetAddress.getLocalHost(), var1); -+ InetAddress add = null; -+ NetworkInterface notLocal = null; -+ for (NetworkInterface ni : Collections.list(NetworkInterface.getNetworkInterfaces())) -+ { -+ if (!ni.isLoopback() && ni.isUp()) -+ { -+ notLocal = ni; -+ break; -+ } -+ } -+ if (notLocal != null) -+ { -+ for (InetAddress inadd : Collections.list(notLocal.getInetAddresses())) -+ { -+ if (inadd.getAddress().length == 4) -+ { -+ add = inadd; -+ break; -+ } -+ } -+ } -+ if (add == null) -+ { -+ add = InetAddress.getLocalHost(); -+ } -+ this.field_71757_g = new ServerListenThread(this, add, var1); ++ this.field_71757_g = new ServerListenThread(this, null, var1); this.field_71757_g.start(); } catch (IOException var3) +@@ -57,7 +67,7 @@ + } + } + +- return this.field_71757_g.func_71767_c().getHostAddress() + ":" + this.field_71757_g.func_71765_d(); ++ return FMLNetworkHandler.computeLocalHost().getHostAddress() + ":" + this.field_71757_g.func_71765_d(); + } + + public void func_71744_a()