Mirror von
https://github.com/PaperMC/Velocity.git
synchronisiert 2024-11-17 05:20:14 +01:00
Add PacketWriter interface.
Dieser Commit ist enthalten in:
Ursprung
f167414ae8
Commit
0294cfda56
@ -31,6 +31,7 @@ import com.velocitypowered.proxy.network.pipeline.MinecraftEncoder;
|
||||
import com.velocitypowered.proxy.util.except.QuietDecoderException;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
@ -47,6 +48,7 @@ import javax.crypto.spec.SecretKeySpec;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A utility class to make working with the pipeline a little less painful and transparently handles
|
||||
@ -242,7 +244,12 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
|
||||
});
|
||||
} else {
|
||||
knownDisconnect = true;
|
||||
channel.writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE);
|
||||
channel.writeAndFlush(msg).addListener((ChannelFutureListener) future -> {
|
||||
if (!future.isSuccess()) {
|
||||
future.cause().printStackTrace();
|
||||
}
|
||||
future.channel().close();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import com.velocitypowered.proxy.config.PingPassthroughMode;
|
||||
import com.velocitypowered.proxy.config.VelocityConfiguration;
|
||||
import com.velocitypowered.proxy.connection.MinecraftConnection;
|
||||
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
|
||||
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundStatusPingPacket;
|
||||
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundStatusResponsePacket;
|
||||
import com.velocitypowered.proxy.network.packet.legacy.LegacyDisconnectPacket;
|
||||
import com.velocitypowered.proxy.network.packet.legacy.LegacyPingPacket;
|
||||
@ -177,7 +178,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
|
||||
|
||||
@Override
|
||||
public boolean handle(ServerboundStatusPingPacket packet) {
|
||||
connection.closeWith(packet);
|
||||
connection.closeWith(new ClientboundStatusPingPacket(packet.getRandomId()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundAvailableCommandsPacket;
|
||||
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundBossBarPacket;
|
||||
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundChatPacket;
|
||||
@ -58,6 +59,7 @@ import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@ -69,6 +71,7 @@ public enum StateRegistry {
|
||||
serverbound.register(
|
||||
ServerboundHandshakePacket.class,
|
||||
ServerboundHandshakePacket.DECODER,
|
||||
ServerboundHandshakePacket.ENCODER,
|
||||
map(0x00, MINECRAFT_1_7_2, false)
|
||||
);
|
||||
}
|
||||
@ -78,22 +81,26 @@ public enum StateRegistry {
|
||||
serverbound.register(
|
||||
ServerboundStatusRequestPacket.class,
|
||||
ServerboundStatusRequestPacket.DECODER,
|
||||
ServerboundStatusRequestPacket.ENCODER,
|
||||
map(0x00, MINECRAFT_1_7_2, false)
|
||||
);
|
||||
serverbound.register(
|
||||
ServerboundStatusPingPacket.class,
|
||||
ServerboundStatusPingPacket.DECODER,
|
||||
ServerboundStatusPingPacket.ENCODER,
|
||||
map(0x01, MINECRAFT_1_7_2, false)
|
||||
);
|
||||
|
||||
clientbound.register(
|
||||
ClientboundStatusResponsePacket.class,
|
||||
ClientboundStatusResponsePacket.DECODER,
|
||||
ClientboundStatusResponsePacket.ENCODER,
|
||||
map(0x00, MINECRAFT_1_7_2, false)
|
||||
);
|
||||
clientbound.register(
|
||||
ClientboundStatusPingPacket.class,
|
||||
ClientboundStatusPingPacket.DECODER,
|
||||
ClientboundStatusPingPacket.ENCODER,
|
||||
map(0x01, MINECRAFT_1_7_2, false)
|
||||
);
|
||||
}
|
||||
@ -103,6 +110,7 @@ public enum StateRegistry {
|
||||
serverbound.register(
|
||||
ServerboundTabCompleteRequestPacket.class,
|
||||
ServerboundTabCompleteRequestPacket.DECODER,
|
||||
ServerboundTabCompleteRequestPacket.ENCODER,
|
||||
map(0x14, MINECRAFT_1_7_2, false),
|
||||
map(0x01, MINECRAFT_1_9, false),
|
||||
map(0x02, MINECRAFT_1_12, false),
|
||||
@ -113,6 +121,7 @@ public enum StateRegistry {
|
||||
serverbound.register(
|
||||
ServerboundChatPacket.class,
|
||||
ServerboundChatPacket.DECODER,
|
||||
ServerboundChatPacket.ENCODER,
|
||||
map(0x01, MINECRAFT_1_7_2, false),
|
||||
map(0x02, MINECRAFT_1_9, false),
|
||||
map(0x03, MINECRAFT_1_12, false),
|
||||
@ -122,6 +131,7 @@ public enum StateRegistry {
|
||||
serverbound.register(
|
||||
ServerboundClientSettingsPacket.class,
|
||||
ServerboundClientSettingsPacket.DECODER,
|
||||
ServerboundClientSettingsPacket.ENCODER,
|
||||
map(0x15, MINECRAFT_1_7_2, false),
|
||||
map(0x04, MINECRAFT_1_9, false),
|
||||
map(0x05, MINECRAFT_1_12, false),
|
||||
@ -131,6 +141,7 @@ public enum StateRegistry {
|
||||
serverbound.register(
|
||||
ServerboundPluginMessagePacket.class,
|
||||
ServerboundPluginMessagePacket.DECODER,
|
||||
ServerboundPluginMessagePacket.ENCODER,
|
||||
map(0x17, MINECRAFT_1_7_2, false),
|
||||
map(0x09, MINECRAFT_1_9, false),
|
||||
map(0x0A, MINECRAFT_1_12, false),
|
||||
@ -141,6 +152,7 @@ public enum StateRegistry {
|
||||
serverbound.register(
|
||||
ServerboundKeepAlivePacket.class,
|
||||
ServerboundKeepAlivePacket.DECODER,
|
||||
ServerboundKeepAlivePacket.ENCODER,
|
||||
map(0x00, MINECRAFT_1_7_2, false),
|
||||
map(0x0B, MINECRAFT_1_9, false),
|
||||
map(0x0C, MINECRAFT_1_12, false),
|
||||
@ -152,6 +164,7 @@ public enum StateRegistry {
|
||||
serverbound.register(
|
||||
ServerboundResourcePackResponsePacket.class,
|
||||
ServerboundResourcePackResponsePacket.DECODER,
|
||||
ServerboundResourcePackResponsePacket.ENCODER,
|
||||
map(0x19, MINECRAFT_1_8, false),
|
||||
map(0x16, MINECRAFT_1_9, false),
|
||||
map(0x18, MINECRAFT_1_12, false),
|
||||
@ -164,6 +177,7 @@ public enum StateRegistry {
|
||||
clientbound.register(
|
||||
ClientboundBossBarPacket.class,
|
||||
ClientboundBossBarPacket.DECODER,
|
||||
ClientboundBossBarPacket.ENCODER,
|
||||
map(0x0C, MINECRAFT_1_9, false),
|
||||
map(0x0D, MINECRAFT_1_15, false),
|
||||
map(0x0C, MINECRAFT_1_16, false)
|
||||
@ -171,6 +185,7 @@ public enum StateRegistry {
|
||||
clientbound.register(
|
||||
ClientboundChatPacket.class,
|
||||
ClientboundChatPacket.DECODER,
|
||||
ClientboundChatPacket.ENCODER,
|
||||
map(0x02, MINECRAFT_1_7_2, true),
|
||||
map(0x0F, MINECRAFT_1_9, true),
|
||||
map(0x0E, MINECRAFT_1_13, true),
|
||||
@ -180,6 +195,7 @@ public enum StateRegistry {
|
||||
clientbound.register(
|
||||
ClientboundTabCompleteResponsePacket.class,
|
||||
ClientboundTabCompleteResponsePacket.DECODER,
|
||||
ClientboundTabCompleteResponsePacket.ENCODER,
|
||||
map(0x3A, MINECRAFT_1_7_2, false),
|
||||
map(0x0E, MINECRAFT_1_9, false),
|
||||
map(0x10, MINECRAFT_1_13, false),
|
||||
@ -190,6 +206,7 @@ public enum StateRegistry {
|
||||
clientbound.register(
|
||||
ClientboundAvailableCommandsPacket.class,
|
||||
ClientboundAvailableCommandsPacket.DECODER,
|
||||
ClientboundAvailableCommandsPacket.ENCODER,
|
||||
map(0x11, MINECRAFT_1_13, false),
|
||||
map(0x12, MINECRAFT_1_15, false),
|
||||
map(0x11, MINECRAFT_1_16, false),
|
||||
@ -198,6 +215,7 @@ public enum StateRegistry {
|
||||
clientbound.register(
|
||||
ClientboundPluginMessagePacket.class,
|
||||
ClientboundPluginMessagePacket.DECODER,
|
||||
ClientboundPluginMessagePacket.ENCODER,
|
||||
map(0x3F, MINECRAFT_1_7_2, false),
|
||||
map(0x18, MINECRAFT_1_9, false),
|
||||
map(0x19, MINECRAFT_1_13, false),
|
||||
@ -209,6 +227,7 @@ public enum StateRegistry {
|
||||
clientbound.register(
|
||||
ClientboundDisconnectPacket.class,
|
||||
ClientboundDisconnectPacket.DECODER,
|
||||
ClientboundDisconnectPacket.ENCODER,
|
||||
map(0x40, MINECRAFT_1_7_2, false),
|
||||
map(0x1A, MINECRAFT_1_9, false),
|
||||
map(0x1B, MINECRAFT_1_13, false),
|
||||
@ -220,6 +239,7 @@ public enum StateRegistry {
|
||||
clientbound.register(
|
||||
ClientboundKeepAlivePacket.class,
|
||||
ClientboundKeepAlivePacket.DECODER,
|
||||
ClientboundKeepAlivePacket.ENCODER,
|
||||
map(0x00, MINECRAFT_1_7_2, false),
|
||||
map(0x1F, MINECRAFT_1_9, false),
|
||||
map(0x21, MINECRAFT_1_13, false),
|
||||
@ -231,6 +251,7 @@ public enum StateRegistry {
|
||||
clientbound.register(
|
||||
ClientboundJoinGamePacket.class,
|
||||
ClientboundJoinGamePacket.DECODER,
|
||||
ClientboundJoinGamePacket.ENCODER,
|
||||
map(0x01, MINECRAFT_1_7_2, false),
|
||||
map(0x23, MINECRAFT_1_9, false),
|
||||
map(0x25, MINECRAFT_1_13, false),
|
||||
@ -242,6 +263,7 @@ public enum StateRegistry {
|
||||
clientbound.register(
|
||||
ClientboundRespawnPacket.class,
|
||||
ClientboundRespawnPacket.DECODER,
|
||||
ClientboundRespawnPacket.ENCODER,
|
||||
map(0x07, MINECRAFT_1_7_2, true),
|
||||
map(0x33, MINECRAFT_1_9, true),
|
||||
map(0x34, MINECRAFT_1_12, true),
|
||||
@ -255,6 +277,7 @@ public enum StateRegistry {
|
||||
clientbound.register(
|
||||
ClientboundResourcePackRequestPacket.class,
|
||||
ClientboundResourcePackRequestPacket.DECODER,
|
||||
ClientboundResourcePackRequestPacket.ENCODER,
|
||||
map(0x48, MINECRAFT_1_8, true),
|
||||
map(0x32, MINECRAFT_1_9, true),
|
||||
map(0x33, MINECRAFT_1_12, true),
|
||||
@ -268,6 +291,7 @@ public enum StateRegistry {
|
||||
clientbound.register(
|
||||
ClientboundHeaderAndFooterPacket.class,
|
||||
ClientboundHeaderAndFooterPacket.DECODER,
|
||||
ClientboundHeaderAndFooterPacket.ENCODER,
|
||||
map(0x47, MINECRAFT_1_8, true),
|
||||
map(0x48, MINECRAFT_1_9, true),
|
||||
map(0x47, MINECRAFT_1_9_4, true),
|
||||
@ -281,6 +305,7 @@ public enum StateRegistry {
|
||||
clientbound.register(
|
||||
ClientboundTitlePacket.class,
|
||||
ClientboundTitlePacket.DECODER,
|
||||
ClientboundTitlePacket.ENCODER,
|
||||
map(0x45, MINECRAFT_1_8, true),
|
||||
map(0x45, MINECRAFT_1_9, true),
|
||||
map(0x47, MINECRAFT_1_12, true),
|
||||
@ -293,6 +318,7 @@ public enum StateRegistry {
|
||||
clientbound.register(
|
||||
ClientboundPlayerListItemPacket.class,
|
||||
ClientboundPlayerListItemPacket.DECODER,
|
||||
ClientboundPlayerListItemPacket.ENCODER,
|
||||
map(0x38, MINECRAFT_1_7_2, false),
|
||||
map(0x2D, MINECRAFT_1_9, false),
|
||||
map(0x2E, MINECRAFT_1_12_1, false),
|
||||
@ -309,42 +335,50 @@ public enum StateRegistry {
|
||||
serverbound.register(
|
||||
ServerboundServerLoginPacket.class,
|
||||
ServerboundServerLoginPacket.DECODER,
|
||||
ServerboundServerLoginPacket.ENCODER,
|
||||
map(0x00, MINECRAFT_1_7_2, false)
|
||||
);
|
||||
serverbound.register(
|
||||
ServerboundEncryptionResponsePacket.class,
|
||||
ServerboundEncryptionResponsePacket.DECODER,
|
||||
ServerboundEncryptionResponsePacket.ENCODER,
|
||||
map(0x01, MINECRAFT_1_7_2, false)
|
||||
);
|
||||
serverbound.register(
|
||||
ServerboundLoginPluginResponsePacket.class,
|
||||
ServerboundLoginPluginResponsePacket.DECODER,
|
||||
ServerboundLoginPluginResponsePacket.ENCODER,
|
||||
map(0x02, MINECRAFT_1_13, false)
|
||||
);
|
||||
|
||||
clientbound.register(
|
||||
ClientboundDisconnectPacket.class,
|
||||
ClientboundDisconnectPacket.DECODER,
|
||||
ClientboundDisconnectPacket.ENCODER,
|
||||
map(0x00, MINECRAFT_1_7_2, false)
|
||||
);
|
||||
clientbound.register(
|
||||
ClientboundEncryptionRequestPacket.class,
|
||||
ClientboundEncryptionRequestPacket.DECODER,
|
||||
ClientboundEncryptionRequestPacket.ENCODER,
|
||||
map(0x01, MINECRAFT_1_7_2, false)
|
||||
);
|
||||
clientbound.register(
|
||||
ClientboundServerLoginSuccessPacket.class,
|
||||
ClientboundServerLoginSuccessPacket.DECODER,
|
||||
ClientboundServerLoginSuccessPacket.ENCODER,
|
||||
map(0x02, MINECRAFT_1_7_2, false)
|
||||
);
|
||||
clientbound.register(
|
||||
ClientboundSetCompressionPacket.class,
|
||||
ClientboundSetCompressionPacket.DECODER,
|
||||
ClientboundSetCompressionPacket.ENCODER,
|
||||
map(0x03, MINECRAFT_1_8, false)
|
||||
);
|
||||
clientbound.register(
|
||||
ClientboundLoginPluginMessagePacket.class,
|
||||
ClientboundLoginPluginMessagePacket.DECODER,
|
||||
ClientboundLoginPluginMessagePacket.ENCODER,
|
||||
map(0x04, MINECRAFT_1_13, false)
|
||||
);
|
||||
}
|
||||
@ -401,7 +435,7 @@ public enum StateRegistry {
|
||||
return registry;
|
||||
}
|
||||
|
||||
<P extends Packet> void register(Class<P> clazz, PacketReader<P> decoder,
|
||||
<P extends Packet> void register(Class<P> clazz, PacketReader<P> decoder, PacketWriter<P> encoder,
|
||||
PacketMapping... mappings) {
|
||||
if (mappings.length == 0) {
|
||||
throw new IllegalArgumentException("At least one mapping must be provided.");
|
||||
@ -443,6 +477,7 @@ public enum StateRegistry {
|
||||
registry.packetIdToReader.put(current.id, decoder);
|
||||
}
|
||||
registry.packetClassToId.put(clazz, current.id);
|
||||
registry.packetClassToWriter.put(clazz, encoder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -454,6 +489,8 @@ public enum StateRegistry {
|
||||
new IntObjectHashMap<>(16, 0.5f);
|
||||
final Object2IntMap<Class<? extends Packet>> packetClassToId =
|
||||
new Object2IntOpenHashMap<>(16, 0.5f);
|
||||
final Map<Class<? extends Packet>, PacketWriter<? extends Packet>> packetClassToWriter =
|
||||
new HashMap<>(16, 0.5f);
|
||||
|
||||
ProtocolRegistry(final ProtocolVersion version) {
|
||||
this.version = version;
|
||||
@ -465,27 +502,25 @@ public enum StateRegistry {
|
||||
*
|
||||
* @param id the packet ID
|
||||
* @param buf the bytebuf
|
||||
* @param direction the packet direction
|
||||
* @param version the protocol version
|
||||
* @return the packet instance, or {@code null} if the ID is not registered
|
||||
*/
|
||||
public @Nullable Packet readPacket(final int id, ByteBuf buf, PacketDirection direction,
|
||||
ProtocolVersion version) {
|
||||
public @Nullable Packet readPacket(final int id, ByteBuf buf, ProtocolVersion version) {
|
||||
final PacketReader<? extends Packet> decoder = this.packetIdToReader.get(id);
|
||||
if (decoder == null) {
|
||||
return null;
|
||||
}
|
||||
return decoder.read(buf, direction, version);
|
||||
return decoder.read(buf, version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to look up the packet ID for an {@code packet}.
|
||||
* Attempts to serialize the specified {@code packet}.
|
||||
*
|
||||
* @param packet the packet to look up
|
||||
* @return the packet ID
|
||||
* @throws IllegalArgumentException if the packet ID is not found
|
||||
* @param packet the packet
|
||||
* @param buf the bytebuf
|
||||
* @param version the protocol version
|
||||
*/
|
||||
public int getPacketId(final Packet packet) {
|
||||
public <P extends Packet> void writePacket(P packet, ByteBuf buf, ProtocolVersion version) {
|
||||
final int id = this.packetClassToId.getInt(packet.getClass());
|
||||
if (id == Integer.MIN_VALUE) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
@ -493,7 +528,16 @@ public enum StateRegistry {
|
||||
packet.getClass().getName(), PacketRegistry.this.direction, this.version
|
||||
));
|
||||
}
|
||||
return id;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
// Safe because all registering actions are type-safe.
|
||||
final PacketWriter encoder = this.packetClassToWriter.get(packet.getClass());
|
||||
|
||||
assert encoder != null : "Couldn't look up encoder - shouldn't happen!";
|
||||
|
||||
ProtocolUtils.writeVarInt(buf, id);
|
||||
//noinspection unchecked
|
||||
encoder.write(buf, packet, version);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import java.util.function.LongFunction;
|
||||
|
||||
public abstract class AbstractKeepAlivePacket implements Packet {
|
||||
protected static <P extends AbstractKeepAlivePacket> PacketReader<P> decoder(final LongFunction<P> factory) {
|
||||
return (buf, direction, version) -> {
|
||||
return (buf, version) -> {
|
||||
final long randomId;
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_12_2)) {
|
||||
randomId = buf.readLong();
|
||||
@ -21,23 +21,24 @@ public abstract class AbstractKeepAlivePacket implements Packet {
|
||||
};
|
||||
}
|
||||
|
||||
protected static <P extends AbstractKeepAlivePacket> PacketWriter<P> encoder() {
|
||||
return (buf, packet, version) -> {
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_12_2)) {
|
||||
buf.writeLong(packet.getRandomId());
|
||||
} else if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
ProtocolUtils.writeVarInt(buf, (int) packet.getRandomId());
|
||||
} else {
|
||||
buf.writeInt((int) packet.getRandomId());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private final long randomId;
|
||||
|
||||
protected AbstractKeepAlivePacket(final long randomId) {
|
||||
this.randomId = randomId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_12_2)) {
|
||||
buf.writeLong(randomId);
|
||||
} else if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
ProtocolUtils.writeVarInt(buf, (int) randomId);
|
||||
} else {
|
||||
buf.writeInt((int) randomId);
|
||||
}
|
||||
}
|
||||
|
||||
public long getRandomId() {
|
||||
return randomId;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public abstract class AbstractPluginMessagePacket<S extends AbstractPluginMessagePacket<S>> extends TypedDefaultByteBufHolder<S> implements Packet {
|
||||
protected static <P extends AbstractPluginMessagePacket<P>> PacketReader<P> decoder(final Factory<P> factory) {
|
||||
return (buf, direction, version) -> {
|
||||
return (buf, version) -> {
|
||||
String channel = ProtocolUtils.readString(buf);
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_13)) {
|
||||
channel = transformLegacyToModernChannel(channel);
|
||||
@ -28,6 +28,24 @@ public abstract class AbstractPluginMessagePacket<S extends AbstractPluginMessag
|
||||
};
|
||||
}
|
||||
|
||||
protected static <P extends AbstractPluginMessagePacket<P>> PacketWriter<P> encoder() {
|
||||
return (buf, packet, version) -> {
|
||||
if (packet.channel == null) {
|
||||
throw new IllegalStateException("Channel is not specified.");
|
||||
}
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_13)) {
|
||||
ProtocolUtils.writeString(buf, transformLegacyToModernChannel(packet.channel));
|
||||
} else {
|
||||
ProtocolUtils.writeString(buf, packet.channel);
|
||||
}
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
buf.writeBytes(packet.content());
|
||||
} else {
|
||||
ProtocolUtils.writeByteBuf17(packet.content(), buf, true); // True for Forge support
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected final @Nullable String channel;
|
||||
|
||||
protected AbstractPluginMessagePacket(String channel,
|
||||
@ -36,23 +54,6 @@ public abstract class AbstractPluginMessagePacket<S extends AbstractPluginMessag
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
if (channel == null) {
|
||||
throw new IllegalStateException("Channel is not specified.");
|
||||
}
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_13)) {
|
||||
ProtocolUtils.writeString(buf, transformLegacyToModernChannel(this.channel));
|
||||
} else {
|
||||
ProtocolUtils.writeString(buf, this.channel);
|
||||
}
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
buf.writeBytes(content());
|
||||
} else {
|
||||
ProtocolUtils.writeByteBuf17(content(), buf, true); // True for Forge support
|
||||
}
|
||||
}
|
||||
|
||||
public String getChannel() {
|
||||
if (channel == null) {
|
||||
throw new IllegalStateException("Channel is not specified.");
|
||||
|
@ -7,11 +7,14 @@ import java.util.function.LongFunction;
|
||||
|
||||
public abstract class AbstractStatusPingPacket implements Packet {
|
||||
protected static <P extends AbstractStatusPingPacket> PacketReader<P> decoder(final LongFunction<P> factory) {
|
||||
return (buf, direction, version) -> {
|
||||
return (buf, version) -> {
|
||||
final long randomId = buf.readLong();
|
||||
return factory.apply(randomId);
|
||||
};
|
||||
}
|
||||
protected static <P extends AbstractStatusPingPacket> PacketWriter<P> encoder() {
|
||||
return (buf, packet, version) -> buf.writeLong(packet.getRandomId());
|
||||
}
|
||||
|
||||
private final long randomId;
|
||||
|
||||
@ -19,9 +22,8 @@ public abstract class AbstractStatusPingPacket implements Packet {
|
||||
this.randomId = randomId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
buf.writeLong(this.randomId);
|
||||
public long getRandomId() {
|
||||
return randomId;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,7 +2,6 @@ package com.velocitypowered.proxy.network.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface Packet {
|
||||
|
||||
@ -11,7 +10,10 @@ public interface Packet {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion protocolVersion);
|
||||
@Deprecated
|
||||
default void encode(ByteBuf buf, ProtocolVersion protocolVersion) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
boolean handle(PacketHandler handler);
|
||||
|
||||
|
@ -5,23 +5,31 @@ import io.netty.buffer.ByteBuf;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public interface PacketReader<P extends Packet> {
|
||||
P read(final ByteBuf buf, final PacketDirection direction, final ProtocolVersion version);
|
||||
P read(final ByteBuf buf, final ProtocolVersion version);
|
||||
|
||||
default int expectedMinLength(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
default int expectedMaxLength(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
static <P extends Packet> PacketReader<P> unsupported() {
|
||||
return (buf, direction, version) -> {
|
||||
return (buf, version) -> {
|
||||
throw new UnsupportedOperationException();
|
||||
};
|
||||
}
|
||||
|
||||
static <P extends Packet> PacketReader<P> instance(final P packet) {
|
||||
return (buf, direction, version) -> packet;
|
||||
return (buf, version) -> packet;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
static <P extends Packet> PacketReader<P> method(final Supplier<P> factory) {
|
||||
return (buf, direction, version) -> {
|
||||
return (buf, version) -> {
|
||||
final P packet = factory.get();
|
||||
packet.decode(buf, direction, version);
|
||||
packet.decode(buf, null, version);
|
||||
return packet;
|
||||
};
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package com.velocitypowered.proxy.network.packet;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public interface PacketWriter<P extends Packet> {
|
||||
void write(final ByteBuf out, final P packet, final ProtocolVersion version);
|
||||
|
||||
static <P extends Packet> PacketWriter<P> unsupported() {
|
||||
return (buf, packet, version) -> {
|
||||
throw new UnsupportedOperationException();
|
||||
};
|
||||
}
|
||||
|
||||
static <P extends Packet> PacketWriter<P> noop() {
|
||||
return (buf, packet, version) -> { };
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
static <P extends Packet> PacketWriter<P> deprecatedEncode() {
|
||||
return (buf, packet, version) -> packet.encode(buf, version);
|
||||
}
|
||||
}
|
@ -23,11 +23,11 @@ import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import com.velocitypowered.proxy.network.serialization.brigadier.ArgumentPropertyRegistry;
|
||||
import com.velocitypowered.proxy.util.collect.IdentityHashStrategy;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenCustomHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2IntMap;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Arrays;
|
||||
@ -40,6 +40,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ClientboundAvailableCommandsPacket implements Packet {
|
||||
public static final PacketReader<ClientboundAvailableCommandsPacket> DECODER = PacketReader.method(ClientboundAvailableCommandsPacket::new);
|
||||
public static final PacketWriter<ClientboundAvailableCommandsPacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
private static final Command<CommandSource> PLACEHOLDER_COMMAND = source -> 0;
|
||||
|
||||
@ -98,7 +99,7 @@ public class ClientboundAvailableCommandsPacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion protocolVersion) {
|
||||
// Assign all the children an index.
|
||||
Deque<CommandNode<CommandSource>> childrenQueue = new ArrayDeque<>(ImmutableList.of(rootNode));
|
||||
Object2IntMap<CommandNode<CommandSource>> idMappings = new Object2IntLinkedOpenCustomHashMap<>(
|
||||
|
@ -7,6 +7,7 @@ import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.UUID;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@ -14,6 +15,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
public class ClientboundBossBarPacket implements Packet {
|
||||
|
||||
public static final PacketReader<ClientboundBossBarPacket> DECODER = PacketReader.method(ClientboundBossBarPacket::new);
|
||||
public static final PacketWriter<ClientboundBossBarPacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
public static final int ADD = 0;
|
||||
public static final int REMOVE = 1;
|
||||
@ -122,7 +124,7 @@ public class ClientboundBossBarPacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
if (uuid == null) {
|
||||
throw new IllegalStateException("No boss bar UUID specified");
|
||||
}
|
||||
|
@ -7,12 +7,14 @@ import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.UUID;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ClientboundChatPacket implements Packet {
|
||||
public static final PacketReader<ClientboundChatPacket> DECODER = PacketReader.method(ClientboundChatPacket::new);
|
||||
public static final PacketWriter<ClientboundChatPacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
public static final byte CHAT_TYPE = (byte) 0;
|
||||
public static final byte SYSTEM_TYPE = (byte) 1;
|
||||
@ -43,7 +45,7 @@ public class ClientboundChatPacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
if (message == null) {
|
||||
throw new IllegalStateException("Message is not specified");
|
||||
}
|
||||
|
@ -8,12 +8,14 @@ import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ClientboundDisconnectPacket implements Packet {
|
||||
public static final PacketReader<ClientboundDisconnectPacket> DECODER = PacketReader.method(ClientboundDisconnectPacket::new);
|
||||
public static final PacketWriter<ClientboundDisconnectPacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
private @Nullable String reason;
|
||||
|
||||
@ -41,7 +43,7 @@ public class ClientboundDisconnectPacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
if (reason == null) {
|
||||
throw new IllegalStateException("No reason specified.");
|
||||
}
|
||||
|
@ -9,10 +9,12 @@ import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ClientboundEncryptionRequestPacket implements Packet {
|
||||
public static final PacketReader<ClientboundEncryptionRequestPacket> DECODER = PacketReader.method(ClientboundEncryptionRequestPacket::new);
|
||||
public static final PacketWriter<ClientboundEncryptionRequestPacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
private String serverId = "";
|
||||
private byte[] publicKey = EMPTY_BYTE_ARRAY;
|
||||
@ -48,7 +50,7 @@ public class ClientboundEncryptionRequestPacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
ProtocolUtils.writeString(buf, this.serverId);
|
||||
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
|
@ -6,13 +6,14 @@ import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ClientboundHeaderAndFooterPacket implements Packet {
|
||||
public static final PacketReader<ClientboundHeaderAndFooterPacket> DECODER = PacketReader.method(ClientboundHeaderAndFooterPacket::new);
|
||||
public static final PacketWriter<ClientboundHeaderAndFooterPacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
private static final String EMPTY_COMPONENT = "{\"translate\":\"\"}";
|
||||
private static final ClientboundHeaderAndFooterPacket RESET
|
||||
@ -31,7 +32,7 @@ public class ClientboundHeaderAndFooterPacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
writeString(buf, header);
|
||||
writeString(buf, footer);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.velocitypowered.proxy.network.packet.clientbound;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.connection.registry.DimensionData;
|
||||
@ -11,6 +10,7 @@ import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.kyori.adventure.nbt.BinaryTagIO;
|
||||
import net.kyori.adventure.nbt.BinaryTagTypes;
|
||||
@ -20,6 +20,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ClientboundJoinGamePacket implements Packet {
|
||||
public static final PacketReader<ClientboundJoinGamePacket> DECODER = PacketReader.method(ClientboundJoinGamePacket::new);
|
||||
public static final PacketWriter<ClientboundJoinGamePacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
private static final BinaryTagIO.Reader JOINGAME_READER = BinaryTagIO.reader(2 * 1024 * 1024);
|
||||
private int entityId;
|
||||
@ -243,7 +244,7 @@ public class ClientboundJoinGamePacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
buf.writeInt(entityId);
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_16_2)) {
|
||||
buf.writeBoolean(isHardcore);
|
||||
|
@ -4,9 +4,11 @@ import com.velocitypowered.proxy.network.packet.AbstractKeepAlivePacket;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
|
||||
public class ClientboundKeepAlivePacket extends AbstractKeepAlivePacket implements Packet {
|
||||
public static final PacketReader<ClientboundKeepAlivePacket> DECODER = decoder(ClientboundKeepAlivePacket::new);
|
||||
public static final PacketWriter<ClientboundKeepAlivePacket> ENCODER = encoder();
|
||||
|
||||
public ClientboundKeepAlivePacket(final long randomId) {
|
||||
super(randomId);
|
||||
|
@ -4,9 +4,9 @@ import com.google.common.base.MoreObjects;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.network.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.DefaultByteBufHolder;
|
||||
import io.netty.buffer.Unpooled;
|
||||
@ -14,17 +14,18 @@ import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ClientboundLoginPluginMessagePacket extends DefaultByteBufHolder implements Packet {
|
||||
public static final PacketReader<ClientboundLoginPluginMessagePacket> DECODER = (buf, direction, version) -> {
|
||||
public static final PacketReader<ClientboundLoginPluginMessagePacket> DECODER = (buf, version) -> {
|
||||
final int id = ProtocolUtils.readVarInt(buf);
|
||||
final String channel = ProtocolUtils.readString(buf);
|
||||
final ByteBuf data;
|
||||
if (buf.isReadable()) {
|
||||
data = buf.readSlice(buf.readableBytes());
|
||||
data = buf.readRetainedSlice(buf.readableBytes());
|
||||
} else {
|
||||
data = Unpooled.EMPTY_BUFFER;
|
||||
}
|
||||
return new ClientboundLoginPluginMessagePacket(id, channel, data);
|
||||
};
|
||||
public static final PacketWriter<ClientboundLoginPluginMessagePacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
private final int id;
|
||||
private final @Nullable String channel;
|
||||
@ -36,7 +37,7 @@ public class ClientboundLoginPluginMessagePacket extends DefaultByteBufHolder im
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
ProtocolUtils.writeVarInt(buf, id);
|
||||
if (channel == null) {
|
||||
throw new IllegalStateException("Channel is not specified!");
|
||||
|
@ -10,6 +10,7 @@ import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -20,6 +21,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ClientboundPlayerListItemPacket implements Packet {
|
||||
public static final PacketReader<ClientboundPlayerListItemPacket> DECODER = PacketReader.method(ClientboundPlayerListItemPacket::new);
|
||||
public static final PacketWriter<ClientboundPlayerListItemPacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
public static final int ADD_PLAYER = 0;
|
||||
public static final int UPDATE_GAMEMODE = 1;
|
||||
@ -96,7 +98,7 @@ public class ClientboundPlayerListItemPacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
ProtocolUtils.writeVarInt(buf, action);
|
||||
ProtocolUtils.writeVarInt(buf, items.size());
|
||||
|
@ -4,11 +4,13 @@ import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ClientboundPluginMessagePacket extends AbstractPluginMessagePacket<ClientboundPluginMessagePacket> implements Packet {
|
||||
public static final Factory<ClientboundPluginMessagePacket> FACTORY = ClientboundPluginMessagePacket::new;
|
||||
public static final PacketReader<ClientboundPluginMessagePacket> DECODER = decoder(FACTORY);
|
||||
public static final PacketWriter<ClientboundPluginMessagePacket> ENCODER = encoder();
|
||||
|
||||
public ClientboundPluginMessagePacket(final String channel, final ByteBuf backing) {
|
||||
super(channel, backing);
|
||||
|
@ -4,18 +4,19 @@ import com.google.common.base.MoreObjects;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.network.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ClientboundResourcePackRequestPacket implements Packet {
|
||||
public static final PacketReader<ClientboundResourcePackRequestPacket> DECODER = (buf, direction, version) -> {
|
||||
public static final PacketReader<ClientboundResourcePackRequestPacket> DECODER = (buf, version) -> {
|
||||
final String url = ProtocolUtils.readString(buf);
|
||||
final String hash = ProtocolUtils.readString(buf);
|
||||
return new ClientboundResourcePackRequestPacket(url, hash);
|
||||
};
|
||||
public static final PacketWriter<ClientboundResourcePackRequestPacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
private final String url;
|
||||
private final String hash;
|
||||
@ -26,7 +27,7 @@ public class ClientboundResourcePackRequestPacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion protocolVersion) {
|
||||
ProtocolUtils.writeString(buf, url);
|
||||
ProtocolUtils.writeString(buf, hash);
|
||||
}
|
||||
|
@ -9,12 +9,14 @@ import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.kyori.adventure.nbt.BinaryTagIO;
|
||||
import net.kyori.adventure.nbt.CompoundBinaryTag;
|
||||
|
||||
public class ClientboundRespawnPacket implements Packet {
|
||||
public static final PacketReader<ClientboundRespawnPacket> DECODER = PacketReader.method(ClientboundRespawnPacket::new);
|
||||
public static final PacketWriter<ClientboundRespawnPacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
private int dimension;
|
||||
private long partialHashedSeed;
|
||||
@ -135,7 +137,7 @@ public class ClientboundRespawnPacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_16)) {
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_16_2)) {
|
||||
ProtocolUtils.writeCompoundTag(buf, currentDimensionData.serializeDimensionDetails());
|
||||
|
@ -5,15 +5,15 @@ import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.util.UuidUtils;
|
||||
import com.velocitypowered.proxy.network.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ClientboundServerLoginSuccessPacket implements Packet {
|
||||
public static final PacketReader<ClientboundServerLoginSuccessPacket> DECODER = (buf, direction, version) -> {
|
||||
public static final PacketReader<ClientboundServerLoginSuccessPacket> DECODER = (buf, version) -> {
|
||||
final UUID uuid;
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_16)) {
|
||||
uuid = ProtocolUtils.readUuidIntArray(buf);
|
||||
@ -25,6 +25,7 @@ public class ClientboundServerLoginSuccessPacket implements Packet {
|
||||
final String username = ProtocolUtils.readString(buf, 16);
|
||||
return new ClientboundServerLoginSuccessPacket(uuid, username);
|
||||
};
|
||||
public static final PacketWriter<ClientboundServerLoginSuccessPacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
private final UUID uuid;
|
||||
private final String username;
|
||||
@ -35,7 +36,7 @@ public class ClientboundServerLoginSuccessPacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_16)) {
|
||||
ProtocolUtils.writeUuidIntArray(buf, uuid);
|
||||
} else if (version.gte(ProtocolVersion.MINECRAFT_1_7_6)) {
|
||||
|
@ -1,19 +1,19 @@
|
||||
package com.velocitypowered.proxy.network.packet.clientbound;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.network.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
|
||||
public class ClientboundSetCompressionPacket implements Packet {
|
||||
public static final PacketReader<ClientboundSetCompressionPacket> DECODER = (buf, direction, version) -> {
|
||||
public static final PacketReader<ClientboundSetCompressionPacket> DECODER = (buf, version) -> {
|
||||
final int threshold = ProtocolUtils.readVarInt(buf);
|
||||
return new ClientboundSetCompressionPacket(threshold);
|
||||
};
|
||||
public static final PacketWriter<ClientboundSetCompressionPacket> ENCODER = (buf, packet, version) ->
|
||||
ProtocolUtils.writeVarInt(buf, packet.threshold);
|
||||
|
||||
private final int threshold;
|
||||
|
||||
@ -21,11 +21,6 @@ public class ClientboundSetCompressionPacket implements Packet {
|
||||
this.threshold = threshold;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
ProtocolUtils.writeVarInt(buf, threshold);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(PacketHandler handler) {
|
||||
return handler.handle(this);
|
||||
|
@ -4,9 +4,11 @@ import com.velocitypowered.proxy.network.packet.AbstractStatusPingPacket;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
|
||||
public class ClientboundStatusPingPacket extends AbstractStatusPingPacket implements Packet {
|
||||
public static final PacketReader<ClientboundStatusPingPacket> DECODER = decoder(ClientboundStatusPingPacket::new);
|
||||
public static final PacketWriter<ClientboundStatusPingPacket> ENCODER = encoder();
|
||||
|
||||
public ClientboundStatusPingPacket(final long randomId) {
|
||||
super(randomId);
|
||||
|
@ -4,17 +4,19 @@ import com.google.common.base.MoreObjects;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.network.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ClientboundStatusResponsePacket implements Packet {
|
||||
public static final PacketReader<ClientboundStatusResponsePacket> DECODER = (buf, direction, version) -> {
|
||||
public static final PacketReader<ClientboundStatusResponsePacket> DECODER = (buf, version) -> {
|
||||
final String status = ProtocolUtils.readString(buf, Short.MAX_VALUE);
|
||||
return new ClientboundStatusResponsePacket(status);
|
||||
};
|
||||
public static final PacketWriter<ClientboundStatusResponsePacket> ENCODER = (buf, packet, version) ->
|
||||
ProtocolUtils.writeString(buf, packet.status);
|
||||
|
||||
private final @Nullable CharSequence status;
|
||||
|
||||
@ -23,7 +25,7 @@ public class ClientboundStatusResponsePacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
if (status == null) {
|
||||
throw new IllegalStateException("Status is not specified");
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -15,6 +16,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ClientboundTabCompleteResponsePacket implements Packet {
|
||||
public static final PacketReader<ClientboundTabCompleteResponsePacket> DECODER = PacketReader.method(ClientboundTabCompleteResponsePacket::new);
|
||||
public static final PacketWriter<ClientboundTabCompleteResponsePacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
private int transactionId;
|
||||
private int start;
|
||||
@ -71,7 +73,7 @@ public class ClientboundTabCompleteResponsePacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_13)) {
|
||||
ProtocolUtils.writeVarInt(buf, this.transactionId);
|
||||
ProtocolUtils.writeVarInt(buf, this.start);
|
||||
|
@ -5,9 +5,9 @@ import com.google.common.primitives.Ints;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.network.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import com.velocitypowered.proxy.util.DurationUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.Arrays;
|
||||
@ -16,6 +16,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ClientboundTitlePacket implements Packet {
|
||||
public static final PacketReader<ClientboundTitlePacket> DECODER = PacketReader.unsupported();
|
||||
public static final PacketWriter<ClientboundTitlePacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
public static ClientboundTitlePacket hide(final ProtocolVersion version) {
|
||||
return version.gte(ProtocolVersion.MINECRAFT_1_11)
|
||||
@ -92,7 +93,7 @@ public class ClientboundTitlePacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
ProtocolUtils.writeVarInt(buf, action);
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_11)) {
|
||||
// 1.11+ shifted the action enum by 1 to handle the action bar
|
||||
|
@ -2,14 +2,13 @@ package com.velocitypowered.proxy.network.packet.legacy;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class LegacyHandshakePacket implements LegacyPacket, Packet {
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ package com.velocitypowered.proxy.network.packet.legacy;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.net.InetSocketAddress;
|
||||
@ -24,7 +23,7 @@ public class LegacyPingPacket implements LegacyPacket, Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
@ -1,19 +1,19 @@
|
||||
package com.velocitypowered.proxy.network.packet.serverbound;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.network.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
|
||||
public class ServerboundChatPacket implements Packet {
|
||||
public static final PacketReader<ServerboundChatPacket> DECODER = (buf, direction, version) -> {
|
||||
public static final PacketReader<ServerboundChatPacket> DECODER = (buf, version) -> {
|
||||
final String message = ProtocolUtils.readString(buf);
|
||||
return new ServerboundChatPacket(message);
|
||||
};
|
||||
public static final PacketWriter<ServerboundChatPacket> ENCODER = (buf, packet, version) ->
|
||||
ProtocolUtils.writeString(buf, packet.message);
|
||||
|
||||
public static final int MAX_MESSAGE_LENGTH = 256;
|
||||
|
||||
@ -23,11 +23,6 @@ public class ServerboundChatPacket implements Packet {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
ProtocolUtils.writeString(buf, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(PacketHandler handler) {
|
||||
return handler.handle(this);
|
||||
|
@ -7,11 +7,13 @@ import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ServerboundClientSettingsPacket implements Packet {
|
||||
public static final PacketReader<ServerboundClientSettingsPacket> DECODER = PacketReader.method(ServerboundClientSettingsPacket::new);
|
||||
public static final PacketWriter<ServerboundClientSettingsPacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
private @Nullable String locale;
|
||||
private byte viewDistance;
|
||||
@ -53,7 +55,7 @@ public class ServerboundClientSettingsPacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
if (locale == null) {
|
||||
throw new IllegalStateException("No locale specified");
|
||||
}
|
||||
|
@ -4,13 +4,13 @@ import com.google.common.base.MoreObjects;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.network.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ServerboundEncryptionResponsePacket implements Packet {
|
||||
public static final PacketReader<ServerboundEncryptionResponsePacket> DECODER = (buf, direction, version) -> {
|
||||
public static final PacketReader<ServerboundEncryptionResponsePacket> DECODER = (buf, version) -> {
|
||||
final byte[] sharedSecret;
|
||||
final byte[] verifyToken;
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
@ -22,6 +22,7 @@ public class ServerboundEncryptionResponsePacket implements Packet {
|
||||
}
|
||||
return new ServerboundEncryptionResponsePacket(sharedSecret, verifyToken);
|
||||
};
|
||||
public static final PacketWriter<ServerboundEncryptionResponsePacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
private final byte[] sharedSecret;
|
||||
private final byte[] verifyToken;
|
||||
@ -32,7 +33,7 @@ public class ServerboundEncryptionResponsePacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
|
||||
ProtocolUtils.writeByteArray(buf, sharedSecret);
|
||||
ProtocolUtils.writeByteArray(buf, verifyToken);
|
||||
|
@ -4,13 +4,13 @@ import com.google.common.base.MoreObjects;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.network.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ServerboundHandshakePacket implements Packet {
|
||||
public static final PacketReader<ServerboundHandshakePacket> DECODER = (buf, direction, version) -> {
|
||||
public static final PacketReader<ServerboundHandshakePacket> DECODER = (buf, version) -> {
|
||||
int realProtocolVersion = ProtocolUtils.readVarInt(buf);
|
||||
final ProtocolVersion protocolVersion = ProtocolVersion.getProtocolVersion(realProtocolVersion);
|
||||
final String hostname = ProtocolUtils.readString(buf);
|
||||
@ -18,6 +18,7 @@ public class ServerboundHandshakePacket implements Packet {
|
||||
final int nextStatus = ProtocolUtils.readVarInt(buf);
|
||||
return new ServerboundHandshakePacket(protocolVersion, hostname, port, nextStatus);
|
||||
};
|
||||
public static final PacketWriter<ServerboundHandshakePacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
private ProtocolVersion protocolVersion;
|
||||
private String serverAddress = "";
|
||||
@ -35,7 +36,7 @@ public class ServerboundHandshakePacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion ignored) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion ignored) {
|
||||
ProtocolUtils.writeVarInt(buf, this.protocolVersion.getProtocol());
|
||||
ProtocolUtils.writeString(buf, this.serverAddress);
|
||||
buf.writeShort(this.port);
|
||||
|
@ -4,9 +4,11 @@ import com.velocitypowered.proxy.network.packet.AbstractKeepAlivePacket;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
|
||||
public class ServerboundKeepAlivePacket extends AbstractKeepAlivePacket implements Packet {
|
||||
public static final PacketReader<ServerboundKeepAlivePacket> DECODER = decoder(ServerboundKeepAlivePacket::new);
|
||||
public static final PacketWriter<ServerboundKeepAlivePacket> ENCODER = encoder();
|
||||
|
||||
public ServerboundKeepAlivePacket(final long randomId) {
|
||||
super(randomId);
|
||||
|
@ -4,9 +4,9 @@ import com.google.common.base.MoreObjects;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.network.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.DefaultByteBufHolder;
|
||||
import io.netty.buffer.Unpooled;
|
||||
@ -14,7 +14,7 @@ import java.util.Objects;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
|
||||
public class ServerboundLoginPluginResponsePacket extends DefaultByteBufHolder implements Packet {
|
||||
public static final PacketReader<ServerboundLoginPluginResponsePacket> DECODER = (buf, direction, version) -> {
|
||||
public static final PacketReader<ServerboundLoginPluginResponsePacket> DECODER = (buf, version) -> {
|
||||
final int id = ProtocolUtils.readVarInt(buf);
|
||||
final boolean success = buf.readBoolean();
|
||||
final ByteBuf data;
|
||||
@ -25,6 +25,7 @@ public class ServerboundLoginPluginResponsePacket extends DefaultByteBufHolder i
|
||||
}
|
||||
return new ServerboundLoginPluginResponsePacket(id, success, data);
|
||||
};
|
||||
public static final PacketWriter<ServerboundLoginPluginResponsePacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
private final int id;
|
||||
private final boolean success;
|
||||
@ -36,7 +37,7 @@ public class ServerboundLoginPluginResponsePacket extends DefaultByteBufHolder i
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
ProtocolUtils.writeVarInt(buf, id);
|
||||
buf.writeBoolean(success);
|
||||
buf.writeBytes(content());
|
||||
|
@ -4,11 +4,13 @@ import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ServerboundPluginMessagePacket extends AbstractPluginMessagePacket<ServerboundPluginMessagePacket> implements Packet {
|
||||
public static final Factory<ServerboundPluginMessagePacket> FACTORY = ServerboundPluginMessagePacket::new;
|
||||
public static final PacketReader<ServerboundPluginMessagePacket> DECODER = decoder(FACTORY);
|
||||
public static final PacketWriter<ServerboundPluginMessagePacket> ENCODER = encoder();
|
||||
|
||||
public ServerboundPluginMessagePacket(final String channel, final ByteBuf backing) {
|
||||
super(channel, backing);
|
||||
|
@ -5,14 +5,14 @@ import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent.Status
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.network.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ServerboundResourcePackResponsePacket implements Packet {
|
||||
public static final PacketReader<ServerboundResourcePackResponsePacket> DECODER = (buf, direction, version) -> {
|
||||
public static final PacketReader<ServerboundResourcePackResponsePacket> DECODER = (buf, version) -> {
|
||||
final String hash;
|
||||
if (version.lte(ProtocolVersion.MINECRAFT_1_9_4)) {
|
||||
hash = ProtocolUtils.readString(buf);
|
||||
@ -22,6 +22,7 @@ public class ServerboundResourcePackResponsePacket implements Packet {
|
||||
final Status status = Status.values()[ProtocolUtils.readVarInt(buf)];
|
||||
return new ServerboundResourcePackResponsePacket(hash, status);
|
||||
};
|
||||
public static final PacketWriter<ServerboundResourcePackResponsePacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
private final @Nullable String hash;
|
||||
private final Status status;
|
||||
@ -32,7 +33,7 @@ public class ServerboundResourcePackResponsePacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion protocolVersion) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion protocolVersion) {
|
||||
if (protocolVersion.lte(ProtocolVersion.MINECRAFT_1_9_4)) {
|
||||
ProtocolUtils.writeString(buf, hash);
|
||||
}
|
||||
|
@ -4,9 +4,9 @@ import com.google.common.base.MoreObjects;
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.network.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import com.velocitypowered.proxy.util.except.QuietDecoderException;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.Objects;
|
||||
@ -14,13 +14,15 @@ import java.util.Objects;
|
||||
public class ServerboundServerLoginPacket implements Packet {
|
||||
private static final QuietDecoderException EMPTY_USERNAME = new QuietDecoderException("Empty username!");
|
||||
|
||||
public static final PacketReader<ServerboundServerLoginPacket> DECODER = (buf, direction, version) -> {
|
||||
public static final PacketReader<ServerboundServerLoginPacket> DECODER = (buf, version) -> {
|
||||
final String username = ProtocolUtils.readString(buf, 16);
|
||||
if (username.isEmpty()) {
|
||||
throw EMPTY_USERNAME;
|
||||
}
|
||||
return new ServerboundServerLoginPacket(username);
|
||||
};
|
||||
public static final PacketWriter<ServerboundServerLoginPacket> ENCODER = (buf, packet, version) ->
|
||||
ProtocolUtils.writeString(buf, packet.username);
|
||||
|
||||
private final String username;
|
||||
|
||||
@ -28,11 +30,6 @@ public class ServerboundServerLoginPacket implements Packet {
|
||||
this.username = Objects.requireNonNull(username, "username");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
ProtocolUtils.writeString(buf, username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(PacketHandler handler) {
|
||||
return handler.handle(this);
|
||||
|
@ -4,9 +4,11 @@ import com.velocitypowered.proxy.network.packet.AbstractStatusPingPacket;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
|
||||
public class ServerboundStatusPingPacket extends AbstractStatusPingPacket implements Packet {
|
||||
public static final PacketReader<ServerboundStatusPingPacket> DECODER = decoder(ServerboundStatusPingPacket::new);
|
||||
public static final PacketWriter<ServerboundStatusPingPacket> ENCODER = encoder();
|
||||
|
||||
public ServerboundStatusPingPacket(final long randomId) {
|
||||
super(randomId);
|
||||
|
@ -2,23 +2,19 @@ package com.velocitypowered.proxy.network.packet.serverbound;
|
||||
|
||||
import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class ServerboundStatusRequestPacket implements Packet {
|
||||
public static final ServerboundStatusRequestPacket INSTANCE = new ServerboundStatusRequestPacket();
|
||||
public static final PacketReader<ServerboundStatusRequestPacket> DECODER = PacketReader.instance(INSTANCE);
|
||||
public static final PacketWriter<ServerboundStatusRequestPacket> ENCODER = PacketWriter.noop();
|
||||
|
||||
private ServerboundStatusRequestPacket() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
// There is no data to decode.
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handle(PacketHandler handler) {
|
||||
return handler.handle(this);
|
||||
|
@ -11,11 +11,13 @@ import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.network.packet.PacketHandler;
|
||||
import com.velocitypowered.proxy.network.packet.PacketReader;
|
||||
import com.velocitypowered.proxy.network.packet.PacketWriter;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ServerboundTabCompleteRequestPacket implements Packet {
|
||||
public static final PacketReader<ServerboundTabCompleteRequestPacket> DECODER = PacketReader.method(ServerboundTabCompleteRequestPacket::new);
|
||||
public static final PacketWriter<ServerboundTabCompleteRequestPacket> ENCODER = PacketWriter.deprecatedEncode();
|
||||
|
||||
private static final int VANILLA_MAX_TAB_COMPLETE_LEN = 2048;
|
||||
|
||||
@ -88,7 +90,7 @@ public class ServerboundTabCompleteRequestPacket implements Packet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
|
||||
public void encode(ByteBuf buf, ProtocolVersion version) {
|
||||
if (command == null) {
|
||||
throw new IllegalStateException("Command is not specified");
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import com.velocitypowered.proxy.network.ProtocolUtils;
|
||||
import com.velocitypowered.proxy.network.StateRegistry;
|
||||
import com.velocitypowered.proxy.network.packet.Packet;
|
||||
import com.velocitypowered.proxy.network.packet.PacketDirection;
|
||||
import com.velocitypowered.proxy.util.except.QuietDecoderException;
|
||||
import com.velocitypowered.proxy.util.except.QuietRuntimeException;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
@ -56,7 +55,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
|
||||
int packetId = ProtocolUtils.readVarInt(buf);
|
||||
Packet packet = null;
|
||||
try {
|
||||
packet = this.registry.readPacket(packetId, buf, direction, registry.version);
|
||||
packet = this.registry.readPacket(packetId, buf, registry.version);
|
||||
} catch (Exception e) {
|
||||
throw handleDecodeFailure(e, packet, packetId); // TODO: packet is always null
|
||||
}
|
||||
@ -65,14 +64,6 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
|
||||
ctx.fireChannelRead(buf);
|
||||
} else {
|
||||
try {
|
||||
doLengthSanityChecks(buf, packet);
|
||||
|
||||
try {
|
||||
packet.decode(buf, direction, registry.version);
|
||||
} catch (Exception e) {
|
||||
throw handleDecodeFailure(e, packet, packetId);
|
||||
}
|
||||
|
||||
if (buf.isReadable()) {
|
||||
throw handleOverflow(packet, buf.readerIndex(), buf.writerIndex());
|
||||
}
|
||||
|
@ -30,9 +30,7 @@ public class MinecraftEncoder extends MessageToByteEncoder<Packet> {
|
||||
|
||||
@Override
|
||||
protected void encode(ChannelHandlerContext ctx, Packet msg, ByteBuf out) {
|
||||
int packetId = this.registry.getPacketId(msg);
|
||||
ProtocolUtils.writeVarInt(out, packetId);
|
||||
msg.encode(out, direction, registry.version);
|
||||
this.registry.writePacket(msg, out, registry.version);
|
||||
}
|
||||
|
||||
public void setProtocolVersion(final ProtocolVersion protocolVersion) {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren