From d484545bef8b893d47113d07525f109e468a742a Mon Sep 17 00:00:00 2001 From: Matsv Date: Mon, 5 Feb 2018 20:51:34 +0100 Subject: [PATCH] Change keepAlive's initial value to fix Gerrygames/ViaRewind#14 --- .../KeepAliveTracker.java | 28 +++++++++++++++++++ .../Protocol1_12_1To1_12_2.java | 6 ++-- .../KeepAliveTracker.java | 18 ------------ 3 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/KeepAliveTracker.java delete mode 100644 core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_12_1/KeepAliveTracker.java diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/KeepAliveTracker.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/KeepAliveTracker.java new file mode 100644 index 00000000..300d2bc7 --- /dev/null +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/KeepAliveTracker.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2016 Matsv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package nl.matsv.viabackwards.protocol.protocol1_12_1to1_12_2; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import us.myles.ViaVersion.api.data.StoredObject; +import us.myles.ViaVersion.api.data.UserConnection; + +@Getter +@Setter +@ToString +public class KeepAliveTracker extends StoredObject { + private long keepAlive = Integer.MAX_VALUE; + + public KeepAliveTracker(UserConnection user) { + super(user); + } +} diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/Protocol1_12_1To1_12_2.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/Protocol1_12_1To1_12_2.java index 67d5eb18..820f21b3 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/Protocol1_12_1To1_12_2.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_1to1_12_2/Protocol1_12_1To1_12_2.java @@ -11,7 +11,6 @@ package nl.matsv.viabackwards.protocol.protocol1_12_1to1_12_2; import nl.matsv.viabackwards.api.BackwardsProtocol; -import nl.matsv.viabackwards.protocol.protocol1_12to1_12_1.KeepAliveTracker; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.remapper.PacketHandler; @@ -36,7 +35,8 @@ public class Protocol1_12_1To1_12_2 extends BackwardsProtocol { } }); } - }); // Keep alive + }); + // Incoming // 0xb - Keep alive registerIncoming(State.PLAY, 0xb, 0xb, new PacketRemapper() { @@ -53,7 +53,7 @@ public class Protocol1_12_1To1_12_2 extends BackwardsProtocol { } 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); + packetWrapper.user().get(KeepAliveTracker.class).setKeepAlive(Integer.MAX_VALUE); } }); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_12_1/KeepAliveTracker.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_12_1/KeepAliveTracker.java deleted file mode 100644 index 07b02154..00000000 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_12_1/KeepAliveTracker.java +++ /dev/null @@ -1,18 +0,0 @@ -package nl.matsv.viabackwards.protocol.protocol1_12to1_12_1; - -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; -import us.myles.ViaVersion.api.data.StoredObject; -import us.myles.ViaVersion.api.data.UserConnection; - -@Getter -@Setter -@ToString -public class KeepAliveTracker extends StoredObject { - private long keepAlive; - - public KeepAliveTracker(UserConnection user) { - super(user); - } -}