24w07a, Port to upstream changes (maybe)

This commit is contained in:
FlorianMichael 2024-02-15 03:25:28 +01:00
parent becd446c77
commit 39005eb04f
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
45 changed files with 191 additions and 174 deletions

View File

@ -60,8 +60,8 @@ dependencies {
implementation(kotlin("stdlib-jdk8")) implementation(kotlin("stdlib-jdk8"))
implementation(kotlin("reflect")) implementation(kotlin("reflect"))
val vvVer = "4.10.0-24w04a-SNAPSHOT" val vvVer = "4.10.0-24w07a-SNAPSHOT"
val vbVer = "4.10.0-24w04a-SNAPSHOT" val vbVer = "4.10.0-24w07a-SNAPSHOT"
val vrVer = "3.0.6-SNAPSHOT" val vrVer = "3.0.6-SNAPSHOT"
implementation("com.viaversion:viaversion:$vvVer") { isTransitive = false } implementation("com.viaversion:viaversion:$vvVer") { isTransitive = false }
implementation("com.viaversion:viabackwards:$vbVer") { isTransitive = false } implementation("com.viaversion:viabackwards:$vbVer") { isTransitive = false }

View File

@ -6,6 +6,7 @@ import com.viaversion.aas.codec.packet.PacketRegistry;
import com.viaversion.aas.handler.MinecraftHandler; import com.viaversion.aas.handler.MinecraftHandler;
import com.viaversion.aas.util.StacklessException; import com.viaversion.aas.util.StacklessException;
import com.viaversion.viaversion.api.protocol.packet.Direction; import com.viaversion.viaversion.api.protocol.packet.Direction;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.exception.CancelEncoderException; import com.viaversion.viaversion.exception.CancelEncoderException;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufAllocator;
@ -43,7 +44,7 @@ public class MinecraftCodec extends MessageToMessageCodec<ByteBuf, Packet> {
var handler = ctx.pipeline().get(MinecraftHandler.class); var handler = ctx.pipeline().get(MinecraftHandler.class);
var frontVer = handler.getData().getFrontVer(); var frontVer = handler.getData().getFrontVer();
if (frontVer == null) { if (frontVer == null) {
frontVer = 0; frontVer = ProtocolVersion.unknown;
} }
out.add(PacketRegistry.INSTANCE.decode( out.add(PacketRegistry.INSTANCE.decode(
msg, msg,

View File

@ -1,5 +1,6 @@
package com.viaversion.aas.codec.packet; package com.viaversion.aas.codec.packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -9,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
* A mutable object which represents a Minecraft packet data * A mutable object which represents a Minecraft packet data
*/ */
public interface Packet { public interface Packet {
void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception; void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception;
void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception; void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception;
} }

View File

@ -1,6 +1,7 @@
package com.viaversion.aas.codec.packet.common; package com.viaversion.aas.codec.packet.common;
import com.viaversion.aas.codec.packet.Packet; import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -17,12 +18,12 @@ public class AbstractCompression implements Packet {
} }
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
threshold = Type.VAR_INT.readPrimitive(byteBuf); threshold = Type.VAR_INT.readPrimitive(byteBuf);
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.VAR_INT.writePrimitive(byteBuf, threshold); Type.VAR_INT.writePrimitive(byteBuf, threshold);
} }
} }

View File

@ -1,15 +1,16 @@
package com.viaversion.aas.codec.packet.common; package com.viaversion.aas.codec.packet.common;
import com.viaversion.aas.codec.packet.Packet; import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class AbstractEmpty implements Packet { public class AbstractEmpty implements Packet {
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
} }
} }

View File

@ -1,6 +1,7 @@
package com.viaversion.aas.codec.packet.common; package com.viaversion.aas.codec.packet.common;
import com.viaversion.aas.codec.packet.Packet; import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -16,12 +17,12 @@ public class AbstractPing implements Packet {
} }
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
number = byteBuf.readLong(); number = byteBuf.readLong();
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
byteBuf.writeLong(number); byteBuf.writeLong(number);
} }
} }

View File

@ -36,8 +36,8 @@ public class AbstractSingleChat implements Packet {
return null; return null;
} }
public void setMsgForVersion(JsonElement msg, int protocolVersion) { public void setMsgForVersion(JsonElement msg, ProtocolVersion protocolVersion) {
if (protocolVersion >= ProtocolVersion.v1_20_3.getVersion()) { if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_3)) {
this.msgTag = ComponentUtil.jsonToTag(com.viaversion.viaversion.libs.gson.JsonParser.parseString(msg.toString())); this.msgTag = ComponentUtil.jsonToTag(com.viaversion.viaversion.libs.gson.JsonParser.parseString(msg.toString()));
} else { } else {
this.msg = msg; this.msg = msg;
@ -45,8 +45,8 @@ public class AbstractSingleChat implements Packet {
} }
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
if (protocolVersion < ProtocolVersion.v1_20_3.getVersion()) { if (protocolVersion.olderThan(ProtocolVersion.v1_20_3)) {
msg = JsonParser.parseString(Type.STRING.read(byteBuf)); msg = JsonParser.parseString(Type.STRING.read(byteBuf));
} else { } else {
msgTag = Type.TAG.read(byteBuf); msgTag = Type.TAG.read(byteBuf);
@ -54,8 +54,8 @@ public class AbstractSingleChat implements Packet {
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
if (protocolVersion < ProtocolVersion.v1_20_3.getVersion()) { if (protocolVersion.olderThan(ProtocolVersion.v1_20_3)) {
Type.STRING.write(byteBuf, msg.toString()); Type.STRING.write(byteBuf, msg.toString());
} }
} }

View File

@ -3,6 +3,7 @@ package com.viaversion.aas.codec.packet.common;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
import com.viaversion.aas.codec.packet.Packet; import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -19,12 +20,12 @@ public class AbstractSingleJson implements Packet {
} }
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
msg = JsonParser.parseString(Type.STRING.read(byteBuf)); msg = JsonParser.parseString(Type.STRING.read(byteBuf));
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.STRING.write(byteBuf, msg.toString()); Type.STRING.write(byteBuf, msg.toString());
} }
} }

View File

@ -1,6 +1,7 @@
package com.viaversion.aas.codec.packet.configuration; package com.viaversion.aas.codec.packet.configuration;
import com.viaversion.aas.codec.packet.Packet; import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -8,12 +9,12 @@ public class ConfigurationKeepAlive implements Packet {
private long id; private long id;
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
this.id = byteBuf.readLong(); this.id = byteBuf.readLong();
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
byteBuf.writeLong(this.id); byteBuf.writeLong(this.id);
} }

View File

@ -2,6 +2,7 @@ package com.viaversion.aas.codec.packet.configuration;
import com.viaversion.aas.UtilKt; import com.viaversion.aas.UtilKt;
import com.viaversion.aas.codec.packet.Packet; import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -11,13 +12,13 @@ public class ConfigurationPluginMessage implements Packet {
private byte[] data; private byte[] data;
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
channel = Type.STRING.read(byteBuf); channel = Type.STRING.read(byteBuf);
data = UtilKt.readRemainingBytes(byteBuf); data = UtilKt.readRemainingBytes(byteBuf);
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.STRING.write(byteBuf, channel); Type.STRING.write(byteBuf, channel);
Type.REMAINING_BYTES.write(byteBuf, data); Type.REMAINING_BYTES.write(byteBuf, data);
} }

View File

@ -1,15 +1,16 @@
package com.viaversion.aas.codec.packet.configuration; package com.viaversion.aas.codec.packet.configuration;
import com.viaversion.aas.codec.packet.Packet; import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class FinishConfig implements Packet { public class FinishConfig implements Packet {
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
} }
} }

View File

@ -2,6 +2,7 @@ package com.viaversion.aas.codec.packet.handshake;
import com.viaversion.aas.codec.packet.Packet; import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.packet.State; import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -13,7 +14,7 @@ public class Handshake implements Packet {
private State nextState; private State nextState;
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
protocolId = Type.VAR_INT.readPrimitive(byteBuf); protocolId = Type.VAR_INT.readPrimitive(byteBuf);
address = Type.STRING.read(byteBuf); address = Type.STRING.read(byteBuf);
port = byteBuf.readUnsignedShort(); port = byteBuf.readUnsignedShort();
@ -21,7 +22,7 @@ public class Handshake implements Packet {
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.VAR_INT.writePrimitive(byteBuf, protocolId); Type.VAR_INT.writePrimitive(byteBuf, protocolId);
Type.STRING.write(byteBuf, address); Type.STRING.write(byteBuf, address);
byteBuf.writeShort(port); byteBuf.writeShort(port);

View File

@ -18,10 +18,10 @@ public class CryptoRequest implements Packet {
private byte[] nonce; private byte[] nonce;
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
serverId = Type.STRING.read(byteBuf); serverId = Type.STRING.read(byteBuf);
if (protocolVersion >= ProtocolVersion.v1_8.getVersion() if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_8)
|| protocolVersion == AspirinProtocolsKt.getSharewareVersion().getVersion()) { || protocolVersion.equalTo(AspirinProtocolsKt.getSharewareVersion())) {
publicKey = KeyFactory.getInstance("RSA") publicKey = KeyFactory.getInstance("RSA")
.generatePublic(new X509EncodedKeySpec(Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf))); .generatePublic(new X509EncodedKeySpec(Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf)));
nonce = Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf); nonce = Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf);
@ -33,11 +33,11 @@ public class CryptoRequest implements Packet {
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.STRING.write(byteBuf, serverId); Type.STRING.write(byteBuf, serverId);
if (protocolVersion >= ProtocolVersion.v1_8.getVersion() if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_8)
|| protocolVersion == AspirinProtocolsKt.getSharewareVersion().getVersion()) { || protocolVersion.equalTo(AspirinProtocolsKt.getSharewareVersion())) {
Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, publicKey.getEncoded()); Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, publicKey.getEncoded());
Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, nonce); Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, nonce);
} else { } else {

View File

@ -40,30 +40,30 @@ public class LoginStart implements Packet {
} }
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
username = new StringType(16).read(byteBuf); username = new StringType(16).read(byteBuf);
if (protocolVersion >= ProtocolVersion.v1_19.getVersion() if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19)
&& protocolVersion < ProtocolVersion.v1_19_3.getVersion()) { && protocolVersion.olderThan(ProtocolVersion.v1_19_3)) {
profileKey = Type.OPTIONAL_PROFILE_KEY.read(byteBuf); profileKey = Type.OPTIONAL_PROFILE_KEY.read(byteBuf);
} }
if (protocolVersion >= ProtocolVersion.v1_20_2.getVersion()) { if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_2)) {
profileId = Type.UUID.read(byteBuf); profileId = Type.UUID.read(byteBuf);
} else if (protocolVersion >= ProtocolVersion.v1_19_1.getVersion()) { } else if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19_1)) {
profileId = Type.OPTIONAL_UUID.read(byteBuf); profileId = Type.OPTIONAL_UUID.read(byteBuf);
} }
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.STRING.write(byteBuf, username); Type.STRING.write(byteBuf, username);
if (protocolVersion >= ProtocolVersion.v1_19.getVersion() if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19)
&& protocolVersion < ProtocolVersion.v1_19_3.getVersion()) { && protocolVersion.olderThan(ProtocolVersion.v1_19_3)) {
Type.OPTIONAL_PROFILE_KEY.write(byteBuf, profileKey); Type.OPTIONAL_PROFILE_KEY.write(byteBuf, profileKey);
} }
if (protocolVersion >= ProtocolVersion.v1_20_2.getVersion()) { if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_2)) {
Type.UUID.write(byteBuf, profileId); Type.UUID.write(byteBuf, profileId);
} else if (protocolVersion >= ProtocolVersion.v1_19_1.getVersion()) { } else if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19_1)) {
Type.OPTIONAL_UUID.write(byteBuf, profileId); Type.OPTIONAL_UUID.write(byteBuf, profileId);
} }
} }

View File

@ -2,6 +2,7 @@ package com.viaversion.aas.codec.packet.login;
import com.viaversion.aas.UtilKt; import com.viaversion.aas.UtilKt;
import com.viaversion.aas.codec.packet.Packet; import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -12,14 +13,14 @@ public class PluginRequest implements Packet {
private byte[] data; private byte[] data;
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
id = Type.VAR_INT.readPrimitive(byteBuf); id = Type.VAR_INT.readPrimitive(byteBuf);
channel = Type.STRING.read(byteBuf); channel = Type.STRING.read(byteBuf);
data = UtilKt.readRemainingBytes(byteBuf); data = UtilKt.readRemainingBytes(byteBuf);
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.VAR_INT.writePrimitive(byteBuf, id); Type.VAR_INT.writePrimitive(byteBuf, id);
Type.STRING.write(byteBuf, channel); Type.STRING.write(byteBuf, channel);
byteBuf.writeBytes(data); byteBuf.writeBytes(data);

View File

@ -2,6 +2,7 @@ package com.viaversion.aas.codec.packet.login;
import com.viaversion.aas.UtilKt; import com.viaversion.aas.UtilKt;
import com.viaversion.aas.codec.packet.Packet; import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -12,7 +13,7 @@ public class PluginResponse implements Packet {
private byte[] data; private byte[] data;
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
id = Type.VAR_INT.readPrimitive(byteBuf); id = Type.VAR_INT.readPrimitive(byteBuf);
success = byteBuf.readBoolean(); success = byteBuf.readBoolean();
if (success) { if (success) {
@ -21,7 +22,7 @@ public class PluginResponse implements Packet {
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.VAR_INT.writePrimitive(byteBuf, id); Type.VAR_INT.writePrimitive(byteBuf, id);
byteBuf.writeBoolean(success); byteBuf.writeBoolean(success);
if (success) { if (success) {

View File

@ -1,15 +1,16 @@
package com.viaversion.aas.codec.packet.play; package com.viaversion.aas.codec.packet.play;
import com.viaversion.aas.codec.packet.Packet; import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class ConfigurationAck implements Packet { public class ConfigurationAck implements Packet {
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
} }
} }

View File

@ -12,9 +12,9 @@ public class PluginMessage implements Packet {
private byte[] data; private byte[] data;
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
channel = Type.STRING.read(byteBuf); channel = Type.STRING.read(byteBuf);
if (protocolVersion <= ProtocolVersion.v1_7_6.getVersion()) { if (protocolVersion.olderThanOrEqualTo(ProtocolVersion.v1_7_6)) {
data = UtilKt.readByteArray(byteBuf, readExtendedForgeShort(byteBuf)); data = UtilKt.readByteArray(byteBuf, readExtendedForgeShort(byteBuf));
} else { } else {
data = UtilKt.readRemainingBytes(byteBuf); data = UtilKt.readRemainingBytes(byteBuf);
@ -22,9 +22,9 @@ public class PluginMessage implements Packet {
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.STRING.write(byteBuf, channel); Type.STRING.write(byteBuf, channel);
if (protocolVersion <= ProtocolVersion.v1_7_6.getVersion()) { if (protocolVersion.olderThanOrEqualTo(ProtocolVersion.v1_7_6)) {
writeExtendedForgeShort(byteBuf, data.length); writeExtendedForgeShort(byteBuf, data.length);
} }
byteBuf.writeBytes(data); byteBuf.writeBytes(data);

View File

@ -44,7 +44,7 @@ public class ServerboundChatCommand implements Packet {
} }
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
message = Type.STRING.read(byteBuf); message = Type.STRING.read(byteBuf);
timestamp = byteBuf.readLong(); timestamp = byteBuf.readLong();
salt = byteBuf.readLong(); salt = byteBuf.readLong();
@ -53,14 +53,14 @@ public class ServerboundChatCommand implements Packet {
signatures[i] = new ArgumentSignature(Type.STRING.read(byteBuf), Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf)); signatures[i] = new ArgumentSignature(Type.STRING.read(byteBuf), Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf));
} }
signedPreview = byteBuf.readBoolean(); signedPreview = byteBuf.readBoolean();
if (protocolVersion >= ProtocolVersion.v1_19_1.getVersion()) { if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19_1)) {
lastSeenMessages = Type.PLAYER_MESSAGE_SIGNATURE_ARRAY.read(byteBuf); lastSeenMessages = Type.PLAYER_MESSAGE_SIGNATURE_ARRAY.read(byteBuf);
lastReceivedMessage = Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE.read(byteBuf); lastReceivedMessage = Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE.read(byteBuf);
} }
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.STRING.write(byteBuf, message); Type.STRING.write(byteBuf, message);
byteBuf.writeLong(timestamp); byteBuf.writeLong(timestamp);
byteBuf.writeLong(salt); byteBuf.writeLong(salt);
@ -70,7 +70,7 @@ public class ServerboundChatCommand implements Packet {
Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, signature.getSignature()); Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, signature.getSignature());
} }
byteBuf.writeBoolean(signedPreview); byteBuf.writeBoolean(signedPreview);
if (protocolVersion >= ProtocolVersion.v1_19_1.getVersion()) { if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19_1)) {
Type.PLAYER_MESSAGE_SIGNATURE_ARRAY.write(byteBuf, lastSeenMessages); Type.PLAYER_MESSAGE_SIGNATURE_ARRAY.write(byteBuf, lastSeenMessages);
Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE.write(byteBuf, lastReceivedMessage); Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE.write(byteBuf, lastReceivedMessage);
} }

View File

@ -17,26 +17,26 @@ public class ServerboundChatMessage implements Packet {
private PlayerMessageSignature lastReceivedMessage; private PlayerMessageSignature lastReceivedMessage;
@Override @Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
message = Type.STRING.read(byteBuf); message = Type.STRING.read(byteBuf);
timestamp = byteBuf.readLong(); timestamp = byteBuf.readLong();
salt = byteBuf.readLong(); salt = byteBuf.readLong();
signature = Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf); signature = Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf);
signedPreview = byteBuf.readBoolean(); signedPreview = byteBuf.readBoolean();
if (protocolVersion >= ProtocolVersion.v1_19_1.getVersion()) { if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19_1)) {
lastSeenMessages = Type.PLAYER_MESSAGE_SIGNATURE_ARRAY.read(byteBuf); lastSeenMessages = Type.PLAYER_MESSAGE_SIGNATURE_ARRAY.read(byteBuf);
lastReceivedMessage = Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE.read(byteBuf); lastReceivedMessage = Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE.read(byteBuf);
} }
} }
@Override @Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception { public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
Type.STRING.write(byteBuf, message); Type.STRING.write(byteBuf, message);
byteBuf.writeLong(timestamp); byteBuf.writeLong(timestamp);
byteBuf.writeLong(salt); byteBuf.writeLong(salt);
Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, signature); Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, signature);
byteBuf.writeBoolean(signedPreview); byteBuf.writeBoolean(signedPreview);
if (protocolVersion >= ProtocolVersion.v1_19_1.getVersion()) { if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19_1)) {
Type.PLAYER_MESSAGE_SIGNATURE_ARRAY.write(byteBuf, lastSeenMessages); Type.PLAYER_MESSAGE_SIGNATURE_ARRAY.write(byteBuf, lastSeenMessages);
Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE.write(byteBuf, lastReceivedMessage); Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE.write(byteBuf, lastReceivedMessage);
} }

View File

@ -1,8 +1,20 @@
package com.viaversion.aas.platform; package com.viaversion.aas.platform;
import com.viaversion.viaversion.ViaAPIBase; import com.viaversion.viaversion.ViaAPIBase;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.ByteBuf;
import java.util.UUID; import java.util.UUID;
public class AspirinApi extends ViaAPIBase<UUID> { public class AspirinApi extends ViaAPIBase<UserConnection> {
@Override
public ProtocolVersion getPlayerProtocolVersion(UserConnection player) {
return player.getProtocolInfo().protocolVersion();
}
@Override
public void sendRawPacket(UserConnection player, ByteBuf packet) {
player.scheduleSendRawPacket(packet);
}
} }

View File

@ -4,7 +4,11 @@ import com.viaversion.viaversion.api.platform.ViaInjector;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.libs.fastutil.ints.IntLinkedOpenHashSet; import com.viaversion.viaversion.libs.fastutil.ints.IntLinkedOpenHashSet;
import com.viaversion.viaversion.libs.fastutil.ints.IntSortedSet; import com.viaversion.viaversion.libs.fastutil.ints.IntSortedSet;
import com.viaversion.viaversion.libs.fastutil.objects.ObjectLinkedOpenHashSet;
import com.viaversion.viaversion.libs.gson.JsonObject; import com.viaversion.viaversion.libs.gson.JsonObject;
import it.unimi.dsi.fastutil.objects.ObjectSortedSet;
import java.util.SortedSet;
public class AspirinInjector implements ViaInjector { public class AspirinInjector implements ViaInjector {
@Override @Override
@ -16,8 +20,8 @@ public class AspirinInjector implements ViaInjector {
} }
@Override @Override
public int getServerProtocolVersion() { public ProtocolVersion getServerProtocolVersion() {
return getServerProtocolVersions().firstInt(); return getServerProtocolVersions().first();
} }
@Override @Override
@ -36,13 +40,9 @@ public class AspirinInjector implements ViaInjector {
} }
@Override @Override
public IntSortedSet getServerProtocolVersions() { public SortedSet<ProtocolVersion> getServerProtocolVersions() {
var versions = new IntLinkedOpenHashSet(); var versions = new ObjectLinkedOpenHashSet<ProtocolVersion>();
versions.add(ProtocolVersion.v1_7_1.getOriginalVersion()); versions.addAll(ProtocolVersion.getProtocols());
versions.add(ProtocolVersion.getProtocols()
.stream()
.mapToInt(ProtocolVersion::getOriginalVersion)
.max().orElseThrow());
return versions; return versions;
} }
} }

View File

@ -2,11 +2,12 @@ package com.viaversion.aas.provider;
import com.viaversion.aas.handler.MinecraftHandler; import com.viaversion.aas.handler.MinecraftHandler;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.protocols.base.BaseVersionProvider; import com.viaversion.viaversion.protocols.base.BaseVersionProvider;
public class AspirinVersionProvider extends BaseVersionProvider { public class AspirinVersionProvider extends BaseVersionProvider {
@Override @Override
public int getClosestServerProtocol(UserConnection connection) throws Exception { public ProtocolVersion getClosestServerProtocol(UserConnection connection) throws Exception {
var ver = connection.getChannel().pipeline().get(MinecraftHandler.class).getData().getBackServerVer(); var ver = connection.getChannel().pipeline().get(MinecraftHandler.class).getData().getBackServerVer();
if (ver != null) return ver; if (ver != null) return ver;
return super.getClosestServerProtocol(connection); return super.getClosestServerProtocol(connection);

View File

@ -9,7 +9,7 @@ import java.util.*;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class AddressParser { public class AddressParser {
public Integer protocol; public ProtocolVersion protocol;
public String viaSuffix; public String viaSuffix;
public String serverAddress; public String serverAddress;
public String viaOptions; public String viaOptions;
@ -113,10 +113,11 @@ public class AddressParser {
} }
public void parseProtocol(String arg) { public void parseProtocol(String arg) {
protocol = Ints.tryParse(arg); final Integer protocolId = Ints.tryParse(arg);
if (protocol == null) { if (protocolId == null) {
ProtocolVersion ver = ProtocolVersion.getClosest(arg.replace("_", ".")); protocol = ProtocolVersion.getClosest(arg.replace("_", "."));
if (ver != null) protocol = ver.getVersion(); } else {
protocol = ProtocolVersion.getProtocol(protocolId);
} }
} }
} }

View File

@ -208,8 +208,6 @@ fun generateServerId() = ByteArray(13).let {
// https://developer.mozilla.org/en-US/docs/Glossary/Base64 133% of original // https://developer.mozilla.org/en-US/docs/Glossary/Base64 133% of original
} }
fun Int.parseProtocol() = ProtocolVersion.getProtocol(this)
fun sha512Hex(data: ByteArray): String { fun sha512Hex(data: ByteArray): String {
return MessageDigest.getInstance("SHA-512").digest(data) return MessageDigest.getInstance("SHA-512").digest(data)
.asUByteArray() .asUByteArray()

View File

@ -11,6 +11,7 @@ import com.viaversion.aas.protocol.registerAspirinProtocols
import com.viaversion.aas.web.ViaWebApp import com.viaversion.aas.web.ViaWebApp
import com.viaversion.viaversion.api.Via import com.viaversion.viaversion.api.Via
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
import com.viaversion.viaversion.api.protocol.version.VersionType
import io.ktor.server.application.* import io.ktor.server.application.*
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
@ -55,7 +56,7 @@ private fun printSplash() {
println("VIAaaS ${AspirinServer.version}") println("VIAaaS ${AspirinServer.version}")
} }
val autoProtocolId = -2 val AUTO = ProtocolVersion(VersionType.SPECIAL, -2, -1, "AUTO", null)
private fun initVia() { private fun initVia() {
AspirinPlatform.initVia { AspirinPlatform.initVia {
@ -66,7 +67,7 @@ private fun initVia() {
Via.getManager().configurationProvider.register(VIAaaSConfig) Via.getManager().configurationProvider.register(VIAaaSConfig)
} }
ProtocolVersion.register(autoProtocolId, "AUTO") ProtocolVersion.register(AUTO)
registerAspirinProtocols() registerAspirinProtocols()
} }

View File

@ -9,12 +9,7 @@ import com.viaversion.aas.codec.packet.configuration.ConfigurationPluginMessage
import com.viaversion.aas.codec.packet.configuration.FinishConfig import com.viaversion.aas.codec.packet.configuration.FinishConfig
import com.viaversion.aas.codec.packet.handshake.Handshake import com.viaversion.aas.codec.packet.handshake.Handshake
import com.viaversion.aas.codec.packet.login.* import com.viaversion.aas.codec.packet.login.*
import com.viaversion.aas.codec.packet.play.ConfigurationAck import com.viaversion.aas.codec.packet.play.*
import com.viaversion.aas.codec.packet.play.Kick
import com.viaversion.aas.codec.packet.play.PluginMessage
import com.viaversion.aas.codec.packet.play.ServerboundChatCommand
import com.viaversion.aas.codec.packet.play.ServerboundChatMessage
import com.viaversion.aas.codec.packet.play.SetPlayCompression
import com.viaversion.aas.codec.packet.status.StatusPing import com.viaversion.aas.codec.packet.status.StatusPing
import com.viaversion.aas.codec.packet.status.StatusPong import com.viaversion.aas.codec.packet.status.StatusPong
import com.viaversion.aas.codec.packet.status.StatusRequest import com.viaversion.aas.codec.packet.status.StatusRequest
@ -49,10 +44,10 @@ import java.util.function.Supplier
object PacketRegistry { object PacketRegistry {
// state, direction, packet id, protocol version -> entry // state, direction, packet id, protocol version -> entry
val entriesDecoding = hashMapOf<Triple<State, Direction, Int>, RangeMap<Int, DecodingInfo>>() private val entriesDecoding = hashMapOf<Triple<State, Direction, Int>, RangeMap<ProtocolVersion, DecodingInfo>>()
// direction, type, protocol version -> entry // direction, type, protocol version -> entry
val entriesEncoding = hashMapOf<Pair<Direction, Class<out Packet>>, RangeMap<Int, EncodingInfo>>() private val entriesEncoding = hashMapOf<Pair<Direction, Class<out Packet>>, RangeMap<ProtocolVersion, EncodingInfo>>()
init { init {
// Obviously stolen from https://github.com/VelocityPowered/Velocity/blob/dev/1.1.0/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java // Obviously stolen from https://github.com/VelocityPowered/Velocity/blob/dev/1.1.0/proxy/src/main/java/com/velocitypowered/proxy/protocol/StateRegistry.java
@ -60,7 +55,7 @@ object PacketRegistry {
register(State.LOGIN, Direction.SERVERBOUND, ::LoginStart, Range.all(), 0) register(State.LOGIN, Direction.SERVERBOUND, ::LoginStart, Range.all(), 0)
register(State.LOGIN, Direction.SERVERBOUND, ::CryptoResponse, Range.all(), 1) register(State.LOGIN, Direction.SERVERBOUND, ::CryptoResponse, Range.all(), 1)
register(State.LOGIN, Direction.SERVERBOUND, ::PluginResponse, Range.atLeast(ProtocolVersion.v1_13.version), 2) register(State.LOGIN, Direction.SERVERBOUND, ::PluginResponse, Range.atLeast(ProtocolVersion.v1_13), 2)
register(State.LOGIN, Direction.SERVERBOUND, ::PluginResponse, sharewareVersion.singleton, 2) register(State.LOGIN, Direction.SERVERBOUND, ::PluginResponse, sharewareVersion.singleton, 2)
register(State.LOGIN, Direction.CLIENTBOUND, ::LoginDisconnect, Range.all(), 0) register(State.LOGIN, Direction.CLIENTBOUND, ::LoginDisconnect, Range.all(), 0)
@ -68,13 +63,13 @@ object PacketRegistry {
register(State.LOGIN, Direction.CLIENTBOUND, ::LoginSuccess, Range.all(), 2) register(State.LOGIN, Direction.CLIENTBOUND, ::LoginSuccess, Range.all(), 2)
register( register(
State.LOGIN, Direction.CLIENTBOUND, ::SetCompression, mapOf( State.LOGIN, Direction.CLIENTBOUND, ::SetCompression, mapOf(
Range.atLeast(ProtocolVersion.v1_8.version) to 3, Range.atLeast(ProtocolVersion.v1_8) to 3,
sharewareVersion.singleton to 3 sharewareVersion.singleton to 3
) )
) )
register( register(
State.LOGIN, Direction.CLIENTBOUND, ::PluginRequest, mapOf( State.LOGIN, Direction.CLIENTBOUND, ::PluginRequest, mapOf(
Range.atLeast(ProtocolVersion.v1_13.version) to 4, Range.atLeast(ProtocolVersion.v1_13) to 4,
sharewareVersion.singleton to 4 sharewareVersion.singleton to 4
) )
) )
@ -94,7 +89,7 @@ object PacketRegistry {
register( register(
State.PLAY, Direction.CLIENTBOUND, ::Kick, mapOf( State.PLAY, Direction.CLIENTBOUND, ::Kick, mapOf(
ProtocolVersion.v1_7_1..ProtocolVersion.v1_8 to ClientboundPackets1_8.DISCONNECT.id, ProtocolVersion.v1_7_2..ProtocolVersion.v1_8 to ClientboundPackets1_8.DISCONNECT.id,
ProtocolVersion.v1_9..ProtocolVersion.v1_12_2 to ClientboundPackets1_9.DISCONNECT.id, ProtocolVersion.v1_9..ProtocolVersion.v1_12_2 to ClientboundPackets1_9.DISCONNECT.id,
ProtocolVersion.v1_13..ProtocolVersion.v1_13_2 to ClientboundPackets1_13.DISCONNECT.id, ProtocolVersion.v1_13..ProtocolVersion.v1_13_2 to ClientboundPackets1_13.DISCONNECT.id,
ProtocolVersion.v1_14..ProtocolVersion.v1_14_4 to ClientboundPackets1_14.DISCONNECT.id, ProtocolVersion.v1_14..ProtocolVersion.v1_14_4 to ClientboundPackets1_14.DISCONNECT.id,
@ -112,7 +107,7 @@ object PacketRegistry {
) )
register( register(
State.PLAY, Direction.CLIENTBOUND, ::PluginMessage, mapOf( State.PLAY, Direction.CLIENTBOUND, ::PluginMessage, mapOf(
ProtocolVersion.v1_7_1..ProtocolVersion.v1_8 to ClientboundPackets1_8.PLUGIN_MESSAGE.id, ProtocolVersion.v1_7_2..ProtocolVersion.v1_8 to ClientboundPackets1_8.PLUGIN_MESSAGE.id,
ProtocolVersion.v1_9..ProtocolVersion.v1_12_2 to ClientboundPackets1_9.PLUGIN_MESSAGE.id, ProtocolVersion.v1_9..ProtocolVersion.v1_12_2 to ClientboundPackets1_9.PLUGIN_MESSAGE.id,
ProtocolVersion.v1_13..ProtocolVersion.v1_13_2 to ClientboundPackets1_13.PLUGIN_MESSAGE.id, ProtocolVersion.v1_13..ProtocolVersion.v1_13_2 to ClientboundPackets1_13.PLUGIN_MESSAGE.id,
ProtocolVersion.v1_14..ProtocolVersion.v1_14_4 to ClientboundPackets1_14.PLUGIN_MESSAGE.id, ProtocolVersion.v1_14..ProtocolVersion.v1_14_4 to ClientboundPackets1_14.PLUGIN_MESSAGE.id,
@ -154,17 +149,17 @@ object PacketRegistry {
) )
} }
operator fun ProtocolVersion.rangeTo(o: ProtocolVersion): Range<Int> { operator fun ProtocolVersion.rangeTo(o: ProtocolVersion): Range<ProtocolVersion> {
return Range.closed(this.originalVersion, o.originalVersion) return Range.closed(this, o)
} }
private val ProtocolVersion.singleton get() = Range.singleton(this.originalVersion) private val ProtocolVersion.singleton get() = Range.singleton(this)
inline fun <reified P : Packet> register( private inline fun <reified P : Packet> register(
state: State, state: State,
direction: Direction, direction: Direction,
constructor: Supplier<P>, constructor: Supplier<P>,
idByProtocol: Map<Range<Int>, Int>, idByProtocol: Map<Range<ProtocolVersion>, Int>,
klass: Class<P> = P::class.java, klass: Class<P> = P::class.java,
) { ) {
idByProtocol.forEach { (protocolRange, packetId) -> idByProtocol.forEach { (protocolRange, packetId) ->
@ -176,7 +171,7 @@ object PacketRegistry {
} }
} }
val protocolRangeToId = TreeRangeMap.create<Int, Int>() val protocolRangeToId = TreeRangeMap.create<ProtocolVersion, Int>()
idByProtocol.forEach { (range, id) -> protocolRangeToId.put(range, id) } idByProtocol.forEach { (range, id) -> protocolRangeToId.put(range, id) }
entriesEncoding.computeIfAbsent(direction to klass) { TreeRangeMap.create() }.also { rangeMap -> entriesEncoding.computeIfAbsent(direction to klass) { TreeRangeMap.create() }.also { rangeMap ->
@ -188,11 +183,11 @@ object PacketRegistry {
} }
} }
inline fun <reified P : Packet> register( private inline fun <reified P : Packet> register(
state: State, state: State,
direction: Direction, direction: Direction,
constructor: Supplier<P>, constructor: Supplier<P>,
protocol: Range<Int>, protocol: Range<ProtocolVersion>,
id: Int id: Int
) { ) {
register(constructor = constructor, direction = direction, state = state, idByProtocol = mapOf(protocol to id)) register(constructor = constructor, direction = direction, state = state, idByProtocol = mapOf(protocol to id))
@ -202,7 +197,7 @@ object PacketRegistry {
data class EncodingInfo(val packetId: Int) data class EncodingInfo(val packetId: Int)
private fun getPacketConstructor( private fun getPacketConstructor(
protocolVersion: Int, protocolVersion: ProtocolVersion,
state: State, state: State,
id: Int, id: Int,
direction: Direction direction: Direction
@ -210,11 +205,11 @@ object PacketRegistry {
return entriesDecoding[Triple(state, direction, id)]?.get(protocolVersion)?.constructor return entriesDecoding[Triple(state, direction, id)]?.get(protocolVersion)?.constructor
} }
private fun getPacketId(packetClass: Class<out Packet>, protocolVersion: Int, direction: Direction): Int? { private fun getPacketId(packetClass: Class<out Packet>, protocolVersion: ProtocolVersion, direction: Direction): Int? {
return entriesEncoding[direction to packetClass]?.get(protocolVersion)?.packetId return entriesEncoding[direction to packetClass]?.get(protocolVersion)?.packetId
} }
fun decode(byteBuf: ByteBuf, protocolVersion: Int, state: State, direction: Direction): Packet { fun decode(byteBuf: ByteBuf, protocolVersion: ProtocolVersion, state: State, direction: Direction): Packet {
val packetId = Type.VAR_INT.readPrimitive(byteBuf) val packetId = Type.VAR_INT.readPrimitive(byteBuf)
val packet = getPacketConstructor(protocolVersion, state, packetId, direction)?.get() val packet = getPacketConstructor(protocolVersion, state, packetId, direction)?.get()
?: UnknownPacket(packetId, ByteBufAllocator.DEFAULT.buffer()) ?: UnknownPacket(packetId, ByteBufAllocator.DEFAULT.buffer())
@ -228,7 +223,7 @@ object PacketRegistry {
} }
} }
fun encode(packet: Packet, byteBuf: ByteBuf, protocolVersion: Int, direction: Direction) { fun encode(packet: Packet, byteBuf: ByteBuf, protocolVersion: ProtocolVersion, direction: Direction) {
val id = if (packet is UnknownPacket) { val id = if (packet is UnknownPacket) {
packet.id packet.id
} else { } else {

View File

@ -1,14 +1,15 @@
package com.viaversion.aas.codec.packet package com.viaversion.aas.codec.packet
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
import io.netty.buffer.ByteBuf import io.netty.buffer.ByteBuf
import io.netty.buffer.ByteBufHolder import io.netty.buffer.ByteBufHolder
class UnknownPacket(val id: Int, val content: ByteBuf) : Packet, ByteBufHolder { class UnknownPacket(val id: Int, private val content: ByteBuf) : Packet, ByteBufHolder {
override fun decode(byteBuf: ByteBuf, protocolVersion: Int) { override fun decode(byteBuf: ByteBuf, protocolVersion: ProtocolVersion) {
content.writeBytes(byteBuf) content.writeBytes(byteBuf)
} }
override fun encode(byteBuf: ByteBuf, protocolVersion: Int) { override fun encode(byteBuf: ByteBuf, protocolVersion: ProtocolVersion) {
byteBuf.writeBytes(content) byteBuf.writeBytes(content)
} }

View File

@ -13,10 +13,10 @@ class CryptoResponse : Packet {
var salt: Long? = null var salt: Long? = null
var signature: ByteArray? = null var signature: ByteArray? = null
override fun decode(byteBuf: ByteBuf, protocolVersion: Int) { override fun decode(byteBuf: ByteBuf, protocolVersion: ProtocolVersion) {
when { when {
protocolVersion >= ProtocolVersion.v1_19.version protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19)
&& protocolVersion < ProtocolVersion.v1_19_3.version -> { && protocolVersion.olderThan(ProtocolVersion.v1_19_3) -> {
encryptedKey = Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf) encryptedKey = Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf)
if (byteBuf.readBoolean()) { if (byteBuf.readBoolean()) {
encryptedNonce = Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf) encryptedNonce = Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf)
@ -26,7 +26,7 @@ class CryptoResponse : Packet {
} }
} }
protocolVersion >= ProtocolVersion.v1_8.version || protocolVersion == sharewareVersion.version -> { protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_8) || protocolVersion.equalTo(sharewareVersion) -> {
encryptedKey = Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf) encryptedKey = Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf)
encryptedNonce = Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf) encryptedNonce = Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf)
} }
@ -38,10 +38,10 @@ class CryptoResponse : Packet {
} }
} }
override fun encode(byteBuf: ByteBuf, protocolVersion: Int) { override fun encode(byteBuf: ByteBuf, protocolVersion: ProtocolVersion) {
when { when {
protocolVersion >= ProtocolVersion.v1_19.version protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19)
&& protocolVersion < ProtocolVersion.v1_19_3.version -> { && protocolVersion.olderThan(ProtocolVersion.v1_19_3) -> {
Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, encryptedKey) Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, encryptedKey)
if (encryptedNonce != null) { if (encryptedNonce != null) {
byteBuf.writeBoolean(true) byteBuf.writeBoolean(true)
@ -53,7 +53,7 @@ class CryptoResponse : Packet {
} }
} }
protocolVersion >= ProtocolVersion.v1_8.version || protocolVersion == sharewareVersion.version -> { protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_8) || protocolVersion.equalTo(sharewareVersion) -> {
Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, encryptedKey) Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, encryptedKey)
Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, encryptedNonce) Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, encryptedNonce)
} }

View File

@ -13,36 +13,36 @@ import java.util.*
class LoginSuccess : Packet { class LoginSuccess : Packet {
lateinit var id: UUID lateinit var id: UUID
lateinit var username: String lateinit var username: String
val properties = mutableListOf<SignableProperty>() private val properties = mutableListOf<SignableProperty>()
override fun decode(byteBuf: ByteBuf, protocolVersion: Int) { override fun decode(byteBuf: ByteBuf, protocolVersion: ProtocolVersion) {
id = when { id = when {
protocolVersion >= ProtocolVersion.v1_16.version -> { protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_16) -> {
Type.UUID.read(byteBuf) Type.UUID.read(byteBuf)
} }
protocolVersion >= ProtocolVersion.v1_7_6.version || protocolVersion == sharewareVersion.version -> { protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_7_6) || protocolVersion.equalTo(sharewareVersion) -> {
UUID.fromString(Type.STRING.read(byteBuf)) UUID.fromString(Type.STRING.read(byteBuf))
} }
else -> parseUndashedId(Type.STRING.read(byteBuf)) else -> parseUndashedId(Type.STRING.read(byteBuf))
} }
username = Type.STRING.read(byteBuf) username = Type.STRING.read(byteBuf)
if (protocolVersion >= ProtocolVersion.v1_19.version) { if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19)) {
properties.addAll(AspirinTypes.SIGNABLE_PROPERTY_ARRAY.read(byteBuf).asList()) properties.addAll(AspirinTypes.SIGNABLE_PROPERTY_ARRAY.read(byteBuf).asList())
} }
} }
override fun encode(byteBuf: ByteBuf, protocolVersion: Int) { override fun encode(byteBuf: ByteBuf, protocolVersion: ProtocolVersion) {
when { when {
protocolVersion >= ProtocolVersion.v1_16.version -> { protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_16) -> {
Type.UUID.write(byteBuf, id) Type.UUID.write(byteBuf, id)
} }
protocolVersion >= ProtocolVersion.v1_7_6.version || protocolVersion == sharewareVersion.version -> { protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_7_6) || protocolVersion.equalTo(sharewareVersion) -> {
Type.STRING.write(byteBuf, id.toString()) Type.STRING.write(byteBuf, id.toString())
} }
else -> Type.STRING.write(byteBuf, id.toString().replace("-", "")) else -> Type.STRING.write(byteBuf, id.toString().replace("-", ""))
} }
Type.STRING.write(byteBuf, username) Type.STRING.write(byteBuf, username)
if (protocolVersion >= ProtocolVersion.v1_19.version) { if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19)) {
AspirinTypes.SIGNABLE_PROPERTY_ARRAY.write(byteBuf, properties.toTypedArray()) AspirinTypes.SIGNABLE_PROPERTY_ARRAY.write(byteBuf, properties.toTypedArray())
} }
} }

View File

@ -1,7 +1,6 @@
package com.viaversion.aas.command.sub package com.viaversion.aas.command.sub
import com.viaversion.aas.handler.MinecraftHandler import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.parseProtocol
import com.viaversion.viaversion.api.Via import com.viaversion.viaversion.api.Via
import com.viaversion.viaversion.api.command.ViaCommandSender import com.viaversion.viaversion.api.command.ViaCommandSender
import com.viaversion.viaversion.api.command.ViaSubCommand import com.viaversion.viaversion.api.command.ViaSubCommand
@ -14,9 +13,9 @@ object ConnectionsSubCommand : ViaSubCommand() {
Via.getManager().connectionManager.connections.forEach { Via.getManager().connectionManager.connections.forEach {
val handler = it.channel?.pipeline()?.get(MinecraftHandler::class.java) val handler = it.channel?.pipeline()?.get(MinecraftHandler::class.java)
val backAddr = handler?.endRemoteAddress val backAddr = handler?.endRemoteAddress
val pVer = it.protocolInfo?.protocolVersion?.parseProtocol() val pVer = it.protocolInfo?.protocolVersion()
val backName = it.protocolInfo?.username val backName = it.protocolInfo?.username
val backVer = it.protocolInfo?.serverProtocolVersion?.parseProtocol() val backVer = it.protocolInfo?.serverProtocolVersion()
val pAddr = handler?.data?.frontHandler?.endRemoteAddress val pAddr = handler?.data?.frontHandler?.endRemoteAddress
p0.sendMessage("$pAddr $pVer -> $backVer ($backName) $backAddr") p0.sendMessage("$pAddr $pVer -> $backVer ($backName) $backAddr")
} }

View File

@ -47,24 +47,16 @@ object VIAaaSConfig : Config(File("config/viaaas.yml")), com.viaversion.viaversi
private fun reloadFields() { private fun reloadFields() {
reloadIcon() reloadIcon()
defaultParameters = this.get("default-parameters", Map::class.java, emptyMap<Int, String>())!!.map { defaultParameters = this.get("default-parameters", emptyMap<Int, String>())!!.map {
(it.key as Number).toInt() to AddressParser().parse(it.value.toString()) (it.key as Number).toInt() to AddressParser().parse(it.value)
}.toMap() }.toMap()
bindAddresses = this.getStringList("bind-addresses").map { HostAndPort.fromString(it).withDefaultPort(25565) } bindAddresses = this.getStringList("bind-addresses").map { HostAndPort.fromString(it).withDefaultPort(25565) }
hostName = this.get("host-name", List::class.java, emptyList<String>())!!.map { it.toString() } hostName = this.get("host-name", emptyList<String>())!!.map { it }
blockLocalAddress = this.getBoolean("block-local-address", true) blockLocalAddress = this.getBoolean("block-local-address", true)
requireHostName = this.getBoolean("require-host-name", true) requireHostName = this.getBoolean("require-host-name", true)
defaultBackendPort = this.getInt("default-backend-port", 25565).let { if (it == -1) null else it } defaultBackendPort = this.getInt("default-backend-port", 25565).let { if (it == -1) null else it }
blockedBackAddresses = this.get( blockedBackAddresses = this.get("blocked-back-addresses", emptyList())!!
"blocked-back-addresses", allowedBackAddresses = this.get("allowed-back-addresses", emptyList())!!
List::class.java,
emptyList<String>()
)!!.map { it.toString() }
allowedBackAddresses = this.get(
"allowed-back-addresses",
List::class.java,
emptyList<String>()
)!!.map { it.toString() }
forceOnlineMode = this.getBoolean("force-online-mode", false) forceOnlineMode = this.getBoolean("force-online-mode", false)
showVersionPing = this.getBoolean("show-version-ping", true) showVersionPing = this.getBoolean("show-version-ping", true)
showBrandInfo = this.getBoolean("show-brand-info", true) showBrandInfo = this.getBoolean("show-brand-info", true)
@ -81,7 +73,7 @@ object VIAaaSConfig : Config(File("config/viaaas.yml")), com.viaversion.viaversi
compressionLevel = this.getInt("compression-level", 6) compressionLevel = this.getInt("compression-level", 6)
} }
fun reloadIcon() { private fun reloadIcon() {
val rawUrl = this.getString("favicon-url", "")!! val rawUrl = this.getString("favicon-url", "")!!
try { try {
faviconUrl = when { faviconUrl = when {

View File

@ -14,13 +14,13 @@ import java.net.InetSocketAddress
import java.net.URI import java.net.URI
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
class BackEndInit(val connectionData: ConnectionData, val proxyUri: URI?, val proxyAddress: InetSocketAddress?) : class BackEndInit(private val connectionData: ConnectionData, private val proxyUri: URI?, private val proxyAddress: InetSocketAddress?) :
ChannelInitializer<Channel>() { ChannelInitializer<Channel>() {
override fun initChannel(ch: Channel) { override fun initChannel(ch: Channel) {
val user = UserConnectionImpl(ch, true) val user = UserConnectionImpl(ch, true)
val pipeline = ProtocolPipelineImpl(user) val pipeline = ProtocolPipelineImpl(user)
val version = connectionData.backServerVer!! val version = connectionData.backServerVer!!
val isLegacy = LegacyProtocolVersion.protocolCompare(version, LegacyProtocolVersion.r1_6_4.version) <= 0 val isLegacy = version.olderThanOrEqualTo(LegacyProtocolVersion.r1_6_4)
if (isLegacy) { if (isLegacy) {
pipeline.add(PreNettyBaseProtocol.INSTANCE) pipeline.add(PreNettyBaseProtocol.INSTANCE)

View File

@ -4,14 +4,15 @@ import com.viaversion.aas.codec.CompressionCodec
import com.viaversion.aas.codec.CryptoCodec import com.viaversion.aas.codec.CryptoCodec
import com.viaversion.aas.handler.state.ConnectionState import com.viaversion.aas.handler.state.ConnectionState
import com.viaversion.aas.handler.state.HandshakeState import com.viaversion.aas.handler.state.HandshakeState
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
import io.netty.channel.Channel import io.netty.channel.Channel
class ConnectionData( class ConnectionData(
val frontChannel: Channel, val frontChannel: Channel,
var backChannel: Channel? = null, var backChannel: Channel? = null,
var state: ConnectionState = HandshakeState(), var state: ConnectionState = HandshakeState(),
var frontVer: Int? = null, var frontVer: ProtocolVersion? = null,
var backServerVer: Int? = null, var backServerVer: ProtocolVersion? = null,
var autoDetectProtocol: Boolean = false var autoDetectProtocol: Boolean = false
) { ) {
val frontHandler get() = frontChannel.pipeline()[MinecraftHandler::class.java] val frontHandler get() = frontChannel.pipeline()[MinecraftHandler::class.java]

View File

@ -20,7 +20,7 @@ fun forward(handler: MinecraftHandler, packet: Packet, flush: Boolean = false) {
send(handler.other!!, packet, flush) send(handler.other!!, packet, flush)
} }
fun is17(handler: MinecraftHandler) = handler.data.frontVer!! <= ProtocolVersion.v1_7_6.version fun is17(handler: MinecraftHandler) = handler.data.frontVer!!.olderThanOrEqualTo(ProtocolVersion.v1_7_6)
fun addProxyHandler(pipe: ChannelPipeline, proxyUri: URI?, socket: InetSocketAddress?) { fun addProxyHandler(pipe: ChannelPipeline, proxyUri: URI?, socket: InetSocketAddress?) {
if (proxyUri != null) { if (proxyUri != null) {

View File

@ -5,22 +5,20 @@ import com.viaversion.aas.codec.packet.status.StatusResponse
import com.viaversion.aas.handler.MinecraftHandler import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.handler.state.ConnectionState import com.viaversion.aas.handler.state.ConnectionState
import com.viaversion.aas.mcLogger import com.viaversion.aas.mcLogger
import com.viaversion.aas.parseProtocol
import com.viaversion.aas.util.StacklessException import com.viaversion.aas.util.StacklessException
import com.viaversion.viaversion.api.protocol.packet.State import com.viaversion.viaversion.api.protocol.packet.State
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
import io.netty.channel.ChannelHandlerContext import io.netty.channel.ChannelHandlerContext
import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletableFuture
class ProtocolDetectionState(val future: CompletableFuture<ProtocolVersion>) : ConnectionState { class ProtocolDetectionState(private val future: CompletableFuture<ProtocolVersion>) : ConnectionState {
override val state: State override val state: State
get() = State.STATUS get() = State.STATUS
override fun handlePacket(handler: MinecraftHandler, ctx: ChannelHandlerContext, packet: Packet) { override fun handlePacket(handler: MinecraftHandler, ctx: ChannelHandlerContext, packet: Packet) {
handler.data.frontChannel.close() handler.data.frontChannel.close()
if (packet !is StatusResponse) throw StacklessException("Unexpected packet") if (packet !is StatusResponse) throw StacklessException("Unexpected packet")
val ver = packet.msg.asJsonObject val ver = ProtocolVersion.getProtocol(packet.msg.asJsonObject.getAsJsonObject("version")["protocol"].asInt)
.getAsJsonObject("version")["protocol"].asInt.parseProtocol()
future.complete(ver) future.complete(ver)
mcLogger.info("A.D.: {} {}", handler.endRemoteAddress, ver) mcLogger.info("A.D.: {} {}", handler.endRemoteAddress, ver)
} }

View File

@ -49,7 +49,7 @@ object ProtocolDetector {
.option(ChannelOption.IP_TOS, 0x18) .option(ChannelOption.IP_TOS, 0x18)
.handler(object : ChannelInitializer<Channel>() { .handler(object : ChannelInitializer<Channel>() {
override fun initChannel(channel: Channel) { override fun initChannel(channel: Channel) {
val data = ConnectionData(channel, state = ProtocolDetectionState(future), frontVer = -1) val data = ConnectionData(channel, state = ProtocolDetectionState(future), frontVer = ProtocolVersion.unknown)
channel.pipeline().also { addProxyHandler(it, proxyUri, proxySocket) } channel.pipeline().also { addProxyHandler(it, proxyUri, proxySocket) }
.addLast("timeout", ReadTimeoutHandler(30, TimeUnit.SECONDS)) .addLast("timeout", ReadTimeoutHandler(30, TimeUnit.SECONDS))
.addLast("frame", FrameCodec()) .addLast("frame", FrameCodec())

View File

@ -62,7 +62,7 @@ private suspend fun createBackChannel(
val packet = Handshake() val packet = Handshake()
packet.nextState = state packet.nextState = state
packet.protocolId = handler.data.frontVer!! packet.protocolId = handler.data.frontVer!!.version
packet.address = socketAddr.hostString + if (extraData != null) 0.toChar() + extraData else "" packet.address = socketAddr.hostString + if (extraData != null) 0.toChar() + extraData else ""
packet.port = socketAddr.port packet.port = socketAddr.port
@ -88,7 +88,7 @@ private suspend fun autoDetectVersion(handler: MinecraftHandler, socketAddr: Ine
handler.data.backServerVer = if (detectedProtocol != null handler.data.backServerVer = if (detectedProtocol != null
&& detectedProtocol.version !in arrayOf(-1, -2) && detectedProtocol.version !in arrayOf(-1, -2)
&& ProtocolVersion.isRegistered(detectedProtocol.version) && ProtocolVersion.isRegistered(detectedProtocol.version)
) detectedProtocol.version else 47 // fallback 1.8 ) detectedProtocol else ProtocolVersion.v1_8 // fallback
} }
} }

View File

@ -4,15 +4,16 @@ import com.google.common.cache.CacheBuilder
import com.google.common.cache.CacheLoader import com.google.common.cache.CacheLoader
import com.google.common.net.HostAndPort import com.google.common.net.HostAndPort
import com.google.common.util.concurrent.RateLimiter import com.google.common.util.concurrent.RateLimiter
import com.viaversion.aas.AUTO
import com.viaversion.aas.codec.packet.Packet import com.viaversion.aas.codec.packet.Packet
import com.viaversion.aas.codec.packet.handshake.Handshake import com.viaversion.aas.codec.packet.handshake.Handshake
import com.viaversion.aas.config.VIAaaSConfig import com.viaversion.aas.config.VIAaaSConfig
import com.viaversion.aas.handler.MinecraftHandler import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.autoProtocolId
import com.viaversion.aas.mcLogger import com.viaversion.aas.mcLogger
import com.viaversion.aas.util.AddressParser import com.viaversion.aas.util.AddressParser
import com.viaversion.aas.util.StacklessException import com.viaversion.aas.util.StacklessException
import com.viaversion.viaversion.api.protocol.packet.State import com.viaversion.viaversion.api.protocol.packet.State
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
import io.netty.channel.ChannelHandlerContext import io.netty.channel.ChannelHandlerContext
import java.net.InetAddress import java.net.InetAddress
import java.net.InetSocketAddress import java.net.InetSocketAddress
@ -47,7 +48,7 @@ class HandshakeState : ConnectionState {
} }
private fun handleNextState(handler: MinecraftHandler, packet: Handshake) { private fun handleNextState(handler: MinecraftHandler, packet: Handshake) {
handler.data.frontVer = packet.protocolId handler.data.frontVer = ProtocolVersion.getProtocol(packet.protocolId)
when (packet.nextState.ordinal) { when (packet.nextState.ordinal) {
1 -> handler.data.state = StatusState() 1 -> handler.data.state = StatusState()
2 -> handler.data.state = LoginState() 2 -> handler.data.state = LoginState()
@ -73,7 +74,7 @@ class HandshakeState : ConnectionState {
} }
} }
val backProto = parsed.protocol ?: autoProtocolId val backProto = parsed.protocol ?: AUTO
val backAddress = parsed.serverAddress!! val backAddress = parsed.serverAddress!!
val port = parsed.port ?: VIAaaSConfig.defaultBackendPort ?: virtualPort val port = parsed.port ?: VIAaaSConfig.defaultBackendPort ?: virtualPort
@ -84,7 +85,7 @@ class HandshakeState : ConnectionState {
val addressFromWeb = VIAaaSConfig.hostName.any { parsed.serverAddress.equals(it, ignoreCase = true) } val addressFromWeb = VIAaaSConfig.hostName.any { parsed.serverAddress.equals(it, ignoreCase = true) }
handler.data.backServerVer = backProto handler.data.backServerVer = backProto
if (backProto == autoProtocolId) handler.data.autoDetectProtocol = true if (backProto == AUTO) handler.data.autoDetectProtocol = true
(handler.data.state as? LoginState)?.also { (handler.data.state as? LoginState)?.also {
it.frontOnline = frontOnline it.frontOnline = frontOnline
it.backName = parsed.username it.backName = parsed.username

View File

@ -84,14 +84,14 @@ class LoginState : ConnectionState {
} }
private fun handleLoginSuccess(handler: MinecraftHandler, loginSuccess: LoginSuccess) { private fun handleLoginSuccess(handler: MinecraftHandler, loginSuccess: LoginSuccess) {
if (handler.data.compressionLevel == -1 && handler.data.frontVer!! >= ProtocolVersion.v1_8.version) { if (handler.data.compressionLevel == -1 && handler.data.frontVer!!.newerThanOrEqualTo(ProtocolVersion.v1_8)) {
// Enable front-end compression // Enable front-end compression
val threshold = 256 val threshold = 256
forward(handler, SetCompression().also { it.threshold = threshold }) forward(handler, SetCompression().also { it.threshold = threshold })
setCompression(handler.data.frontChannel, threshold) setCompression(handler.data.frontChannel, threshold)
} }
handler.data.state = when { handler.data.state = when {
handler.data.frontVer!! >= ProtocolVersion.v1_20_2.version -> ConfigurationState() handler.data.frontVer!!.newerThanOrEqualTo(ProtocolVersion.v1_20_2) -> ConfigurationState()
else -> PlayState() else -> PlayState()
} }
forward(handler, loginSuccess) forward(handler, loginSuccess)
@ -122,7 +122,7 @@ class LoginState : ConnectionState {
fun reauthMessage(handler: MinecraftHandler, backName: String, backHash: String): CompletableFuture<Boolean> { fun reauthMessage(handler: MinecraftHandler, backName: String, backHash: String): CompletableFuture<Boolean> {
if (!handler.data.frontEncrypted if (!handler.data.frontEncrypted
|| !frontName.equals(backName, ignoreCase = true) || !frontName.equals(backName, ignoreCase = true)
|| handler.data.frontVer!! < ProtocolVersion.v1_8.version || handler.data.frontVer!!.olderThan(ProtocolVersion.v1_8)
) { ) {
callbackReauth.complete(false) callbackReauth.complete(false)
return callbackReauth return callbackReauth
@ -140,7 +140,7 @@ class LoginState : ConnectionState {
} }
private fun sendOpenAuthRequest(handler: MinecraftHandler, channel: String, id: Int, data: ByteArray) { private fun sendOpenAuthRequest(handler: MinecraftHandler, channel: String, id: Int, data: ByteArray) {
if (handler.data.frontVer!! < ProtocolVersion.v1_13.version) { if (handler.data.frontVer!!.olderThan(ProtocolVersion.v1_13)) {
encodeCompressionOpenAuth(channel, id, data).forEach { entry -> encodeCompressionOpenAuth(channel, id, data).forEach { entry ->
send(handler.data.frontChannel, SetCompression().also { it.threshold = entry }) send(handler.data.frontChannel, SetCompression().also { it.threshold = entry })
} }
@ -269,7 +269,7 @@ class LoginState : ConnectionState {
val info = AspirinServer.viaWebServer.requestAddressInfo(frontName).await() val info = AspirinServer.viaWebServer.requestAddressInfo(frontName).await()
backAddress = info.backHostAndPort backAddress = info.backHostAndPort
handler.data.backServerVer = info.backVersion handler.data.backServerVer = info.backVersion
if (info.backVersion == autoProtocolId) handler.data.autoDetectProtocol = true if (info.backVersion == AUTO) handler.data.autoDetectProtocol = true
frontOnline = info.frontOnline frontOnline = info.frontOnline
info.backName?.also { backName = info.backName } info.backName?.also { backName = info.backName }
} }

View File

@ -12,7 +12,6 @@ import com.viaversion.aas.codec.packet.play.SetPlayCompression
import com.viaversion.aas.config.VIAaaSConfig import com.viaversion.aas.config.VIAaaSConfig
import com.viaversion.aas.handler.* import com.viaversion.aas.handler.*
import com.viaversion.aas.mcLogger import com.viaversion.aas.mcLogger
import com.viaversion.aas.parseProtocol
import com.viaversion.aas.util.StacklessException import com.viaversion.aas.util.StacklessException
import com.viaversion.aas.writeFlushClose import com.viaversion.aas.writeFlushClose
import com.viaversion.viaversion.api.protocol.packet.State import com.viaversion.viaversion.api.protocol.packet.State
@ -74,7 +73,7 @@ class PlayState : ConnectionState {
pluginMessage.data, pluginMessage.data,
is17(handler) is17(handler)
) )
}${" (VIAaaS C: ${handler.data.frontVer?.parseProtocol()} S: ${handler.data.backServerVer?.parseProtocol()})"}" }${" (VIAaaS C: ${handler.data.frontVer} S: ${handler.data.backServerVer})"}"
pluginMessage.data = encodeBrand(brand, is17(handler)) pluginMessage.data = encodeBrand(brand, is17(handler))
} }

View File

@ -39,7 +39,7 @@ class StatusState : ConnectionState {
it.addProperty("id", UUID.nameUUIDFromBytes("VIAaaS".toByteArray(Charsets.UTF_8)).toString()) it.addProperty("id", UUID.nameUUIDFromBytes("VIAaaS".toByteArray(Charsets.UTF_8)).toString())
it.addProperty( it.addProperty(
"name", "§9VIAaaS§r C: §7%s§'r S: §7%s" "name", "§9VIAaaS§r C: §7%s§'r S: §7%s"
.format(handler.data.frontVer?.parseProtocol(), handler.data.backServerVer?.parseProtocol()) .format(handler.data.frontVer, handler.data.backServerVer)
) )
}) })
} }
@ -52,7 +52,7 @@ class StatusState : ConnectionState {
packet.msg = JsonObject().also { packet.msg = JsonObject().also {
it.add("version", JsonObject().also { it.add("version", JsonObject().also {
it.addProperty("name", "VIAaaS") it.addProperty("name", "VIAaaS")
it.addProperty("protocol", handler.data.frontVer) it.addProperty("protocol", handler.data.frontVer!!.version)
}) })
it.add("players", JsonObject().also { it.add("players", JsonObject().also {
it.addProperty("max", VIAaaSConfig.maxPlayers ?: -1) it.addProperty("max", VIAaaSConfig.maxPlayers ?: -1)

View File

@ -7,6 +7,7 @@ import com.viaversion.aas.config.AspirinViaConfig
import com.viaversion.viaversion.ViaManagerImpl import com.viaversion.viaversion.ViaManagerImpl
import com.viaversion.viaversion.api.Via import com.viaversion.viaversion.api.Via
import com.viaversion.viaversion.api.command.ViaCommandSender import com.viaversion.viaversion.api.command.ViaCommandSender
import com.viaversion.viaversion.api.connection.UserConnection
import com.viaversion.viaversion.api.platform.PlatformTask import com.viaversion.viaversion.api.platform.PlatformTask
import com.viaversion.viaversion.api.platform.ViaPlatform import com.viaversion.viaversion.api.platform.ViaPlatform
import com.viaversion.viaversion.libs.gson.JsonObject import com.viaversion.viaversion.libs.gson.JsonObject
@ -19,7 +20,7 @@ import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import java.util.logging.Logger import java.util.logging.Logger
object AspirinPlatform : ViaPlatform<UUID> { object AspirinPlatform : ViaPlatform<UserConnection> {
private lateinit var conf: AspirinViaConfig private lateinit var conf: AspirinViaConfig
val executor = Executors.newCachedThreadPool( val executor = Executors.newCachedThreadPool(
ThreadFactoryBuilder() ThreadFactoryBuilder()

View File

@ -1,9 +1,10 @@
package com.viaversion.aas.web package com.viaversion.aas.web
import com.google.common.net.HostAndPort import com.google.common.net.HostAndPort
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
data class AddressInfo( data class AddressInfo(
val backVersion: Int, val backVersion: ProtocolVersion,
val backHostAndPort: HostAndPort, val backHostAndPort: HostAndPort,
var frontOnline: Boolean? = null, var frontOnline: Boolean? = null,
var backName: String? = null var backName: String? = null

View File

@ -148,12 +148,15 @@ class WebLogin : WebState {
webClient.server.addressCallbacks[callback].complete( webClient.server.addressCallbacks[callback].complete(
AddressInfo( AddressInfo(
backVersion = obj["version"].asString.let { backVersion = obj["version"].asString.let {
var protocol = Ints.tryParse(it) var protocol: ProtocolVersion? = null
if (protocol == null) { val output = Ints.tryParse(it)
if (output == null) {
val ver = ProtocolVersion.getClosest(it) val ver = ProtocolVersion.getClosest(it)
if (ver != null) protocol = ver.version if (ver != null) protocol = ver
} else {
protocol = ProtocolVersion.getProtocol(output)
} }
protocol ?: -2 protocol ?: AUTO
}, },
backHostAndPort = HostAndPort.fromParts(obj["host"].asString, obj["port"].asInt), backHostAndPort = HostAndPort.fromParts(obj["host"].asString, obj["port"].asInt),
frontOnline = obj["frontOnline"].asString.toBooleanStrictOrNull(), frontOnline = obj["frontOnline"].asString.toBooleanStrictOrNull(),