mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-16 15:24:44 +01:00
Allow users to set a public port
This commit is contained in:
@@ -3,6 +3,8 @@ package emu.lunarcore;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import emu.lunarcore.data.common.ItemParam;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -49,11 +51,32 @@ public class Config {
|
||||
@Getter
|
||||
private static class ServerConfig {
|
||||
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 int port;
|
||||
|
||||
// Will return bindPort if publicPort is null
|
||||
public Integer publicPort;
|
||||
|
||||
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() {
|
||||
return (useSSL ? "https" : "http") + "://" + publicAddress + ":" + port;
|
||||
return (useSSL ? "https" : "http") + "://" + getPublicAddress() + ":" + getPublicPort();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public class GameServer extends KcpServer {
|
||||
// Game Server base
|
||||
this.serverConfig = serverConfig;
|
||||
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<>();
|
||||
|
||||
// Setup managers
|
||||
|
||||
@@ -110,17 +110,17 @@ public class HttpServer {
|
||||
if (getServerConfig().isUseSSL()) {
|
||||
ServerConnector sslConnector = new ServerConnector(getApp().jettyServer().server(), getSSLContextFactory(), getHttpFactory());
|
||||
sslConnector.setHost(getServerConfig().getBindAddress());
|
||||
sslConnector.setPort(getServerConfig().getPort());
|
||||
sslConnector.setPort(getServerConfig().getBindPort());
|
||||
getApp().jettyServer().server().addConnector(sslConnector);
|
||||
|
||||
getApp().start();
|
||||
} else {
|
||||
getApp().start(getServerConfig().getBindAddress(), getServerConfig().getPort());
|
||||
getApp().start(getServerConfig().getBindAddress(), getServerConfig().getBindPort());
|
||||
}
|
||||
|
||||
// Done
|
||||
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() {
|
||||
|
||||
@@ -23,7 +23,7 @@ public class QueryGatewayHandler implements Handler {
|
||||
Gateserver gateserver = Gateserver.newInstance()
|
||||
.setRegionName(LunarCore.getConfig().getGameServer().getId())
|
||||
.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
|
||||
.setUnk1(true)
|
||||
.setUnk2(true)
|
||||
|
||||
Reference in New Issue
Block a user