Add Unix domain socket support

This commit is contained in:
Andrew Steinborn
2021-05-11 17:39:22 -04:00
parent 15d02795ea
commit cc2c25ba55
4 changed files with 122 additions and 58 deletions

View File

@@ -148,7 +148,7 @@
DedicatedServer.LOGGER.info("Starting minecraft server version {}", SharedConstants.getCurrentVersion().getName());
if (Runtime.getRuntime().maxMemory() / 1024L / 1024L < 512L) {
DedicatedServer.LOGGER.warn("To start the server with more ram, launch it as \"java -Xmx1024M -Xms1024M -jar minecraft_server.jar\"");
@@ -126,13 +203,35 @@
@@ -126,14 +203,50 @@
this.setPreventProxyConnections(dedicatedserverproperties.preventProxyConnections);
this.setLocalIp(dedicatedserverproperties.serverIp);
}
@@ -183,9 +183,41 @@
- this.worldData.setGameType(dedicatedserverproperties.gamemode);
+ // this.worldData.setGameType(dedicatedserverproperties.gamemode); // CraftBukkit - moved to world loading
DedicatedServer.LOGGER.info("Default game type: {}", dedicatedserverproperties.gamemode);
+ // Paper start - Unix domain socket support
+ java.net.SocketAddress bindAddress;
+ if (this.getLocalIp().startsWith("unix:")) {
+ if (!io.netty.channel.epoll.Epoll.isAvailable()) {
+ DedicatedServer.LOGGER.error("**** INVALID CONFIGURATION!");
+ DedicatedServer.LOGGER.error("You are trying to use a Unix domain socket but you're not on a supported OS.");
+ return false;
+ } else if (!io.papermc.paper.configuration.GlobalConfiguration.get().proxies.velocity.enabled && !org.spigotmc.SpigotConfig.bungee) {
+ DedicatedServer.LOGGER.error("**** INVALID CONFIGURATION!");
+ DedicatedServer.LOGGER.error("Unix domain sockets require IPs to be forwarded from a proxy.");
+ return false;
+ }
+ bindAddress = new io.netty.channel.unix.DomainSocketAddress(this.getLocalIp().substring("unix:".length()));
+ } else {
InetAddress inetaddress = null;
@@ -156,21 +255,31 @@
if (!this.getLocalIp().isEmpty()) {
@@ -143,12 +256,15 @@
if (this.getPort() < 0) {
this.setPort(dedicatedserverproperties.serverPort);
}
+ bindAddress = new java.net.InetSocketAddress(inetaddress, this.getPort());
+ }
+ // Paper end - Unix domain socket support
this.initializeKeyPair();
DedicatedServer.LOGGER.info("Starting Minecraft server on {}:{}", this.getLocalIp().isEmpty() ? "*" : this.getLocalIp(), this.getPort());
try {
- this.getConnection().startTcpServerListener(inetaddress, this.getPort());
+ this.getConnection().bind(bindAddress); // Paper - Unix domain socket support
} catch (IOException ioexception) {
DedicatedServer.LOGGER.warn("**** FAILED TO BIND TO PORT!");
DedicatedServer.LOGGER.warn("The exception was: {}", ioexception.toString());
@@ -156,21 +272,31 @@
return false;
}
@@ -222,7 +254,7 @@
this.debugSampleSubscriptionTracker = new DebugSampleSubscriptionTracker(this.getPlayerList());
this.tickTimeLogger = new RemoteSampleLogger(TpsDebugDimensions.values().length, this.debugSampleSubscriptionTracker, RemoteDebugSampleType.TICK_TIME);
long i = Util.getNanos();
@@ -178,13 +287,13 @@
@@ -178,13 +304,13 @@
SkullBlockEntity.setup(this.services, this);
GameProfileCache.setUsesAuthentication(this.usesAuthentication());
DedicatedServer.LOGGER.info("Preparing level \"{}\"", this.getLevelIdName());
@@ -238,7 +270,7 @@
}
if (dedicatedserverproperties.enableQuery) {
@@ -197,7 +306,7 @@
@@ -197,7 +323,7 @@
this.rconThread = RconThread.create(this);
}
@@ -247,7 +279,7 @@
Thread thread1 = new Thread(new ServerWatchdog(this));
thread1.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandlerWithName(DedicatedServer.LOGGER));
@@ -215,6 +324,12 @@
@@ -215,6 +341,12 @@
}
}
@@ -260,7 +292,7 @@
@Override
public boolean isSpawningMonsters() {
return this.settings.getProperties().spawnMonsters && super.isSpawningMonsters();
@@ -227,7 +342,7 @@
@@ -227,7 +359,7 @@
@Override
public void forceDifficulty() {
@@ -269,7 +301,7 @@
}
@Override
@@ -286,13 +401,14 @@
@@ -286,13 +418,14 @@
}
if (this.rconThread != null) {
@@ -286,7 +318,7 @@
}
@Override
@@ -302,19 +418,29 @@
@@ -302,19 +435,29 @@
}
@Override
@@ -322,7 +354,7 @@
}
}
@@ -383,7 +509,7 @@
@@ -383,7 +526,7 @@
@Override
public boolean isUnderSpawnProtection(ServerLevel world, BlockPos pos, Player player) {
@@ -331,7 +363,7 @@
return false;
} else if (this.getPlayerList().getOps().isEmpty()) {
return false;
@@ -453,7 +579,11 @@
@@ -453,7 +596,11 @@
public boolean enforceSecureProfile() {
DedicatedServerProperties dedicatedserverproperties = this.getProperties();
@@ -344,7 +376,7 @@
}
@Override
@@ -541,16 +671,52 @@
@@ -541,16 +688,52 @@
@Override
public String getPluginNames() {
@@ -401,7 +433,7 @@
}
public void storeUsingWhiteList(boolean useWhitelist) {
@@ -660,4 +826,15 @@
@@ -660,4 +843,15 @@
}
}
}