3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-06 00:00:47 +01:00

Fix sending keep alive response to wrong backend server (#1253)

Dieser Commit ist enthalten in:
Adrian 2024-02-24 14:24:06 -05:00 committet von GitHub
Ursprung 409ab7b118
Commit 74c932e579
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194

Datei anzeigen

@ -42,6 +42,8 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Handles the client config stage.
@ -72,17 +74,11 @@ public class ClientConfigSessionHandler implements MinecraftSessionHandler {
}
@Override
public boolean handle(KeepAlivePacket packet) {
public boolean handle(final KeepAlivePacket packet) {
final VelocityServerConnection serverConnection = player.getConnectedServer();
if (serverConnection != null) {
final Long sentTime = serverConnection.getPendingPings().remove(packet.getRandomId());
if (sentTime != null) {
final MinecraftConnection smc = serverConnection.getConnection();
if (smc != null) {
player.setPing(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - sentTime));
smc.write(packet);
}
}
if (!this.sendKeepAliveToBackend(serverConnection, packet)) {
final VelocityServerConnection connectionInFlight = player.getConnectionInFlight();
this.sendKeepAliveToBackend(connectionInFlight, packet);
}
return true;
}
@ -177,6 +173,24 @@ public class ClientConfigSessionHandler implements MinecraftSessionHandler {
Component.translatable("velocity.error.player-connection-error", NamedTextColor.RED));
}
private boolean sendKeepAliveToBackend(
final @Nullable VelocityServerConnection serverConnection,
final @NotNull KeepAlivePacket packet
) {
if (serverConnection != null) {
final Long sentTime = serverConnection.getPendingPings().remove(packet.getRandomId());
if (sentTime != null) {
final MinecraftConnection smc = serverConnection.getConnection();
if (smc != null) {
player.setPing(TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - sentTime));
smc.write(packet);
return true;
}
}
}
return false;
}
/**
* Handles the backend finishing the config stage.
*