mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-18 17:07:43 +01:00
Upstream has released updates that appears to apply and compile correctly Paper Changes: f65f95ce3 Do not let the server load chunks from newer versions 1799ef140 Apply 1.16's light optimizations to 1.15.2 too 5a28de666 Further optimize chunk light prioritization 4e364423e Fix deadlock issue with watchdog stopping 82e048ebc Remove ability to disable async chunks unless single core cpu b317f0dc4 [1.15] Fix off by one error for scheduling block ticks (#4013) 51741a180 [1.15] Tighten logic for handling target tick times in tick scheduler (#4011) 5657364b4 Fix Light Prioritization Issues 013374629 Fix AdvancementDataPlayer leak due from quitting early in login 74231d422 [1.15] Move range check for block placing up (#3918) 48ea17fa1 Optimize the advancement data player iteration to be O(N) rather than O(N^2) be4d74d93 Fix Explosion location - Fixes #3574 31e5f6688 [1.15] Optimize NetworkManager exception handling (#3820) 2248fffcd Clean up duplicated GameProfile Properties 49491f32d Fix Player Profile textures being duplicated - Fixes #3667 3fc989992 [1.15] Fix MobGoals#getAllGoals not actually returning all goals (#3671) 1d1c0561f Manually inline PooledBlockPosition#d(int, int, int) 5fc45f4db Revert recent changes around player skulls using user cache Tuinity Changes: 5794d12 Fix up lock handling for UserCache
201 lines
8.0 KiB
Diff
201 lines
8.0 KiB
Diff
From dd1db1bb351658ef5b4dd5dbf1e1640b172e7d05 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 Service
|
|
|
|
---
|
|
pom.xml | 10 ++++
|
|
.../net/minecraft/server/DedicatedServer.java | 25 ++++++++++
|
|
.../net/minecraft/server/MinecraftServer.java | 10 ++++
|
|
.../java/net/pl3x/purpur/PurpurConfig.java | 5 ++
|
|
.../net/pl3x/purpur/gui/info/JInfoPanel.java | 3 ++
|
|
.../pl3x/purpur/gui/info/UPnPComponent.java | 47 +++++++++++++++++++
|
|
6 files changed, 100 insertions(+)
|
|
create mode 100644 src/main/java/net/pl3x/purpur/gui/info/UPnPComponent.java
|
|
|
|
diff --git a/pom.xml b/pom.xml
|
|
index 097c736bc3..adf7f78dab 100644
|
|
--- a/pom.xml
|
|
+++ b/pom.xml
|
|
@@ -55,6 +55,12 @@
|
|
<version>1.7.7.1</version>
|
|
<scope>compile</scope>
|
|
</dependency>
|
|
+ <dependency>
|
|
+ <groupId>com.dosse.upnp</groupId>
|
|
+ <artifactId>UPnP</artifactId>
|
|
+ <version>1.0</version>
|
|
+ <scope>compile</scope>
|
|
+ </dependency>
|
|
<!-- Purpur end -->
|
|
<dependency>
|
|
<groupId>net.minecrell</groupId>
|
|
@@ -166,6 +172,10 @@
|
|
<id>spigotmc-public</id>
|
|
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
|
</repository>
|
|
+ <repository>
|
|
+ <id>pl3x</id>
|
|
+ <url>https://repo.pl3x.net/</url>
|
|
+ </repository>
|
|
</repositories>
|
|
|
|
<pluginRepositories>
|
|
diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java
|
|
index 7f2db5f0b0..5cfb6fd3d6 100644
|
|
--- a/src/main/java/net/minecraft/server/DedicatedServer.java
|
|
+++ b/src/main/java/net/minecraft/server/DedicatedServer.java
|
|
@@ -242,6 +242,31 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer
|
|
return false;
|
|
}
|
|
|
|
+ // Purpur start
|
|
+ if (net.pl3x.purpur.PurpurConfig.useUPnP) {
|
|
+ LOGGER.info("[UPnP] Attempting to start UPnP port forwarding service...");
|
|
+ com.dosse.upnp.UPnP.NAME = "Purpur UPnP";
|
|
+ if (com.dosse.upnp.UPnP.isUPnPAvailable()) {
|
|
+ if (com.dosse.upnp.UPnP.isMappedTCP(getPort())) {
|
|
+ upnp = false;
|
|
+ LOGGER.info("[UPnP] Port " + getPort() + " is already open");
|
|
+ } else if (com.dosse.upnp.UPnP.openPortTCP(getPort())) {
|
|
+ upnp = true;
|
|
+ LOGGER.info("[UPnP] Successfully opened port " + getPort());
|
|
+ } else {
|
|
+ upnp = false;
|
|
+ LOGGER.info("[UPnP] Failed to open port " + getPort());
|
|
+ }
|
|
+ if (upnp) {
|
|
+ LOGGER.info("[UPnP] " + com.dosse.upnp.UPnP.getExternalIP() + ":" + getPort());
|
|
+ }
|
|
+ } else {
|
|
+ upnp = false;
|
|
+ LOGGER.error("[UPnP] Service is unavailable");
|
|
+ }
|
|
+ }
|
|
+ // Purpur end
|
|
+
|
|
// CraftBukkit start
|
|
// this.a((PlayerList) (new DedicatedPlayerList(this))); // Spigot - moved up
|
|
server.loadPlugins();
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index 555b4920c3..94e1ca897c 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -187,6 +187,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
public boolean lagging = false; // Purpur
|
|
public final SlackActivityAccountant slackActivityAccountant = new SlackActivityAccountant();
|
|
// Spigot end
|
|
+ protected boolean upnp = false; public boolean isUPnPEnabled() { return upnp; } // Purpur
|
|
|
|
public MinecraftServer(OptionSet options, Proxy proxy, DataFixer datafixer, CommandDispatcher commanddispatcher, YggdrasilAuthenticationService yggdrasilauthenticationservice, MinecraftSessionService minecraftsessionservice, GameProfileRepository gameprofilerepository, UserCache usercache, WorldLoadListenerFactory worldloadlistenerfactory, String s) {
|
|
super("Server");
|
|
@@ -746,6 +747,15 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
|
// CraftBukkit end
|
|
MinecraftServer.LOGGER.info("Stopping server");
|
|
MinecraftTimings.stopServer(); // Paper
|
|
+ // Purpur start
|
|
+ if (upnp) {
|
|
+ if (com.dosse.upnp.UPnP.closePortTCP(getPort())) {
|
|
+ LOGGER.info("[UPnP] Port " + getPort() + " closed");
|
|
+ } else {
|
|
+ LOGGER.error("[UPnP] Failed to close port " + getPort());
|
|
+ }
|
|
+ }
|
|
+ // Purpur end
|
|
// CraftBukkit start
|
|
if (this.server != null) {
|
|
this.server.disablePlugins();
|
|
diff --git a/src/main/java/net/pl3x/purpur/PurpurConfig.java b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
|
index c3ecd6fc70..fe38b3ce90 100644
|
|
--- a/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
|
+++ b/src/main/java/net/pl3x/purpur/PurpurConfig.java
|
|
@@ -150,6 +150,11 @@ public class PurpurConfig {
|
|
useAlternateKeepAlive = getBoolean("settings.use-alternate-keepalive", useAlternateKeepAlive);
|
|
}
|
|
|
|
+ public static boolean useUPnP = false;
|
|
+ private static void upnpSettings() {
|
|
+ useUPnP = getBoolean("settings.upnp-port-forwarding", useUPnP);
|
|
+ }
|
|
+
|
|
public static boolean dontSendUselessEntityPackets = false;
|
|
private static void dontSendUselessEntityPackets() {
|
|
dontSendUselessEntityPackets = getBoolean("settings.dont-send-useless-entity-packets", dontSendUselessEntityPackets);
|
|
diff --git a/src/main/java/net/pl3x/purpur/gui/info/JInfoPanel.java b/src/main/java/net/pl3x/purpur/gui/info/JInfoPanel.java
|
|
index c4903c7db6..ee4f022fc5 100644
|
|
--- a/src/main/java/net/pl3x/purpur/gui/info/JInfoPanel.java
|
|
+++ b/src/main/java/net/pl3x/purpur/gui/info/JInfoPanel.java
|
|
@@ -19,13 +19,16 @@ public class JInfoPanel extends JPanel {
|
|
|
|
ramGraph = new RAMGraph();
|
|
RAMDetails ramDetails = new RAMDetails(server);
|
|
+ UPnPComponent upnpComponent = new UPnPComponent(server);
|
|
|
|
add(ramGraph, "North");
|
|
add(ramDetails, "Center");
|
|
+ add(upnpComponent, "South");
|
|
|
|
timer = new Timer(500, (event) -> {
|
|
ramGraph.update();
|
|
ramDetails.update();
|
|
+ upnpComponent.repaint();
|
|
});
|
|
timer.start();
|
|
}
|
|
diff --git a/src/main/java/net/pl3x/purpur/gui/info/UPnPComponent.java b/src/main/java/net/pl3x/purpur/gui/info/UPnPComponent.java
|
|
new file mode 100644
|
|
index 0000000000..b0465d3608
|
|
--- /dev/null
|
|
+++ b/src/main/java/net/pl3x/purpur/gui/info/UPnPComponent.java
|
|
@@ -0,0 +1,47 @@
|
|
+package net.pl3x.purpur.gui.info;
|
|
+
|
|
+import net.minecraft.server.MinecraftServer;
|
|
+import net.pl3x.purpur.PurpurConfig;
|
|
+
|
|
+import javax.swing.JTextPane;
|
|
+import javax.swing.border.EmptyBorder;
|
|
+import java.awt.Color;
|
|
+import java.awt.Dimension;
|
|
+import java.awt.Graphics;
|
|
+
|
|
+public class UPnPComponent extends JTextPane {
|
|
+ private final MinecraftServer server;
|
|
+
|
|
+ public UPnPComponent(MinecraftServer server) {
|
|
+ this.server = server;
|
|
+ setBorder(new EmptyBorder(0, 30, 0, 10));
|
|
+ setEditable(false);
|
|
+ setText("UPnP Status");
|
|
+ setOpaque(false);
|
|
+ setHighlighter(null);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public Dimension getPreferredSize() {
|
|
+ return new Dimension(350, 20);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void paint(Graphics graphics) {
|
|
+ super.paint(graphics);
|
|
+ graphics.setColor(server.isUPnPEnabled() ? Color.GREEN : Color.RED);
|
|
+ graphics.fillOval(10, 0, 15, 15);
|
|
+ setToolTipText(getTooltip());
|
|
+ }
|
|
+
|
|
+ private String getTooltip() {
|
|
+ if (!PurpurConfig.useUPnP) {
|
|
+ return "UPnP Disabled";
|
|
+ }
|
|
+ if (server.isUPnPEnabled()) {
|
|
+ return "UPnP Enabled";
|
|
+ } else {
|
|
+ return "UPnP Unavailable";
|
|
+ }
|
|
+ }
|
|
+}
|
|
--
|
|
2.26.2
|
|
|