UPnP Port Forwarding

Co-authored-by: omega24 <ben@omega24.dev>
This commit is contained in:
William Blake Galbreath
2025-01-12 13:04:46 -08:00
committed by granny
parent 7703bd1fd1
commit 77adc2f882
5 changed files with 57 additions and 85 deletions

View File

@@ -17,14 +17,32 @@
// Spigot end
public volatile boolean hasFullyShutdown; // Paper - Improved watchdog support
public volatile boolean abnormalExit; // Paper - Improved watchdog support
@@ -302,6 +_,7 @@
@@ -302,7 +_,9 @@
public final io.papermc.paper.configuration.PaperConfigurations paperConfigurations; // Paper - add paper configuration files
public boolean isIteratingOverLevels = false; // Paper - Throw exception on world create while being ticked
private final Set<String> pluginsBlockingSleep = new java.util.HashSet<>(); // Paper - API to allow/disallow tick sleeping
+ public boolean lagging = false; // Purpur - Lagging threshold
public static final long SERVER_INIT = System.nanoTime(); // Paper - Lag compensation
+ protected boolean upnp = false; // Purpur - UPnP Port Forwarding
public static <S extends MinecraftServer> S spin(Function<Thread, S> threadFunction) {
ca.spottedleaf.dataconverter.minecraft.datatypes.MCTypeRegistry.init(); // Paper - rewrite data converter system
@@ -1001,6 +_,15 @@
LOGGER.info("Stopping server");
Commands.COMMAND_SENDING_POOL.shutdownNow(); // Paper - Perf: Async command map building; Shutdown and don't bother finishing
+ // Purpur start - UPnP Port Forwarding
+ 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());
+ }
+ }
+ // Purpur end - UPnP Port Forwarding
// CraftBukkit start
if (this.server != null) {
this.server.spark.disable(); // Paper - spark
@@ -1093,6 +_,7 @@
this.safeShutdown(waitForServer, false);
}