mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Simply pingpassthrough logic, add fabric ping passthrough (#3930)
* Check if PingPassthrough is null * Remove QueryPacketHandler * Fabric ping passthrough
This commit is contained in:
parent
13339f1ed1
commit
bb6a1ec40a
14 changed files with 160 additions and 394 deletions
|
@ -40,7 +40,6 @@ import org.geysermc.geyser.ping.IGeyserPingPassthrough;
|
|||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
@ -61,16 +60,11 @@ public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, List
|
|||
}));
|
||||
ProxyPingEvent event = future.join();
|
||||
ServerPing response = event.getResponse();
|
||||
GeyserPingInfo geyserPingInfo = new GeyserPingInfo(
|
||||
return new GeyserPingInfo(
|
||||
response.getDescriptionComponent().toLegacyText(),
|
||||
new GeyserPingInfo.Players(response.getPlayers().getMax(), response.getPlayers().getOnline()),
|
||||
new GeyserPingInfo.Version(response.getVersion().getName(), response.getVersion().getProtocol())
|
||||
response.getPlayers().getMax(),
|
||||
response.getPlayers().getOnline()
|
||||
);
|
||||
if (event.getResponse().getPlayers().getSample() != null) {
|
||||
Arrays.stream(event.getResponse().getPlayers().getSample()).forEach(proxiedPlayer ->
|
||||
geyserPingInfo.getPlayerList().add(proxiedPlayer.getName()));
|
||||
}
|
||||
return geyserPingInfo;
|
||||
}
|
||||
|
||||
// This is static so pending connection can use it
|
||||
|
|
|
@ -144,7 +144,11 @@ public class GeyserFabricMod implements ModInitializer, GeyserBootstrap {
|
|||
|
||||
GeyserImpl.start();
|
||||
|
||||
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(geyser);
|
||||
if (geyserConfig.isLegacyPingPassthrough()) {
|
||||
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(geyser);
|
||||
} else {
|
||||
this.geyserPingPassthrough = new ModPingPassthrough(server, geyserLogger);
|
||||
}
|
||||
|
||||
this.geyserCommandManager = new GeyserCommandManager(geyser);
|
||||
this.geyserCommandManager.init();
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* @author GeyserMC
|
||||
* @link https://github.com/GeyserMC/Geyser
|
||||
*/
|
||||
|
||||
package org.geysermc.geyser.platform.fabric;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.PacketSendListener;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import net.minecraft.network.protocol.status.ClientboundStatusResponsePacket;
|
||||
import net.minecraft.network.protocol.status.ServerStatus;
|
||||
import net.minecraft.network.protocol.status.ServerStatusPacketListener;
|
||||
import net.minecraft.network.protocol.status.ServerboundStatusRequestPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerStatusPacketListenerImpl;
|
||||
import org.geysermc.geyser.GeyserLogger;
|
||||
import org.geysermc.geyser.ping.GeyserPingInfo;
|
||||
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Objects;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class ModPingPassthrough implements IGeyserPingPassthrough {
|
||||
|
||||
private static final GsonComponentSerializer GSON_SERIALIZER = GsonComponentSerializer.gson();
|
||||
private static final LegacyComponentSerializer LEGACY_SERIALIZER = LegacyComponentSerializer.legacySection();
|
||||
|
||||
private final MinecraftServer server;
|
||||
private final GeyserLogger logger;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
|
||||
ServerStatus status = server.getStatus();
|
||||
if (status == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
StatusInterceptor connection = new StatusInterceptor();
|
||||
ServerStatusPacketListener statusPacketListener = new ServerStatusPacketListenerImpl(status, connection);
|
||||
|
||||
statusPacketListener.handleStatusRequest(new ServerboundStatusRequestPacket());
|
||||
// mods like MiniMOTD (that inject into the above method) have now processed the response
|
||||
status = Objects.requireNonNull(connection.status, "status response");
|
||||
} catch (Exception e) {
|
||||
if (logger.isDebug()) {
|
||||
logger.debug("Failed to listen for modified ServerStatus: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
String jsonDescription = net.minecraft.network.chat.Component.Serializer.toJson(status.description());
|
||||
String legacyDescription = LEGACY_SERIALIZER.serialize(GSON_SERIALIZER.deserializeOr(jsonDescription, Component.empty()));
|
||||
|
||||
return new GeyserPingInfo(
|
||||
legacyDescription,
|
||||
status.players().map(ServerStatus.Players::max).orElse(1),
|
||||
status.players().map(ServerStatus.Players::online).orElse(0)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Connection that intercepts the status response right before it is sent
|
||||
*/
|
||||
private static class StatusInterceptor extends Connection {
|
||||
|
||||
ServerStatus status;
|
||||
|
||||
StatusInterceptor() {
|
||||
super(PacketFlow.SERVERBOUND); // we are the server.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Packet<?> packet, @Nullable PacketSendListener packetSendListener, boolean bl) {
|
||||
if (packet instanceof ClientboundStatusResponsePacket statusResponse) {
|
||||
status = statusResponse.status();
|
||||
}
|
||||
super.send(packet, packetSendListener, bl);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,7 +27,6 @@ package org.geysermc.geyser.platform.spigot;
|
|||
|
||||
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
|
||||
import com.destroystokyo.paper.network.StatusClient;
|
||||
import com.destroystokyo.paper.profile.PlayerProfile;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.geysermc.geyser.network.GameProtocol;
|
||||
import org.geysermc.geyser.ping.GeyserPingInfo;
|
||||
|
@ -81,16 +80,7 @@ public final class GeyserPaperPingPassthrough implements IGeyserPingPassthrough
|
|||
players = new GeyserPingInfo.Players(event.getMaxPlayers(), event.getNumPlayers());
|
||||
}
|
||||
|
||||
GeyserPingInfo geyserPingInfo = new GeyserPingInfo(event.getMotd(), players,
|
||||
new GeyserPingInfo.Version(Bukkit.getVersion(), GameProtocol.getJavaProtocolVersion()));
|
||||
|
||||
if (!event.shouldHidePlayers()) {
|
||||
for (PlayerProfile profile : event.getPlayerSample()) {
|
||||
geyserPingInfo.getPlayerList().add(profile.getName());
|
||||
}
|
||||
}
|
||||
|
||||
return geyserPingInfo;
|
||||
return new GeyserPingInfo(event.getMotd(), players);
|
||||
} catch (Exception | LinkageError e) { // LinkageError in the event that method/constructor signatures change
|
||||
logger.debug("Error while getting Paper ping passthrough: " + e);
|
||||
return null;
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
import org.bukkit.util.CachedServerIcon;
|
||||
import org.geysermc.geyser.network.GameProtocol;
|
||||
import org.geysermc.geyser.ping.GeyserPingInfo;
|
||||
import org.geysermc.geyser.ping.IGeyserPingPassthrough;
|
||||
|
||||
|
@ -50,12 +49,7 @@ public class GeyserSpigotPingPassthrough implements IGeyserPingPassthrough {
|
|||
try {
|
||||
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()),
|
||||
new GeyserPingInfo.Version(Bukkit.getVersion(), GameProtocol.getJavaProtocolVersion()) // thanks Spigot for not exposing this, just default to latest
|
||||
);
|
||||
Bukkit.getOnlinePlayers().stream().map(Player::getName).forEach(geyserPingInfo.getPlayerList()::add);
|
||||
return geyserPingInfo;
|
||||
return new GeyserPingInfo(event.getMotd(), event.getMaxPlayers(), event.getNumPlayers());
|
||||
} catch (Exception | LinkageError e) { // LinkageError in the event that method/constructor signatures change
|
||||
logger.debug("Error while getting Bukkit ping passthrough: " + e);
|
||||
return null;
|
||||
|
|
|
@ -54,19 +54,11 @@ public class GeyserVelocityPingPassthrough implements IGeyserPingPassthrough {
|
|||
} catch (ExecutionException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
GeyserPingInfo geyserPingInfo = new GeyserPingInfo(
|
||||
return new GeyserPingInfo(
|
||||
LegacyComponentSerializer.legacy('§').serialize(event.getPing().getDescriptionComponent()),
|
||||
new GeyserPingInfo.Players(
|
||||
event.getPing().getPlayers().orElseThrow(IllegalStateException::new).getMax(),
|
||||
event.getPing().getPlayers().orElseThrow(IllegalStateException::new).getOnline()
|
||||
),
|
||||
new GeyserPingInfo.Version(
|
||||
event.getPing().getVersion().getName(),
|
||||
event.getPing().getVersion().getProtocol()
|
||||
)
|
||||
event.getPing().getPlayers().map(ServerPing.Players::getMax).orElse(1),
|
||||
event.getPing().getPlayers().map(ServerPing.Players::getOnline).orElse(0)
|
||||
);
|
||||
event.getPing().getPlayers().get().getSample().stream().map(ServerPing.SamplePlayer::getName).forEach(geyserPingInfo.getPlayerList()::add);
|
||||
return geyserPingInfo;
|
||||
}
|
||||
|
||||
private static class GeyserInboundConnection implements InboundConnection {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue