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("reflect"))
val vvVer = "4.10.0-24w04a-SNAPSHOT"
val vbVer = "4.10.0-24w04a-SNAPSHOT"
val vvVer = "4.10.0-24w07a-SNAPSHOT"
val vbVer = "4.10.0-24w07a-SNAPSHOT"
val vrVer = "3.0.6-SNAPSHOT"
implementation("com.viaversion:viaversion:$vvVer") { 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.util.StacklessException;
import com.viaversion.viaversion.api.protocol.packet.Direction;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.exception.CancelEncoderException;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
@ -43,7 +44,7 @@ public class MinecraftCodec extends MessageToMessageCodec<ByteBuf, Packet> {
var handler = ctx.pipeline().get(MinecraftHandler.class);
var frontVer = handler.getData().getFrontVer();
if (frontVer == null) {
frontVer = 0;
frontVer = ProtocolVersion.unknown;
}
out.add(PacketRegistry.INSTANCE.decode(
msg,

View File

@ -1,5 +1,6 @@
package com.viaversion.aas.codec.packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
@ -9,7 +10,7 @@ import org.jetbrains.annotations.NotNull;
* A mutable object which represents a Minecraft packet data
*/
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;
import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
@ -17,12 +18,12 @@ public class AbstractCompression implements Packet {
}
@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);
}
@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);
}
}

View File

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

View File

@ -36,8 +36,8 @@ public class AbstractSingleChat implements Packet {
return null;
}
public void setMsgForVersion(JsonElement msg, int protocolVersion) {
if (protocolVersion >= ProtocolVersion.v1_20_3.getVersion()) {
public void setMsgForVersion(JsonElement msg, ProtocolVersion protocolVersion) {
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_20_3)) {
this.msgTag = ComponentUtil.jsonToTag(com.viaversion.viaversion.libs.gson.JsonParser.parseString(msg.toString()));
} else {
this.msg = msg;
@ -45,8 +45,8 @@ public class AbstractSingleChat implements Packet {
}
@Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception {
if (protocolVersion < ProtocolVersion.v1_20_3.getVersion()) {
public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
if (protocolVersion.olderThan(ProtocolVersion.v1_20_3)) {
msg = JsonParser.parseString(Type.STRING.read(byteBuf));
} else {
msgTag = Type.TAG.read(byteBuf);
@ -54,8 +54,8 @@ public class AbstractSingleChat implements Packet {
}
@Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception {
if (protocolVersion < ProtocolVersion.v1_20_3.getVersion()) {
public void encode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
if (protocolVersion.olderThan(ProtocolVersion.v1_20_3)) {
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.JsonParser;
import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
@ -19,12 +20,12 @@ public class AbstractSingleJson implements Packet {
}
@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));
}
@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());
}
}

View File

@ -1,6 +1,7 @@
package com.viaversion.aas.codec.packet.configuration;
import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
@ -8,12 +9,12 @@ public class ConfigurationKeepAlive implements Packet {
private long id;
@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();
}
@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);
}

View File

@ -2,6 +2,7 @@ package com.viaversion.aas.codec.packet.configuration;
import com.viaversion.aas.UtilKt;
import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
@ -11,13 +12,13 @@ public class ConfigurationPluginMessage implements Packet {
private byte[] data;
@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);
data = UtilKt.readRemainingBytes(byteBuf);
}
@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.REMAINING_BYTES.write(byteBuf, data);
}

View File

@ -1,15 +1,16 @@
package com.viaversion.aas.codec.packet.configuration;
import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
public class FinishConfig implements Packet {
@Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception {
public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
}
@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.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
@ -13,7 +14,7 @@ public class Handshake implements Packet {
private State nextState;
@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);
address = Type.STRING.read(byteBuf);
port = byteBuf.readUnsignedShort();
@ -21,7 +22,7 @@ public class Handshake implements Packet {
}
@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.STRING.write(byteBuf, address);
byteBuf.writeShort(port);

View File

@ -18,10 +18,10 @@ public class CryptoRequest implements Packet {
private byte[] nonce;
@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);
if (protocolVersion >= ProtocolVersion.v1_8.getVersion()
|| protocolVersion == AspirinProtocolsKt.getSharewareVersion().getVersion()) {
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_8)
|| protocolVersion.equalTo(AspirinProtocolsKt.getSharewareVersion())) {
publicKey = KeyFactory.getInstance("RSA")
.generatePublic(new X509EncodedKeySpec(Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf)));
nonce = Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf);
@ -33,11 +33,11 @@ public class CryptoRequest implements Packet {
}
@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);
if (protocolVersion >= ProtocolVersion.v1_8.getVersion()
|| protocolVersion == AspirinProtocolsKt.getSharewareVersion().getVersion()) {
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_8)
|| protocolVersion.equalTo(AspirinProtocolsKt.getSharewareVersion())) {
Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, publicKey.getEncoded());
Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, nonce);
} else {

View File

@ -40,30 +40,30 @@ public class LoginStart implements Packet {
}
@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);
if (protocolVersion >= ProtocolVersion.v1_19.getVersion()
&& protocolVersion < ProtocolVersion.v1_19_3.getVersion()) {
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19)
&& protocolVersion.olderThan(ProtocolVersion.v1_19_3)) {
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);
} else if (protocolVersion >= ProtocolVersion.v1_19_1.getVersion()) {
} else if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19_1)) {
profileId = Type.OPTIONAL_UUID.read(byteBuf);
}
}
@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);
if (protocolVersion >= ProtocolVersion.v1_19.getVersion()
&& protocolVersion < ProtocolVersion.v1_19_3.getVersion()) {
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19)
&& protocolVersion.olderThan(ProtocolVersion.v1_19_3)) {
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);
} else if (protocolVersion >= ProtocolVersion.v1_19_1.getVersion()) {
} else if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19_1)) {
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.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
@ -12,14 +13,14 @@ public class PluginRequest implements Packet {
private byte[] data;
@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);
channel = Type.STRING.read(byteBuf);
data = UtilKt.readRemainingBytes(byteBuf);
}
@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.STRING.write(byteBuf, channel);
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.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
@ -12,7 +13,7 @@ public class PluginResponse implements Packet {
private byte[] data;
@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);
success = byteBuf.readBoolean();
if (success) {
@ -21,7 +22,7 @@ public class PluginResponse implements Packet {
}
@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);
byteBuf.writeBoolean(success);
if (success) {

View File

@ -1,15 +1,16 @@
package com.viaversion.aas.codec.packet.play;
import com.viaversion.aas.codec.packet.Packet;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
public class ConfigurationAck implements Packet {
@Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception {
public void decode(@NotNull ByteBuf byteBuf, ProtocolVersion protocolVersion) throws Exception {
}
@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;
@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);
if (protocolVersion <= ProtocolVersion.v1_7_6.getVersion()) {
if (protocolVersion.olderThanOrEqualTo(ProtocolVersion.v1_7_6)) {
data = UtilKt.readByteArray(byteBuf, readExtendedForgeShort(byteBuf));
} else {
data = UtilKt.readRemainingBytes(byteBuf);
@ -22,9 +22,9 @@ public class PluginMessage implements Packet {
}
@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);
if (protocolVersion <= ProtocolVersion.v1_7_6.getVersion()) {
if (protocolVersion.olderThanOrEqualTo(ProtocolVersion.v1_7_6)) {
writeExtendedForgeShort(byteBuf, data.length);
}
byteBuf.writeBytes(data);

View File

@ -44,7 +44,7 @@ public class ServerboundChatCommand implements Packet {
}
@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);
timestamp = 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));
}
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);
lastReceivedMessage = Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE.read(byteBuf);
}
}
@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);
byteBuf.writeLong(timestamp);
byteBuf.writeLong(salt);
@ -70,7 +70,7 @@ public class ServerboundChatCommand implements Packet {
Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, signature.getSignature());
}
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.OPTIONAL_PLAYER_MESSAGE_SIGNATURE.write(byteBuf, lastReceivedMessage);
}

View File

@ -17,26 +17,26 @@ public class ServerboundChatMessage implements Packet {
private PlayerMessageSignature lastReceivedMessage;
@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);
timestamp = byteBuf.readLong();
salt = byteBuf.readLong();
signature = Type.BYTE_ARRAY_PRIMITIVE.read(byteBuf);
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);
lastReceivedMessage = Type.OPTIONAL_PLAYER_MESSAGE_SIGNATURE.read(byteBuf);
}
}
@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);
byteBuf.writeLong(timestamp);
byteBuf.writeLong(salt);
Type.BYTE_ARRAY_PRIMITIVE.write(byteBuf, signature);
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.OPTIONAL_PLAYER_MESSAGE_SIGNATURE.write(byteBuf, lastReceivedMessage);
}

View File

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

View File

@ -2,11 +2,12 @@ package com.viaversion.aas.provider;
import com.viaversion.aas.handler.MinecraftHandler;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import com.viaversion.viaversion.protocols.base.BaseVersionProvider;
public class AspirinVersionProvider extends BaseVersionProvider {
@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();
if (ver != null) return ver;
return super.getClosestServerProtocol(connection);

View File

@ -9,7 +9,7 @@ import java.util.*;
import java.util.regex.Pattern;
public class AddressParser {
public Integer protocol;
public ProtocolVersion protocol;
public String viaSuffix;
public String serverAddress;
public String viaOptions;
@ -113,10 +113,11 @@ public class AddressParser {
}
public void parseProtocol(String arg) {
protocol = Ints.tryParse(arg);
if (protocol == null) {
ProtocolVersion ver = ProtocolVersion.getClosest(arg.replace("_", "."));
if (ver != null) protocol = ver.getVersion();
final Integer protocolId = Ints.tryParse(arg);
if (protocolId == null) {
protocol = ProtocolVersion.getClosest(arg.replace("_", "."));
} 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
}
fun Int.parseProtocol() = ProtocolVersion.getProtocol(this)
fun sha512Hex(data: ByteArray): String {
return MessageDigest.getInstance("SHA-512").digest(data)
.asUByteArray()

View File

@ -11,6 +11,7 @@ import com.viaversion.aas.protocol.registerAspirinProtocols
import com.viaversion.aas.web.ViaWebApp
import com.viaversion.viaversion.api.Via
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
import com.viaversion.viaversion.api.protocol.version.VersionType
import io.ktor.server.application.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
@ -55,7 +56,7 @@ private fun printSplash() {
println("VIAaaS ${AspirinServer.version}")
}
val autoProtocolId = -2
val AUTO = ProtocolVersion(VersionType.SPECIAL, -2, -1, "AUTO", null)
private fun initVia() {
AspirinPlatform.initVia {
@ -66,7 +67,7 @@ private fun initVia() {
Via.getManager().configurationProvider.register(VIAaaSConfig)
}
ProtocolVersion.register(autoProtocolId, "AUTO")
ProtocolVersion.register(AUTO)
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.handshake.Handshake
import com.viaversion.aas.codec.packet.login.*
import com.viaversion.aas.codec.packet.play.ConfigurationAck
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.play.*
import com.viaversion.aas.codec.packet.status.StatusPing
import com.viaversion.aas.codec.packet.status.StatusPong
import com.viaversion.aas.codec.packet.status.StatusRequest
@ -49,10 +44,10 @@ import java.util.function.Supplier
object PacketRegistry {
// 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
val entriesEncoding = hashMapOf<Pair<Direction, Class<out Packet>>, RangeMap<Int, EncodingInfo>>()
private val entriesEncoding = hashMapOf<Pair<Direction, Class<out Packet>>, RangeMap<ProtocolVersion, EncodingInfo>>()
init {
// 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, ::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.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, ::SetCompression, mapOf(
Range.atLeast(ProtocolVersion.v1_8.version) to 3,
Range.atLeast(ProtocolVersion.v1_8) to 3,
sharewareVersion.singleton to 3
)
)
register(
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
)
)
@ -94,7 +89,7 @@ object PacketRegistry {
register(
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_13..ProtocolVersion.v1_13_2 to ClientboundPackets1_13.DISCONNECT.id,
ProtocolVersion.v1_14..ProtocolVersion.v1_14_4 to ClientboundPackets1_14.DISCONNECT.id,
@ -112,7 +107,7 @@ object PacketRegistry {
)
register(
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_13..ProtocolVersion.v1_13_2 to ClientboundPackets1_13.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> {
return Range.closed(this.originalVersion, o.originalVersion)
operator fun ProtocolVersion.rangeTo(o: ProtocolVersion): Range<ProtocolVersion> {
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,
direction: Direction,
constructor: Supplier<P>,
idByProtocol: Map<Range<Int>, Int>,
idByProtocol: Map<Range<ProtocolVersion>, Int>,
klass: Class<P> = P::class.java,
) {
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) }
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,
direction: Direction,
constructor: Supplier<P>,
protocol: Range<Int>,
protocol: Range<ProtocolVersion>,
id: Int
) {
register(constructor = constructor, direction = direction, state = state, idByProtocol = mapOf(protocol to id))
@ -202,7 +197,7 @@ object PacketRegistry {
data class EncodingInfo(val packetId: Int)
private fun getPacketConstructor(
protocolVersion: Int,
protocolVersion: ProtocolVersion,
state: State,
id: Int,
direction: Direction
@ -210,11 +205,11 @@ object PacketRegistry {
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
}
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 packet = getPacketConstructor(protocolVersion, state, packetId, direction)?.get()
?: 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) {
packet.id
} else {

View File

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

View File

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

View File

@ -13,36 +13,36 @@ import java.util.*
class LoginSuccess : Packet {
lateinit var id: UUID
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 {
protocolVersion >= ProtocolVersion.v1_16.version -> {
protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_16) -> {
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))
}
else -> parseUndashedId(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())
}
}
override fun encode(byteBuf: ByteBuf, protocolVersion: Int) {
override fun encode(byteBuf: ByteBuf, protocolVersion: ProtocolVersion) {
when {
protocolVersion >= ProtocolVersion.v1_16.version -> {
protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_16) -> {
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())
}
else -> Type.STRING.write(byteBuf, id.toString().replace("-", ""))
}
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())
}
}

View File

@ -1,7 +1,6 @@
package com.viaversion.aas.command.sub
import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.parseProtocol
import com.viaversion.viaversion.api.Via
import com.viaversion.viaversion.api.command.ViaCommandSender
import com.viaversion.viaversion.api.command.ViaSubCommand
@ -14,9 +13,9 @@ object ConnectionsSubCommand : ViaSubCommand() {
Via.getManager().connectionManager.connections.forEach {
val handler = it.channel?.pipeline()?.get(MinecraftHandler::class.java)
val backAddr = handler?.endRemoteAddress
val pVer = it.protocolInfo?.protocolVersion?.parseProtocol()
val pVer = it.protocolInfo?.protocolVersion()
val backName = it.protocolInfo?.username
val backVer = it.protocolInfo?.serverProtocolVersion?.parseProtocol()
val backVer = it.protocolInfo?.serverProtocolVersion()
val pAddr = handler?.data?.frontHandler?.endRemoteAddress
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() {
reloadIcon()
defaultParameters = this.get("default-parameters", Map::class.java, emptyMap<Int, String>())!!.map {
(it.key as Number).toInt() to AddressParser().parse(it.value.toString())
defaultParameters = this.get("default-parameters", emptyMap<Int, String>())!!.map {
(it.key as Number).toInt() to AddressParser().parse(it.value)
}.toMap()
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)
requireHostName = this.getBoolean("require-host-name", true)
defaultBackendPort = this.getInt("default-backend-port", 25565).let { if (it == -1) null else it }
blockedBackAddresses = this.get(
"blocked-back-addresses",
List::class.java,
emptyList<String>()
)!!.map { it.toString() }
allowedBackAddresses = this.get(
"allowed-back-addresses",
List::class.java,
emptyList<String>()
)!!.map { it.toString() }
blockedBackAddresses = this.get("blocked-back-addresses", emptyList())!!
allowedBackAddresses = this.get("allowed-back-addresses", emptyList())!!
forceOnlineMode = this.getBoolean("force-online-mode", false)
showVersionPing = this.getBoolean("show-version-ping", 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)
}
fun reloadIcon() {
private fun reloadIcon() {
val rawUrl = this.getString("favicon-url", "")!!
try {
faviconUrl = when {

View File

@ -14,13 +14,13 @@ import java.net.InetSocketAddress
import java.net.URI
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>() {
override fun initChannel(ch: Channel) {
val user = UserConnectionImpl(ch, true)
val pipeline = ProtocolPipelineImpl(user)
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) {
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.handler.state.ConnectionState
import com.viaversion.aas.handler.state.HandshakeState
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
import io.netty.channel.Channel
class ConnectionData(
val frontChannel: Channel,
var backChannel: Channel? = null,
var state: ConnectionState = HandshakeState(),
var frontVer: Int? = null,
var backServerVer: Int? = null,
var frontVer: ProtocolVersion? = null,
var backServerVer: ProtocolVersion? = null,
var autoDetectProtocol: Boolean = false
) {
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)
}
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?) {
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.state.ConnectionState
import com.viaversion.aas.mcLogger
import com.viaversion.aas.parseProtocol
import com.viaversion.aas.util.StacklessException
import com.viaversion.viaversion.api.protocol.packet.State
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
import io.netty.channel.ChannelHandlerContext
import java.util.concurrent.CompletableFuture
class ProtocolDetectionState(val future: CompletableFuture<ProtocolVersion>) : ConnectionState {
class ProtocolDetectionState(private val future: CompletableFuture<ProtocolVersion>) : ConnectionState {
override val state: State
get() = State.STATUS
override fun handlePacket(handler: MinecraftHandler, ctx: ChannelHandlerContext, packet: Packet) {
handler.data.frontChannel.close()
if (packet !is StatusResponse) throw StacklessException("Unexpected packet")
val ver = packet.msg.asJsonObject
.getAsJsonObject("version")["protocol"].asInt.parseProtocol()
val ver = ProtocolVersion.getProtocol(packet.msg.asJsonObject.getAsJsonObject("version")["protocol"].asInt)
future.complete(ver)
mcLogger.info("A.D.: {} {}", handler.endRemoteAddress, ver)
}

View File

@ -49,7 +49,7 @@ object ProtocolDetector {
.option(ChannelOption.IP_TOS, 0x18)
.handler(object : ChannelInitializer<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) }
.addLast("timeout", ReadTimeoutHandler(30, TimeUnit.SECONDS))
.addLast("frame", FrameCodec())

View File

@ -62,7 +62,7 @@ private suspend fun createBackChannel(
val packet = Handshake()
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.port = socketAddr.port
@ -88,7 +88,7 @@ private suspend fun autoDetectVersion(handler: MinecraftHandler, socketAddr: Ine
handler.data.backServerVer = if (detectedProtocol != null
&& detectedProtocol.version !in arrayOf(-1, -2)
&& 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.net.HostAndPort
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.handshake.Handshake
import com.viaversion.aas.config.VIAaaSConfig
import com.viaversion.aas.handler.MinecraftHandler
import com.viaversion.aas.autoProtocolId
import com.viaversion.aas.mcLogger
import com.viaversion.aas.util.AddressParser
import com.viaversion.aas.util.StacklessException
import com.viaversion.viaversion.api.protocol.packet.State
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
import io.netty.channel.ChannelHandlerContext
import java.net.InetAddress
import java.net.InetSocketAddress
@ -47,7 +48,7 @@ class HandshakeState : ConnectionState {
}
private fun handleNextState(handler: MinecraftHandler, packet: Handshake) {
handler.data.frontVer = packet.protocolId
handler.data.frontVer = ProtocolVersion.getProtocol(packet.protocolId)
when (packet.nextState.ordinal) {
1 -> handler.data.state = StatusState()
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 port = parsed.port ?: VIAaaSConfig.defaultBackendPort ?: virtualPort
@ -84,7 +85,7 @@ class HandshakeState : ConnectionState {
val addressFromWeb = VIAaaSConfig.hostName.any { parsed.serverAddress.equals(it, ignoreCase = true) }
handler.data.backServerVer = backProto
if (backProto == autoProtocolId) handler.data.autoDetectProtocol = true
if (backProto == AUTO) handler.data.autoDetectProtocol = true
(handler.data.state as? LoginState)?.also {
it.frontOnline = frontOnline
it.backName = parsed.username

View File

@ -84,14 +84,14 @@ class LoginState : ConnectionState {
}
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
val threshold = 256
forward(handler, SetCompression().also { it.threshold = threshold })
setCompression(handler.data.frontChannel, threshold)
}
handler.data.state = when {
handler.data.frontVer!! >= ProtocolVersion.v1_20_2.version -> ConfigurationState()
handler.data.frontVer!!.newerThanOrEqualTo(ProtocolVersion.v1_20_2) -> ConfigurationState()
else -> PlayState()
}
forward(handler, loginSuccess)
@ -122,7 +122,7 @@ class LoginState : ConnectionState {
fun reauthMessage(handler: MinecraftHandler, backName: String, backHash: String): CompletableFuture<Boolean> {
if (!handler.data.frontEncrypted
|| !frontName.equals(backName, ignoreCase = true)
|| handler.data.frontVer!! < ProtocolVersion.v1_8.version
|| handler.data.frontVer!!.olderThan(ProtocolVersion.v1_8)
) {
callbackReauth.complete(false)
return callbackReauth
@ -140,7 +140,7 @@ class LoginState : ConnectionState {
}
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 ->
send(handler.data.frontChannel, SetCompression().also { it.threshold = entry })
}
@ -269,7 +269,7 @@ class LoginState : ConnectionState {
val info = AspirinServer.viaWebServer.requestAddressInfo(frontName).await()
backAddress = info.backHostAndPort
handler.data.backServerVer = info.backVersion
if (info.backVersion == autoProtocolId) handler.data.autoDetectProtocol = true
if (info.backVersion == AUTO) handler.data.autoDetectProtocol = true
frontOnline = info.frontOnline
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.handler.*
import com.viaversion.aas.mcLogger
import com.viaversion.aas.parseProtocol
import com.viaversion.aas.util.StacklessException
import com.viaversion.aas.writeFlushClose
import com.viaversion.viaversion.api.protocol.packet.State
@ -74,7 +73,7 @@ class PlayState : ConnectionState {
pluginMessage.data,
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))
}

View File

@ -39,7 +39,7 @@ class StatusState : ConnectionState {
it.addProperty("id", UUID.nameUUIDFromBytes("VIAaaS".toByteArray(Charsets.UTF_8)).toString())
it.addProperty(
"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 {
it.add("version", JsonObject().also {
it.addProperty("name", "VIAaaS")
it.addProperty("protocol", handler.data.frontVer)
it.addProperty("protocol", handler.data.frontVer!!.version)
})
it.add("players", JsonObject().also {
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.api.Via
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.ViaPlatform
import com.viaversion.viaversion.libs.gson.JsonObject
@ -19,7 +20,7 @@ import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import java.util.logging.Logger
object AspirinPlatform : ViaPlatform<UUID> {
object AspirinPlatform : ViaPlatform<UserConnection> {
private lateinit var conf: AspirinViaConfig
val executor = Executors.newCachedThreadPool(
ThreadFactoryBuilder()

View File

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

View File

@ -148,12 +148,15 @@ class WebLogin : WebState {
webClient.server.addressCallbacks[callback].complete(
AddressInfo(
backVersion = obj["version"].asString.let {
var protocol = Ints.tryParse(it)
if (protocol == null) {
var protocol: ProtocolVersion? = null
val output = Ints.tryParse(it)
if (output == null) {
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),
frontOnline = obj["frontOnline"].asString.toBooleanStrictOrNull(),