From a173005767389feba625f5ca2efdd2ef55273a9b Mon Sep 17 00:00:00 2001 From: qlow <20094418+qlow@users.noreply.github.com> Date: Mon, 7 Dec 2020 20:04:50 +0100 Subject: [PATCH] Added IGeyserPingPassthrough#getPingInformation(InetSocketAddress) to make logging of the pinging IPs possible (#1633) Co-authored-by: qlow --- .../GeyserBungeePingPassthrough.java | 15 +++++++++------ .../spigot/GeyserSpigotPingPassthrough.java | 5 +++-- .../sponge/GeyserSpongePingPassthrough.java | 18 ++++++++++-------- .../GeyserVelocityPingPassthrough.java | 14 ++++++++------ .../network/ConnectorServerEventHandler.java | 2 +- .../ping/GeyserLegacyPingPassthrough.java | 2 +- .../connector/ping/IGeyserPingPassthrough.java | 18 ++++++++++++++++-- 7 files changed, 48 insertions(+), 26 deletions(-) diff --git a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePingPassthrough.java b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePingPassthrough.java index 15c8fa9e..884bd7c3 100644 --- a/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePingPassthrough.java +++ b/bootstrap/bungeecord/src/main/java/org/geysermc/platform/bungeecord/GeyserBungeePingPassthrough.java @@ -47,14 +47,12 @@ import java.util.concurrent.CompletableFuture; @AllArgsConstructor public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, Listener { - private static final GeyserPendingConnection PENDING_CONNECTION = new GeyserPendingConnection(); - private final ProxyServer proxyServer; @Override - public GeyserPingInfo getPingInformation() { + public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) { CompletableFuture future = new CompletableFuture<>(); - proxyServer.getPluginManager().callEvent(new ProxyPingEvent(PENDING_CONNECTION, getPingInfo(), (event, throwable) -> { + proxyServer.getPluginManager().callEvent(new ProxyPingEvent(new GeyserPendingConnection(inetSocketAddress), getPingInfo(), (event, throwable) -> { if (throwable != null) future.completeExceptionally(throwable); else future.complete(event); })); @@ -89,7 +87,12 @@ public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, List private static class GeyserPendingConnection implements PendingConnection { private static final UUID FAKE_UUID = UUID.nameUUIDFromBytes("geyser!internal".getBytes()); - private static final InetSocketAddress FAKE_REMOTE = new InetSocketAddress(Inet4Address.getLoopbackAddress(), 69); + + private final InetSocketAddress remote; + + public GeyserPendingConnection(InetSocketAddress remote) { + this.remote = remote; + } @Override public String getName() { @@ -143,7 +146,7 @@ public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, List @Override public InetSocketAddress getAddress() { - return FAKE_REMOTE; + return remote; } @Override diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/GeyserSpigotPingPassthrough.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/GeyserSpigotPingPassthrough.java index 7196f429..5673d85b 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/GeyserSpigotPingPassthrough.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/GeyserSpigotPingPassthrough.java @@ -35,6 +35,7 @@ import org.geysermc.connector.common.ping.GeyserPingInfo; import org.geysermc.connector.ping.IGeyserPingPassthrough; import java.net.InetAddress; +import java.net.InetSocketAddress; import java.util.Collections; import java.util.Iterator; @@ -44,9 +45,9 @@ public class GeyserSpigotPingPassthrough implements IGeyserPingPassthrough { private final GeyserSpigotLogger logger; @Override - public GeyserPingInfo getPingInformation() { + public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) { try { - ServerListPingEvent event = new GeyserPingEvent(InetAddress.getLocalHost(), Bukkit.getMotd(), Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers()); + ServerListPingEvent event = new GeyserPingEvent(inetSocketAddress.getAddress(), Bukkit.getMotd(), Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers()); Bukkit.getPluginManager().callEvent(event); GeyserPingInfo geyserPingInfo = new GeyserPingInfo(event.getMotd(), new GeyserPingInfo.Players(event.getMaxPlayers(), event.getNumPlayers()), diff --git a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePingPassthrough.java b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePingPassthrough.java index 251b9703..c5b6b831 100644 --- a/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePingPassthrough.java +++ b/bootstrap/sponge/src/main/java/org/geysermc/platform/sponge/GeyserSpongePingPassthrough.java @@ -38,31 +38,29 @@ import org.spongepowered.api.network.status.StatusClient; import org.spongepowered.api.profile.GameProfile; import java.lang.reflect.Method; -import java.net.Inet4Address; import java.net.InetSocketAddress; import java.util.Optional; public class GeyserSpongePingPassthrough implements IGeyserPingPassthrough { - private static final GeyserStatusClient STATUS_CLIENT = new GeyserStatusClient(); private static final Cause CAUSE = Cause.of(EventContext.empty(), Sponge.getServer()); private static Method SpongeStatusResponse_create; @SuppressWarnings({"unchecked", "rawtypes"}) @Override - public GeyserPingInfo getPingInformation() { + public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) { // come on Sponge, this is in commons, why not expose it :( ClientPingServerEvent event; try { - if(SpongeStatusResponse_create == null) { + if (SpongeStatusResponse_create == null) { Class SpongeStatusResponse = Class.forName("org.spongepowered.common.network.status.SpongeStatusResponse"); Class MinecraftServer = Class.forName("net.minecraft.server.MinecraftServer"); SpongeStatusResponse_create = SpongeStatusResponse.getDeclaredMethod("create", MinecraftServer); } Object response = SpongeStatusResponse_create.invoke(null, Sponge.getServer()); - event = SpongeEventFactory.createClientPingServerEvent(CAUSE, STATUS_CLIENT, (ClientPingServerEvent.Response) response); + event = SpongeEventFactory.createClientPingServerEvent(CAUSE, new GeyserStatusClient(inetSocketAddress), (ClientPingServerEvent.Response) response); } catch (ReflectiveOperationException e) { throw new RuntimeException(e); } @@ -76,7 +74,7 @@ public class GeyserSpongePingPassthrough implements IGeyserPingPassthrough { new GeyserPingInfo.Version( event.getResponse().getVersion().getName(), MinecraftConstants.PROTOCOL_VERSION) // thanks for also not exposing this sponge - ); + ); event.getResponse().getPlayers().get().getProfiles().stream() .map(GameProfile::getName) .map(op -> op.orElseThrow(IllegalStateException::new)) @@ -87,11 +85,15 @@ public class GeyserSpongePingPassthrough implements IGeyserPingPassthrough { @SuppressWarnings("NullableProblems") private static class GeyserStatusClient implements StatusClient { - private static final InetSocketAddress FAKE_REMOTE = new InetSocketAddress(Inet4Address.getLoopbackAddress(), 69); + private final InetSocketAddress remote; + + public GeyserStatusClient(InetSocketAddress remote) { + this.remote = remote; + } @Override public InetSocketAddress getAddress() { - return FAKE_REMOTE; + return this.remote; } @Override diff --git a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityPingPassthrough.java b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityPingPassthrough.java index ff8376e4..9674d27e 100644 --- a/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityPingPassthrough.java +++ b/bootstrap/velocity/src/main/java/org/geysermc/platform/velocity/GeyserVelocityPingPassthrough.java @@ -43,15 +43,13 @@ import java.util.concurrent.ExecutionException; @AllArgsConstructor public class GeyserVelocityPingPassthrough implements IGeyserPingPassthrough { - private static final GeyserInboundConnection FAKE_INBOUND_CONNECTION = new GeyserInboundConnection(); - private final ProxyServer server; @Override - public GeyserPingInfo getPingInformation() { + public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) { ProxyPingEvent event; try { - event = server.getEventManager().fire(new ProxyPingEvent(FAKE_INBOUND_CONNECTION, ServerPing.builder() + event = server.getEventManager().fire(new ProxyPingEvent(new GeyserInboundConnection(inetSocketAddress), ServerPing.builder() .description(server.getConfiguration().getMotdComponent()).onlinePlayers(server.getPlayerCount()) .maximumPlayers(server.getConfiguration().getShowMaxPlayers()).build())).get(); } catch (ExecutionException | InterruptedException e) { @@ -74,11 +72,15 @@ public class GeyserVelocityPingPassthrough implements IGeyserPingPassthrough { private static class GeyserInboundConnection implements InboundConnection { - private static final InetSocketAddress FAKE_REMOTE = new InetSocketAddress(Inet4Address.getLoopbackAddress(), 69); + private final InetSocketAddress remote; + + public GeyserInboundConnection(InetSocketAddress remote) { + this.remote = remote; + } @Override public InetSocketAddress getRemoteAddress() { - return FAKE_REMOTE; + return this.remote; } @Override diff --git a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java index 150d298c..fade4d78 100644 --- a/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java +++ b/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler.java @@ -63,7 +63,7 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler { GeyserPingInfo pingInfo = null; if (config.isPassthroughMotd() || config.isPassthroughPlayerCounts()) { IGeyserPingPassthrough pingPassthrough = connector.getBootstrap().getGeyserPingPassthrough(); - pingInfo = pingPassthrough.getPingInformation(); + pingInfo = pingPassthrough.getPingInformation(inetSocketAddress); } BedrockPong pong = new BedrockPong(); diff --git a/connector/src/main/java/org/geysermc/connector/ping/GeyserLegacyPingPassthrough.java b/connector/src/main/java/org/geysermc/connector/ping/GeyserLegacyPingPassthrough.java index 519d847d..6d54cc4c 100644 --- a/connector/src/main/java/org/geysermc/connector/ping/GeyserLegacyPingPassthrough.java +++ b/connector/src/main/java/org/geysermc/connector/ping/GeyserLegacyPingPassthrough.java @@ -70,7 +70,7 @@ public class GeyserLegacyPingPassthrough implements IGeyserPingPassthrough, Runn } @Override - public GeyserPingInfo getPingInformation() { + public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) { return pingInfo; } diff --git a/connector/src/main/java/org/geysermc/connector/ping/IGeyserPingPassthrough.java b/connector/src/main/java/org/geysermc/connector/ping/IGeyserPingPassthrough.java index 049f8504..85ef7733 100644 --- a/connector/src/main/java/org/geysermc/connector/ping/IGeyserPingPassthrough.java +++ b/connector/src/main/java/org/geysermc/connector/ping/IGeyserPingPassthrough.java @@ -27,15 +27,29 @@ package org.geysermc.connector.ping; import org.geysermc.connector.common.ping.GeyserPingInfo; +import java.net.Inet4Address; +import java.net.InetSocketAddress; + /** * Interface that retrieves ping passthrough information from the Java server */ public interface IGeyserPingPassthrough { /** - * Get the MOTD of the server displayed on the multiplayer screen + * Get the MOTD of the server displayed on the multiplayer screen. It uses a fake remote, as the remote isn't important in this context. + * * @return string of the MOTD */ - GeyserPingInfo getPingInformation(); + default GeyserPingInfo getPingInformation() { + return this.getPingInformation(new InetSocketAddress(Inet4Address.getLoopbackAddress(), 69)); + } + + /** + * Get the MOTD of the server displayed on the multiplayer screen + * + * @param inetSocketAddress the ip address of the client pinging the server + * @return string of the MOTD + */ + GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress); }