Drop UPnP patch (not ready yet)

This commit is contained in:
Etil
2021-10-16 11:03:28 +02:00
parent d11c614f97
commit db9df65c90
2 changed files with 0 additions and 100 deletions

View File

@@ -19,7 +19,6 @@
- **New NBT cache** which reduces a lot of I/O operations from the main thread while preserving correct data.
- **Pre-tweaked** configuration files to reach optimal performance with minimal impact on normal behaviors.
- **IP and login location** hiding feature, which adds another security layer in the logs.
- **UPnP Port Forwarding** which helps users who can not open their ports.
- **Removed metrics**, no one can collect data, not even us.
- **Bugfixes** for several Minecraft issues.
- **Safer methods** for Vanilla calls.

View File

@@ -1,99 +0,0 @@
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] (Purpur) UPnP Port Forwarding
Original code by pl3xgaming, licensed under MIT
You can find the original code on https://github.com/pl3xgaming/Purpur
diff --git a/build.gradle.kts b/build.gradle.kts
index 74f8760264aa93af9d4d2895a96ed416a8ef411e..a9de7cb9101b56eeac3fdc6db38aff451ce8be0b 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -64,6 +64,8 @@ dependencies {
implementation("co.aikar:cleaner:1.0-SNAPSHOT") // Paper
implementation("io.netty:netty-all:4.1.65.Final") // Paper
+ implementation("cat.inspiracio:rhino-js-engine:1.7.7.1") // Purpur
+ implementation("dev.omega24:upnp4j:1.0") // Purpur
implementation("org.quiltmc:tiny-mappings-parser:0.3.0") // Paper - needed to read mappings for stacktrace deobfuscation
implementation("com.velocitypowered:velocity-native:1.1.0-SNAPSHOT") // Paper
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 586df67649d8f022299bb40c07b330118ba28c7b..3b408e54b57b349bee80b11f0ee289cdf5f3e68c 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<Runnab
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
@@ -1041,6 +1042,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<Runnab
// 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 d0ca92837e95483e94faf4115f5de7a4e6adbfc9..505201b0356e8715d8501452fbc15b383568fb98 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -290,6 +290,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 (xyz.arthurb.mirai.MiraiConfig.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.a((PlayerList) (new DedicatedPlayerList(this, this.customRegistry, this.worldNBTStorage))); // Spigot - moved up
diff --git a/src/main/java/xyz/arthurb/mirai/MiraiConfig.java b/src/main/java/xyz/arthurb/mirai/MiraiConfig.java
index 1a2b4333ae71bc328b2509433023b459a74e6f37..91d1ea500f222034cdc835e3c9842796cfa05a7c 100644
--- a/src/main/java/xyz/arthurb/mirai/MiraiConfig.java
+++ b/src/main/java/xyz/arthurb/mirai/MiraiConfig.java
@@ -250,4 +250,10 @@ public class MiraiConfig {
entitiesCanUsePortals = getBoolean("settings.entities-can-use-portals", entitiesCanUsePortals);
}
+ public static boolean useUPnP = false;
+
+ private static void networkSettings() {
+ useUPnP = getBoolean("settings.network.upnp-port-forwarding", useUPnP);
+ }
+
}
\ No newline at end of file