Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-06 00:00:47 +01:00
Forward the keep-alive packet directly onto the client.
This improves anti-cheat compatibility.
Dieser Commit ist enthalten in:
Ursprung
5787709ed3
Commit
671df77c1f
@ -27,8 +27,9 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
||||
ClientPlaySessionHandler playerHandler =
|
||||
(ClientPlaySessionHandler) connection.getProxyPlayer().getConnection().getSessionHandler();
|
||||
if (packet instanceof KeepAlive) {
|
||||
// Forward onto the server
|
||||
connection.getMinecraftConnection().write(packet);
|
||||
// Forward onto the player
|
||||
playerHandler.setLastPing(((KeepAlive) packet).getRandomId());
|
||||
connection.getProxyPlayer().getConnection().write(packet);
|
||||
} else if (packet instanceof Disconnect) {
|
||||
Disconnect original = (Disconnect) packet;
|
||||
connection.getProxyPlayer().handleConnectionException(connection.getServerInfo(), original);
|
||||
|
@ -25,7 +25,6 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
private static final int MAX_PLUGIN_CHANNELS = 128;
|
||||
|
||||
private final ConnectedPlayer player;
|
||||
private ScheduledFuture<?> pingTask;
|
||||
private long lastPing = -1;
|
||||
private boolean spawned = false;
|
||||
private final List<UUID> serverBossBars = new ArrayList<>();
|
||||
@ -36,31 +35,16 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activated() {
|
||||
EventLoop loop = player.getConnection().getChannel().eventLoop();
|
||||
pingTask = loop.scheduleAtFixedRate(this::ping, 5, 15, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private void ping() {
|
||||
long randomId = ThreadLocalRandom.current().nextInt();
|
||||
lastPing = randomId;
|
||||
KeepAlive keepAlive = new KeepAlive();
|
||||
keepAlive.setRandomId(randomId);
|
||||
player.getConnection().write(keepAlive);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(MinecraftPacket packet) {
|
||||
if (packet instanceof KeepAlive) {
|
||||
KeepAlive keepAlive = (KeepAlive) packet;
|
||||
if (keepAlive.getRandomId() != lastPing) {
|
||||
throw new IllegalStateException("Client sent invalid keepAlive; expected " + lastPing + ", got " + keepAlive.getRandomId());
|
||||
}
|
||||
|
||||
// Do not forward the packet to the player's server, because we handle pings for all servers already.
|
||||
// The last keep alive we got was probably from a different server. Let's ignore it, and hope the next
|
||||
// ping is alright.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (packet instanceof ClientSettings) {
|
||||
player.setClientSettings((ClientSettings) packet);
|
||||
@ -132,11 +116,6 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
@Override
|
||||
public void disconnected() {
|
||||
player.teardown();
|
||||
|
||||
if (pingTask != null && !pingTask.isCancelled()) {
|
||||
pingTask.cancel(false);
|
||||
pingTask = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -149,6 +128,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
}
|
||||
|
||||
public void handleBackendJoinGame(JoinGame joinGame) {
|
||||
lastPing = Long.MIN_VALUE; // reset last ping
|
||||
if (!spawned) {
|
||||
// nothing special to do here
|
||||
spawned = true;
|
||||
@ -244,4 +224,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
||||
public EntityIdRemapper getIdRemapper() {
|
||||
return idRemapper;
|
||||
}
|
||||
|
||||
public void setLastPing(long lastPing) {
|
||||
this.lastPing = lastPing;
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren