3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-27 08:30:10 +01:00

Don't use casting for validation of keep alive, use hashCodes.

Also disregard valid ones sent twice.
Dieser Commit ist enthalten in:
Myles 2017-09-30 21:08:05 +01:00
Ursprung d36a076942
Commit 903c1999eb

Datei anzeigen

@ -30,9 +30,9 @@ public class Protocol1_12_1To1_12_2 extends BackwardsProtocol {
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper packetWrapper) throws Exception { 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.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 @Override
public void handle(PacketWrapper packetWrapper) throws Exception { public void handle(PacketWrapper packetWrapper) throws Exception {
int keepAlive = packetWrapper.read(Type.VAR_INT); int keepAlive = packetWrapper.read(Type.VAR_INT);
long realKeepAlive = packetWrapper.user().get(KeepAliveTracker.class).getKeepAlive(); Long realKeepAlive = packetWrapper.user().get(KeepAliveTracker.class).getKeepAlive();
if (keepAlive != (int) realKeepAlive) { if (keepAlive != realKeepAlive.hashCode()) {
packetWrapper.cancel(); // Wrong data, cancel packet packetWrapper.cancel(); // Wrong data, cancel packet
return;
} }
packetWrapper.write(Type.LONG, realKeepAlive); 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);
} }
}); });
} }