Files
Purpur/patches/server/0239-UPnP-Port-Forwarding.patch
Encode42 26e5f080f2 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@b4192fd fix NPE from changes in e4358b82171
PaperMC/Paper@5b6445a Revert "fix NPE from changes in e4358b82171"
PaperMC/Paper@323c087 Revert "#686: Fix contains for default section generating real sections"
PaperMC/Paper@c837002 Fix client world difficulty sync issue (#7035)
PaperMC/Paper@a4782f7 [ci skip] fixup indent
PaperMC/Paper@83aee0f [ci skip] Clarify setSize consequences for Slimes (#7036)
PaperMC/Paper@7c8fdc1 Add dropped hunk from mid-tick tasks (#7034)
PaperMC/Paper@fd263ef Fix empty/null chunk section check in LevelChunk#getBlockData, rename… (#7039)
PaperMC/Paper@b8d486c Create workflow to add new PRs to the PR Queue project (#6918)
PaperMC/Paper@a50e273 Include axolotls in affected entities for water splash potions (#7024)
PaperMC/Paper@af95df8 Port Actually unload POI data from Tuinity 1.16 (#7044)
PaperMC/Paper@04897b1 [ci skip] Revert "Create workflow to add new PRs to the PR Queue project (#6918)" (#7046)
PaperMC/Paper@b4a77a8 Updated Upstream (Bukkit/CraftBukkit) (#7045)
PaperMC/Paper@0e25db2 Fix mis-placed processEnchantOrder from 1.18 update (#7052)
PaperMC/Paper@53d026e Fix unused EntitySectionStorage#getEntities(AABB, Consumer) method being broken
PaperMC/Paper@772e880 Fix light propagation in high y sections
PaperMC/Paper@33ea869 Bump Starlight light version
PaperMC/Paper@74fd151 Fix entity equipment on cancellation of EntityDeathEvent (#5740)
PaperMC/Paper@758e2a7 Fix bad ticking checks for blocks
PaperMC/Paper@0e91b6a Return 0 for light values if a dimenion does not have them
PaperMC/Paper@188a8df Fix ChunkSnapshot#isSectionEmpty(int)
PaperMC/Paper@bbc7451 Fix issue with snapshotted biomes in last commit
PaperMC/Paper@b475c6a Backport log4j fix
PaperMC/Paper@4e355c4 Updated Upstream (CraftBukkit)
PaperMC/Paper@dce79f3 Update Log4J (#7069)
2021-12-09 22:46:19 -05:00

83 lines
4.3 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Wed, 22 Jan 2020 20:13:40 -0600
Subject: [PATCH] UPnP Port Forwarding
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 3d45aa3cf8e25790dba332105c397dce2b1ef5b1..5d1bd07046af00aea3bde2f1000a4b8a1d8528cb 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -309,6 +309,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public final SlackActivityAccountant slackActivityAccountant = new SlackActivityAccountant();
// Spigot end
public static long currentTickLong = 0L; // Paper
+ protected boolean upnp = false; // Purpur
public volatile Thread shutdownThread; // Paper
public volatile boolean abnormalExit = false; // Paper
@@ -1033,6 +1034,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// CraftBukkit end
MinecraftServer.LOGGER.info("Stopping server");
MinecraftTimings.stopServer(); // Paper
+ // Purpur start
+ if (upnp) {
+ if (dev.omega24.upnp4j.UPnP4J.close(this.getPort(), dev.omega24.upnp4j.util.Protocol.TCP)) {
+ LOGGER.info("[UPnP] Port {} closed", this.getPort());
+ } else {
+ LOGGER.error("[UPnP] Failed to close port {}", this.getPort());
+ }
+ }
// CraftBukkit start
if (this.server != null) {
this.server.disablePlugins();
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index cd859eec6b0bee44bce83614e55709381baf5e6b..9412a238aa3538bf958cf3b5ce2be5a9beead90f 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -288,6 +288,30 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
DedicatedServer.LOGGER.warn("Perhaps a server is already running on that port?");
return false;
}
+ // Purpur start
+ if (org.purpurmc.purpur.PurpurConfig.useUPnP) {
+ LOGGER.info("[UPnP] Attempting to start UPnP port forwarding service...");
+ if (dev.omega24.upnp4j.UPnP4J.isUPnPAvailable()) {
+ if (dev.omega24.upnp4j.UPnP4J.isOpen(this.getPort(), dev.omega24.upnp4j.util.Protocol.TCP)) {
+ this.upnp = false;
+ LOGGER.info("[UPnP] Port {} is already open", this.getPort());
+ } else if (dev.omega24.upnp4j.UPnP4J.open(this.getPort(), dev.omega24.upnp4j.util.Protocol.TCP)) {
+ this.upnp = true;
+ LOGGER.info("[UPnP] Successfully opened port {}", this.getPort());
+ } else {
+ this.upnp = false;
+ LOGGER.info("[UPnP] Failed to open port {}", this.getPort());
+ }
+
+ if (upnp) {
+ LOGGER.info("[UPnP] {}:{}", dev.omega24.upnp4j.UPnP4J.getExternalIP(), this.getPort());
+ }
+ } else {
+ this.upnp = false;
+ LOGGER.error("[UPnP] Service is unavailable");
+ }
+ }
+ // Purpur end
// CraftBukkit start
// this.setPlayerList(new DedicatedPlayerList(this, this.registryHolder, this.playerDataStorage)); // Spigot - moved up
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
index b651a42f268e0636ccd86a7de9acfeb1cf3810f7..141a46499eb2cba73a3f71fb50926bc08f37f9f0 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
@@ -391,4 +391,9 @@ public class PurpurConfig {
private static void tpsCatchup() {
tpsCatchup = getBoolean("settings.tps-catchup", tpsCatchup);
}
+
+ public static boolean useUPnP = false;
+ private static void networkSettings() {
+ useUPnP = getBoolean("settings.network.upnp-port-forwarding", useUPnP);
+ }
}