diff options
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/server/rcon')
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/server/rcon/RconConsoleSource.java.patch | 61 | ||||
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/server/rcon/thread/RconClient.java.patch | 226 |
2 files changed, 287 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/server/rcon/RconConsoleSource.java.patch b/patch-remap/mache-vineflower/net/minecraft/server/rcon/RconConsoleSource.java.patch new file mode 100644 index 0000000000..02e3da3298 --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/server/rcon/RconConsoleSource.java.patch @@ -0,0 +1,61 @@ +--- a/net/minecraft/server/rcon/RconConsoleSource.java ++++ b/net/minecraft/server/rcon/RconConsoleSource.java +@@ -5,17 +5,27 @@ + import net.minecraft.network.chat.Component; + import net.minecraft.server.MinecraftServer; + import net.minecraft.server.level.ServerLevel; ++import net.minecraft.world.entity.Entity; + import net.minecraft.world.phys.Vec2; + import net.minecraft.world.phys.Vec3; +- ++// CraftBukkit start ++import java.net.SocketAddress; ++import org.bukkit.craftbukkit.command.CraftRemoteConsoleCommandSender; ++// CraftBukkit end + public class RconConsoleSource implements CommandSource { ++ + private static final String RCON = "Rcon"; + private static final Component RCON_COMPONENT = Component.literal("Rcon"); + private final StringBuffer buffer = new StringBuffer(); + private final MinecraftServer server; ++ // CraftBukkit start ++ public final SocketAddress socketAddress; ++ private final CraftRemoteConsoleCommandSender remoteConsole = new CraftRemoteConsoleCommandSender(this); + +- public RconConsoleSource(MinecraftServer server) { +- this.server = server; ++ public RconConsoleSource(MinecraftServer minecraftserver, SocketAddress socketAddress) { ++ this.socketAddress = socketAddress; ++ // CraftBukkit end ++ this.server = minecraftserver; + } + + public void prepareForCommand() { +@@ -27,13 +37,23 @@ + } + + public CommandSourceStack createCommandSourceStack() { +- ServerLevel serverLevel = this.server.overworld(); +- return new CommandSourceStack( +- this, Vec3.atLowerCornerOf(serverLevel.getSharedSpawnPos()), Vec2.ZERO, serverLevel, 4, "Rcon", RCON_COMPONENT, this.server, null +- ); ++ ServerLevel worldserver = this.server.overworld(); ++ ++ return new CommandSourceStack(this, Vec3.atLowerCornerOf(worldserver.getSharedSpawnPos()), Vec2.ZERO, worldserver, 4, "Rcon", RconConsoleSource.RCON_COMPONENT, this.server, (Entity) null); + } + ++ // CraftBukkit start - Send a String ++ public void sendMessage(String message) { ++ this.buffer.append(message); ++ } ++ + @Override ++ public org.bukkit.command.CommandSender getBukkitSender(CommandSourceStack wrapper) { ++ return this.remoteConsole; ++ } ++ // CraftBukkit end ++ ++ @Override + public void sendSystemMessage(Component component) { + this.buffer.append(component.getString()); + } diff --git a/patch-remap/mache-vineflower/net/minecraft/server/rcon/thread/RconClient.java.patch b/patch-remap/mache-vineflower/net/minecraft/server/rcon/thread/RconClient.java.patch new file mode 100644 index 0000000000..8c571cd718 --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/server/rcon/thread/RconClient.java.patch @@ -0,0 +1,226 @@ +--- a/net/minecraft/server/rcon/thread/RconClient.java ++++ b/net/minecraft/server/rcon/thread/RconClient.java +@@ -8,11 +8,15 @@ + import java.net.Socket; + import java.nio.charset.StandardCharsets; + import java.util.Locale; ++import org.slf4j.Logger; + import net.minecraft.server.ServerInterface; ++// CraftBukkit start ++import net.minecraft.server.dedicated.DedicatedServer; + import net.minecraft.server.rcon.PktUtils; +-import org.slf4j.Logger; ++import net.minecraft.server.rcon.RconConsoleSource; + + public class RconClient extends GenericThread { ++ + private static final Logger LOGGER = LogUtils.getLogger(); + private static final int SERVERDATA_AUTH = 3; + private static final int SERVERDATA_EXECCOMMAND = 2; +@@ -23,99 +27,116 @@ + private final Socket client; + private final byte[] buf = new byte[1460]; + private final String rconPassword; +- private final ServerInterface serverInterface; ++ // CraftBukkit start ++ private final DedicatedServer serverInterface; ++ private final RconConsoleSource rconConsoleSource; ++ // CraftBukkit end + + RconClient(ServerInterface serverInterface, String rconPassword, Socket client) { + super("RCON Client " + client.getInetAddress()); +- this.serverInterface = serverInterface; ++ this.serverInterface = (DedicatedServer) serverInterface; // CraftBukkit + this.client = client; + + try { + this.client.setSoTimeout(0); +- } catch (Exception var5) { ++ } catch (Exception exception) { + this.running = false; + } + + this.rconPassword = rconPassword; ++ this.rconConsoleSource = new net.minecraft.server.rcon.RconConsoleSource(this.serverInterface, client.getRemoteSocketAddress()); // CraftBukkit + } + +- @Override + public void run() { ++ // CraftBukkit start - decompile error: switch try / while statement + try { +- try { +- while (this.running) { +- BufferedInputStream bufferedInputStream = new BufferedInputStream(this.client.getInputStream()); +- int i = bufferedInputStream.read(this.buf, 0, 1460); +- if (10 > i) { +- return; +- } ++ while (true) { ++ // CraftBukkit end ++ if (!this.running) { ++ return; ++ } + +- int i1 = 0; +- int i2 = PktUtils.intFromByteArray(this.buf, 0, i); +- if (i2 != i - 4) { +- return; +- } ++ BufferedInputStream bufferedinputstream = new BufferedInputStream(this.client.getInputStream()); ++ int i = bufferedinputstream.read(this.buf, 0, 1460); + +- i1 += 4; +- int i3 = PktUtils.intFromByteArray(this.buf, i1, i); +- i1 += 4; +- int i4 = PktUtils.intFromByteArray(this.buf, i1); +- int var21 = i1 + 4; +- switch (i4) { ++ if (10 > i) { ++ return; ++ } ++ ++ byte b0 = 0; ++ int j = PktUtils.intFromByteArray(this.buf, 0, i); ++ ++ if (j == i - 4) { ++ int k = b0 + 4; ++ int l = PktUtils.intFromByteArray(this.buf, k, i); ++ ++ k += 4; ++ int i1 = PktUtils.intFromByteArray(this.buf, k); ++ ++ k += 4; ++ switch (i1) { + case 2: + if (this.authed) { +- String string1 = PktUtils.stringFromByteArray(this.buf, var21, i); ++ String s = PktUtils.stringFromByteArray(this.buf, k, i); + + try { +- this.sendCmdResponse(i3, this.serverInterface.runCommand(string1)); +- } catch (Exception var15) { +- this.sendCmdResponse(i3, "Error executing: " + string1 + " (" + var15.getMessage() + ")"); ++ this.sendCmdResponse(l, this.serverInterface.runCommand(this.rconConsoleSource, s)); // CraftBukkit ++ } catch (Exception exception) { ++ this.sendCmdResponse(l, "Error executing: " + s + " (" + exception.getMessage() + ")"); + } +- break; ++ continue; + } + + this.sendAuthFailure(); +- break; ++ continue; + case 3: +- String string = PktUtils.stringFromByteArray(this.buf, var21, i); +- i1 = var21 + string.length(); +- if (!string.isEmpty() && string.equals(this.rconPassword)) { ++ String s1 = PktUtils.stringFromByteArray(this.buf, k, i); ++ int j1 = k + s1.length(); ++ ++ if (!s1.isEmpty() && s1.equals(this.rconPassword)) { + this.authed = true; +- this.send(i3, 2, ""); +- break; ++ this.send(l, 2, ""); ++ continue; + } + + this.authed = false; + this.sendAuthFailure(); +- break; ++ continue; + default: +- this.sendCmdResponse(i3, String.format(Locale.ROOT, "Unknown request %s", Integer.toHexString(i4))); ++ this.sendCmdResponse(l, String.format(Locale.ROOT, "Unknown request %s", Integer.toHexString(i1))); ++ continue; + } + } +- ++ } // CraftBukkit - decompile error: switch try / while statement ++ } catch (IOException ioexception) { + return; +- } catch (IOException var16) { +- } catch (Exception var17) { +- LOGGER.error("Exception whilst parsing RCON input", (Throwable)var17); ++ } catch (Exception exception1) { ++ RconClient.LOGGER.error("Exception whilst parsing RCON input", exception1); ++ return; ++ } finally { ++ this.closeSocket(); ++ RconClient.LOGGER.info("Thread {} shutting down", this.name); ++ this.running = false; + } +- } finally { +- this.closeSocket(); +- LOGGER.info("Thread {} shutting down", this.name); +- this.running = false; +- } ++ ++ // CraftBukkit start - decompile error: switch try / while statement ++ // return; ++ // } ++ // CraftBukkit end + } + +- private void send(int id, int i, String message) throws IOException { +- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(1248); +- DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); +- byte[] bytes = message.getBytes(StandardCharsets.UTF_8); +- dataOutputStream.writeInt(Integer.reverseBytes(bytes.length + 10)); +- dataOutputStream.writeInt(Integer.reverseBytes(id)); +- dataOutputStream.writeInt(Integer.reverseBytes(i)); +- dataOutputStream.write(bytes); +- dataOutputStream.write(0); +- dataOutputStream.write(0); +- this.client.getOutputStream().write(byteArrayOutputStream.toByteArray()); ++ private void send(int id, int j, String message) throws IOException { ++ ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(1248); ++ DataOutputStream dataoutputstream = new DataOutputStream(bytearrayoutputstream); ++ byte[] abyte = message.getBytes(StandardCharsets.UTF_8); ++ ++ dataoutputstream.writeInt(Integer.reverseBytes(abyte.length + 10)); ++ dataoutputstream.writeInt(Integer.reverseBytes(id)); ++ dataoutputstream.writeInt(Integer.reverseBytes(j)); ++ dataoutputstream.write(abyte); ++ dataoutputstream.write(0); ++ dataoutputstream.write(0); ++ this.client.getOutputStream().write(bytearrayoutputstream.toByteArray()); + } + + private void sendAuthFailure() throws IOException { +@@ -123,14 +144,16 @@ + } + + private void sendCmdResponse(int id, String message) throws IOException { +- int len = message.length(); ++ int j = message.length(); + + do { +- int i = 4096 <= len ? 4096 : len; +- this.send(id, 0, message.substring(0, i)); +- message = message.substring(i); +- len = message.length(); +- } while (0 != len); ++ int k = 4096 <= j ? 4096 : j; ++ ++ this.send(id, 0, message.substring(0, k)); ++ message = message.substring(k); ++ j = message.length(); ++ } while (0 != j); ++ + } + + @Override +@@ -143,8 +166,9 @@ + private void closeSocket() { + try { + this.client.close(); +- } catch (IOException var2) { +- LOGGER.warn("Failed to close socket", (Throwable)var2); ++ } catch (IOException ioexception) { ++ RconClient.LOGGER.warn("Failed to close socket", ioexception); + } ++ + } + } |