Skip to content

Commit

Permalink
fix for rcon response
Browse files Browse the repository at this point in the history
  • Loading branch information
AltronMaxX committed Oct 5, 2023
1 parent f9be566 commit 32b6735
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 25 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ tasks.register("foliaRefLatest") {
)

val foliaLatestCommitJson = layout.cache.resolve("foliaLatestCommit.json");
download.get().download("https://api.github.com/repos/PaperMC/Folia/commits/master", foliaLatestCommitJson);
download.get().download("https://api.github.com/repos/PaperMC/Folia/commits/dev/1.20.2", foliaLatestCommitJson);
val foliaLatestCommit = gson.fromJson<paper.libs.com.google.gson.JsonObject>(foliaLatestCommitJson)["sha"].asString;

copy {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ group=dev.edenor.foldenor

version=1.20.2-R0.1
mcVersion=1.20.2
foliaRef=cdf356915b9051a6a895e53f663f24afb05c04a2
foliaRef=e876103942278b4a392634a2e9b204e02d2993a3

org.gradle.caching=true
org.gradle.parallel=true
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0001-Rebranding.patch
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ index 1d714d3eff11ed14f218656008190017494d4830..f12730abec2e4998f712efcb8b51314c
stringbuilder.append(CrashReport.getErrorComment());
stringbuilder.append("\n\n");
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index f9cf331202d0768a054e575c8909369920b3d59f..7c3c862e0cda474a46b32aee6b3c59af97878a6d 100644
index 2f2a8a0c05024115f3b7bd69ae400fadff2f36c5..160e368591a70e943c65e16bdf5fe90fda68ca96 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1816,7 +1816,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1833,7 +1833,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa

@DontObfuscate
public String getServerModName() {
Expand Down
7 changes: 3 additions & 4 deletions patches/server/0002-Feature-secure-seed.patch
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ index c5598adb8cbcbcf7277c2fd4dd72c243d44d9700..4544b6234fc356e7a06c462f5f136a48
return GsonHelper.parse(!s1.isEmpty() ? s1 : "{}");
}, new JsonObject()), (String) this.get("level-type", (s1) -> {
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
index 18735dbd0d2bae1576d2bdb7402d98e9affbd599..8e24fe638a6f43baf86ffc03082667c1e25dc398 100644
index 72a5973c6e150533ec70496d72b53c80a142eef7..f7a6e5f18b02395706ae825ea247a623b8941d88 100644
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
@@ -48,6 +48,8 @@ import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemp
Expand All @@ -426,7 +426,7 @@ index 18735dbd0d2bae1576d2bdb7402d98e9affbd599..8e24fe638a6f43baf86ffc03082667c1

public class ServerChunkCache extends ChunkSource {

@@ -673,6 +675,7 @@ public class ServerChunkCache extends ChunkSource {
@@ -695,6 +697,7 @@ public class ServerChunkCache extends ChunkSource {
}

public ChunkGenerator getGenerator() {
Expand All @@ -435,7 +435,7 @@ index 18735dbd0d2bae1576d2bdb7402d98e9affbd599..8e24fe638a6f43baf86ffc03082667c1
}

diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 8b41da9d1f43340b6ba3812a93f681419d0d7cd8..7218200b140f658ae3009c1a423124cd4287dcbd 100644
index a4af151e6a2d428d7c9b2a81ada7310b73867d5a..0f385f409d4469f5eba4410504a3f4544fc849dc 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -177,6 +177,7 @@ import org.bukkit.event.world.GenericGameEvent;
Expand All @@ -454,7 +454,6 @@ index 8b41da9d1f43340b6ba3812a93f681419d0d7cd8..7218200b140f658ae3009c1a423124cd
boolean flag2 = minecraftserver.forceSynchronousWrites();
DataFixer datafixer = minecraftserver.getFixerUpper();
this.entityStorage = new EntityRegionFileStorage(convertable_conversionsession.getDimensionPath(resourcekey).resolve("entities"), flag2); // Paper - rewrite chunk system //EntityPersistentStorage<Entity> entitypersistentstorage = new EntityStorage(this, convertable_conversionsession.getDimensionPath(resourcekey).resolve("entities"), datafixer, flag2, minecraftserver);

diff --git a/src/main/java/net/minecraft/world/entity/monster/Slime.java b/src/main/java/net/minecraft/world/entity/monster/Slime.java
index b14979ab7bed34a37fceff5589ecb789bab31318..7463140f9d5afcfc02d02535c1d56ab750c45010 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Slime.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,64 @@ Date: Sat, 16 Sep 2023 21:29:08 +0400
Subject: [PATCH] Return-rcon-and-allow-dispatching-commands-async


diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 160e368591a70e943c65e16bdf5fe90fda68ca96..78ff02761308da8916be8b56bb542561743fc245 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -314,25 +314,25 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa

@Override
public void execute(Runnable runnable) {
- if (true) {
+ /*if (true) {
throw new UnsupportedOperationException();
- }
+ }*/
super.execute(runnable);
}

@Override
public void executeBlocking(Runnable runnable) {
- if (true) {
+ /*if (true) {
throw new UnsupportedOperationException();
- }
+ }*/
super.executeBlocking(runnable);
}

@Override
public void tell(TickTask runnable) {
- if (true) {
+ /*if (true) {
throw new UnsupportedOperationException();
- }
+ }*/
super.tell(runnable);
}
// Folia end - regionised ticking
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index 0db571d23bc730372f6811052779661f7d95a354..9a79e75424fc912689cb2119334e36a0e7f04732 100644
index 0db571d23bc730372f6811052779661f7d95a354..f738e7ae26bdd29b27af8636707d3f227c33c73f 100644
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
@@ -769,14 +769,15 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
@@ -17,6 +17,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BooleanSupplier;
import javax.annotation.Nullable;

@@ -52,6 +53,8 @@ import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.block.entity.SkullBlockEntity;
import net.minecraft.world.level.storage.LevelStorageSource;
+import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.craftbukkit.CraftServer;
import org.slf4j.Logger;

// CraftBukkit start
@@ -769,39 +772,40 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
public String runCommand(RconConsoleSource rconConsoleSource, String s) {
// Folia start - region threading
// RIP RCON
Expand All @@ -23,16 +76,120 @@ index 0db571d23bc730372f6811052779661f7d95a354..9a79e75424fc912689cb2119334e36a0
rconConsoleSource.prepareForCommand();
final java.util.concurrent.atomic.AtomicReference<String> command = new java.util.concurrent.atomic.AtomicReference<>(s); // Paper
- this.executeBlocking(() -> {
+ io.papermc.paper.threadedregions.RegionizedServer.getInstance().addTaskWithoutNotify(() ->{
CommandSourceStack wrapper = rconConsoleSource.createCommandSourceStack();
RemoteServerCommandEvent event = new RemoteServerCommandEvent(rconConsoleSource.getBukkitSender(wrapper), s);
server.getPluginManager().callEvent(event);

- CommandSourceStack wrapper = rconConsoleSource.createCommandSourceStack();
- RemoteServerCommandEvent event = new RemoteServerCommandEvent(rconConsoleSource.getBukkitSender(wrapper), s);
- server.getPluginManager().callEvent(event);
- if (event.isCancelled()) {
- return;
- }
+ CommandSourceStack wrapper = rconConsoleSource.createCommandSourceStack();
+ RemoteServerCommandEvent event = new RemoteServerCommandEvent(rconConsoleSource.getBukkitSender(wrapper), s);
+ server.getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return "null";
+ }

- // Paper start
- command.set(event.getCommand());
- if (event.getCommand().toLowerCase().startsWith("timings") && event.getCommand().toLowerCase().matches("timings (report|paste|get|merged|seperate)")) {
- org.bukkit.command.BufferedCommandSender sender = new org.bukkit.command.BufferedCommandSender();
- Waitable<String> waitable = new Waitable<>() {
- @Override
- protected String evaluate() {
- return sender.getBuffer();
- }
- };
- waitableArray[0] = waitable;
- co.aikar.timings.Timings.generateReport(new co.aikar.timings.TimingsReportListener(sender, waitable));
- } else {
+ // Paper start
+ command.set(event.getCommand());
+ if (event.getCommand().toLowerCase().startsWith("timings") && event.getCommand().toLowerCase().matches("timings (report|paste|get|merged|seperate)")) {
+ org.bukkit.command.BufferedCommandSender sender = new org.bukkit.command.BufferedCommandSender();
+ Waitable<String> waitable = new Waitable<>() {
+ @Override
+ protected String evaluate() {
+ return sender.getBuffer();
+ }
+ };
+ waitableArray[0] = waitable;
+ co.aikar.timings.Timings.generateReport(new co.aikar.timings.TimingsReportListener(sender, waitable));
+ } else {
// Paper end
- ConsoleInput serverCommand = new ConsoleInput(event.getCommand(), wrapper);
- server.dispatchServerCommand(event.getSender(), serverCommand);
- } // Paper
- });
+ ConsoleInput serverCommand = new ConsoleInput(event.getCommand(), wrapper);
+ if (!server.dispatchServerCommand(rconConsoleSource.getBukkitSender(wrapper), serverCommand)){
+ rconConsoleSource.sendMessage("Error while dispatching command!");
+ }
+ } // Paper
// Paper start
if (waitableArray[0] != null) {
//noinspection unchecked
diff --git a/src/main/java/net/minecraft/server/rcon/RconConsoleSource.java b/src/main/java/net/minecraft/server/rcon/RconConsoleSource.java
index a04cf04cb694237ec77b38fc576f0dfc9264a25a..a88873878fa8291ab0ad0740ad908e1aa76747a1 100644
--- a/src/main/java/net/minecraft/server/rcon/RconConsoleSource.java
+++ b/src/main/java/net/minecraft/server/rcon/RconConsoleSource.java
@@ -48,7 +48,7 @@ public class RconConsoleSource implements CommandSource {
}

@Override
- public org.bukkit.command.CommandSender getBukkitSender(CommandSourceStack wrapper) {
+ public CraftRemoteConsoleCommandSender getBukkitSender(CommandSourceStack wrapper) {
return this.remoteConsole;
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/server/rcon/thread/RconClient.java b/src/main/java/net/minecraft/server/rcon/thread/RconClient.java
index dd7cd41a334ab6c3d5c76f9dcc64c34b093e3be0..4ec8409fae0e68411d9c9bb01b72cdba2f29d605 100644
--- a/src/main/java/net/minecraft/server/rcon/thread/RconClient.java
+++ b/src/main/java/net/minecraft/server/rcon/thread/RconClient.java
@@ -79,11 +79,26 @@ public class RconClient extends GenericThread {
if (this.authed) {
String s = PktUtils.stringFromByteArray(this.buf, k, i);

- try {
- this.sendCmdResponse(l, this.serverInterface.runCommand(this.rconConsoleSource, s)); // CraftBukkit
- } catch (Exception exception) {
- this.sendCmdResponse(l, "Error executing: " + s + " (" + exception.getMessage() + ")");
- }
+ io.papermc.paper.threadedregions.RegionizedServer.getInstance().addTask(() -> {
+ try {
+ this.sendCmdResponse(l, this.serverInterface.runCommand(this.rconConsoleSource, s)); // CraftBukkit
+ } catch (Exception exception) {
+ String msg = "";
+ for (StackTraceElement el : exception.getStackTrace()){
+ msg += el.toString() + '\n';
+ }
+ try {
+ this.sendCmdResponse(l, "Error executing: " + s + "\n" + msg);
+ } catch (IOException e) {
+ String msg2 = "";
+ for (StackTraceElement el : e.getStackTrace()){
+ msg2 += el.toString() + '\n';
+ }
+ System.out.println("Error executing: " + s + "\n" + msg2);
+ }
+ }
+ });
+
continue;
}

diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index d95cb97098afce6e35d3c55bfb9ac3902acc5bfc..98eb9b3b760e7d865f1e88177011500ee07a1bbb 100644
index d95cb97098afce6e35d3c55bfb9ac3902acc5bfc..62000c2021bfd695374b2a7fd922c6dbb6a13b4c 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1012,7 +1012,7 @@ public final class CraftServer implements Server {
@@ -259,6 +259,7 @@ import org.bukkit.scoreboard.Criteria;
import org.bukkit.structure.StructureManager;
import org.bukkit.util.StringUtil;
import org.bukkit.util.permissions.DefaultPermissions;
+import org.spigotmc.AsyncCatcher;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;
@@ -1012,7 +1013,7 @@ public final class CraftServer implements Server {
});
} else {
// huh?
Expand All @@ -41,7 +198,7 @@ index d95cb97098afce6e35d3c55bfb9ac3902acc5bfc..98eb9b3b760e7d865f1e88177011500e
}
}
// Folia end - region threading
@@ -1021,19 +1021,40 @@ public final class CraftServer implements Server {
@@ -1021,19 +1022,40 @@ public final class CraftServer implements Server {
public boolean dispatchCommand(CommandSender sender, String commandLine) {
Preconditions.checkArgument(sender != null, "sender cannot be null");
Preconditions.checkArgument(commandLine != null, "commandLine cannot be null");
Expand All @@ -62,7 +219,7 @@ index d95cb97098afce6e35d3c55bfb9ac3902acc5bfc..98eb9b3b760e7d865f1e88177011500e
// Folia end - region threading
-
+ // Paper Start
+ if (/*!org.spigotmc.AsyncCatcher.shuttingDown && */!Bukkit.isPrimaryThread()) {
+ if (AsyncCatcher.enabled && !Bukkit.isPrimaryThread()) {
+ final CommandSender fSender = sender;
+ final String fCommandLine = commandLine;
+ Bukkit.getLogger().log(Level.SEVERE, "Command Dispatched Async: " + commandLine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Subject: [PATCH] Use-thread-unsafe-random-for-mob-spawning


diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
index 7218200b140f658ae3009c1a423124cd4287dcbd..291d26afaea1a492f59c2e0ab33ca232a411ac58 100644
index 0f385f409d4469f5eba4410504a3f4544fc849dc..212f34d7bb41148addca45d9c0dc70e440e3f9cb 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -1078,7 +1078,8 @@ public class ServerLevel extends Level implements WorldGenLevel {
@@ -1098,7 +1098,8 @@ public class ServerLevel extends Level implements WorldGenLevel {
}
// Paper start - optimise random block ticking
private final ThreadLocal<BlockPos.MutableBlockPos> chunkTickMutablePosition = ThreadLocal.withInitial(() -> new BlockPos.MutableBlockPos()); // Folia - region threading
Expand Down
4 changes: 2 additions & 2 deletions patches/server/0015-Add-Foldenor-commands.patch
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ index 0000000000000000000000000000000000000000..ad854d09999ce2bee9e48976eb79ef02
+ }
+}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 98eb9b3b760e7d865f1e88177011500ee07a1bbb..b18f8e47a52cb4c705a17c2cee814b9dccc3ca5a 100644
index 62000c2021bfd695374b2a7fd922c6dbb6a13b4c..95fd5ca9d4b93b0a350040d31493ee7ef4a5478b 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1139,6 +1139,7 @@ public final class CraftServer implements Server {
@@ -1140,6 +1140,7 @@ public final class CraftServer implements Server {
this.reloadData();
org.spigotmc.SpigotConfig.registerCommands(); // Spigot
io.papermc.paper.command.PaperCommands.registerCommands(this.console); // Paper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Subject: [PATCH] Redirect-getTPS-function-to-tegion-tps-or-return-20-tps


diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index b18f8e47a52cb4c705a17c2cee814b9dccc3ca5a..24f7606bcfa12d3971f94880e2d4554831f9b55b 100644
index 95fd5ca9d4b93b0a350040d31493ee7ef4a5478b..cf6efdc6a81dfe154b496c7bfbd0782b4791d868 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -15,6 +15,9 @@ import com.mojang.brigadier.tree.LiteralCommandNode;
Expand All @@ -18,7 +18,7 @@ index b18f8e47a52cb4c705a17c2cee814b9dccc3ca5a..24f7606bcfa12d3971f94880e2d45548
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
@@ -2940,11 +2943,21 @@ public final class CraftServer implements Server {
@@ -2941,11 +2944,21 @@ public final class CraftServer implements Server {
// Paper - Add getTPS API - Further improve tick loop
@Override
public double[] getTPS() {
Expand Down

0 comments on commit 32b6735

Please sign in to comment.