3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 00:23:03 +01:00

Added IGeyserPingPassthrough#getPingInformation(InetSocketAddress) to make logging of the pinging IPs possible (#1633)

Co-authored-by: qlow <info@qlow.eu>
Dieser Commit ist enthalten in:
qlow 2020-12-07 20:04:50 +01:00 committet von GitHub
Ursprung 798ae34cd1
Commit a173005767
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
7 geänderte Dateien mit 48 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -47,14 +47,12 @@ import java.util.concurrent.CompletableFuture;
@AllArgsConstructor @AllArgsConstructor
public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, Listener { public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, Listener {
private static final GeyserPendingConnection PENDING_CONNECTION = new GeyserPendingConnection();
private final ProxyServer proxyServer; private final ProxyServer proxyServer;
@Override @Override
public GeyserPingInfo getPingInformation() { public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
CompletableFuture<ProxyPingEvent> future = new CompletableFuture<>(); CompletableFuture<ProxyPingEvent> 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); if (throwable != null) future.completeExceptionally(throwable);
else future.complete(event); else future.complete(event);
})); }));
@ -89,7 +87,12 @@ public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, List
private static class GeyserPendingConnection implements PendingConnection { private static class GeyserPendingConnection implements PendingConnection {
private static final UUID FAKE_UUID = UUID.nameUUIDFromBytes("geyser!internal".getBytes()); 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 @Override
public String getName() { public String getName() {
@ -143,7 +146,7 @@ public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, List
@Override @Override
public InetSocketAddress getAddress() { public InetSocketAddress getAddress() {
return FAKE_REMOTE; return remote;
} }
@Override @Override

Datei anzeigen

@ -35,6 +35,7 @@ import org.geysermc.connector.common.ping.GeyserPingInfo;
import org.geysermc.connector.ping.IGeyserPingPassthrough; import org.geysermc.connector.ping.IGeyserPingPassthrough;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
@ -44,9 +45,9 @@ public class GeyserSpigotPingPassthrough implements IGeyserPingPassthrough {
private final GeyserSpigotLogger logger; private final GeyserSpigotLogger logger;
@Override @Override
public GeyserPingInfo getPingInformation() { public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
try { 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); Bukkit.getPluginManager().callEvent(event);
GeyserPingInfo geyserPingInfo = new GeyserPingInfo(event.getMotd(), GeyserPingInfo geyserPingInfo = new GeyserPingInfo(event.getMotd(),
new GeyserPingInfo.Players(event.getMaxPlayers(), event.getNumPlayers()), new GeyserPingInfo.Players(event.getMaxPlayers(), event.getNumPlayers()),

Datei anzeigen

@ -38,31 +38,29 @@ import org.spongepowered.api.network.status.StatusClient;
import org.spongepowered.api.profile.GameProfile; import org.spongepowered.api.profile.GameProfile;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.Inet4Address;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Optional; import java.util.Optional;
public class GeyserSpongePingPassthrough implements IGeyserPingPassthrough { 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 final Cause CAUSE = Cause.of(EventContext.empty(), Sponge.getServer());
private static Method SpongeStatusResponse_create; private static Method SpongeStatusResponse_create;
@SuppressWarnings({"unchecked", "rawtypes"}) @SuppressWarnings({"unchecked", "rawtypes"})
@Override @Override
public GeyserPingInfo getPingInformation() { public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
// come on Sponge, this is in commons, why not expose it :( // come on Sponge, this is in commons, why not expose it :(
ClientPingServerEvent event; ClientPingServerEvent event;
try { try {
if(SpongeStatusResponse_create == null) { if (SpongeStatusResponse_create == null) {
Class SpongeStatusResponse = Class.forName("org.spongepowered.common.network.status.SpongeStatusResponse"); Class SpongeStatusResponse = Class.forName("org.spongepowered.common.network.status.SpongeStatusResponse");
Class MinecraftServer = Class.forName("net.minecraft.server.MinecraftServer"); Class MinecraftServer = Class.forName("net.minecraft.server.MinecraftServer");
SpongeStatusResponse_create = SpongeStatusResponse.getDeclaredMethod("create", MinecraftServer); SpongeStatusResponse_create = SpongeStatusResponse.getDeclaredMethod("create", MinecraftServer);
} }
Object response = SpongeStatusResponse_create.invoke(null, Sponge.getServer()); 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) { } catch (ReflectiveOperationException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -76,7 +74,7 @@ public class GeyserSpongePingPassthrough implements IGeyserPingPassthrough {
new GeyserPingInfo.Version( new GeyserPingInfo.Version(
event.getResponse().getVersion().getName(), event.getResponse().getVersion().getName(),
MinecraftConstants.PROTOCOL_VERSION) // thanks for also not exposing this sponge MinecraftConstants.PROTOCOL_VERSION) // thanks for also not exposing this sponge
); );
event.getResponse().getPlayers().get().getProfiles().stream() event.getResponse().getPlayers().get().getProfiles().stream()
.map(GameProfile::getName) .map(GameProfile::getName)
.map(op -> op.orElseThrow(IllegalStateException::new)) .map(op -> op.orElseThrow(IllegalStateException::new))
@ -87,11 +85,15 @@ public class GeyserSpongePingPassthrough implements IGeyserPingPassthrough {
@SuppressWarnings("NullableProblems") @SuppressWarnings("NullableProblems")
private static class GeyserStatusClient implements StatusClient { 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 @Override
public InetSocketAddress getAddress() { public InetSocketAddress getAddress() {
return FAKE_REMOTE; return this.remote;
} }
@Override @Override

Datei anzeigen

@ -43,15 +43,13 @@ import java.util.concurrent.ExecutionException;
@AllArgsConstructor @AllArgsConstructor
public class GeyserVelocityPingPassthrough implements IGeyserPingPassthrough { public class GeyserVelocityPingPassthrough implements IGeyserPingPassthrough {
private static final GeyserInboundConnection FAKE_INBOUND_CONNECTION = new GeyserInboundConnection();
private final ProxyServer server; private final ProxyServer server;
@Override @Override
public GeyserPingInfo getPingInformation() { public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
ProxyPingEvent event; ProxyPingEvent event;
try { 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()) .description(server.getConfiguration().getMotdComponent()).onlinePlayers(server.getPlayerCount())
.maximumPlayers(server.getConfiguration().getShowMaxPlayers()).build())).get(); .maximumPlayers(server.getConfiguration().getShowMaxPlayers()).build())).get();
} catch (ExecutionException | InterruptedException e) { } catch (ExecutionException | InterruptedException e) {
@ -74,11 +72,15 @@ public class GeyserVelocityPingPassthrough implements IGeyserPingPassthrough {
private static class GeyserInboundConnection implements InboundConnection { 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 @Override
public InetSocketAddress getRemoteAddress() { public InetSocketAddress getRemoteAddress() {
return FAKE_REMOTE; return this.remote;
} }
@Override @Override

Datei anzeigen

@ -63,7 +63,7 @@ public class ConnectorServerEventHandler implements BedrockServerEventHandler {
GeyserPingInfo pingInfo = null; GeyserPingInfo pingInfo = null;
if (config.isPassthroughMotd() || config.isPassthroughPlayerCounts()) { if (config.isPassthroughMotd() || config.isPassthroughPlayerCounts()) {
IGeyserPingPassthrough pingPassthrough = connector.getBootstrap().getGeyserPingPassthrough(); IGeyserPingPassthrough pingPassthrough = connector.getBootstrap().getGeyserPingPassthrough();
pingInfo = pingPassthrough.getPingInformation(); pingInfo = pingPassthrough.getPingInformation(inetSocketAddress);
} }
BedrockPong pong = new BedrockPong(); BedrockPong pong = new BedrockPong();

Datei anzeigen

@ -70,7 +70,7 @@ public class GeyserLegacyPingPassthrough implements IGeyserPingPassthrough, Runn
} }
@Override @Override
public GeyserPingInfo getPingInformation() { public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
return pingInfo; return pingInfo;
} }

Datei anzeigen

@ -27,15 +27,29 @@ package org.geysermc.connector.ping;
import org.geysermc.connector.common.ping.GeyserPingInfo; 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 * Interface that retrieves ping passthrough information from the Java server
*/ */
public interface IGeyserPingPassthrough { 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 * @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);
} }