Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-11-20 06:50:10 +01:00
Ursprung
0912e33358
Commit
65158455cc
@ -119,6 +119,14 @@ public final class Protocol1_20_2To1_20_3 extends BackwardsProtocol<ClientboundP
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
registerClientbound(ClientboundPackets1_20_2.BOSSBAR, wrapper -> {
|
||||||
|
wrapper.passthrough(Type.UUID); // Id
|
||||||
|
|
||||||
|
final int action = wrapper.passthrough(Type.VAR_INT);
|
||||||
|
if (action == 0 || action == 3) {
|
||||||
|
convertComponent(wrapper);
|
||||||
|
}
|
||||||
|
});
|
||||||
registerClientbound(ClientboundPackets1_20_2.PLAYER_CHAT, wrapper -> {
|
registerClientbound(ClientboundPackets1_20_2.PLAYER_CHAT, wrapper -> {
|
||||||
wrapper.passthrough(Type.UUID); // Sender
|
wrapper.passthrough(Type.UUID); // Sender
|
||||||
wrapper.passthrough(Type.VAR_INT); // Index
|
wrapper.passthrough(Type.VAR_INT); // Index
|
||||||
|
@ -111,9 +111,26 @@ public final class Protocol1_20To1_20_2 extends BackwardsProtocol<ClientboundPac
|
|||||||
cancelClientbound(ClientboundPackets1_20_2.PONG_RESPONSE);
|
cancelClientbound(ClientboundPackets1_20_2.PONG_RESPONSE);
|
||||||
|
|
||||||
// Some can be directly remapped to play packets, others need to be queued
|
// Some can be directly remapped to play packets, others need to be queued
|
||||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.DISCONNECT.getId(), ClientboundPackets1_19_4.DISCONNECT.getId());
|
// Set the packet type properly so the state on it is changed
|
||||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.KEEP_ALIVE.getId(), ClientboundPackets1_19_4.KEEP_ALIVE.getId());
|
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.DISCONNECT.getId(), -1, wrapper -> {
|
||||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.RESOURCE_PACK.getId(), ClientboundPackets1_19_4.RESOURCE_PACK.getId());
|
wrapper.setPacketType(ClientboundPackets1_19_4.DISCONNECT);
|
||||||
|
});
|
||||||
|
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.KEEP_ALIVE.getId(), -1, wrapper -> {
|
||||||
|
wrapper.setPacketType(ClientboundPackets1_19_4.KEEP_ALIVE);
|
||||||
|
});
|
||||||
|
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.RESOURCE_PACK.getId(), -1, wrapper -> {
|
||||||
|
// Send after join. We have to pretend the client accepted, else the server won't continue...
|
||||||
|
wrapper.user().get(ConfigurationPacketStorage.class).setResourcePack(wrapper);
|
||||||
|
wrapper.cancel();
|
||||||
|
|
||||||
|
final PacketWrapper acceptedResponse = wrapper.create(ServerboundConfigurationPackets1_20_2.RESOURCE_PACK);
|
||||||
|
acceptedResponse.write(Type.VAR_INT, 3);
|
||||||
|
acceptedResponse.sendToServer(Protocol1_20To1_20_2.class);
|
||||||
|
|
||||||
|
final PacketWrapper downloadedResponse = wrapper.create(ServerboundConfigurationPackets1_20_2.RESOURCE_PACK);
|
||||||
|
downloadedResponse.write(Type.VAR_INT, 0);
|
||||||
|
downloadedResponse.sendToServer(Protocol1_20To1_20_2.class);
|
||||||
|
});
|
||||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.REGISTRY_DATA.getId(), -1, wrapper -> {
|
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.REGISTRY_DATA.getId(), -1, wrapper -> {
|
||||||
wrapper.cancel();
|
wrapper.cancel();
|
||||||
|
|
||||||
@ -123,18 +140,17 @@ public final class Protocol1_20To1_20_2 extends BackwardsProtocol<ClientboundPac
|
|||||||
wrapper.user().get(ConfigurationPacketStorage.class).setRegistry(registry);
|
wrapper.user().get(ConfigurationPacketStorage.class).setRegistry(registry);
|
||||||
});
|
});
|
||||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.UPDATE_ENABLED_FEATURES.getId(), -1, wrapper -> {
|
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.UPDATE_ENABLED_FEATURES.getId(), -1, wrapper -> {
|
||||||
wrapper.cancel();
|
|
||||||
|
|
||||||
final String[] enabledFeatures = wrapper.read(Type.STRING_ARRAY);
|
final String[] enabledFeatures = wrapper.read(Type.STRING_ARRAY);
|
||||||
wrapper.user().get(ConfigurationPacketStorage.class).setEnabledFeatures(enabledFeatures);
|
wrapper.user().get(ConfigurationPacketStorage.class).setEnabledFeatures(enabledFeatures);
|
||||||
|
wrapper.cancel();
|
||||||
});
|
});
|
||||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.UPDATE_TAGS.getId(), -1, wrapper -> {
|
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.UPDATE_TAGS.getId(), -1, wrapper -> {
|
||||||
wrapper.cancel();
|
|
||||||
wrapper.user().get(ConfigurationPacketStorage.class).addRawPacket(wrapper, ClientboundPackets1_19_4.TAGS);
|
wrapper.user().get(ConfigurationPacketStorage.class).addRawPacket(wrapper, ClientboundPackets1_19_4.TAGS);
|
||||||
|
wrapper.cancel();
|
||||||
});
|
});
|
||||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.CUSTOM_PAYLOAD.getId(), -1, wrapper -> {
|
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_2.CUSTOM_PAYLOAD.getId(), -1, wrapper -> {
|
||||||
wrapper.cancel();
|
|
||||||
wrapper.user().get(ConfigurationPacketStorage.class).addRawPacket(wrapper, ClientboundPackets1_19_4.PLUGIN_MESSAGE);
|
wrapper.user().get(ConfigurationPacketStorage.class).addRawPacket(wrapper, ClientboundPackets1_19_4.PLUGIN_MESSAGE);
|
||||||
|
wrapper.cancel();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
|||||||
import com.viaversion.viaversion.api.protocol.packet.PacketType;
|
import com.viaversion.viaversion.api.protocol.packet.PacketType;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||||
|
import com.viaversion.viaversion.protocols.protocol1_19_4to1_19_3.ClientboundPackets1_19_4;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -35,6 +36,11 @@ public final class ConfigurationPacketStorage implements StorableObject {
|
|||||||
private CompoundTag registry;
|
private CompoundTag registry;
|
||||||
private String[] enabledFeatures;
|
private String[] enabledFeatures;
|
||||||
private boolean finished;
|
private boolean finished;
|
||||||
|
private QueuedPacket resourcePack;
|
||||||
|
|
||||||
|
public void setResourcePack(final PacketWrapper wrapper) throws Exception {
|
||||||
|
resourcePack = toQueuedPacket(wrapper, ClientboundPackets1_19_4.RESOURCE_PACK);
|
||||||
|
}
|
||||||
|
|
||||||
public CompoundTag registry() {
|
public CompoundTag registry() {
|
||||||
Preconditions.checkNotNull(registry);
|
Preconditions.checkNotNull(registry);
|
||||||
@ -55,15 +61,27 @@ public final class ConfigurationPacketStorage implements StorableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addRawPacket(final PacketWrapper wrapper, final PacketType type) throws Exception {
|
public void addRawPacket(final PacketWrapper wrapper, final PacketType type) throws Exception {
|
||||||
|
rawPackets.add(toQueuedPacket(wrapper, type));
|
||||||
|
}
|
||||||
|
|
||||||
|
private QueuedPacket toQueuedPacket(final PacketWrapper wrapper, final PacketType type) throws Exception {
|
||||||
|
Preconditions.checkArgument(!wrapper.isCancelled(), "Wrapper should be cancelled AFTER calling toQueuedPacket");
|
||||||
|
|
||||||
// It's easier to just copy it to a byte array buffer than to manually read the data
|
// It's easier to just copy it to a byte array buffer than to manually read the data
|
||||||
final ByteBuf buf = Unpooled.buffer();
|
final ByteBuf buf = Unpooled.buffer();
|
||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
wrapper.setId(-1); // Don't write the packet id to the buffer
|
wrapper.setId(-1); // Don't write the packet id to the buffer
|
||||||
wrapper.writeToBuffer(buf);
|
wrapper.writeToBuffer(buf);
|
||||||
rawPackets.add(new QueuedPacket(buf, type));
|
return new QueuedPacket(buf, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendQueuedPackets(final UserConnection connection) throws Exception {
|
public void sendQueuedPackets(final UserConnection connection) throws Exception {
|
||||||
|
// Send resource pack at the end
|
||||||
|
if (resourcePack != null) {
|
||||||
|
rawPackets.add(resourcePack);
|
||||||
|
resourcePack = null;
|
||||||
|
}
|
||||||
|
|
||||||
for (final QueuedPacket queuedPacket : rawPackets) {
|
for (final QueuedPacket queuedPacket : rawPackets) {
|
||||||
try {
|
try {
|
||||||
final PacketWrapper packet = PacketWrapper.create(queuedPacket.packetType(), queuedPacket.buf(), connection);
|
final PacketWrapper packet = PacketWrapper.create(queuedPacket.packetType(), queuedPacket.buf(), connection);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren