Allow users to set a public port

This commit is contained in:
Melledy
2023-12-08 05:41:12 -08:00
parent 8d57e357c0
commit 6af08f5034
4 changed files with 32 additions and 9 deletions

View File

@@ -3,6 +3,8 @@ package emu.lunarcore;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import com.google.gson.annotations.SerializedName;
import emu.lunarcore.data.common.ItemParam; import emu.lunarcore.data.common.ItemParam;
import lombok.Getter; import lombok.Getter;
@@ -49,11 +51,32 @@ public class Config {
@Getter @Getter
private static class ServerConfig { private static class ServerConfig {
public String bindAddress = "0.0.0.0"; public String bindAddress = "0.0.0.0";
@SerializedName(value = "bindPort", alternate = {"port"})
public int bindPort;
// Will return bindAddress if publicAddress is null
public String publicAddress = "127.0.0.1"; public String publicAddress = "127.0.0.1";
public int port; // Will return bindPort if publicPort is null
public Integer publicPort;
public ServerConfig(int port) { public ServerConfig(int port) {
this.port = port; this.bindPort = port;
}
public String getPublicAddress() {
if (this.publicAddress != null && !this.publicAddress.isEmpty()) {
return this.publicAddress;
}
return this.bindAddress;
}
public int getPublicPort() {
if (this.publicPort != null && this.publicPort != 0) {
return this.publicPort;
}
return this.bindPort;
} }
} }
@@ -67,7 +90,7 @@ public class Config {
} }
public String getDisplayAddress() { public String getDisplayAddress() {
return (useSSL ? "https" : "http") + "://" + publicAddress + ":" + port; return (useSSL ? "https" : "http") + "://" + getPublicAddress() + ":" + getPublicPort();
} }
} }

View File

@@ -42,7 +42,7 @@ public class GameServer extends KcpServer {
// Game Server base // Game Server base
this.serverConfig = serverConfig; this.serverConfig = serverConfig;
this.info = new RegionInfo(this); this.info = new RegionInfo(this);
this.address = new InetSocketAddress(serverConfig.bindAddress, serverConfig.getPort()); this.address = new InetSocketAddress(serverConfig.getBindAddress(), serverConfig.getBindPort());
this.players = new Int2ObjectOpenHashMap<>(); this.players = new Int2ObjectOpenHashMap<>();
// Setup managers // Setup managers

View File

@@ -110,17 +110,17 @@ public class HttpServer {
if (getServerConfig().isUseSSL()) { if (getServerConfig().isUseSSL()) {
ServerConnector sslConnector = new ServerConnector(getApp().jettyServer().server(), getSSLContextFactory(), getHttpFactory()); ServerConnector sslConnector = new ServerConnector(getApp().jettyServer().server(), getSSLContextFactory(), getHttpFactory());
sslConnector.setHost(getServerConfig().getBindAddress()); sslConnector.setHost(getServerConfig().getBindAddress());
sslConnector.setPort(getServerConfig().getPort()); sslConnector.setPort(getServerConfig().getBindPort());
getApp().jettyServer().server().addConnector(sslConnector); getApp().jettyServer().server().addConnector(sslConnector);
getApp().start(); getApp().start();
} else { } else {
getApp().start(getServerConfig().getBindAddress(), getServerConfig().getPort()); getApp().start(getServerConfig().getBindAddress(), getServerConfig().getBindPort());
} }
// Done // Done
LunarCore.getLogger().info("Http Server running as: " + this.modes.stream().collect(Collectors.joining(", "))); LunarCore.getLogger().info("Http Server running as: " + this.modes.stream().collect(Collectors.joining(", ")));
LunarCore.getLogger().info("Http Server started on " + getServerConfig().getPort()); LunarCore.getLogger().info("Http Server started on " + getServerConfig().getBindPort());
} }
private void addRoutes() { private void addRoutes() {

View File

@@ -23,7 +23,7 @@ public class QueryGatewayHandler implements Handler {
Gateserver gateserver = Gateserver.newInstance() Gateserver gateserver = Gateserver.newInstance()
.setRegionName(LunarCore.getConfig().getGameServer().getId()) .setRegionName(LunarCore.getConfig().getGameServer().getId())
.setIp(LunarCore.getConfig().getGameServer().getPublicAddress()) .setIp(LunarCore.getConfig().getGameServer().getPublicAddress())
.setPort(LunarCore.getConfig().getGameServer().getPort()) .setPort(LunarCore.getConfig().getGameServer().getPublicPort())
.setMsg("Access verification failed. Please check if you have logged in to the correct account and server.") // in case there is some error idk .setMsg("Access verification failed. Please check if you have logged in to the correct account and server.") // in case there is some error idk
.setUnk1(true) .setUnk1(true)
.setUnk2(true) .setUnk2(true)