Browse Source

Network autoconfig now uses eth0 or default outgoing ip route.

master
MagicBot 1 year ago
parent
commit
48aef2ef01
  1. 4
      src/engine/gameManager/ConfigManager.java
  2. 2
      src/engine/net/client/msg/login/GameServerIPResponseMsg.java
  3. 19
      src/engine/server/login/LoginServer.java
  4. 12
      src/engine/server/world/WorldServer.java

4
src/engine/gameManager/ConfigManager.java

@ -24,10 +24,6 @@ import java.util.regex.Pattern; @@ -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

2
src/engine/net/client/msg/login/GameServerIPResponseMsg.java

@ -36,7 +36,7 @@ public class GameServerIPResponseMsg extends ClientNetMsg { @@ -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());
}

19
src/engine/server/login/LoginServer.java

@ -32,8 +32,8 @@ import org.pmw.tinylog.policies.StartupPolicy; @@ -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 { @@ -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());

12
src/engine/server/world/WorldServer.java

@ -54,6 +54,7 @@ import org.pmw.tinylog.writers.RollingFileWriter; @@ -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 { @@ -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());

Loading…
Cancel
Save