Paper/removed/1.16/0356-Fire-event-on-GS4-query.patch

218 lines
12 KiB
Diff
Raw Normal View History

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/RemoteConnectionThread.java b/src/main/java/net/minecraft/server/RemoteConnectionThread.java
index 66bfbcf02b5584a3abb29f5d7a32e3bb2c6abbea..d821ef9a757494d02eb3be36a619c67562faf967 100644
2019-03-24 18:01:31 +01:00
--- a/src/main/java/net/minecraft/server/RemoteConnectionThread.java
+++ b/src/main/java/net/minecraft/server/RemoteConnectionThread.java
@@ -15,7 +15,7 @@ public abstract class RemoteConnectionThread implements Runnable {
2019-05-05 19:19:34 +02:00
private static final Logger LOGGER = LogManager.getLogger();
2019-03-24 18:01:31 +01:00
private static final AtomicInteger i = new AtomicInteger(0);
protected boolean a;
2019-05-05 19:19:34 +02:00
- protected final IMinecraftServer b;
+ protected final IMinecraftServer b; protected IMinecraftServer getServer() { return this.b; } // Paper - OBFHELPER
2019-03-24 18:01:31 +01:00
protected final String c;
protected Thread d;
2019-05-05 19:19:34 +02:00
protected final int e = 5;
@@ -94,6 +94,7 @@ public abstract class RemoteConnectionThread implements Runnable {
this.b.g(s);
2019-03-24 18:01:31 +01:00
}
2019-05-05 19:19:34 +02:00
+ protected int getPlayerCount() { return this.d(); } // Paper - OBFHELPER
2019-03-24 18:01:31 +01:00
protected int d() {
return this.b.getPlayerCount();
}
diff --git a/src/main/java/net/minecraft/server/RemoteStatusListener.java b/src/main/java/net/minecraft/server/RemoteStatusListener.java
index f4f4e31d3c2ee8c7ecbe441f38b518217baa4ba5..d5025938473d3585e83994e890f742cf26c8061e 100644
2019-03-24 18:01:31 +01:00
--- a/src/main/java/net/minecraft/server/RemoteStatusListener.java
+++ b/src/main/java/net/minecraft/server/RemoteStatusListener.java
@@ -21,19 +21,19 @@ public class RemoteStatusListener extends RemoteConnectionThread {
private long h;
2019-05-05 19:19:34 +02:00
private final int i;
2019-03-24 18:01:31 +01:00
- private final int j;
- private final int k;
- private final String l;
- private final String m;
2019-05-05 19:19:34 +02:00
+ private final int j; private int getServerPort() { return this.j; } // Paper - OBFHELPER
+ private final int k; private int getMaxPlayers() { return this.k; } // Paper - OBFHELPER
+ private final String l; private String getMotd() { return this.l; } // Paper - OBFHELPER
+ private final String m; private String getWorldName() { return this.m; } // Paper - OBFHELPER
2019-03-24 18:01:31 +01:00
private DatagramSocket n;
private final byte[] o = new byte[1460];
private DatagramPacket p;
private final Map<SocketAddress, String> q;
- private String r;
2019-05-05 19:19:34 +02:00
+ private String r; private String getServerHost() { return this.r; } // Paper - OBFHELPER
2019-03-24 18:01:31 +01:00
private String s;
private final Map<SocketAddress, RemoteStatusListener.RemoteStatusChallenge> t;
private final long u;
- private final RemoteStatusReply v;
2019-05-05 19:19:34 +02:00
+ private final RemoteStatusReply v; private RemoteStatusReply getCachedFullResponse() { return this.v; } // Paper - OBFHELPER
2019-03-24 18:01:31 +01:00
private long w;
public RemoteStatusListener(IMinecraftServer iminecraftserver) {
2019-05-05 19:19:34 +02:00
@@ -91,6 +91,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()));
2019-03-24 18:01:31 +01:00
+ /* Paper start - GS4 Query event
2019-05-28 01:01:45 +02:00
remotestatusreply.a(this.l);
remotestatusreply.a("SMP");
remotestatusreply.a(this.m);
2019-05-05 19:19:34 +02:00
@@ -98,6 +99,31 @@ public class RemoteStatusListener extends RemoteConnectionThread {
2019-05-28 01:01:45 +02:00
remotestatusreply.a(Integer.toString(this.k));
remotestatusreply.a((short) this.j);
remotestatusreply.a(this.r);
2019-03-24 18:01:31 +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.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);
this.a("Status [" + socketaddress + "]");
}
2019-05-05 19:19:34 +02:00
@@ -134,6 +160,7 @@ public class RemoteStatusListener extends RemoteConnectionThread {
2019-03-24 18:01:31 +01:00
this.v.a("splitnum");
this.v.a((int) 128);
this.v.a((int) 0);
+ /* Paper start - GS4 Query event
this.v.a("hostname");
this.v.a(this.l);
this.v.a("gametype");
2019-05-05 19:19:34 +02:00
@@ -169,6 +196,79 @@ public class RemoteStatusListener extends RemoteConnectionThread {
2019-03-24 18:01:31 +01:00
}
this.v.a((int) 0);
+ */
+ // Pack plugins
+ java.util.List<com.destroystokyo.paper.event.server.GS4QueryEvent.QueryResponse.PluginInformation> plugins = java.util.Collections.emptyList();
+ org.bukkit.plugin.Plugin[] bukkitPlugins;
+ if(((DedicatedServer) this.getServer()).server.getQueryPlugins() && (bukkitPlugins = org.bukkit.Bukkit.getPluginManager().getPlugins()).length > 0) {
+ 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())
+ .currentPlayers(this.getPlayerCount())
+ .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());
+ if(!queryResponse.getPlugins().isEmpty()) {
+ pluginsString.append(": ");
+ Iterator<com.destroystokyo.paper.event.server.GS4QueryEvent.QueryResponse.PluginInformation> iter = queryResponse.getPlugins().iterator();
+ while(iter.hasNext()) {
+ com.destroystokyo.paper.event.server.GS4QueryEvent.QueryResponse.PluginInformation info = iter.next();
+ pluginsString.append(info.getName());
+ if (info.getVersion() != null) {
+ pluginsString.append(' ').append(info.getVersion().replaceAll(";", ","));
+ }
+ 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
return this.v.a();
}
}
diff --git a/src/main/java/net/minecraft/server/RemoteStatusReply.java b/src/main/java/net/minecraft/server/RemoteStatusReply.java
index 848b5c3f0e00f32d565dc5a241e17fa6d152ae8d..73efea7e1354df306c0eadfc52b75ec8ed9883d9 100644
2019-03-24 18:01:31 +01:00
--- a/src/main/java/net/minecraft/server/RemoteStatusReply.java
+++ b/src/main/java/net/minecraft/server/RemoteStatusReply.java
@@ -18,15 +18,27 @@ public class RemoteStatusReply {
this.b.write(abyte, 0, abyte.length);
}
2019-05-05 19:19:34 +02:00
+ public void writeString(String string) throws IOException { this.a(string); } // Paper - OBFHELPER
2019-03-24 18:01:31 +01:00
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
2019-05-05 19:19:34 +02:00
+ public void writeInt(int i) throws IOException { this.a(i); } // Paper - OBFHELPER
2019-03-24 18:01:31 +01:00
public void a(int i) throws IOException {
this.b.write(i);
}
2019-05-05 19:19:34 +02:00
+ public void writeShort(short i) throws IOException { this.a(i); } // Paper - OBFHELPER
2019-03-24 18:01:31 +01:00
public void a(short short0) throws IOException {
this.b.writeShort(Short.reverseBytes(short0));
}