2.3.0 - 1.12.2 Support

This commit is contained in:
Myles 2017-09-19 00:25:33 +01:00
parent af190b0422
commit 30f339400e
9 changed files with 94 additions and 10 deletions

View File

@ -15,7 +15,7 @@
<parent>
<artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId>
<version>2.2.0</version>
<version>2.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -15,7 +15,7 @@
<parent>
<artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId>
<version>2.2.0</version>
<version>2.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -15,7 +15,7 @@
<parent>
<artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId>
<version>2.2.0</version>
<version>2.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -15,7 +15,7 @@
<parent>
<artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId>
<version>2.2.0</version>
<version>2.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -13,6 +13,7 @@ package nl.matsv.viabackwards.api;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
import nl.matsv.viabackwards.protocol.protocol1_12_1to1_12_2.Protocol1_12_1To1_12_2;
import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.Protocol1_11_1To1_12;
import nl.matsv.viabackwards.protocol.protocol1_12to1_12_1.Protocol1_12To1_12_1;
import nl.matsv.viabackwards.protocol.protocol1_9_4to1_10.Protocol1_9_4To1_10;
@ -36,6 +37,7 @@ public interface ViaBackwardsPlatform {
ProtocolRegistry.registerProtocol(new Protocol1_11To1_11_1(), Collections.singletonList(ProtocolVersion.v1_11.getId()), ProtocolVersion.v1_11_1.getId());
ProtocolRegistry.registerProtocol(new Protocol1_11_1To1_12(), Collections.singletonList(ProtocolVersion.v1_11_1.getId()), ProtocolVersion.v1_12.getId());
ProtocolRegistry.registerProtocol(new Protocol1_12To1_12_1(), Collections.singletonList(ProtocolVersion.v1_12.getId()), ProtocolVersion.v1_12_1.getId());
ProtocolRegistry.registerProtocol(new Protocol1_12_1To1_12_2(), Collections.singletonList(ProtocolVersion.v1_12_1.getId()), ProtocolVersion.v1_12_2.getId());
}
}
@ -51,9 +53,9 @@ public interface ViaBackwardsPlatform {
boolean upToDate = false;
try {
Class<?> clazz = Class.forName("us.myles.ViaVersion.api.protocol.ProtocolVersion");
Field v1_12_1 = clazz.getField("v1_12_1");
Field v1_12_2 = clazz.getField("v1_12_2");
upToDate = (v1_12_1 != null);
upToDate = (v1_12_2 != null);
} catch (ClassNotFoundException | NoSuchFieldException ignored) {
}

View File

@ -0,0 +1,64 @@
/*
* 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 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;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
public class Protocol1_12_1To1_12_2 extends BackwardsProtocol {
@Override
protected void registerPackets() {
// Outgoing
// 0x1f - Keep alive
registerOutgoing(State.PLAY, 0x1f, 0x1f, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper packetWrapper) throws Exception {
long keepAlive = packetWrapper.read(Type.LONG);
packetWrapper.user().get(KeepAliveTracker.class).setKeepAlive(keepAlive);
packetWrapper.write(Type.VAR_INT, (int) keepAlive);
}
});
}
}); // Keep alive
// Incoming
// 0xb - Keep alive
registerIncoming(State.PLAY, 0xb, 0xb, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@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) {
realKeepAlive = 0L; // Client sent wrong data, timeout
}
packetWrapper.write(Type.LONG, realKeepAlive);
}
});
}
});
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new KeepAliveTracker(userConnection));
}
}

View File

@ -0,0 +1,18 @@
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);
}
}

View File

@ -16,7 +16,7 @@
<groupId>nl.matsv</groupId>
<artifactId>viabackwards-parent</artifactId>
<version>2.2.0</version>
<version>2.3.0</version>
<packaging>pom</packaging>
<description>Allow newer clients to join older server versions.</description>
@ -61,11 +61,11 @@
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<!--ViaVersion -->
<!-- ViaVersion -->
<dependency>
<groupId>us.myles</groupId>
<artifactId>viaversion</artifactId>
<version>1.2.0-1_12_1-pre1</version>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -15,7 +15,7 @@
<parent>
<artifactId>viabackwards-parent</artifactId>
<groupId>nl.matsv</groupId>
<version>2.2.0</version>
<version>2.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>