3
0
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:
Andrew Steinborn 2021-02-21 20:45:59 -05:00
Ursprung f167414ae8
Commit 0294cfda56
44 geänderte Dateien mit 246 neuen und 144 gelöschten Zeilen

Datei anzeigen

@ -31,6 +31,7 @@ import com.velocitypowered.proxy.network.pipeline.MinecraftEncoder;
import com.velocitypowered.proxy.util.except.QuietDecoderException; import com.velocitypowered.proxy.util.except.QuietDecoderException;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter; 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.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.Nullable; 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 * 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 { } else {
knownDisconnect = true; knownDisconnect = true;
channel.writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE); channel.writeAndFlush(msg).addListener((ChannelFutureListener) future -> {
if (!future.isSuccess()) {
future.cause().printStackTrace();
}
future.channel().close();
});
} }
} }
} }

Datei anzeigen

@ -13,6 +13,7 @@ import com.velocitypowered.proxy.config.PingPassthroughMode;
import com.velocitypowered.proxy.config.VelocityConfiguration; import com.velocitypowered.proxy.config.VelocityConfiguration;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; 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.clientbound.ClientboundStatusResponsePacket;
import com.velocitypowered.proxy.network.packet.legacy.LegacyDisconnectPacket; import com.velocitypowered.proxy.network.packet.legacy.LegacyDisconnectPacket;
import com.velocitypowered.proxy.network.packet.legacy.LegacyPingPacket; import com.velocitypowered.proxy.network.packet.legacy.LegacyPingPacket;
@ -177,7 +178,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
@Override @Override
public boolean handle(ServerboundStatusPingPacket packet) { public boolean handle(ServerboundStatusPingPacket packet) {
connection.closeWith(packet); connection.closeWith(new ClientboundStatusPingPacket(packet.getRandomId()));
return true; return true;
} }

Datei anzeigen

@ -19,6 +19,7 @@ import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketDirection; import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketReader; 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.ClientboundAvailableCommandsPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundBossBarPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundBossBarPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundChatPacket; 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.Collections;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -69,6 +71,7 @@ public enum StateRegistry {
serverbound.register( serverbound.register(
ServerboundHandshakePacket.class, ServerboundHandshakePacket.class,
ServerboundHandshakePacket.DECODER, ServerboundHandshakePacket.DECODER,
ServerboundHandshakePacket.ENCODER,
map(0x00, MINECRAFT_1_7_2, false) map(0x00, MINECRAFT_1_7_2, false)
); );
} }
@ -78,22 +81,26 @@ public enum StateRegistry {
serverbound.register( serverbound.register(
ServerboundStatusRequestPacket.class, ServerboundStatusRequestPacket.class,
ServerboundStatusRequestPacket.DECODER, ServerboundStatusRequestPacket.DECODER,
ServerboundStatusRequestPacket.ENCODER,
map(0x00, MINECRAFT_1_7_2, false) map(0x00, MINECRAFT_1_7_2, false)
); );
serverbound.register( serverbound.register(
ServerboundStatusPingPacket.class, ServerboundStatusPingPacket.class,
ServerboundStatusPingPacket.DECODER, ServerboundStatusPingPacket.DECODER,
ServerboundStatusPingPacket.ENCODER,
map(0x01, MINECRAFT_1_7_2, false) map(0x01, MINECRAFT_1_7_2, false)
); );
clientbound.register( clientbound.register(
ClientboundStatusResponsePacket.class, ClientboundStatusResponsePacket.class,
ClientboundStatusResponsePacket.DECODER, ClientboundStatusResponsePacket.DECODER,
ClientboundStatusResponsePacket.ENCODER,
map(0x00, MINECRAFT_1_7_2, false) map(0x00, MINECRAFT_1_7_2, false)
); );
clientbound.register( clientbound.register(
ClientboundStatusPingPacket.class, ClientboundStatusPingPacket.class,
ClientboundStatusPingPacket.DECODER, ClientboundStatusPingPacket.DECODER,
ClientboundStatusPingPacket.ENCODER,
map(0x01, MINECRAFT_1_7_2, false) map(0x01, MINECRAFT_1_7_2, false)
); );
} }
@ -103,6 +110,7 @@ public enum StateRegistry {
serverbound.register( serverbound.register(
ServerboundTabCompleteRequestPacket.class, ServerboundTabCompleteRequestPacket.class,
ServerboundTabCompleteRequestPacket.DECODER, ServerboundTabCompleteRequestPacket.DECODER,
ServerboundTabCompleteRequestPacket.ENCODER,
map(0x14, MINECRAFT_1_7_2, false), map(0x14, MINECRAFT_1_7_2, false),
map(0x01, MINECRAFT_1_9, false), map(0x01, MINECRAFT_1_9, false),
map(0x02, MINECRAFT_1_12, false), map(0x02, MINECRAFT_1_12, false),
@ -113,6 +121,7 @@ public enum StateRegistry {
serverbound.register( serverbound.register(
ServerboundChatPacket.class, ServerboundChatPacket.class,
ServerboundChatPacket.DECODER, ServerboundChatPacket.DECODER,
ServerboundChatPacket.ENCODER,
map(0x01, MINECRAFT_1_7_2, false), map(0x01, MINECRAFT_1_7_2, false),
map(0x02, MINECRAFT_1_9, false), map(0x02, MINECRAFT_1_9, false),
map(0x03, MINECRAFT_1_12, false), map(0x03, MINECRAFT_1_12, false),
@ -122,6 +131,7 @@ public enum StateRegistry {
serverbound.register( serverbound.register(
ServerboundClientSettingsPacket.class, ServerboundClientSettingsPacket.class,
ServerboundClientSettingsPacket.DECODER, ServerboundClientSettingsPacket.DECODER,
ServerboundClientSettingsPacket.ENCODER,
map(0x15, MINECRAFT_1_7_2, false), map(0x15, MINECRAFT_1_7_2, false),
map(0x04, MINECRAFT_1_9, false), map(0x04, MINECRAFT_1_9, false),
map(0x05, MINECRAFT_1_12, false), map(0x05, MINECRAFT_1_12, false),
@ -131,6 +141,7 @@ public enum StateRegistry {
serverbound.register( serverbound.register(
ServerboundPluginMessagePacket.class, ServerboundPluginMessagePacket.class,
ServerboundPluginMessagePacket.DECODER, ServerboundPluginMessagePacket.DECODER,
ServerboundPluginMessagePacket.ENCODER,
map(0x17, MINECRAFT_1_7_2, false), map(0x17, MINECRAFT_1_7_2, false),
map(0x09, MINECRAFT_1_9, false), map(0x09, MINECRAFT_1_9, false),
map(0x0A, MINECRAFT_1_12, false), map(0x0A, MINECRAFT_1_12, false),
@ -141,6 +152,7 @@ public enum StateRegistry {
serverbound.register( serverbound.register(
ServerboundKeepAlivePacket.class, ServerboundKeepAlivePacket.class,
ServerboundKeepAlivePacket.DECODER, ServerboundKeepAlivePacket.DECODER,
ServerboundKeepAlivePacket.ENCODER,
map(0x00, MINECRAFT_1_7_2, false), map(0x00, MINECRAFT_1_7_2, false),
map(0x0B, MINECRAFT_1_9, false), map(0x0B, MINECRAFT_1_9, false),
map(0x0C, MINECRAFT_1_12, false), map(0x0C, MINECRAFT_1_12, false),
@ -152,6 +164,7 @@ public enum StateRegistry {
serverbound.register( serverbound.register(
ServerboundResourcePackResponsePacket.class, ServerboundResourcePackResponsePacket.class,
ServerboundResourcePackResponsePacket.DECODER, ServerboundResourcePackResponsePacket.DECODER,
ServerboundResourcePackResponsePacket.ENCODER,
map(0x19, MINECRAFT_1_8, false), map(0x19, MINECRAFT_1_8, false),
map(0x16, MINECRAFT_1_9, false), map(0x16, MINECRAFT_1_9, false),
map(0x18, MINECRAFT_1_12, false), map(0x18, MINECRAFT_1_12, false),
@ -164,6 +177,7 @@ public enum StateRegistry {
clientbound.register( clientbound.register(
ClientboundBossBarPacket.class, ClientboundBossBarPacket.class,
ClientboundBossBarPacket.DECODER, ClientboundBossBarPacket.DECODER,
ClientboundBossBarPacket.ENCODER,
map(0x0C, MINECRAFT_1_9, false), map(0x0C, MINECRAFT_1_9, false),
map(0x0D, MINECRAFT_1_15, false), map(0x0D, MINECRAFT_1_15, false),
map(0x0C, MINECRAFT_1_16, false) map(0x0C, MINECRAFT_1_16, false)
@ -171,6 +185,7 @@ public enum StateRegistry {
clientbound.register( clientbound.register(
ClientboundChatPacket.class, ClientboundChatPacket.class,
ClientboundChatPacket.DECODER, ClientboundChatPacket.DECODER,
ClientboundChatPacket.ENCODER,
map(0x02, MINECRAFT_1_7_2, true), map(0x02, MINECRAFT_1_7_2, true),
map(0x0F, MINECRAFT_1_9, true), map(0x0F, MINECRAFT_1_9, true),
map(0x0E, MINECRAFT_1_13, true), map(0x0E, MINECRAFT_1_13, true),
@ -180,6 +195,7 @@ public enum StateRegistry {
clientbound.register( clientbound.register(
ClientboundTabCompleteResponsePacket.class, ClientboundTabCompleteResponsePacket.class,
ClientboundTabCompleteResponsePacket.DECODER, ClientboundTabCompleteResponsePacket.DECODER,
ClientboundTabCompleteResponsePacket.ENCODER,
map(0x3A, MINECRAFT_1_7_2, false), map(0x3A, MINECRAFT_1_7_2, false),
map(0x0E, MINECRAFT_1_9, false), map(0x0E, MINECRAFT_1_9, false),
map(0x10, MINECRAFT_1_13, false), map(0x10, MINECRAFT_1_13, false),
@ -190,6 +206,7 @@ public enum StateRegistry {
clientbound.register( clientbound.register(
ClientboundAvailableCommandsPacket.class, ClientboundAvailableCommandsPacket.class,
ClientboundAvailableCommandsPacket.DECODER, ClientboundAvailableCommandsPacket.DECODER,
ClientboundAvailableCommandsPacket.ENCODER,
map(0x11, MINECRAFT_1_13, false), map(0x11, MINECRAFT_1_13, false),
map(0x12, MINECRAFT_1_15, false), map(0x12, MINECRAFT_1_15, false),
map(0x11, MINECRAFT_1_16, false), map(0x11, MINECRAFT_1_16, false),
@ -198,6 +215,7 @@ public enum StateRegistry {
clientbound.register( clientbound.register(
ClientboundPluginMessagePacket.class, ClientboundPluginMessagePacket.class,
ClientboundPluginMessagePacket.DECODER, ClientboundPluginMessagePacket.DECODER,
ClientboundPluginMessagePacket.ENCODER,
map(0x3F, MINECRAFT_1_7_2, false), map(0x3F, MINECRAFT_1_7_2, false),
map(0x18, MINECRAFT_1_9, false), map(0x18, MINECRAFT_1_9, false),
map(0x19, MINECRAFT_1_13, false), map(0x19, MINECRAFT_1_13, false),
@ -209,6 +227,7 @@ public enum StateRegistry {
clientbound.register( clientbound.register(
ClientboundDisconnectPacket.class, ClientboundDisconnectPacket.class,
ClientboundDisconnectPacket.DECODER, ClientboundDisconnectPacket.DECODER,
ClientboundDisconnectPacket.ENCODER,
map(0x40, MINECRAFT_1_7_2, false), map(0x40, MINECRAFT_1_7_2, false),
map(0x1A, MINECRAFT_1_9, false), map(0x1A, MINECRAFT_1_9, false),
map(0x1B, MINECRAFT_1_13, false), map(0x1B, MINECRAFT_1_13, false),
@ -220,6 +239,7 @@ public enum StateRegistry {
clientbound.register( clientbound.register(
ClientboundKeepAlivePacket.class, ClientboundKeepAlivePacket.class,
ClientboundKeepAlivePacket.DECODER, ClientboundKeepAlivePacket.DECODER,
ClientboundKeepAlivePacket.ENCODER,
map(0x00, MINECRAFT_1_7_2, false), map(0x00, MINECRAFT_1_7_2, false),
map(0x1F, MINECRAFT_1_9, false), map(0x1F, MINECRAFT_1_9, false),
map(0x21, MINECRAFT_1_13, false), map(0x21, MINECRAFT_1_13, false),
@ -231,6 +251,7 @@ public enum StateRegistry {
clientbound.register( clientbound.register(
ClientboundJoinGamePacket.class, ClientboundJoinGamePacket.class,
ClientboundJoinGamePacket.DECODER, ClientboundJoinGamePacket.DECODER,
ClientboundJoinGamePacket.ENCODER,
map(0x01, MINECRAFT_1_7_2, false), map(0x01, MINECRAFT_1_7_2, false),
map(0x23, MINECRAFT_1_9, false), map(0x23, MINECRAFT_1_9, false),
map(0x25, MINECRAFT_1_13, false), map(0x25, MINECRAFT_1_13, false),
@ -242,6 +263,7 @@ public enum StateRegistry {
clientbound.register( clientbound.register(
ClientboundRespawnPacket.class, ClientboundRespawnPacket.class,
ClientboundRespawnPacket.DECODER, ClientboundRespawnPacket.DECODER,
ClientboundRespawnPacket.ENCODER,
map(0x07, MINECRAFT_1_7_2, true), map(0x07, MINECRAFT_1_7_2, true),
map(0x33, MINECRAFT_1_9, true), map(0x33, MINECRAFT_1_9, true),
map(0x34, MINECRAFT_1_12, true), map(0x34, MINECRAFT_1_12, true),
@ -255,6 +277,7 @@ public enum StateRegistry {
clientbound.register( clientbound.register(
ClientboundResourcePackRequestPacket.class, ClientboundResourcePackRequestPacket.class,
ClientboundResourcePackRequestPacket.DECODER, ClientboundResourcePackRequestPacket.DECODER,
ClientboundResourcePackRequestPacket.ENCODER,
map(0x48, MINECRAFT_1_8, true), map(0x48, MINECRAFT_1_8, true),
map(0x32, MINECRAFT_1_9, true), map(0x32, MINECRAFT_1_9, true),
map(0x33, MINECRAFT_1_12, true), map(0x33, MINECRAFT_1_12, true),
@ -268,6 +291,7 @@ public enum StateRegistry {
clientbound.register( clientbound.register(
ClientboundHeaderAndFooterPacket.class, ClientboundHeaderAndFooterPacket.class,
ClientboundHeaderAndFooterPacket.DECODER, ClientboundHeaderAndFooterPacket.DECODER,
ClientboundHeaderAndFooterPacket.ENCODER,
map(0x47, MINECRAFT_1_8, true), map(0x47, MINECRAFT_1_8, true),
map(0x48, MINECRAFT_1_9, true), map(0x48, MINECRAFT_1_9, true),
map(0x47, MINECRAFT_1_9_4, true), map(0x47, MINECRAFT_1_9_4, true),
@ -281,6 +305,7 @@ public enum StateRegistry {
clientbound.register( clientbound.register(
ClientboundTitlePacket.class, ClientboundTitlePacket.class,
ClientboundTitlePacket.DECODER, ClientboundTitlePacket.DECODER,
ClientboundTitlePacket.ENCODER,
map(0x45, MINECRAFT_1_8, true), map(0x45, MINECRAFT_1_8, true),
map(0x45, MINECRAFT_1_9, true), map(0x45, MINECRAFT_1_9, true),
map(0x47, MINECRAFT_1_12, true), map(0x47, MINECRAFT_1_12, true),
@ -293,6 +318,7 @@ public enum StateRegistry {
clientbound.register( clientbound.register(
ClientboundPlayerListItemPacket.class, ClientboundPlayerListItemPacket.class,
ClientboundPlayerListItemPacket.DECODER, ClientboundPlayerListItemPacket.DECODER,
ClientboundPlayerListItemPacket.ENCODER,
map(0x38, MINECRAFT_1_7_2, false), map(0x38, MINECRAFT_1_7_2, false),
map(0x2D, MINECRAFT_1_9, false), map(0x2D, MINECRAFT_1_9, false),
map(0x2E, MINECRAFT_1_12_1, false), map(0x2E, MINECRAFT_1_12_1, false),
@ -309,42 +335,50 @@ public enum StateRegistry {
serverbound.register( serverbound.register(
ServerboundServerLoginPacket.class, ServerboundServerLoginPacket.class,
ServerboundServerLoginPacket.DECODER, ServerboundServerLoginPacket.DECODER,
ServerboundServerLoginPacket.ENCODER,
map(0x00, MINECRAFT_1_7_2, false) map(0x00, MINECRAFT_1_7_2, false)
); );
serverbound.register( serverbound.register(
ServerboundEncryptionResponsePacket.class, ServerboundEncryptionResponsePacket.class,
ServerboundEncryptionResponsePacket.DECODER, ServerboundEncryptionResponsePacket.DECODER,
ServerboundEncryptionResponsePacket.ENCODER,
map(0x01, MINECRAFT_1_7_2, false) map(0x01, MINECRAFT_1_7_2, false)
); );
serverbound.register( serverbound.register(
ServerboundLoginPluginResponsePacket.class, ServerboundLoginPluginResponsePacket.class,
ServerboundLoginPluginResponsePacket.DECODER, ServerboundLoginPluginResponsePacket.DECODER,
ServerboundLoginPluginResponsePacket.ENCODER,
map(0x02, MINECRAFT_1_13, false) map(0x02, MINECRAFT_1_13, false)
); );
clientbound.register( clientbound.register(
ClientboundDisconnectPacket.class, ClientboundDisconnectPacket.class,
ClientboundDisconnectPacket.DECODER, ClientboundDisconnectPacket.DECODER,
ClientboundDisconnectPacket.ENCODER,
map(0x00, MINECRAFT_1_7_2, false) map(0x00, MINECRAFT_1_7_2, false)
); );
clientbound.register( clientbound.register(
ClientboundEncryptionRequestPacket.class, ClientboundEncryptionRequestPacket.class,
ClientboundEncryptionRequestPacket.DECODER, ClientboundEncryptionRequestPacket.DECODER,
ClientboundEncryptionRequestPacket.ENCODER,
map(0x01, MINECRAFT_1_7_2, false) map(0x01, MINECRAFT_1_7_2, false)
); );
clientbound.register( clientbound.register(
ClientboundServerLoginSuccessPacket.class, ClientboundServerLoginSuccessPacket.class,
ClientboundServerLoginSuccessPacket.DECODER, ClientboundServerLoginSuccessPacket.DECODER,
ClientboundServerLoginSuccessPacket.ENCODER,
map(0x02, MINECRAFT_1_7_2, false) map(0x02, MINECRAFT_1_7_2, false)
); );
clientbound.register( clientbound.register(
ClientboundSetCompressionPacket.class, ClientboundSetCompressionPacket.class,
ClientboundSetCompressionPacket.DECODER, ClientboundSetCompressionPacket.DECODER,
ClientboundSetCompressionPacket.ENCODER,
map(0x03, MINECRAFT_1_8, false) map(0x03, MINECRAFT_1_8, false)
); );
clientbound.register( clientbound.register(
ClientboundLoginPluginMessagePacket.class, ClientboundLoginPluginMessagePacket.class,
ClientboundLoginPluginMessagePacket.DECODER, ClientboundLoginPluginMessagePacket.DECODER,
ClientboundLoginPluginMessagePacket.ENCODER,
map(0x04, MINECRAFT_1_13, false) map(0x04, MINECRAFT_1_13, false)
); );
} }
@ -401,7 +435,7 @@ public enum StateRegistry {
return registry; 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) { PacketMapping... mappings) {
if (mappings.length == 0) { if (mappings.length == 0) {
throw new IllegalArgumentException("At least one mapping must be provided."); throw new IllegalArgumentException("At least one mapping must be provided.");
@ -443,6 +477,7 @@ public enum StateRegistry {
registry.packetIdToReader.put(current.id, decoder); registry.packetIdToReader.put(current.id, decoder);
} }
registry.packetClassToId.put(clazz, current.id); registry.packetClassToId.put(clazz, current.id);
registry.packetClassToWriter.put(clazz, encoder);
} }
} }
} }
@ -454,6 +489,8 @@ public enum StateRegistry {
new IntObjectHashMap<>(16, 0.5f); new IntObjectHashMap<>(16, 0.5f);
final Object2IntMap<Class<? extends Packet>> packetClassToId = final Object2IntMap<Class<? extends Packet>> packetClassToId =
new Object2IntOpenHashMap<>(16, 0.5f); new Object2IntOpenHashMap<>(16, 0.5f);
final Map<Class<? extends Packet>, PacketWriter<? extends Packet>> packetClassToWriter =
new HashMap<>(16, 0.5f);
ProtocolRegistry(final ProtocolVersion version) { ProtocolRegistry(final ProtocolVersion version) {
this.version = version; this.version = version;
@ -465,27 +502,25 @@ public enum StateRegistry {
* *
* @param id the packet ID * @param id the packet ID
* @param buf the bytebuf * @param buf the bytebuf
* @param direction the packet direction
* @param version the protocol version * @param version the protocol version
* @return the packet instance, or {@code null} if the ID is not registered * @return the packet instance, or {@code null} if the ID is not registered
*/ */
public @Nullable Packet readPacket(final int id, ByteBuf buf, PacketDirection direction, public @Nullable Packet readPacket(final int id, ByteBuf buf, ProtocolVersion version) {
ProtocolVersion version) {
final PacketReader<? extends Packet> decoder = this.packetIdToReader.get(id); final PacketReader<? extends Packet> decoder = this.packetIdToReader.get(id);
if (decoder == null) { if (decoder == null) {
return 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 * @param packet the packet
* @return the packet ID * @param buf the bytebuf
* @throws IllegalArgumentException if the packet ID is not found * @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()); final int id = this.packetClassToId.getInt(packet.getClass());
if (id == Integer.MIN_VALUE) { if (id == Integer.MIN_VALUE) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(
@ -493,7 +528,16 @@ public enum StateRegistry {
packet.getClass().getName(), PacketRegistry.this.direction, this.version 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);
} }
} }
} }

Datei anzeigen

@ -8,7 +8,7 @@ import java.util.function.LongFunction;
public abstract class AbstractKeepAlivePacket implements Packet { public abstract class AbstractKeepAlivePacket implements Packet {
protected static <P extends AbstractKeepAlivePacket> PacketReader<P> decoder(final LongFunction<P> factory) { protected static <P extends AbstractKeepAlivePacket> PacketReader<P> decoder(final LongFunction<P> factory) {
return (buf, direction, version) -> { return (buf, version) -> {
final long randomId; final long randomId;
if (version.gte(ProtocolVersion.MINECRAFT_1_12_2)) { if (version.gte(ProtocolVersion.MINECRAFT_1_12_2)) {
randomId = buf.readLong(); 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; private final long randomId;
protected AbstractKeepAlivePacket(final long randomId) { protected AbstractKeepAlivePacket(final long randomId) {
this.randomId = 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() { public long getRandomId() {
return randomId; return randomId;
} }

Datei anzeigen

@ -13,7 +13,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public abstract class AbstractPluginMessagePacket<S extends AbstractPluginMessagePacket<S>> extends TypedDefaultByteBufHolder<S> implements Packet { 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) { 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); String channel = ProtocolUtils.readString(buf);
if (version.gte(ProtocolVersion.MINECRAFT_1_13)) { if (version.gte(ProtocolVersion.MINECRAFT_1_13)) {
channel = transformLegacyToModernChannel(channel); 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 final @Nullable String channel;
protected AbstractPluginMessagePacket(String channel, protected AbstractPluginMessagePacket(String channel,
@ -36,23 +54,6 @@ public abstract class AbstractPluginMessagePacket<S extends AbstractPluginMessag
this.channel = channel; 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() { public String getChannel() {
if (channel == null) { if (channel == null) {
throw new IllegalStateException("Channel is not specified."); throw new IllegalStateException("Channel is not specified.");

Datei anzeigen

@ -7,11 +7,14 @@ import java.util.function.LongFunction;
public abstract class AbstractStatusPingPacket implements Packet { public abstract class AbstractStatusPingPacket implements Packet {
protected static <P extends AbstractStatusPingPacket> PacketReader<P> decoder(final LongFunction<P> factory) { protected static <P extends AbstractStatusPingPacket> PacketReader<P> decoder(final LongFunction<P> factory) {
return (buf, direction, version) -> { return (buf, version) -> {
final long randomId = buf.readLong(); final long randomId = buf.readLong();
return factory.apply(randomId); return factory.apply(randomId);
}; };
} }
protected static <P extends AbstractStatusPingPacket> PacketWriter<P> encoder() {
return (buf, packet, version) -> buf.writeLong(packet.getRandomId());
}
private final long randomId; private final long randomId;
@ -19,9 +22,8 @@ public abstract class AbstractStatusPingPacket implements Packet {
this.randomId = randomId; this.randomId = randomId;
} }
@Override public long getRandomId() {
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { return randomId;
buf.writeLong(this.randomId);
} }
@Override @Override

Datei anzeigen

@ -2,7 +2,6 @@ package com.velocitypowered.proxy.network.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.function.Supplier;
public interface Packet { public interface Packet {
@ -11,7 +10,10 @@ public interface Packet {
throw new UnsupportedOperationException(); 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); boolean handle(PacketHandler handler);

Datei anzeigen

@ -5,23 +5,31 @@ import io.netty.buffer.ByteBuf;
import java.util.function.Supplier; import java.util.function.Supplier;
public interface PacketReader<P extends Packet> { 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() { static <P extends Packet> PacketReader<P> unsupported() {
return (buf, direction, version) -> { return (buf, version) -> {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
}; };
} }
static <P extends Packet> PacketReader<P> instance(final P packet) { static <P extends Packet> PacketReader<P> instance(final P packet) {
return (buf, direction, version) -> packet; return (buf, version) -> packet;
} }
@Deprecated @Deprecated
static <P extends Packet> PacketReader<P> method(final Supplier<P> factory) { static <P extends Packet> PacketReader<P> method(final Supplier<P> factory) {
return (buf, direction, version) -> { return (buf, version) -> {
final P packet = factory.get(); final P packet = factory.get();
packet.decode(buf, direction, version); packet.decode(buf, null, version);
return packet; return packet;
}; };
} }

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -23,11 +23,11 @@ import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketDirection; import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; 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.network.serialization.brigadier.ArgumentPropertyRegistry;
import com.velocitypowered.proxy.util.collect.IdentityHashStrategy; import com.velocitypowered.proxy.util.collect.IdentityHashStrategy;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenCustomHashMap; import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenCustomHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntMap;
import java.util.ArrayDeque; import java.util.ArrayDeque;
import java.util.Arrays; import java.util.Arrays;
@ -40,6 +40,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundAvailableCommandsPacket implements Packet { public class ClientboundAvailableCommandsPacket implements Packet {
public static final PacketReader<ClientboundAvailableCommandsPacket> DECODER = PacketReader.method(ClientboundAvailableCommandsPacket::new); 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; private static final Command<CommandSource> PLACEHOLDER_COMMAND = source -> 0;
@ -98,7 +99,7 @@ public class ClientboundAvailableCommandsPacket implements Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion protocolVersion) { public void encode(ByteBuf buf, ProtocolVersion protocolVersion) {
// Assign all the children an index. // Assign all the children an index.
Deque<CommandNode<CommandSource>> childrenQueue = new ArrayDeque<>(ImmutableList.of(rootNode)); Deque<CommandNode<CommandSource>> childrenQueue = new ArrayDeque<>(ImmutableList.of(rootNode));
Object2IntMap<CommandNode<CommandSource>> idMappings = new Object2IntLinkedOpenCustomHashMap<>( Object2IntMap<CommandNode<CommandSource>> idMappings = new Object2IntLinkedOpenCustomHashMap<>(

Datei anzeigen

@ -7,6 +7,7 @@ import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketDirection; import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.UUID; import java.util.UUID;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -14,6 +15,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundBossBarPacket implements Packet { public class ClientboundBossBarPacket implements Packet {
public static final PacketReader<ClientboundBossBarPacket> DECODER = PacketReader.method(ClientboundBossBarPacket::new); 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 ADD = 0;
public static final int REMOVE = 1; public static final int REMOVE = 1;
@ -122,7 +124,7 @@ public class ClientboundBossBarPacket implements Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
if (uuid == null) { if (uuid == null) {
throw new IllegalStateException("No boss bar UUID specified"); throw new IllegalStateException("No boss bar UUID specified");
} }

Datei anzeigen

@ -7,12 +7,14 @@ import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketDirection; import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.UUID; import java.util.UUID;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundChatPacket implements Packet { public class ClientboundChatPacket implements Packet {
public static final PacketReader<ClientboundChatPacket> DECODER = PacketReader.method(ClientboundChatPacket::new); 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 CHAT_TYPE = (byte) 0;
public static final byte SYSTEM_TYPE = (byte) 1; public static final byte SYSTEM_TYPE = (byte) 1;
@ -43,7 +45,7 @@ public class ClientboundChatPacket implements Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
if (message == null) { if (message == null) {
throw new IllegalStateException("Message is not specified"); throw new IllegalStateException("Message is not specified");
} }

Datei anzeigen

@ -8,12 +8,14 @@ import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketDirection; import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundDisconnectPacket implements Packet { public class ClientboundDisconnectPacket implements Packet {
public static final PacketReader<ClientboundDisconnectPacket> DECODER = PacketReader.method(ClientboundDisconnectPacket::new); public static final PacketReader<ClientboundDisconnectPacket> DECODER = PacketReader.method(ClientboundDisconnectPacket::new);
public static final PacketWriter<ClientboundDisconnectPacket> ENCODER = PacketWriter.deprecatedEncode();
private @Nullable String reason; private @Nullable String reason;
@ -41,7 +43,7 @@ public class ClientboundDisconnectPacket implements Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
if (reason == null) { if (reason == null) {
throw new IllegalStateException("No reason specified."); throw new IllegalStateException("No reason specified.");
} }

Datei anzeigen

@ -9,10 +9,12 @@ import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketDirection; import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ClientboundEncryptionRequestPacket implements Packet { public class ClientboundEncryptionRequestPacket implements Packet {
public static final PacketReader<ClientboundEncryptionRequestPacket> DECODER = PacketReader.method(ClientboundEncryptionRequestPacket::new); public static final PacketReader<ClientboundEncryptionRequestPacket> DECODER = PacketReader.method(ClientboundEncryptionRequestPacket::new);
public static final PacketWriter<ClientboundEncryptionRequestPacket> ENCODER = PacketWriter.deprecatedEncode();
private String serverId = ""; private String serverId = "";
private byte[] publicKey = EMPTY_BYTE_ARRAY; private byte[] publicKey = EMPTY_BYTE_ARRAY;
@ -48,7 +50,7 @@ public class ClientboundEncryptionRequestPacket implements Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
ProtocolUtils.writeString(buf, this.serverId); ProtocolUtils.writeString(buf, this.serverId);
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {

Datei anzeigen

@ -6,13 +6,14 @@ import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.packet.Packet; 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.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ClientboundHeaderAndFooterPacket implements Packet { public class ClientboundHeaderAndFooterPacket implements Packet {
public static final PacketReader<ClientboundHeaderAndFooterPacket> DECODER = PacketReader.method(ClientboundHeaderAndFooterPacket::new); 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 String EMPTY_COMPONENT = "{\"translate\":\"\"}";
private static final ClientboundHeaderAndFooterPacket RESET private static final ClientboundHeaderAndFooterPacket RESET
@ -31,7 +32,7 @@ public class ClientboundHeaderAndFooterPacket implements Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
writeString(buf, header); writeString(buf, header);
writeString(buf, footer); writeString(buf, footer);
} }

Datei anzeigen

@ -1,6 +1,5 @@
package com.velocitypowered.proxy.network.packet.clientbound; package com.velocitypowered.proxy.network.packet.clientbound;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.registry.DimensionData; 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.kyori.adventure.nbt.BinaryTagIO; import net.kyori.adventure.nbt.BinaryTagIO;
import net.kyori.adventure.nbt.BinaryTagTypes; import net.kyori.adventure.nbt.BinaryTagTypes;
@ -20,6 +20,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundJoinGamePacket implements Packet { public class ClientboundJoinGamePacket implements Packet {
public static final PacketReader<ClientboundJoinGamePacket> DECODER = PacketReader.method(ClientboundJoinGamePacket::new); 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 static final BinaryTagIO.Reader JOINGAME_READER = BinaryTagIO.reader(2 * 1024 * 1024);
private int entityId; private int entityId;
@ -243,7 +244,7 @@ public class ClientboundJoinGamePacket implements Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
buf.writeInt(entityId); buf.writeInt(entityId);
if (version.gte(ProtocolVersion.MINECRAFT_1_16_2)) { if (version.gte(ProtocolVersion.MINECRAFT_1_16_2)) {
buf.writeBoolean(isHardcore); buf.writeBoolean(isHardcore);

Datei anzeigen

@ -4,9 +4,11 @@ import com.velocitypowered.proxy.network.packet.AbstractKeepAlivePacket;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
public class ClientboundKeepAlivePacket extends AbstractKeepAlivePacket implements Packet { public class ClientboundKeepAlivePacket extends AbstractKeepAlivePacket implements Packet {
public static final PacketReader<ClientboundKeepAlivePacket> DECODER = decoder(ClientboundKeepAlivePacket::new); public static final PacketReader<ClientboundKeepAlivePacket> DECODER = decoder(ClientboundKeepAlivePacket::new);
public static final PacketWriter<ClientboundKeepAlivePacket> ENCODER = encoder();
public ClientboundKeepAlivePacket(final long randomId) { public ClientboundKeepAlivePacket(final long randomId) {
super(randomId); super(randomId);

Datei anzeigen

@ -4,9 +4,9 @@ import com.google.common.base.MoreObjects;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet; 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.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder; import io.netty.buffer.DefaultByteBufHolder;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -14,17 +14,18 @@ import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundLoginPluginMessagePacket extends DefaultByteBufHolder implements Packet { 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 int id = ProtocolUtils.readVarInt(buf);
final String channel = ProtocolUtils.readString(buf); final String channel = ProtocolUtils.readString(buf);
final ByteBuf data; final ByteBuf data;
if (buf.isReadable()) { if (buf.isReadable()) {
data = buf.readSlice(buf.readableBytes()); data = buf.readRetainedSlice(buf.readableBytes());
} else { } else {
data = Unpooled.EMPTY_BUFFER; data = Unpooled.EMPTY_BUFFER;
} }
return new ClientboundLoginPluginMessagePacket(id, channel, data); return new ClientboundLoginPluginMessagePacket(id, channel, data);
}; };
public static final PacketWriter<ClientboundLoginPluginMessagePacket> ENCODER = PacketWriter.deprecatedEncode();
private final int id; private final int id;
private final @Nullable String channel; private final @Nullable String channel;
@ -36,7 +37,7 @@ public class ClientboundLoginPluginMessagePacket extends DefaultByteBufHolder im
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
ProtocolUtils.writeVarInt(buf, id); ProtocolUtils.writeVarInt(buf, id);
if (channel == null) { if (channel == null) {
throw new IllegalStateException("Channel is not specified!"); throw new IllegalStateException("Channel is not specified!");

Datei anzeigen

@ -10,6 +10,7 @@ import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketDirection; import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -20,6 +21,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundPlayerListItemPacket implements Packet { public class ClientboundPlayerListItemPacket implements Packet {
public static final PacketReader<ClientboundPlayerListItemPacket> DECODER = PacketReader.method(ClientboundPlayerListItemPacket::new); 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 ADD_PLAYER = 0;
public static final int UPDATE_GAMEMODE = 1; public static final int UPDATE_GAMEMODE = 1;
@ -96,7 +98,7 @@ public class ClientboundPlayerListItemPacket implements Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
ProtocolUtils.writeVarInt(buf, action); ProtocolUtils.writeVarInt(buf, action);
ProtocolUtils.writeVarInt(buf, items.size()); ProtocolUtils.writeVarInt(buf, items.size());

Datei anzeigen

@ -4,11 +4,13 @@ import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ClientboundPluginMessagePacket extends AbstractPluginMessagePacket<ClientboundPluginMessagePacket> implements Packet { public class ClientboundPluginMessagePacket extends AbstractPluginMessagePacket<ClientboundPluginMessagePacket> implements Packet {
public static final Factory<ClientboundPluginMessagePacket> FACTORY = ClientboundPluginMessagePacket::new; public static final Factory<ClientboundPluginMessagePacket> FACTORY = ClientboundPluginMessagePacket::new;
public static final PacketReader<ClientboundPluginMessagePacket> DECODER = decoder(FACTORY); public static final PacketReader<ClientboundPluginMessagePacket> DECODER = decoder(FACTORY);
public static final PacketWriter<ClientboundPluginMessagePacket> ENCODER = encoder();
public ClientboundPluginMessagePacket(final String channel, final ByteBuf backing) { public ClientboundPluginMessagePacket(final String channel, final ByteBuf backing) {
super(channel, backing); super(channel, backing);

Datei anzeigen

@ -4,18 +4,19 @@ import com.google.common.base.MoreObjects;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet; 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.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.Objects; import java.util.Objects;
public class ClientboundResourcePackRequestPacket implements Packet { 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 url = ProtocolUtils.readString(buf);
final String hash = ProtocolUtils.readString(buf); final String hash = ProtocolUtils.readString(buf);
return new ClientboundResourcePackRequestPacket(url, hash); return new ClientboundResourcePackRequestPacket(url, hash);
}; };
public static final PacketWriter<ClientboundResourcePackRequestPacket> ENCODER = PacketWriter.deprecatedEncode();
private final String url; private final String url;
private final String hash; private final String hash;
@ -26,7 +27,7 @@ public class ClientboundResourcePackRequestPacket implements Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion protocolVersion) { public void encode(ByteBuf buf, ProtocolVersion protocolVersion) {
ProtocolUtils.writeString(buf, url); ProtocolUtils.writeString(buf, url);
ProtocolUtils.writeString(buf, hash); ProtocolUtils.writeString(buf, hash);
} }

Datei anzeigen

@ -9,12 +9,14 @@ import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketDirection; import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.kyori.adventure.nbt.BinaryTagIO; import net.kyori.adventure.nbt.BinaryTagIO;
import net.kyori.adventure.nbt.CompoundBinaryTag; import net.kyori.adventure.nbt.CompoundBinaryTag;
public class ClientboundRespawnPacket implements Packet { public class ClientboundRespawnPacket implements Packet {
public static final PacketReader<ClientboundRespawnPacket> DECODER = PacketReader.method(ClientboundRespawnPacket::new); public static final PacketReader<ClientboundRespawnPacket> DECODER = PacketReader.method(ClientboundRespawnPacket::new);
public static final PacketWriter<ClientboundRespawnPacket> ENCODER = PacketWriter.deprecatedEncode();
private int dimension; private int dimension;
private long partialHashedSeed; private long partialHashedSeed;
@ -135,7 +137,7 @@ public class ClientboundRespawnPacket implements Packet {
} }
@Override @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)) {
if (version.gte(ProtocolVersion.MINECRAFT_1_16_2)) { if (version.gte(ProtocolVersion.MINECRAFT_1_16_2)) {
ProtocolUtils.writeCompoundTag(buf, currentDimensionData.serializeDimensionDetails()); ProtocolUtils.writeCompoundTag(buf, currentDimensionData.serializeDimensionDetails());

Datei anzeigen

@ -5,15 +5,15 @@ import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.util.UuidUtils; import com.velocitypowered.api.util.UuidUtils;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet; 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.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
public class ClientboundServerLoginSuccessPacket implements Packet { 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; final UUID uuid;
if (version.gte(ProtocolVersion.MINECRAFT_1_16)) { if (version.gte(ProtocolVersion.MINECRAFT_1_16)) {
uuid = ProtocolUtils.readUuidIntArray(buf); uuid = ProtocolUtils.readUuidIntArray(buf);
@ -25,6 +25,7 @@ public class ClientboundServerLoginSuccessPacket implements Packet {
final String username = ProtocolUtils.readString(buf, 16); final String username = ProtocolUtils.readString(buf, 16);
return new ClientboundServerLoginSuccessPacket(uuid, username); return new ClientboundServerLoginSuccessPacket(uuid, username);
}; };
public static final PacketWriter<ClientboundServerLoginSuccessPacket> ENCODER = PacketWriter.deprecatedEncode();
private final UUID uuid; private final UUID uuid;
private final String username; private final String username;
@ -35,7 +36,7 @@ public class ClientboundServerLoginSuccessPacket implements Packet {
} }
@Override @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)) {
ProtocolUtils.writeUuidIntArray(buf, uuid); ProtocolUtils.writeUuidIntArray(buf, uuid);
} else if (version.gte(ProtocolVersion.MINECRAFT_1_7_6)) { } else if (version.gte(ProtocolVersion.MINECRAFT_1_7_6)) {

Datei anzeigen

@ -1,19 +1,19 @@
package com.velocitypowered.proxy.network.packet.clientbound; package com.velocitypowered.proxy.network.packet.clientbound;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet; 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.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; 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 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); final int threshold = ProtocolUtils.readVarInt(buf);
return new ClientboundSetCompressionPacket(threshold); return new ClientboundSetCompressionPacket(threshold);
}; };
public static final PacketWriter<ClientboundSetCompressionPacket> ENCODER = (buf, packet, version) ->
ProtocolUtils.writeVarInt(buf, packet.threshold);
private final int threshold; private final int threshold;
@ -21,11 +21,6 @@ public class ClientboundSetCompressionPacket implements Packet {
this.threshold = threshold; this.threshold = threshold;
} }
@Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
ProtocolUtils.writeVarInt(buf, threshold);
}
@Override @Override
public boolean handle(PacketHandler handler) { public boolean handle(PacketHandler handler) {
return handler.handle(this); return handler.handle(this);

Datei anzeigen

@ -4,9 +4,11 @@ import com.velocitypowered.proxy.network.packet.AbstractStatusPingPacket;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
public class ClientboundStatusPingPacket extends AbstractStatusPingPacket implements Packet { public class ClientboundStatusPingPacket extends AbstractStatusPingPacket implements Packet {
public static final PacketReader<ClientboundStatusPingPacket> DECODER = decoder(ClientboundStatusPingPacket::new); public static final PacketReader<ClientboundStatusPingPacket> DECODER = decoder(ClientboundStatusPingPacket::new);
public static final PacketWriter<ClientboundStatusPingPacket> ENCODER = encoder();
public ClientboundStatusPingPacket(final long randomId) { public ClientboundStatusPingPacket(final long randomId) {
super(randomId); super(randomId);

Datei anzeigen

@ -4,17 +4,19 @@ import com.google.common.base.MoreObjects;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet; 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.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundStatusResponsePacket implements Packet { 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); final String status = ProtocolUtils.readString(buf, Short.MAX_VALUE);
return new ClientboundStatusResponsePacket(status); return new ClientboundStatusResponsePacket(status);
}; };
public static final PacketWriter<ClientboundStatusResponsePacket> ENCODER = (buf, packet, version) ->
ProtocolUtils.writeString(buf, packet.status);
private final @Nullable CharSequence status; private final @Nullable CharSequence status;
@ -23,7 +25,7 @@ public class ClientboundStatusResponsePacket implements Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
if (status == null) { if (status == null) {
throw new IllegalStateException("Status is not specified"); throw new IllegalStateException("Status is not specified");
} }

Datei anzeigen

@ -7,6 +7,7 @@ import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketDirection; import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -15,6 +16,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundTabCompleteResponsePacket implements Packet { public class ClientboundTabCompleteResponsePacket implements Packet {
public static final PacketReader<ClientboundTabCompleteResponsePacket> DECODER = PacketReader.method(ClientboundTabCompleteResponsePacket::new); public static final PacketReader<ClientboundTabCompleteResponsePacket> DECODER = PacketReader.method(ClientboundTabCompleteResponsePacket::new);
public static final PacketWriter<ClientboundTabCompleteResponsePacket> ENCODER = PacketWriter.deprecatedEncode();
private int transactionId; private int transactionId;
private int start; private int start;
@ -71,7 +73,7 @@ public class ClientboundTabCompleteResponsePacket implements Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
if (version.gte(ProtocolVersion.MINECRAFT_1_13)) { if (version.gte(ProtocolVersion.MINECRAFT_1_13)) {
ProtocolUtils.writeVarInt(buf, this.transactionId); ProtocolUtils.writeVarInt(buf, this.transactionId);
ProtocolUtils.writeVarInt(buf, this.start); ProtocolUtils.writeVarInt(buf, this.start);

Datei anzeigen

@ -5,9 +5,9 @@ import com.google.common.primitives.Ints;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet; 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.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import com.velocitypowered.proxy.util.DurationUtils; import com.velocitypowered.proxy.util.DurationUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.Arrays; import java.util.Arrays;
@ -16,6 +16,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundTitlePacket implements Packet { public class ClientboundTitlePacket implements Packet {
public static final PacketReader<ClientboundTitlePacket> DECODER = PacketReader.unsupported(); public static final PacketReader<ClientboundTitlePacket> DECODER = PacketReader.unsupported();
public static final PacketWriter<ClientboundTitlePacket> ENCODER = PacketWriter.deprecatedEncode();
public static ClientboundTitlePacket hide(final ProtocolVersion version) { public static ClientboundTitlePacket hide(final ProtocolVersion version) {
return version.gte(ProtocolVersion.MINECRAFT_1_11) return version.gte(ProtocolVersion.MINECRAFT_1_11)
@ -92,7 +93,7 @@ public class ClientboundTitlePacket implements Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
ProtocolUtils.writeVarInt(buf, action); ProtocolUtils.writeVarInt(buf, action);
if (version.gte(ProtocolVersion.MINECRAFT_1_11)) { if (version.gte(ProtocolVersion.MINECRAFT_1_11)) {
// 1.11+ shifted the action enum by 1 to handle the action bar // 1.11+ shifted the action enum by 1 to handle the action bar

Datei anzeigen

@ -2,14 +2,13 @@ package com.velocitypowered.proxy.network.packet.legacy;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.packet.Packet; 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.PacketHandler;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class LegacyHandshakePacket implements LegacyPacket, Packet { public class LegacyHandshakePacket implements LegacyPacket, Packet {
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

Datei anzeigen

@ -2,7 +2,6 @@ package com.velocitypowered.proxy.network.packet.legacy;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.packet.Packet; 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.PacketHandler;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -24,7 +23,7 @@ public class LegacyPingPacket implements LegacyPacket, Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

Datei anzeigen

@ -1,19 +1,19 @@
package com.velocitypowered.proxy.network.packet.serverbound; package com.velocitypowered.proxy.network.packet.serverbound;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet; 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.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; 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 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); final String message = ProtocolUtils.readString(buf);
return new ServerboundChatPacket(message); 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; public static final int MAX_MESSAGE_LENGTH = 256;
@ -23,11 +23,6 @@ public class ServerboundChatPacket implements Packet {
this.message = message; this.message = message;
} }
@Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
ProtocolUtils.writeString(buf, message);
}
@Override @Override
public boolean handle(PacketHandler handler) { public boolean handle(PacketHandler handler) {
return handler.handle(this); return handler.handle(this);

Datei anzeigen

@ -7,11 +7,13 @@ import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketDirection; import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ServerboundClientSettingsPacket implements Packet { public class ServerboundClientSettingsPacket implements Packet {
public static final PacketReader<ServerboundClientSettingsPacket> DECODER = PacketReader.method(ServerboundClientSettingsPacket::new); public static final PacketReader<ServerboundClientSettingsPacket> DECODER = PacketReader.method(ServerboundClientSettingsPacket::new);
public static final PacketWriter<ServerboundClientSettingsPacket> ENCODER = PacketWriter.deprecatedEncode();
private @Nullable String locale; private @Nullable String locale;
private byte viewDistance; private byte viewDistance;
@ -53,7 +55,7 @@ public class ServerboundClientSettingsPacket implements Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
if (locale == null) { if (locale == null) {
throw new IllegalStateException("No locale specified"); throw new IllegalStateException("No locale specified");
} }

Datei anzeigen

@ -4,13 +4,13 @@ import com.google.common.base.MoreObjects;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet; 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.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ServerboundEncryptionResponsePacket implements Packet { 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[] sharedSecret;
final byte[] verifyToken; final byte[] verifyToken;
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
@ -22,6 +22,7 @@ public class ServerboundEncryptionResponsePacket implements Packet {
} }
return new ServerboundEncryptionResponsePacket(sharedSecret, verifyToken); return new ServerboundEncryptionResponsePacket(sharedSecret, verifyToken);
}; };
public static final PacketWriter<ServerboundEncryptionResponsePacket> ENCODER = PacketWriter.deprecatedEncode();
private final byte[] sharedSecret; private final byte[] sharedSecret;
private final byte[] verifyToken; private final byte[] verifyToken;
@ -32,7 +33,7 @@ public class ServerboundEncryptionResponsePacket implements Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
ProtocolUtils.writeByteArray(buf, sharedSecret); ProtocolUtils.writeByteArray(buf, sharedSecret);
ProtocolUtils.writeByteArray(buf, verifyToken); ProtocolUtils.writeByteArray(buf, verifyToken);

Datei anzeigen

@ -4,13 +4,13 @@ import com.google.common.base.MoreObjects;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet; 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.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ServerboundHandshakePacket implements Packet { 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); int realProtocolVersion = ProtocolUtils.readVarInt(buf);
final ProtocolVersion protocolVersion = ProtocolVersion.getProtocolVersion(realProtocolVersion); final ProtocolVersion protocolVersion = ProtocolVersion.getProtocolVersion(realProtocolVersion);
final String hostname = ProtocolUtils.readString(buf); final String hostname = ProtocolUtils.readString(buf);
@ -18,6 +18,7 @@ public class ServerboundHandshakePacket implements Packet {
final int nextStatus = ProtocolUtils.readVarInt(buf); final int nextStatus = ProtocolUtils.readVarInt(buf);
return new ServerboundHandshakePacket(protocolVersion, hostname, port, nextStatus); return new ServerboundHandshakePacket(protocolVersion, hostname, port, nextStatus);
}; };
public static final PacketWriter<ServerboundHandshakePacket> ENCODER = PacketWriter.deprecatedEncode();
private ProtocolVersion protocolVersion; private ProtocolVersion protocolVersion;
private String serverAddress = ""; private String serverAddress = "";
@ -35,7 +36,7 @@ public class ServerboundHandshakePacket implements Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion ignored) { public void encode(ByteBuf buf, ProtocolVersion ignored) {
ProtocolUtils.writeVarInt(buf, this.protocolVersion.getProtocol()); ProtocolUtils.writeVarInt(buf, this.protocolVersion.getProtocol());
ProtocolUtils.writeString(buf, this.serverAddress); ProtocolUtils.writeString(buf, this.serverAddress);
buf.writeShort(this.port); buf.writeShort(this.port);

Datei anzeigen

@ -4,9 +4,11 @@ import com.velocitypowered.proxy.network.packet.AbstractKeepAlivePacket;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
public class ServerboundKeepAlivePacket extends AbstractKeepAlivePacket implements Packet { public class ServerboundKeepAlivePacket extends AbstractKeepAlivePacket implements Packet {
public static final PacketReader<ServerboundKeepAlivePacket> DECODER = decoder(ServerboundKeepAlivePacket::new); public static final PacketReader<ServerboundKeepAlivePacket> DECODER = decoder(ServerboundKeepAlivePacket::new);
public static final PacketWriter<ServerboundKeepAlivePacket> ENCODER = encoder();
public ServerboundKeepAlivePacket(final long randomId) { public ServerboundKeepAlivePacket(final long randomId) {
super(randomId); super(randomId);

Datei anzeigen

@ -4,9 +4,9 @@ import com.google.common.base.MoreObjects;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet; 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.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder; import io.netty.buffer.DefaultByteBufHolder;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -14,7 +14,7 @@ import java.util.Objects;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
public class ServerboundLoginPluginResponsePacket extends DefaultByteBufHolder implements Packet { 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 int id = ProtocolUtils.readVarInt(buf);
final boolean success = buf.readBoolean(); final boolean success = buf.readBoolean();
final ByteBuf data; final ByteBuf data;
@ -25,6 +25,7 @@ public class ServerboundLoginPluginResponsePacket extends DefaultByteBufHolder i
} }
return new ServerboundLoginPluginResponsePacket(id, success, data); return new ServerboundLoginPluginResponsePacket(id, success, data);
}; };
public static final PacketWriter<ServerboundLoginPluginResponsePacket> ENCODER = PacketWriter.deprecatedEncode();
private final int id; private final int id;
private final boolean success; private final boolean success;
@ -36,7 +37,7 @@ public class ServerboundLoginPluginResponsePacket extends DefaultByteBufHolder i
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
ProtocolUtils.writeVarInt(buf, id); ProtocolUtils.writeVarInt(buf, id);
buf.writeBoolean(success); buf.writeBoolean(success);
buf.writeBytes(content()); buf.writeBytes(content());

Datei anzeigen

@ -4,11 +4,13 @@ import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ServerboundPluginMessagePacket extends AbstractPluginMessagePacket<ServerboundPluginMessagePacket> implements Packet { public class ServerboundPluginMessagePacket extends AbstractPluginMessagePacket<ServerboundPluginMessagePacket> implements Packet {
public static final Factory<ServerboundPluginMessagePacket> FACTORY = ServerboundPluginMessagePacket::new; public static final Factory<ServerboundPluginMessagePacket> FACTORY = ServerboundPluginMessagePacket::new;
public static final PacketReader<ServerboundPluginMessagePacket> DECODER = decoder(FACTORY); public static final PacketReader<ServerboundPluginMessagePacket> DECODER = decoder(FACTORY);
public static final PacketWriter<ServerboundPluginMessagePacket> ENCODER = encoder();
public ServerboundPluginMessagePacket(final String channel, final ByteBuf backing) { public ServerboundPluginMessagePacket(final String channel, final ByteBuf backing) {
super(channel, backing); super(channel, backing);

Datei anzeigen

@ -5,14 +5,14 @@ import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent.Status
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet; 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.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ServerboundResourcePackResponsePacket implements Packet { 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; final String hash;
if (version.lte(ProtocolVersion.MINECRAFT_1_9_4)) { if (version.lte(ProtocolVersion.MINECRAFT_1_9_4)) {
hash = ProtocolUtils.readString(buf); hash = ProtocolUtils.readString(buf);
@ -22,6 +22,7 @@ public class ServerboundResourcePackResponsePacket implements Packet {
final Status status = Status.values()[ProtocolUtils.readVarInt(buf)]; final Status status = Status.values()[ProtocolUtils.readVarInt(buf)];
return new ServerboundResourcePackResponsePacket(hash, status); return new ServerboundResourcePackResponsePacket(hash, status);
}; };
public static final PacketWriter<ServerboundResourcePackResponsePacket> ENCODER = PacketWriter.deprecatedEncode();
private final @Nullable String hash; private final @Nullable String hash;
private final Status status; private final Status status;
@ -32,7 +33,7 @@ public class ServerboundResourcePackResponsePacket implements Packet {
} }
@Override @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)) { if (protocolVersion.lte(ProtocolVersion.MINECRAFT_1_9_4)) {
ProtocolUtils.writeString(buf, hash); ProtocolUtils.writeString(buf, hash);
} }

Datei anzeigen

@ -4,9 +4,9 @@ import com.google.common.base.MoreObjects;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet; 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.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import com.velocitypowered.proxy.util.except.QuietDecoderException; import com.velocitypowered.proxy.util.except.QuietDecoderException;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.Objects; import java.util.Objects;
@ -14,13 +14,15 @@ import java.util.Objects;
public class ServerboundServerLoginPacket implements Packet { public class ServerboundServerLoginPacket implements Packet {
private static final QuietDecoderException EMPTY_USERNAME = new QuietDecoderException("Empty username!"); 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); final String username = ProtocolUtils.readString(buf, 16);
if (username.isEmpty()) { if (username.isEmpty()) {
throw EMPTY_USERNAME; throw EMPTY_USERNAME;
} }
return new ServerboundServerLoginPacket(username); return new ServerboundServerLoginPacket(username);
}; };
public static final PacketWriter<ServerboundServerLoginPacket> ENCODER = (buf, packet, version) ->
ProtocolUtils.writeString(buf, packet.username);
private final String username; private final String username;
@ -28,11 +30,6 @@ public class ServerboundServerLoginPacket implements Packet {
this.username = Objects.requireNonNull(username, "username"); this.username = Objects.requireNonNull(username, "username");
} }
@Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
ProtocolUtils.writeString(buf, username);
}
@Override @Override
public boolean handle(PacketHandler handler) { public boolean handle(PacketHandler handler) {
return handler.handle(this); return handler.handle(this);

Datei anzeigen

@ -4,9 +4,11 @@ import com.velocitypowered.proxy.network.packet.AbstractStatusPingPacket;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
public class ServerboundStatusPingPacket extends AbstractStatusPingPacket implements Packet { public class ServerboundStatusPingPacket extends AbstractStatusPingPacket implements Packet {
public static final PacketReader<ServerboundStatusPingPacket> DECODER = decoder(ServerboundStatusPingPacket::new); public static final PacketReader<ServerboundStatusPingPacket> DECODER = decoder(ServerboundStatusPingPacket::new);
public static final PacketWriter<ServerboundStatusPingPacket> ENCODER = encoder();
public ServerboundStatusPingPacket(final long randomId) { public ServerboundStatusPingPacket(final long randomId) {
super(randomId); super(randomId);

Datei anzeigen

@ -2,23 +2,19 @@ package com.velocitypowered.proxy.network.packet.serverbound;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.packet.Packet; 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.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ServerboundStatusRequestPacket implements Packet { public class ServerboundStatusRequestPacket implements Packet {
public static final ServerboundStatusRequestPacket INSTANCE = new ServerboundStatusRequestPacket(); public static final ServerboundStatusRequestPacket INSTANCE = new ServerboundStatusRequestPacket();
public static final PacketReader<ServerboundStatusRequestPacket> DECODER = PacketReader.instance(INSTANCE); public static final PacketReader<ServerboundStatusRequestPacket> DECODER = PacketReader.instance(INSTANCE);
public static final PacketWriter<ServerboundStatusRequestPacket> ENCODER = PacketWriter.noop();
private ServerboundStatusRequestPacket() { private ServerboundStatusRequestPacket() {
} }
@Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) {
// There is no data to decode.
}
@Override @Override
public boolean handle(PacketHandler handler) { public boolean handle(PacketHandler handler) {
return handler.handle(this); return handler.handle(this);

Datei anzeigen

@ -11,11 +11,13 @@ import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketDirection; import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader; import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.packet.PacketWriter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ServerboundTabCompleteRequestPacket implements Packet { public class ServerboundTabCompleteRequestPacket implements Packet {
public static final PacketReader<ServerboundTabCompleteRequestPacket> DECODER = PacketReader.method(ServerboundTabCompleteRequestPacket::new); 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; private static final int VANILLA_MAX_TAB_COMPLETE_LEN = 2048;
@ -88,7 +90,7 @@ public class ServerboundTabCompleteRequestPacket implements Packet {
} }
@Override @Override
public void encode(ByteBuf buf, PacketDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolVersion version) {
if (command == null) { if (command == null) {
throw new IllegalStateException("Command is not specified"); throw new IllegalStateException("Command is not specified");
} }

Datei anzeigen

@ -6,7 +6,6 @@ import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.StateRegistry; import com.velocitypowered.proxy.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.Packet; import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketDirection; import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.util.except.QuietDecoderException;
import com.velocitypowered.proxy.util.except.QuietRuntimeException; import com.velocitypowered.proxy.util.except.QuietRuntimeException;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -56,7 +55,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
int packetId = ProtocolUtils.readVarInt(buf); int packetId = ProtocolUtils.readVarInt(buf);
Packet packet = null; Packet packet = null;
try { try {
packet = this.registry.readPacket(packetId, buf, direction, registry.version); packet = this.registry.readPacket(packetId, buf, registry.version);
} catch (Exception e) { } catch (Exception e) {
throw handleDecodeFailure(e, packet, packetId); // TODO: packet is always null throw handleDecodeFailure(e, packet, packetId); // TODO: packet is always null
} }
@ -65,14 +64,6 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
ctx.fireChannelRead(buf); ctx.fireChannelRead(buf);
} else { } else {
try { try {
doLengthSanityChecks(buf, packet);
try {
packet.decode(buf, direction, registry.version);
} catch (Exception e) {
throw handleDecodeFailure(e, packet, packetId);
}
if (buf.isReadable()) { if (buf.isReadable()) {
throw handleOverflow(packet, buf.readerIndex(), buf.writerIndex()); throw handleOverflow(packet, buf.readerIndex(), buf.writerIndex());
} }

Datei anzeigen

@ -30,9 +30,7 @@ public class MinecraftEncoder extends MessageToByteEncoder<Packet> {
@Override @Override
protected void encode(ChannelHandlerContext ctx, Packet msg, ByteBuf out) { protected void encode(ChannelHandlerContext ctx, Packet msg, ByteBuf out) {
int packetId = this.registry.getPacketId(msg); this.registry.writePacket(msg, out, registry.version);
ProtocolUtils.writeVarInt(out, packetId);
msg.encode(out, direction, registry.version);
} }
public void setProtocolVersion(final ProtocolVersion protocolVersion) { public void setProtocolVersion(final ProtocolVersion protocolVersion) {