geforkt von Mirrors/Velocity
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 playerHandler =
|
||||||
(ClientPlaySessionHandler) connection.getProxyPlayer().getConnection().getSessionHandler();
|
(ClientPlaySessionHandler) connection.getProxyPlayer().getConnection().getSessionHandler();
|
||||||
if (packet instanceof KeepAlive) {
|
if (packet instanceof KeepAlive) {
|
||||||
// Forward onto the server
|
// Forward onto the player
|
||||||
connection.getMinecraftConnection().write(packet);
|
playerHandler.setLastPing(((KeepAlive) packet).getRandomId());
|
||||||
|
connection.getProxyPlayer().getConnection().write(packet);
|
||||||
} else if (packet instanceof Disconnect) {
|
} else if (packet instanceof Disconnect) {
|
||||||
Disconnect original = (Disconnect) packet;
|
Disconnect original = (Disconnect) packet;
|
||||||
connection.getProxyPlayer().handleConnectionException(connection.getServerInfo(), original);
|
connection.getProxyPlayer().handleConnectionException(connection.getServerInfo(), original);
|
||||||
|
@ -25,7 +25,6 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
private static final int MAX_PLUGIN_CHANNELS = 128;
|
private static final int MAX_PLUGIN_CHANNELS = 128;
|
||||||
|
|
||||||
private final ConnectedPlayer player;
|
private final ConnectedPlayer player;
|
||||||
private ScheduledFuture<?> pingTask;
|
|
||||||
private long lastPing = -1;
|
private long lastPing = -1;
|
||||||
private boolean spawned = false;
|
private boolean spawned = false;
|
||||||
private final List<UUID> serverBossBars = new ArrayList<>();
|
private final List<UUID> serverBossBars = new ArrayList<>();
|
||||||
@ -36,30 +35,15 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
this.player = player;
|
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
|
@Override
|
||||||
public void handle(MinecraftPacket packet) {
|
public void handle(MinecraftPacket packet) {
|
||||||
if (packet instanceof KeepAlive) {
|
if (packet instanceof KeepAlive) {
|
||||||
KeepAlive keepAlive = (KeepAlive) packet;
|
KeepAlive keepAlive = (KeepAlive) packet;
|
||||||
if (keepAlive.getRandomId() != lastPing) {
|
if (keepAlive.getRandomId() != lastPing) {
|
||||||
throw new IllegalStateException("Client sent invalid keepAlive; expected " + lastPing + ", got " + keepAlive.getRandomId());
|
// The last keep alive we got was probably from a different server. Let's ignore it, and hope the next
|
||||||
|
// ping is alright.
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do not forward the packet to the player's server, because we handle pings for all servers already.
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packet instanceof ClientSettings) {
|
if (packet instanceof ClientSettings) {
|
||||||
@ -132,11 +116,6 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void disconnected() {
|
public void disconnected() {
|
||||||
player.teardown();
|
player.teardown();
|
||||||
|
|
||||||
if (pingTask != null && !pingTask.isCancelled()) {
|
|
||||||
pingTask.cancel(false);
|
|
||||||
pingTask = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -149,6 +128,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handleBackendJoinGame(JoinGame joinGame) {
|
public void handleBackendJoinGame(JoinGame joinGame) {
|
||||||
|
lastPing = Long.MIN_VALUE; // reset last ping
|
||||||
if (!spawned) {
|
if (!spawned) {
|
||||||
// nothing special to do here
|
// nothing special to do here
|
||||||
spawned = true;
|
spawned = true;
|
||||||
@ -244,4 +224,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
public EntityIdRemapper getIdRemapper() {
|
public EntityIdRemapper getIdRemapper() {
|
||||||
return idRemapper;
|
return idRemapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLastPing(long lastPing) {
|
||||||
|
this.lastPing = lastPing;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren