3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 12:30:06 +01:00
Paper/Spigot-Server-Patches/0640-Fire-event-on-GS4-query.patch

205 Zeilen
12 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2019-03-24 18:01:31 +01:00
From: Mark Vainomaa <mikroskeem@mikroskeem.eu>
Date: Sun, 17 Mar 2019 21:46:56 +0200
Subject: [PATCH] Fire event on GS4 query
diff --git a/src/main/java/net/minecraft/server/rcon/RemoteStatusReply.java b/src/main/java/net/minecraft/server/rcon/RemoteStatusReply.java
index 57ff3db0a0199ef03045b880e598407886b0306b..1b6761f75d97c49b1bf1ce3db631b7250c9489bd 100644
--- a/src/main/java/net/minecraft/server/rcon/RemoteStatusReply.java
+++ b/src/main/java/net/minecraft/server/rcon/RemoteStatusReply.java
@@ -18,15 +18,27 @@ public class RemoteStatusReply {
this.b.write(abyte, 0, abyte.length);
}
+ public void writeString(String string) throws IOException { this.a(string); } // Paper - OBFHELPER
public void a(String s) throws IOException {
this.b.writeBytes(s);
this.b.write(0);
}
+ // Paper start - unchecked exception variant to use in Stream API
+ public void writeStringUnchecked(String string) {
+ try {
+ writeString(string);
+ } catch (IOException e) {
+ com.destroystokyo.paper.util.SneakyThrow.sneaky(e);
+ }
+ }
+ // Paper end
+ public void writeInt(int i) throws IOException { this.a(i); } // Paper - OBFHELPER
public void a(int i) throws IOException {
this.b.write(i);
}
+ public void writeShort(short i) throws IOException { this.a(i); } // Paper - OBFHELPER
public void a(short short0) throws IOException {
this.b.writeShort(Short.reverseBytes(short0));
}
diff --git a/src/main/java/net/minecraft/server/rcon/thread/RemoteStatusListener.java b/src/main/java/net/minecraft/server/rcon/thread/RemoteStatusListener.java
2021-03-16 16:50:45 +01:00
index 55b379af2e0c8c3513a76a346d381cd3dbcabe40..59769f7ea808b952cd02192c7121c248756998e9 100644
--- a/src/main/java/net/minecraft/server/rcon/thread/RemoteStatusListener.java
+++ b/src/main/java/net/minecraft/server/rcon/thread/RemoteStatusListener.java
2021-03-16 16:50:45 +01:00
@@ -16,6 +16,7 @@ import java.util.Random;
import javax.annotation.Nullable;
import net.minecraft.SystemUtils;
import net.minecraft.server.IMinecraftServer;
+import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.rcon.RemoteStatusReply;
import net.minecraft.server.rcon.StatusChallengeUtils;
import org.apache.logging.log4j.LogManager;
@@ -26,18 +27,18 @@ public class RemoteStatusListener extends RemoteConnectionThread {
2020-12-09 08:21:19 +01:00
private static final Logger LOGGER = LogManager.getLogger();
private long e;
private final int f;
- private final int g;
- private final int h;
- private final String i;
- private final String j;
+ private final int g; private final int getServerPort() { return this.g; } // Paper - OBFHELPER
+ private final int h; private final int getMaxPlayers() { return this.h; } // Paper - OBFHELPER
+ private final String i; private final String getMotd() { return this.i; } // Paper - OBFHELPER
+ private final String j; private final String getWorldName() { return this.j; } // Paper - OBFHELPER
private DatagramSocket k;
private final byte[] l = new byte[1460];
- private String m;
+ private String m; public final String getServerHost() { return this.m; } // Paper - OBFHELPER
private String n;
private final Map<SocketAddress, RemoteStatusListener.RemoteStatusChallenge> o;
- private final RemoteStatusReply p;
+ private final RemoteStatusReply p; private final RemoteStatusReply getCachedFullResponse() { return this.p; } // Paper - OBFHELPER
private long q;
- private final IMinecraftServer r;
+ private final IMinecraftServer r; private final IMinecraftServer getServer() { return this.r; } // Paper - OBFHELPER
2019-03-24 18:01:31 +01:00
2020-12-09 08:21:19 +01:00
private RemoteStatusListener(IMinecraftServer iminecraftserver, int i) {
super("Query Listener");
2021-03-16 16:50:45 +01:00
@@ -107,6 +108,7 @@ public class RemoteStatusListener extends RemoteConnectionThread {
2019-03-24 18:01:31 +01:00
2019-05-28 01:01:45 +02:00
remotestatusreply.a((int) 0);
remotestatusreply.a(this.a(datagrampacket.getSocketAddress()));
2020-12-09 08:21:19 +01:00
+ /* Paper start - GS4 Query event
remotestatusreply.a(this.i);
2019-05-28 01:01:45 +02:00
remotestatusreply.a("SMP");
2020-12-09 08:21:19 +01:00
remotestatusreply.a(this.j);
2021-03-16 16:50:45 +01:00
@@ -114,6 +116,31 @@ public class RemoteStatusListener extends RemoteConnectionThread {
2020-12-09 08:21:19 +01:00
remotestatusreply.a(Integer.toString(this.h));
remotestatusreply.a((short) this.g);
2019-05-28 01:01:45 +02:00
remotestatusreply.a(this.m);
2020-12-09 08:21:19 +01:00
+ */
+ 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()
+ .motd(this.getMotd())
+ .map(this.getWorldName())
+ .currentPlayers(this.getServer().getPlayerCount())
+ .maxPlayers(this.getMaxPlayers())
+ .port(this.getServerPort())
+ .hostname(this.getServerHost())
+ .gameVersion(this.getServer().getVersion())
+ .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, datagrampacket.getAddress(), queryResponse);
+ queryEvent.callEvent();
+ queryResponse = queryEvent.getResponse();
+ remotestatusreply.writeString(queryResponse.getMotd());
+ remotestatusreply.writeString("SMP");
+ remotestatusreply.writeString(queryResponse.getMap());
+ remotestatusreply.writeString(Integer.toString(queryResponse.getCurrentPlayers()));
+ remotestatusreply.writeString(Integer.toString(queryResponse.getMaxPlayers()));
+ remotestatusreply.writeShort((short) queryResponse.getPort());
+ remotestatusreply.writeString(queryResponse.getHostname());
+ // Paper end
2019-05-28 01:01:45 +02:00
this.a(remotestatusreply.a(), datagrampacket);
2020-12-09 08:21:19 +01:00
RemoteStatusListener.LOGGER.debug("Status [{}]", socketaddress);
2019-05-28 01:01:45 +02:00
}
2021-03-16 16:50:45 +01:00
@@ -150,6 +177,7 @@ public class RemoteStatusListener extends RemoteConnectionThread {
2020-12-09 08:21:19 +01:00
this.p.a("splitnum");
this.p.a((int) 128);
this.p.a((int) 0);
2019-03-24 18:01:31 +01:00
+ /* Paper start - GS4 Query event
2020-12-09 08:21:19 +01:00
this.p.a("hostname");
this.p.a(this.i);
this.p.a("gametype");
2021-03-16 16:50:45 +01:00
@@ -185,6 +213,79 @@ public class RemoteStatusListener extends RemoteConnectionThread {
2019-03-24 18:01:31 +01:00
}
2020-12-09 08:21:19 +01:00
this.p.a((int) 0);
2019-03-24 18:01:31 +01:00
+ */
+ // Pack plugins
+ java.util.List<com.destroystokyo.paper.event.server.GS4QueryEvent.QueryResponse.PluginInformation> plugins = java.util.Collections.emptyList();
+ org.bukkit.plugin.Plugin[] bukkitPlugins;
2020-12-09 08:21:19 +01:00
+ if (((DedicatedServer) this.getServer()).server.getQueryPlugins() && (bukkitPlugins = org.bukkit.Bukkit.getPluginManager().getPlugins()).length > 0) {
2019-03-24 18:01:31 +01:00
+ plugins = java.util.stream.Stream.of(bukkitPlugins)
+ .map(plugin -> com.destroystokyo.paper.event.server.GS4QueryEvent.QueryResponse.PluginInformation.of(plugin.getName(), plugin.getDescription().getVersion()))
+ .collect(java.util.stream.Collectors.toList());
+ }
+
+ com.destroystokyo.paper.event.server.GS4QueryEvent.QueryResponse queryResponse = com.destroystokyo.paper.event.server.GS4QueryEvent.QueryResponse.builder()
+ .motd(this.getMotd())
+ .map(this.getWorldName())
2020-12-09 08:21:19 +01:00
+ .currentPlayers(this.getServer().getPlayerCount())
2019-03-24 18:01:31 +01:00
+ .maxPlayers(this.getMaxPlayers())
+ .port(this.getServerPort())
+ .hostname(this.getServerHost())
+ .plugins(plugins)
+ .players(this.getServer().getPlayers())
+ .gameVersion(this.getServer().getVersion())
+ .serverVersion(org.bukkit.Bukkit.getServer().getName() + " on " + org.bukkit.Bukkit.getServer().getBukkitVersion())
+ .build();
+ 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, datagrampacket.getAddress(), queryResponse);
+ queryEvent.callEvent();
+ queryResponse = queryEvent.getResponse();
+ this.getCachedFullResponse().writeString("hostname");
+ this.getCachedFullResponse().writeString(queryResponse.getMotd());
+ this.getCachedFullResponse().writeString("gametype");
+ this.getCachedFullResponse().writeString("SMP");
+ this.getCachedFullResponse().writeString("game_id");
+ this.getCachedFullResponse().writeString("MINECRAFT");
+ this.getCachedFullResponse().writeString("version");
+ this.getCachedFullResponse().writeString(queryResponse.getGameVersion());
+ this.getCachedFullResponse().writeString("plugins");
+ java.lang.StringBuilder pluginsString = new java.lang.StringBuilder();
+ pluginsString.append(queryResponse.getServerVersion());
2020-12-09 08:21:19 +01:00
+ if (!queryResponse.getPlugins().isEmpty()) {
2019-03-24 18:01:31 +01:00
+ pluginsString.append(": ");
2020-12-09 08:21:19 +01:00
+ java.util.Iterator<com.destroystokyo.paper.event.server.GS4QueryEvent.QueryResponse.PluginInformation> iter = queryResponse.getPlugins().iterator();
+ while (iter.hasNext()) {
2019-03-24 18:01:31 +01:00
+ com.destroystokyo.paper.event.server.GS4QueryEvent.QueryResponse.PluginInformation info = iter.next();
+ pluginsString.append(info.getName());
+ if (info.getVersion() != null) {
2020-12-09 08:21:19 +01:00
+ pluginsString.append(' ').append(info.getVersion().replace(";", ","));
2019-03-24 18:01:31 +01:00
+ }
+ if (iter.hasNext()) {
+ pluginsString.append(';').append(' ');
+ }
+ }
+ }
+ this.getCachedFullResponse().writeString(pluginsString.toString());
+ this.getCachedFullResponse().writeString("map");
+ this.getCachedFullResponse().writeString(queryResponse.getMap());
+ this.getCachedFullResponse().writeString("numplayers");
+ this.getCachedFullResponse().writeString(Integer.toString(queryResponse.getCurrentPlayers()));
+ this.getCachedFullResponse().writeString("maxplayers");
+ this.getCachedFullResponse().writeString(Integer.toString(queryResponse.getMaxPlayers()));
+ this.getCachedFullResponse().writeString("hostport");
+ this.getCachedFullResponse().writeString(Integer.toString(queryResponse.getPort()));
+ this.getCachedFullResponse().writeString("hostip");
+ this.getCachedFullResponse().writeString(queryResponse.getHostname());
+ // The "meaningless data" start, copied from above
+ this.getCachedFullResponse().writeInt(0);
+ this.getCachedFullResponse().writeInt(1);
+ this.getCachedFullResponse().writeString("player_");
+ this.getCachedFullResponse().writeInt(0);
+ // "Meaningless data" end
+ queryResponse.getPlayers().forEach(this.getCachedFullResponse()::writeStringUnchecked);
+ this.getCachedFullResponse().writeInt(0);
+ // Paper end
2020-12-09 08:21:19 +01:00
return this.p.a();
2019-03-24 18:01:31 +01:00
}
}