update to 1.20.3/4

This commit is contained in:
creeper123123321 2023-12-15 17:49:01 -03:00
parent 937daf986d
commit 2ea6406db5
8 changed files with 113 additions and 20 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.9.2" val vvVer = "4.9.3-SNAPSHOT"
val vbVer = "4.9.1" val vbVer = "4.9.2-SNAPSHOT"
val vrVer = "3.0.5" val vrVer = "3.0.5"
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

@ -0,0 +1,64 @@
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 com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.util.ComponentConverter;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
public class AbstractSingleChat implements Packet {
private JsonElement msg;
private Tag msgTag;
public JsonElement getMsg() {
return msg;
}
public void setMsg(JsonElement msg) {
this.msg = msg;
}
public Tag getMsgTag() {
return msgTag;
}
public void setMsgTag(Tag msgTag) {
this.msgTag = msgTag;
}
public JsonElement getMsgAsJson() {
if (msg != null) return msg;
if (msgTag != null) return JsonParser.parseString(ComponentConverter.tagComponentToJson(this.msgTag).toString());
return null;
}
public void setMsgForVersion(JsonElement msg, int protocolVersion) {
if (protocolVersion >= ProtocolVersion.v1_20_3.getVersion()) {
this.msgTag = ComponentConverter.jsonComponentToTag(com.viaversion.viaversion.libs.gson.JsonParser.parseString(msg.toString()));
} else {
this.msg = msg;
}
}
@Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception {
if (protocolVersion < ProtocolVersion.v1_20_3.getVersion()) {
msg = JsonParser.parseString(Type.STRING.read(byteBuf));
} else {
msgTag = Type.TAG.read(byteBuf);
}
}
@Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception {
if (protocolVersion < ProtocolVersion.v1_20_3.getVersion()) {
Type.STRING.write(byteBuf, msg.toString());
}
}
}

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.codec.packet.configuration; package com.viaversion.aas.codec.packet.configuration;
import com.viaversion.aas.codec.packet.common.AbstractSingleJson; import com.viaversion.aas.codec.packet.common.AbstractSingleChat;
public class ConfigurationDisconnect extends AbstractSingleJson { public class ConfigurationDisconnect extends AbstractSingleChat {
} }

View File

@ -0,0 +1,27 @@
package com.viaversion.aas.codec.packet.configuration;
import com.viaversion.aas.codec.packet.Packet;
import io.netty.buffer.ByteBuf;
import org.jetbrains.annotations.NotNull;
public class ConfigurationKeepAlive implements Packet {
private long id;
@Override
public void decode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception {
this.id = byteBuf.readLong();
}
@Override
public void encode(@NotNull ByteBuf byteBuf, int protocolVersion) throws Exception {
byteBuf.writeLong(this.id);
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}

View File

@ -1,6 +1,6 @@
package com.viaversion.aas.codec.packet.play; package com.viaversion.aas.codec.packet.play;
import com.viaversion.aas.codec.packet.common.AbstractSingleJson; import com.viaversion.aas.codec.packet.common.AbstractSingleChat;
public class Kick extends AbstractSingleJson { public class Kick extends AbstractSingleChat {
} }

View File

@ -32,7 +32,7 @@ public class ConfigurationState implements ConnectionState {
UtilKt.getMcLogger().debug( UtilKt.getMcLogger().debug(
"{} disconnected on config: {}", "{} disconnected on config: {}",
handler.endRemoteAddress.toString(), handler.endRemoteAddress.toString(),
packet.getMsg() packet.getMsgAsJson()
); );
} }
@ -54,7 +54,7 @@ public class ConfigurationState implements ConnectionState {
public void disconnect(@NotNull MinecraftHandler handler, @NotNull String msg) { public void disconnect(@NotNull MinecraftHandler handler, @NotNull String msg) {
ConnectionState.DefaultImpls.disconnect(this, handler, msg); ConnectionState.DefaultImpls.disconnect(this, handler, msg);
var packet = new ConfigurationDisconnect(); var packet = new ConfigurationDisconnect();
packet.setMsg(new JsonPrimitive("[VIAaaS] §c$msg")); packet.setMsgForVersion(new JsonPrimitive("[VIAaaS] §c$msg"), handler.getData().getFrontVer());
UtilKt.writeFlushClose(handler.getData().getFrontChannel(), packet, false); UtilKt.writeFlushClose(handler.getData().getFrontChannel(), packet, false);
} }

View File

@ -4,6 +4,7 @@ import com.google.common.collect.Range
import com.google.common.collect.RangeMap import com.google.common.collect.RangeMap
import com.google.common.collect.TreeRangeMap import com.google.common.collect.TreeRangeMap
import com.viaversion.aas.codec.packet.configuration.ConfigurationDisconnect import com.viaversion.aas.codec.packet.configuration.ConfigurationDisconnect
import com.viaversion.aas.codec.packet.configuration.ConfigurationKeepAlive
import com.viaversion.aas.codec.packet.configuration.ConfigurationPluginMessage 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
@ -86,8 +87,10 @@ object PacketRegistry {
register(State.CONFIGURATION, Direction.CLIENTBOUND, ::ConfigurationPluginMessage, Range.all(), 0) register(State.CONFIGURATION, Direction.CLIENTBOUND, ::ConfigurationPluginMessage, Range.all(), 0)
register(State.CONFIGURATION, Direction.CLIENTBOUND, ::ConfigurationDisconnect, Range.all(), 1) register(State.CONFIGURATION, Direction.CLIENTBOUND, ::ConfigurationDisconnect, Range.all(), 1)
register(State.CONFIGURATION, Direction.CLIENTBOUND, ::FinishConfig, Range.all(), 2) register(State.CONFIGURATION, Direction.CLIENTBOUND, ::FinishConfig, Range.all(), 2)
register(State.CONFIGURATION, Direction.CLIENTBOUND, ::ConfigurationKeepAlive, Range.all(), 3)
register(State.CONFIGURATION, Direction.SERVERBOUND, ::ConfigurationPluginMessage, Range.all(), 1) register(State.CONFIGURATION, Direction.SERVERBOUND, ::ConfigurationPluginMessage, Range.all(), 1)
register(State.CONFIGURATION, Direction.SERVERBOUND, ::FinishConfig, Range.all(), 2) register(State.CONFIGURATION, Direction.SERVERBOUND, ::FinishConfig, Range.all(), 2)
register(State.CONFIGURATION, Direction.SERVERBOUND, ::ConfigurationKeepAlive, Range.all(), 3)
register( register(
State.PLAY, Direction.CLIENTBOUND, ::Kick, mapOf( State.PLAY, Direction.CLIENTBOUND, ::Kick, mapOf(
@ -104,7 +107,7 @@ object PacketRegistry {
ProtocolVersion.v1_19_1.singleton to ClientboundPackets1_19_1.DISCONNECT.id, ProtocolVersion.v1_19_1.singleton to ClientboundPackets1_19_1.DISCONNECT.id,
ProtocolVersion.v1_19_3.singleton to ClientboundPackets1_19_3.DISCONNECT.id, ProtocolVersion.v1_19_3.singleton to ClientboundPackets1_19_3.DISCONNECT.id,
ProtocolVersion.v1_19_4..ProtocolVersion.v1_20 to ClientboundPackets1_19_4.DISCONNECT.id, ProtocolVersion.v1_19_4..ProtocolVersion.v1_20 to ClientboundPackets1_19_4.DISCONNECT.id,
ProtocolVersion.v1_20_2.singleton to ClientboundPackets1_20_2.DISCONNECT.id ProtocolVersion.v1_20_2..ProtocolVersion.v1_20_3 to ClientboundPackets1_20_2.DISCONNECT.id
) )
) )
register( register(
@ -122,19 +125,18 @@ object PacketRegistry {
ProtocolVersion.v1_19_1.singleton to ClientboundPackets1_19_1.PLUGIN_MESSAGE.id, ProtocolVersion.v1_19_1.singleton to ClientboundPackets1_19_1.PLUGIN_MESSAGE.id,
ProtocolVersion.v1_19_3.singleton to ClientboundPackets1_19_3.PLUGIN_MESSAGE.id, ProtocolVersion.v1_19_3.singleton to ClientboundPackets1_19_3.PLUGIN_MESSAGE.id,
ProtocolVersion.v1_19_4..ProtocolVersion.v1_20 to ClientboundPackets1_19_4.PLUGIN_MESSAGE.id, ProtocolVersion.v1_19_4..ProtocolVersion.v1_20 to ClientboundPackets1_19_4.PLUGIN_MESSAGE.id,
ProtocolVersion.v1_20_2.singleton to ClientboundPackets1_20_2.PLUGIN_MESSAGE.id ProtocolVersion.v1_20_2..ProtocolVersion.v1_20_3 to ClientboundPackets1_20_2.PLUGIN_MESSAGE.id
) )
) )
register( register(
State.PLAY, State.PLAY, Direction.CLIENTBOUND, ::SetPlayCompression,
Direction.CLIENTBOUND, ProtocolVersion.v1_8.singleton, ClientboundPackets1_8.SET_COMPRESSION.id
::SetPlayCompression, )
ProtocolVersion.v1_8.singleton, register(
ClientboundPackets1_8.SET_COMPRESSION.id State.PLAY, Direction.SERVERBOUND, ::ConfigurationAck, mapOf(
ProtocolVersion.v1_20_2..ProtocolVersion.v1_20_3 to ServerboundPackets1_20_2.CONFIGURATION_ACKNOWLEDGED.id
)
) )
register(State.PLAY, Direction.SERVERBOUND, ::ConfigurationAck, mapOf(
ProtocolVersion.v1_20_2.singleton to ServerboundPackets1_20_2.CONFIGURATION_ACKNOWLEDGED.id
))
// todo update this to latest version // todo update this to latest version
register( register(
State.PLAY, Direction.SERVERBOUND, ::ServerboundChatCommand, State.PLAY, Direction.SERVERBOUND, ::ServerboundChatCommand,

View File

@ -48,7 +48,7 @@ class PlayState : ConnectionState {
mcLogger.debug( mcLogger.debug(
"{} disconnected on play: {}", "{} disconnected on play: {}",
handler.endRemoteAddress.toString(), handler.endRemoteAddress.toString(),
packet.msg packet.msgAsJson
) )
} }
@ -98,7 +98,7 @@ class PlayState : ConnectionState {
super.disconnect(handler, msg) super.disconnect(handler, msg)
writeFlushClose( writeFlushClose(
handler.data.frontChannel, handler.data.frontChannel,
Kick().also { it.msg = JsonPrimitive("[VIAaaS] §c$msg") }, Kick().also { it.setMsgForVersion(JsonPrimitive("[VIAaaS] §c$msg"), handler.data.frontVer!!) },
delay = is17(handler) delay = is17(handler)
) )
} }