diff --git a/src/engine/gameManager/ConfigManager.java b/src/engine/gameManager/ConfigManager.java index 8af95ed7..2282c17b 100644 --- a/src/engine/gameManager/ConfigManager.java +++ b/src/engine/gameManager/ConfigManager.java @@ -24,10 +24,6 @@ import java.util.regex.Pattern; public enum ConfigManager { - // Bind address can differ from public address - // when running over a network bridge, etc. - - MB_PUBLIC_ADDR, MB_BIND_ADDR, // Database connection config diff --git a/src/engine/net/client/msg/login/GameServerIPResponseMsg.java b/src/engine/net/client/msg/login/GameServerIPResponseMsg.java index 35061578..c3cfbce4 100644 --- a/src/engine/net/client/msg/login/GameServerIPResponseMsg.java +++ b/src/engine/net/client/msg/login/GameServerIPResponseMsg.java @@ -36,7 +36,7 @@ public class GameServerIPResponseMsg extends ClientNetMsg { */ public GameServerIPResponseMsg( ) { super(Protocol.GAMESERVERIPRESPONSE); - this.ip = ConfigManager.MB_PUBLIC_ADDR.getValue(); + this.ip = ConfigManager.MB_BIND_ADDR.getValue(); this.port = Integer.parseInt(ConfigManager.MB_WORLD_PORT.getValue()); } diff --git a/src/engine/server/login/LoginServer.java b/src/engine/server/login/LoginServer.java index 6664ad41..12cd6f67 100644 --- a/src/engine/server/login/LoginServer.java +++ b/src/engine/server/login/LoginServer.java @@ -32,8 +32,8 @@ import org.pmw.tinylog.policies.StartupPolicy; import org.pmw.tinylog.writers.RollingFileWriter; import java.io.*; +import java.net.DatagramSocket; import java.net.InetAddress; -import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; import java.sql.Connection; @@ -268,19 +268,16 @@ public class LoginServer { String name = ConfigManager.MB_WORLD_NAME.getValue(); - if (ConfigManager.MB_PUBLIC_ADDR.getValue().equals("0.0.0.0")) { + if (ConfigManager.MB_BIND_ADDR.getValue().equals("0.0.0.0")) { + + try (final DatagramSocket socket = new DatagramSocket()) { + socket.connect(InetAddress.getByName("8.8.8.8"), 10002); + ConfigManager.MB_BIND_ADDR.setValue(socket.getLocalAddress().getHostAddress()); + } - // Autoconfigure IP address for use in worldserver response - // . - Logger.info("AUTOCONFIG PUBLIC IP ADDRESS"); - URL whatismyip = new URL("http://checkip.amazonaws.com"); - BufferedReader in = new BufferedReader(new InputStreamReader( - whatismyip.openStream())); - ConfigManager.MB_PUBLIC_ADDR.setValue(in.readLine()); } - Logger.info("Public address: " + ConfigManager.MB_PUBLIC_ADDR.getValue()); - Logger.info("Magicbane bind config: " + ConfigManager.MB_BIND_ADDR.getValue() + ":" + ConfigManager.MB_LOGIN_PORT.getValue()); + Logger.info("Magicbane binding to: " + ConfigManager.MB_BIND_ADDR.getValue() + ":" + ConfigManager.MB_LOGIN_PORT.getValue()); InetAddress addy = InetAddress.getByName(ConfigManager.MB_BIND_ADDR.getValue()); int port = Integer.parseInt(ConfigManager.MB_LOGIN_PORT.getValue()); diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index bf24a170..91c22f69 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -54,6 +54,7 @@ import org.pmw.tinylog.writers.RollingFileWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.net.DatagramSocket; import java.net.InetAddress; import java.nio.file.Files; import java.nio.file.Paths; @@ -248,7 +249,16 @@ public class WorldServer { String name = ConfigManager.MB_WORLD_NAME.getValue(); - Logger.info("Magicbane network config: " + ConfigManager.MB_BIND_ADDR.getValue() + ":" + ConfigManager.MB_WORLD_PORT.getValue()); + if (ConfigManager.MB_BIND_ADDR.getValue().equals("0.0.0.0")) { + + try (final DatagramSocket socket = new DatagramSocket()) { + socket.connect(InetAddress.getByName("8.8.8.8"), 10002); + ConfigManager.MB_BIND_ADDR.setValue(socket.getLocalAddress().getHostAddress()); + } + + } + + Logger.info("Magicbane binding to: " + ConfigManager.MB_BIND_ADDR.getValue() + ":" + ConfigManager.MB_LOGIN_PORT.getValue()); InetAddress addy = InetAddress.getByName(ConfigManager.MB_BIND_ADDR.getValue()); int port = Integer.parseInt(ConfigManager.MB_WORLD_PORT.getValue());