net.minecraft.server.rcon.thread

This commit is contained in:
Jake Potrebic 2024-12-14 18:40:23 -08:00
parent e9680a5afe
commit 92aec10cc4
No known key found for this signature in database
GPG Key ID: ECE0B3C133C016C5
4 changed files with 54 additions and 98 deletions

View File

@ -1,11 +1,11 @@
--- a/net/minecraft/server/rcon/thread/QueryThreadGs4.java
+++ b/net/minecraft/server/rcon/thread/QueryThreadGs4.java
@@ -106,13 +106,32 @@
@@ -106,13 +_,32 @@
NetworkDataOutputStream networkDataOutputStream = new NetworkDataOutputStream(1460);
networkDataOutputStream.write(0);
networkDataOutputStream.writeBytes(this.getIdentBytes(packet.getSocketAddress()));
networkDataOutputStream.writeBytes(this.getIdentBytes(requestPacket.getSocketAddress()));
- networkDataOutputStream.writeString(this.serverName);
+
+ // Paper start
+ com.destroystokyo.paper.event.server.GS4QueryEvent.QueryType queryType =
+ com.destroystokyo.paper.event.server.GS4QueryEvent.QueryType.BASIC;
+ com.destroystokyo.paper.event.server.GS4QueryEvent.QueryResponse queryResponse = com.destroystokyo.paper.event.server.GS4QueryEvent.QueryResponse.builder()
@ -19,7 +19,7 @@
+ .serverVersion(org.bukkit.Bukkit.getServer().getName() + " on " + org.bukkit.Bukkit.getServer().getBukkitVersion())
+ .build();
+ com.destroystokyo.paper.event.server.GS4QueryEvent queryEvent =
+ new com.destroystokyo.paper.event.server.GS4QueryEvent(queryType, packet.getAddress(), queryResponse);
+ new com.destroystokyo.paper.event.server.GS4QueryEvent(queryType, requestPacket.getAddress(), queryResponse);
+ queryEvent.callEvent();
+ queryResponse = queryEvent.getResponse();
+
@ -36,10 +36,10 @@
+ networkDataOutputStream.writeShort((short) queryResponse.getPort());
+ networkDataOutputStream.writeString(queryResponse.getHostname());
+ // Paper end
this.sendTo(networkDataOutputStream.toByteArray(), packet);
this.sendTo(networkDataOutputStream.toByteArray(), requestPacket);
LOGGER.debug("Status [{}]", socketAddress);
}
@@ -147,31 +166,75 @@
@@ -147,31 +_,75 @@
this.rulesResponse.writeString("splitnum");
this.rulesResponse.write(128);
this.rulesResponse.write(0);
@ -68,7 +68,7 @@
+ com.destroystokyo.paper.event.server.GS4QueryEvent.QueryType queryType =
+ com.destroystokyo.paper.event.server.GS4QueryEvent.QueryType.FULL;
+ com.destroystokyo.paper.event.server.GS4QueryEvent queryEvent =
+ new com.destroystokyo.paper.event.server.GS4QueryEvent(queryType, packet.getAddress(), queryResponse);
+ new com.destroystokyo.paper.event.server.GS4QueryEvent(queryType, requestPacket.getAddress(), queryResponse);
+ queryEvent.callEvent();
+ queryResponse = queryEvent.getResponse();
this.rulesResponse.writeString("hostname");
@ -119,8 +119,8 @@
this.rulesResponse.write(1);
this.rulesResponse.writeString("player_");
this.rulesResponse.write(0);
- String[] strings = this.serverInterface.getPlayerNames();
+ String[] strings = queryResponse.getPlayers().toArray(String[]::new);
- String[] playerNames = this.serverInterface.getPlayerNames();
+ String[] playerNames = queryResponse.getPlayers().toArray(String[]::new);
for (String string : strings) {
for (String string : playerNames) {
this.rulesResponse.writeString(string);

View File

@ -0,0 +1,36 @@
--- a/net/minecraft/server/rcon/thread/RconClient.java
+++ b/net/minecraft/server/rcon/thread/RconClient.java
@@ -23,11 +_,14 @@
private final Socket client;
private final byte[] buf = new byte[1460];
private final String rconPassword;
- private final ServerInterface serverInterface;
+ // CraftBukkit start
+ private final net.minecraft.server.dedicated.DedicatedServer serverInterface;
+ private final net.minecraft.server.rcon.RconConsoleSource rconConsoleSource;
+ // CraftBukkit end
RconClient(ServerInterface serverInterface, String rconPassword, Socket client) {
super("RCON Client " + client.getInetAddress());
- this.serverInterface = serverInterface;
+ this.serverInterface = (net.minecraft.server.dedicated.DedicatedServer) serverInterface; // CraftBukkit
this.client = client;
try {
@@ -37,6 +_,7 @@
}
this.rconPassword = rconPassword;
+ this.rconConsoleSource = new net.minecraft.server.rcon.RconConsoleSource(this.serverInterface, client.getRemoteSocketAddress()); // CraftBukkit
}
@Override
@@ -67,7 +_,7 @@
String string1 = PktUtils.stringFromByteArray(this.buf, i1, i);
try {
- this.sendCmdResponse(i3, this.serverInterface.runCommand(string1));
+ this.sendCmdResponse(i3, this.serverInterface.runCommand(this.rconConsoleSource, string1)); // CraftBukkit
} catch (Exception var15) {
this.sendCmdResponse(i3, "Error executing: " + string1 + " (" + var15.getMessage() + ")");
}

View File

@ -1,15 +1,15 @@
--- a/net/minecraft/server/rcon/thread/RconThread.java
+++ b/net/minecraft/server/rcon/thread/RconThread.java
@@ -57,7 +57,7 @@
@@ -57,7 +_,7 @@
@Nullable
public static RconThread create(ServerInterface server) {
DedicatedServerProperties dedicatedServerProperties = server.getProperties();
- String string = server.getServerIp();
+ String string = dedicatedServerProperties.rconIp; // Paper - Configurable rcon ip
if (string.isEmpty()) {
string = "0.0.0.0";
public static RconThread create(ServerInterface serverInterface) {
DedicatedServerProperties properties = serverInterface.getProperties();
- String serverIp = serverInterface.getServerIp();
+ String serverIp = properties.rconIp; // Paper - Configurable rcon ip
if (serverIp.isEmpty()) {
serverIp = "0.0.0.0";
}
@@ -104,6 +104,14 @@
@@ -104,6 +_,14 @@
this.clients.clear();
}

View File

@ -1,80 +0,0 @@
--- a/net/minecraft/server/rcon/thread/RconClient.java
+++ b/net/minecraft/server/rcon/thread/RconClient.java
@@ -8,9 +8,12 @@
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 {
@@ -24,11 +27,14 @@
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 server, String password, Socket socket) {
super("RCON Client " + String.valueOf(socket.getInetAddress()));
- this.serverInterface = server;
+ this.serverInterface = (DedicatedServer) server; // CraftBukkit
this.client = socket;
try {
@@ -38,11 +44,14 @@
}
this.rconPassword = password;
+ this.rconConsoleSource = new net.minecraft.server.rcon.RconConsoleSource(this.serverInterface, socket.getRemoteSocketAddress()); // CraftBukkit
}
public void run() {
- while (true) {
- try {
+ // CraftBukkit start - decompile error: switch try / while statement
+ try {
+ while (true) {
+ // CraftBukkit end
if (!this.running) {
return;
}
@@ -71,7 +80,7 @@
String s = PktUtils.stringFromByteArray(this.buf, j, i);
try {
- this.sendCmdResponse(l, this.serverInterface.runCommand(s));
+ this.sendCmdResponse(l, this.serverInterface.runCommand(this.rconConsoleSource, s)); // CraftBukkit
} catch (Exception exception) {
this.sendCmdResponse(l, "Error executing: " + s + " (" + exception.getMessage() + ")");
}
@@ -98,6 +107,7 @@
continue;
}
}
+ } // CraftBukkit - decompile error: switch try / while statement
} catch (IOException ioexception) {
return;
} catch (Exception exception1) {
@@ -109,8 +119,10 @@
this.running = false;
}
- return;
- }
+ // CraftBukkit start - decompile error: switch try / while statement
+ // return;
+ // }
+ // CraftBukkit end
}
private void send(int sessionToken, int responseType, String message) throws IOException {