geforkt von Mirrors/Velocity
Use keepalive queue instead of just the last keepalive.
Dieser Commit ist enthalten in:
Ursprung
a2a799a8a7
Commit
7aed76ee3d
@ -83,7 +83,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handle(KeepAlive packet) {
|
public boolean handle(KeepAlive packet) {
|
||||||
serverConn.setLastPingId(packet.getRandomId());
|
serverConn.getPendingPings().put(packet.getRandomId(), System.currentTimeMillis());
|
||||||
return false; // forwards on
|
return false; // forwards on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,9 @@ import io.netty.buffer.Unpooled;
|
|||||||
import io.netty.channel.ChannelFutureListener;
|
import io.netty.channel.ChannelFutureListener;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
@ -44,8 +46,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
|||||||
private boolean hasCompletedJoin = false;
|
private boolean hasCompletedJoin = false;
|
||||||
private boolean gracefulDisconnect = false;
|
private boolean gracefulDisconnect = false;
|
||||||
private BackendConnectionPhase connectionPhase = BackendConnectionPhases.UNKNOWN;
|
private BackendConnectionPhase connectionPhase = BackendConnectionPhases.UNKNOWN;
|
||||||
private long lastPingId;
|
private final Map<Long, Long> pendingPings = new HashMap<>();
|
||||||
private long lastPingSent;
|
|
||||||
private @MonotonicNonNull DimensionRegistry activeDimensionRegistry;
|
private @MonotonicNonNull DimensionRegistry activeDimensionRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -244,21 +245,8 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
|
|||||||
return gracefulDisconnect;
|
return gracefulDisconnect;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLastPingId() {
|
public Map<Long, Long> getPendingPings() {
|
||||||
return lastPingId;
|
return pendingPings;
|
||||||
}
|
|
||||||
|
|
||||||
public long getLastPingSent() {
|
|
||||||
return lastPingSent;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setLastPingId(long lastPingId) {
|
|
||||||
this.lastPingId = lastPingId;
|
|
||||||
this.lastPingSent = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void resetLastPingId() {
|
|
||||||
this.lastPingId = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,12 +99,14 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
|
|||||||
@Override
|
@Override
|
||||||
public boolean handle(KeepAlive packet) {
|
public boolean handle(KeepAlive packet) {
|
||||||
VelocityServerConnection serverConnection = player.getConnectedServer();
|
VelocityServerConnection serverConnection = player.getConnectedServer();
|
||||||
if (serverConnection != null && packet.getRandomId() == serverConnection.getLastPingId()) {
|
if (serverConnection != null) {
|
||||||
|
Long sentTime = serverConnection.getPendingPings().remove(packet.getRandomId());
|
||||||
|
if (sentTime != null) {
|
||||||
MinecraftConnection smc = serverConnection.getConnection();
|
MinecraftConnection smc = serverConnection.getConnection();
|
||||||
if (smc != null) {
|
if (smc != null) {
|
||||||
player.setPing(System.currentTimeMillis() - serverConnection.getLastPingSent());
|
player.setPing(System.currentTimeMillis() - sentTime);
|
||||||
smc.write(packet);
|
smc.write(packet);
|
||||||
serverConnection.resetLastPingId();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren