forked from MagicBane/Server
Support for the widest array of network configurations. Auto-configure as best we can.
This commit is contained in:
@@ -25,7 +25,7 @@ import java.util.regex.Pattern;
|
|||||||
public enum ConfigManager {
|
public enum ConfigManager {
|
||||||
|
|
||||||
MB_BIND_ADDR,
|
MB_BIND_ADDR,
|
||||||
|
MB_EXTERNAL_ADDR,
|
||||||
// Database connection config
|
// Database connection config
|
||||||
|
|
||||||
MB_DATABASE_ADDRESS,
|
MB_DATABASE_ADDRESS,
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class GameServerIPResponseMsg extends ClientNetMsg {
|
|||||||
*/
|
*/
|
||||||
public GameServerIPResponseMsg() {
|
public GameServerIPResponseMsg() {
|
||||||
super(Protocol.GAMESERVERIPRESPONSE);
|
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());
|
this.port = Integer.parseInt(ConfigManager.MB_WORLD_PORT.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import org.pmw.tinylog.writers.RollingFileWriter;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@@ -335,6 +336,18 @@ public class LoginServer {
|
|||||||
String name = ConfigManager.MB_WORLD_NAME.getValue();
|
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")) {
|
if (ConfigManager.MB_BIND_ADDR.getValue().equals("0.0.0.0")) {
|
||||||
|
|
||||||
try (final DatagramSocket socket = new DatagramSocket()) {
|
try (final DatagramSocket socket = new DatagramSocket()) {
|
||||||
@@ -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());
|
InetAddress addy = InetAddress.getByName(ConfigManager.MB_BIND_ADDR.getValue());
|
||||||
int port = Integer.parseInt(ConfigManager.MB_LOGIN_PORT.getValue());
|
int port = Integer.parseInt(ConfigManager.MB_LOGIN_PORT.getValue());
|
||||||
|
|
||||||
|
|||||||
@@ -51,11 +51,10 @@ import org.pmw.tinylog.labelers.TimestampLabeler;
|
|||||||
import org.pmw.tinylog.policies.StartupPolicy;
|
import org.pmw.tinylog.policies.StartupPolicy;
|
||||||
import org.pmw.tinylog.writers.RollingFileWriter;
|
import org.pmw.tinylog.writers.RollingFileWriter;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.DatagramSocket;
|
import java.net.DatagramSocket;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -249,6 +248,19 @@ public class WorldServer {
|
|||||||
|
|
||||||
String name = ConfigManager.MB_WORLD_NAME.getValue();
|
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")) {
|
if (ConfigManager.MB_BIND_ADDR.getValue().equals("0.0.0.0")) {
|
||||||
|
|
||||||
try (final DatagramSocket socket = new DatagramSocket()) {
|
try (final DatagramSocket socket = new DatagramSocket()) {
|
||||||
@@ -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());
|
InetAddress addy = InetAddress.getByName(ConfigManager.MB_BIND_ADDR.getValue());
|
||||||
int port = Integer.parseInt(ConfigManager.MB_WORLD_PORT.getValue());
|
int port = Integer.parseInt(ConfigManager.MB_WORLD_PORT.getValue());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user