Browse Source

Support for the widest array of network configurations. Auto-configure as best we can.

master
MagicBot 1 year ago
parent
commit
43090a9bd1
  1. 2
      src/engine/gameManager/ConfigManager.java
  2. 2
      src/engine/net/client/msg/login/GameServerIPResponseMsg.java
  3. 16
      src/engine/server/login/LoginServer.java
  4. 21
      src/engine/server/world/WorldServer.java

2
src/engine/gameManager/ConfigManager.java

@ -25,7 +25,7 @@ import java.util.regex.Pattern; @@ -25,7 +25,7 @@ import java.util.regex.Pattern;
public enum ConfigManager {
MB_BIND_ADDR,
MB_EXTERNAL_ADDR,
// Database connection config
MB_DATABASE_ADDRESS,

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_BIND_ADDR.getValue();
this.ip = ConfigManager.MB_EXTERNAL_ADDR.getValue();
this.port = Integer.parseInt(ConfigManager.MB_WORLD_PORT.getValue());
}

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

@ -34,6 +34,7 @@ import org.pmw.tinylog.writers.RollingFileWriter; @@ -34,6 +34,7 @@ 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;
@ -335,6 +336,18 @@ public class LoginServer { @@ -335,6 +336,18 @@ public class LoginServer {
String name = ConfigManager.MB_WORLD_NAME.getValue();
if (ConfigManager.MB_EXTERNAL_ADDR.getValue().equals("0.0.0.0")) {
// Autoconfigure External address for use in worldserver response
Logger.info("AUTOCONFIG EXTERNAL IP ADDRESS");
URL whatismyip = new URL("http://checkip.amazonaws.com");
BufferedReader in = new BufferedReader(new InputStreamReader(
whatismyip.openStream()));
ConfigManager.MB_EXTERNAL_ADDR.setValue(in.readLine());
}
if (ConfigManager.MB_BIND_ADDR.getValue().equals("0.0.0.0")) {
try (final DatagramSocket socket = new DatagramSocket()) {
@ -344,6 +357,9 @@ public class LoginServer { @@ -344,6 +357,9 @@ public class LoginServer {
}
Logger.info("External address: " + ConfigManager.MB_EXTERNAL_ADDR.getValue() + ":" + ConfigManager.MB_WORLD_PORT.getValue());
Logger.info("Internal address: " + 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());

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

@ -51,11 +51,10 @@ import org.pmw.tinylog.labelers.TimestampLabeler; @@ -51,11 +51,10 @@ import org.pmw.tinylog.labelers.TimestampLabeler;
import org.pmw.tinylog.policies.StartupPolicy;
import org.pmw.tinylog.writers.RollingFileWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
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.time.LocalDateTime;
@ -249,6 +248,19 @@ public class WorldServer { @@ -249,6 +248,19 @@ public class WorldServer {
String name = ConfigManager.MB_WORLD_NAME.getValue();
if (ConfigManager.MB_EXTERNAL_ADDR.getValue().equals("0.0.0.0")) {
// Autoconfigure External IP address. Only used in loginserver but useful
// here for bootstrap display
Logger.info("AUTOCONFIG EXTERNAL IP ADDRESS");
URL whatismyip = new URL("http://checkip.amazonaws.com");
BufferedReader in = new BufferedReader(new InputStreamReader(
whatismyip.openStream()));
ConfigManager.MB_EXTERNAL_ADDR.setValue(in.readLine());
}
if (ConfigManager.MB_BIND_ADDR.getValue().equals("0.0.0.0")) {
try (final DatagramSocket socket = new DatagramSocket()) {
@ -258,6 +270,9 @@ public class WorldServer { @@ -258,6 +270,9 @@ public class WorldServer {
}
Logger.info("External address: " + ConfigManager.MB_EXTERNAL_ADDR.getValue() + ":" + ConfigManager.MB_WORLD_PORT.getValue());
Logger.info("Internal address: " + 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