Files
Purpur/patches/server/0238-UPnP-Port-Forwarding.patch
BillyGalbreath b7f623afe5 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
9259558b58 Fix remapping issue with RangedAttackMob and RangedEntity (#7167)
3d9385e665 Add material tags for copper blocks (#7141)
75f4cb074a Move setShouldBurnInDay to AbstractSkeleton (#7120)
9adc0b243b Fix breakNaturally for fluid-logged blocks (#7134)
76f327471d Move VehicleCollisionEvent HandlerList up (#7112)
d4c819056d Forward CraftEntity in teleport command (#7025)
9012ae8880 Improve scoreboard entries (#6871)
264b11d9f3 Entity powdered snow API (#6833)
a6a6a3db24 [ci skip] Revert change to apatch script
2cf6a57bca Fix entity type tags suggestions in selectors (#6468)
8a21c1742b Add API for item entity health (#6514)
26fbb02aae Adventure changes for Java 17 and Component support for resourcepack prompt
10bfb63f6c Configurable max block light for monster spawning (#7129)
6e5ceb34eb Fix ChunkMap distanceManager field reobf
82eaf4ee15 Fix duplicated BlockPistonRetractEvent call (#7111)
cf621c5eb3 Load effect amplifiers greater than 127 correctly (#7175)
1ce4281666 Fix ABI breakage for plainSerializer (#7178)
bf826b3fac [ci skip] Update Gradle wrapper to 7.3.3
464b1715bb Add uncaught exception handler using logger to usages of ThreadFactoryBuilder (#7179)
2021-12-23 22:44:22 -06: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 022cf286342abe9f5349b70e096373a0db2a810d..58143bf03bd3314a4b7b40acb72e203aebce7fa6 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 3b07195c1255bdac9bdc8b1286edb5d5c1eb7cf4..5c9973374991446c39d6a84d745283eac3eb70ab 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
@@ -378,4 +378,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);
+ }
}