Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-26 16:12:43 +01:00
Don't use casting for validation of keep alive, use hashCodes.
Also disregard valid ones sent twice.
Dieser Commit ist enthalten in:
Ursprung
d36a076942
Commit
903c1999eb
@ -30,9 +30,9 @@ public class Protocol1_12_1To1_12_2 extends BackwardsProtocol {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper packetWrapper) throws Exception {
|
||||
long keepAlive = packetWrapper.read(Type.LONG);
|
||||
Long keepAlive = packetWrapper.read(Type.LONG);
|
||||
packetWrapper.user().get(KeepAliveTracker.class).setKeepAlive(keepAlive);
|
||||
packetWrapper.write(Type.VAR_INT, (int) keepAlive);
|
||||
packetWrapper.write(Type.VAR_INT, keepAlive.hashCode());
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -46,11 +46,14 @@ public class Protocol1_12_1To1_12_2 extends BackwardsProtocol {
|
||||
@Override
|
||||
public void handle(PacketWrapper packetWrapper) throws Exception {
|
||||
int keepAlive = packetWrapper.read(Type.VAR_INT);
|
||||
long realKeepAlive = packetWrapper.user().get(KeepAliveTracker.class).getKeepAlive();
|
||||
if (keepAlive != (int) realKeepAlive) {
|
||||
Long realKeepAlive = packetWrapper.user().get(KeepAliveTracker.class).getKeepAlive();
|
||||
if (keepAlive != realKeepAlive.hashCode()) {
|
||||
packetWrapper.cancel(); // Wrong data, cancel packet
|
||||
return;
|
||||
}
|
||||
packetWrapper.write(Type.LONG, realKeepAlive);
|
||||
// Reset KeepAliveTracker (to prevent sending same valid value in a row causing a timeout)
|
||||
packetWrapper.user().get(KeepAliveTracker.class).setKeepAlive(Long.MIN_VALUE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren