3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

packets packets packets

Dieser Commit ist enthalten in:
Riley Park 2020-11-08 01:28:24 -08:00
Ursprung 7663f7d15f
Commit f873debb72
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: D831AF236C834E45
44 geänderte Dateien mit 426 neuen und 457 gelöschten Zeilen

Datei anzeigen

@ -3,7 +3,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:5.0.0' classpath 'com.github.jengelman.gradle.plugins:shadow:5.2.0'
} }
} }

Datei anzeigen

@ -40,39 +40,30 @@ public interface MinecraftSessionHandler {
} }
default void handleGeneric(Packet packet) { default void handleGeneric(Packet packet) {
} }
default void handleUnknown(ByteBuf buf) { default void handleUnknown(ByteBuf buf) {
} }
default void connected() { default void connected() {
} }
default void disconnected() { default void disconnected() {
} }
default void activated() { default void activated() {
} }
default void deactivated() { default void deactivated() {
} }
default void exception(Throwable throwable) { default void exception(Throwable throwable) {
} }
default void writabilityChanged() { default void writabilityChanged() {
} }
default void readCompleted() { default void readCompleted() {
} }
default boolean handle(AvailableCommandsPacket commands) { default boolean handle(AvailableCommandsPacket commands) {
@ -123,14 +114,6 @@ public interface MinecraftSessionHandler {
return false; return false;
} }
default boolean handle(LegacyHandshakePacket packet) {
return false;
}
default boolean handle(LegacyPingPacket packet) {
return false;
}
default boolean handle(LoginPluginMessagePacket packet) { default boolean handle(LoginPluginMessagePacket packet) {
return false; return false;
} }
@ -194,4 +177,14 @@ public interface MinecraftSessionHandler {
default boolean handle(ResourcePackResponsePacket packet) { default boolean handle(ResourcePackResponsePacket packet) {
return false; return false;
} }
// Legacy
default boolean handle(LegacyHandshakePacket packet) {
return false;
}
default boolean handle(LegacyPingPacket packet) {
return false;
}
} }

Datei anzeigen

@ -72,9 +72,9 @@ class LegacyForgeUtil {
* @return A copy of the reset packet * @return A copy of the reset packet
*/ */
static PluginMessagePacket resetPacket() { static PluginMessagePacket resetPacket() {
PluginMessagePacket msg = new PluginMessagePacket(); return new PluginMessagePacket(
msg.setChannel(FORGE_LEGACY_HANDSHAKE_CHANNEL); FORGE_LEGACY_HANDSHAKE_CHANNEL,
msg.replace(Unpooled.wrappedBuffer(FORGE_LEGACY_HANDSHAKE_RESET_DATA.clone())); Unpooled.wrappedBuffer(FORGE_LEGACY_HANDSHAKE_RESET_DATA.clone())
return msg; );
} }
} }

Datei anzeigen

@ -2,34 +2,10 @@ package com.velocitypowered.proxy.network;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import java.util.function.Supplier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class BackendChannelInitializerHolder implements Supplier<ChannelInitializer<Channel>> { final class BackendChannelInitializerHolder extends ChannelInitializerHolder<Channel> {
private static final Logger LOGGER = LogManager.getLogger(ConnectionManager.class);
private ChannelInitializer<Channel> initializer;
BackendChannelInitializerHolder(final ChannelInitializer<Channel> initializer) { BackendChannelInitializerHolder(final ChannelInitializer<Channel> initializer) {
this.initializer = initializer; super("backend channel", initializer);
}
@Override
public ChannelInitializer<Channel> get() {
return this.initializer;
}
/**
* Sets the channel initializer.
*
* @param initializer the new initializer to use
* @deprecated Internal implementation detail
*/
@Deprecated
public void set(final ChannelInitializer<Channel> initializer) {
LOGGER.warn("The backend channel initializer has been replaced by {}",
Thread.currentThread().getStackTrace()[2]);
this.initializer = initializer;
} }
} }

Datei anzeigen

@ -0,0 +1,37 @@
package com.velocitypowered.proxy.network;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import java.util.function.Supplier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public abstract class ChannelInitializerHolder<C extends Channel>
implements Supplier<ChannelInitializer<C>> {
private static final Logger LOGGER = LogManager.getLogger(ChannelInitializerHolder.class);
private final String name;
private ChannelInitializer<C> initializer;
ChannelInitializerHolder(final String name, final ChannelInitializer<C> initializer) {
this.name = name;
this.initializer = initializer;
}
@Override
public ChannelInitializer<C> get() {
return this.initializer;
}
/**
* Sets the channel initializer.
*
* @param initializer the new initializer to use
* @deprecated Internal implementation detail
*/
@Deprecated
public void set(final ChannelInitializer<C> initializer) {
LOGGER.warn("The {} initializer has been replaced by {}", this.name,
Thread.currentThread().getStackTrace()[2]);
this.initializer = initializer;
}
}

Datei anzeigen

@ -43,9 +43,9 @@ public final class ConnectionManager {
// These are intentionally made public for plugins like ViaVersion, which inject their own // These are intentionally made public for plugins like ViaVersion, which inject their own
// protocol logic into the proxy. // protocol logic into the proxy.
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
public final ServerChannelInitializerHolder serverChannelInitializer; public final ChannelInitializerHolder<Channel> serverChannelInitializer;
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
public final BackendChannelInitializerHolder backendChannelInitializer; public final ChannelInitializerHolder<Channel> backendChannelInitializer;
private final SeparatePoolInetNameResolver resolver; private final SeparatePoolInetNameResolver resolver;
private final AsyncHttpClient httpClient; private final AsyncHttpClient httpClient;
@ -198,7 +198,7 @@ public final class ConnectionManager {
return bossGroup; return bossGroup;
} }
public ServerChannelInitializerHolder getServerChannelInitializer() { public ChannelInitializerHolder<Channel> getServerChannelInitializer() {
return this.serverChannelInitializer; return this.serverChannelInitializer;
} }
@ -206,7 +206,7 @@ public final class ConnectionManager {
return httpClient; return httpClient;
} }
public BackendChannelInitializerHolder getBackendChannelInitializer() { public ChannelInitializerHolder<Channel> getBackendChannelInitializer() {
return this.backendChannelInitializer; return this.backendChannelInitializer;
} }
} }

Datei anzeigen

@ -2,33 +2,10 @@ package com.velocitypowered.proxy.network;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelInitializer;
import java.util.function.Supplier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class ServerChannelInitializerHolder implements Supplier<ChannelInitializer<Channel>> { final class ServerChannelInitializerHolder extends ChannelInitializerHolder<Channel> {
private static final Logger LOGGER = LogManager.getLogger(ConnectionManager.class);
private ChannelInitializer<Channel> initializer;
ServerChannelInitializerHolder(final ChannelInitializer<Channel> initializer) { ServerChannelInitializerHolder(final ChannelInitializer<Channel> initializer) {
this.initializer = initializer; super("server channel", initializer);
}
@Override
public ChannelInitializer<Channel> get() {
return this.initializer;
}
/**
* Sets the channel initializer.
* @param initializer the new initializer to use
* @deprecated Internal implementation detail
*/
@Deprecated
public void set(final ChannelInitializer<Channel> initializer) {
LOGGER.warn("The server channel initializer has been replaced by {}",
Thread.currentThread().getStackTrace()[2]);
this.initializer = initializer;
} }
} }

Datei anzeigen

@ -3,12 +3,13 @@ package com.velocitypowered.proxy.protocol;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.function.Supplier;
public interface Packet { public interface Packet {
@Deprecated @Deprecated
default void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) { default void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) {
throw new IllegalStateException(); throw new UnsupportedOperationException();
} }
void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion); void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion);
@ -16,6 +17,21 @@ public interface Packet {
boolean handle(MinecraftSessionHandler handler); boolean handle(MinecraftSessionHandler handler);
interface Decoder<P extends Packet> { interface Decoder<P extends Packet> {
P decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version); P decode(final ByteBuf buf, final ProtocolDirection direction, final ProtocolVersion version);
static <P extends Packet> Decoder<P> unsupported() {
return (buf, direction, version) -> {
throw new UnsupportedOperationException();
};
}
@Deprecated
static <P extends Packet> Decoder<P> method(final Supplier<P> factory) {
return (buf, direction, version) -> {
final P packet = factory.get();
packet.decode(buf, direction, version);
return packet;
};
}
} }
} }

Datei anzeigen

@ -59,57 +59,54 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public enum StateRegistry { public enum StateRegistry {
HANDSHAKE { HANDSHAKE(true) {
{ {
serverbound.register(HandshakePacket.class, HandshakePacket::new, serverbound.register(HandshakePacket.class, HandshakePacket.DECODER,
map(0x00, MINECRAFT_1_7_2, false)); map(0x00, MINECRAFT_1_7_2, false));
} }
}, },
STATUS { STATUS(true) {
{ {
serverbound.registerNew(StatusRequestPacket.class, StatusRequestPacket.DECODER, serverbound.register(StatusRequestPacket.class, StatusRequestPacket.DECODER,
map(0x00, MINECRAFT_1_7_2, false)); map(0x00, MINECRAFT_1_7_2, false));
serverbound.registerNew(StatusPingPacket.class, StatusPingPacket.DECODER, serverbound.register(StatusPingPacket.class, StatusPingPacket.DECODER,
map(0x01, MINECRAFT_1_7_2, false)); map(0x01, MINECRAFT_1_7_2, false));
clientbound.register(StatusResponsePacket.class, StatusResponsePacket::new, clientbound.register(StatusResponsePacket.class, StatusResponsePacket.DECODER,
map(0x00, MINECRAFT_1_7_2, false)); map(0x00, MINECRAFT_1_7_2, false));
clientbound.registerNew(StatusPingPacket.class, StatusPingPacket.DECODER, clientbound.register(StatusPingPacket.class, StatusPingPacket.DECODER,
map(0x01, MINECRAFT_1_7_2, false)); map(0x01, MINECRAFT_1_7_2, false));
} }
}, },
PLAY { PLAY(false) {
{ {
serverbound.fallback = false; serverbound.register(TabCompleteRequestPacket.class, TabCompleteRequestPacket.DECODER,
clientbound.fallback = false;
serverbound.register(TabCompleteRequestPacket.class, TabCompleteRequestPacket::new,
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),
map(0x01, MINECRAFT_1_12_1, false), map(0x01, MINECRAFT_1_12_1, false),
map(0x05, MINECRAFT_1_13, false), map(0x05, MINECRAFT_1_13, false),
map(0x06, MINECRAFT_1_14, false)); map(0x06, MINECRAFT_1_14, false));
serverbound.registerNew(ServerboundChatPacket.class, ServerboundChatPacket.DECODER, serverbound.register(ServerboundChatPacket.class, ServerboundChatPacket.DECODER,
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),
map(0x02, MINECRAFT_1_12_1, false), map(0x02, MINECRAFT_1_12_1, false),
map(0x03, MINECRAFT_1_14, false)); map(0x03, MINECRAFT_1_14, false));
serverbound.register(ClientSettingsPacket.class, ClientSettingsPacket::new, serverbound.register(ClientSettingsPacket.class, ClientSettingsPacket.DECODER,
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),
map(0x04, MINECRAFT_1_12_1, false), map(0x04, MINECRAFT_1_12_1, false),
map(0x05, MINECRAFT_1_14, false)); map(0x05, MINECRAFT_1_14, false));
serverbound.register(PluginMessagePacket.class, PluginMessagePacket::new, serverbound.register(PluginMessagePacket.class, PluginMessagePacket.DECODER,
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),
map(0x09, MINECRAFT_1_12_1, false), map(0x09, MINECRAFT_1_12_1, false),
map(0x0A, MINECRAFT_1_13, false), map(0x0A, MINECRAFT_1_13, false),
map(0x0B, MINECRAFT_1_14, false)); map(0x0B, MINECRAFT_1_14, false));
serverbound.registerNew(KeepAlivePacket.class, KeepAlivePacket.DECODER, serverbound.register(KeepAlivePacket.class, KeepAlivePacket.DECODER,
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),
@ -117,7 +114,7 @@ public enum StateRegistry {
map(0x0E, MINECRAFT_1_13, false), map(0x0E, MINECRAFT_1_13, false),
map(0x0F, MINECRAFT_1_14, false), map(0x0F, MINECRAFT_1_14, false),
map(0x10, MINECRAFT_1_16, false)); map(0x10, MINECRAFT_1_16, false));
serverbound.register(ResourcePackResponsePacket.class, ResourcePackResponsePacket::new, serverbound.register(ResourcePackResponsePacket.class, ResourcePackResponsePacket.DECODER,
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),
@ -126,29 +123,29 @@ public enum StateRegistry {
map(0x20, MINECRAFT_1_16, false), map(0x20, MINECRAFT_1_16, false),
map(0x21, MINECRAFT_1_16_2, false)); map(0x21, MINECRAFT_1_16_2, false));
clientbound.register(BossBarPacket.class, BossBarPacket::new, clientbound.register(BossBarPacket.class, BossBarPacket.DECODER,
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));
clientbound.register(ClientboundChatPacket.class, ClientboundChatPacket::new, clientbound.register(ClientboundChatPacket.class, ClientboundChatPacket.DECODER,
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),
map(0x0F, MINECRAFT_1_15, true), map(0x0F, MINECRAFT_1_15, true),
map(0x0E, MINECRAFT_1_16, true)); map(0x0E, MINECRAFT_1_16, true));
clientbound.register(TabCompleteResponsePacket.class, TabCompleteResponsePacket::new, clientbound.register(TabCompleteResponsePacket.class, TabCompleteResponsePacket.DECODER,
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),
map(0x11, MINECRAFT_1_15, false), map(0x11, MINECRAFT_1_15, false),
map(0x10, MINECRAFT_1_16, false), map(0x10, MINECRAFT_1_16, false),
map(0x0F, MINECRAFT_1_16_2, false)); map(0x0F, MINECRAFT_1_16_2, false));
clientbound.register(AvailableCommandsPacket.class, AvailableCommandsPacket::new, clientbound.register(AvailableCommandsPacket.class, AvailableCommandsPacket.DECODER,
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),
map(0x10, MINECRAFT_1_16_2, false)); map(0x10, MINECRAFT_1_16_2, false));
clientbound.register(PluginMessagePacket.class, PluginMessagePacket::new, clientbound.register(PluginMessagePacket.class, PluginMessagePacket.DECODER,
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),
@ -156,7 +153,7 @@ public enum StateRegistry {
map(0x19, MINECRAFT_1_15, false), map(0x19, MINECRAFT_1_15, false),
map(0x18, MINECRAFT_1_16, false), map(0x18, MINECRAFT_1_16, false),
map(0x17, MINECRAFT_1_16_2, false)); map(0x17, MINECRAFT_1_16_2, false));
clientbound.register(DisconnectPacket.class, DisconnectPacket::new, clientbound.register(DisconnectPacket.class, DisconnectPacket.DECODER,
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),
@ -164,7 +161,7 @@ public enum StateRegistry {
map(0x1B, MINECRAFT_1_15, false), map(0x1B, MINECRAFT_1_15, false),
map(0x1A, MINECRAFT_1_16, false), map(0x1A, MINECRAFT_1_16, false),
map(0x19, MINECRAFT_1_16_2, false)); map(0x19, MINECRAFT_1_16_2, false));
clientbound.registerNew(KeepAlivePacket.class, KeepAlivePacket.DECODER, clientbound.register(KeepAlivePacket.class, KeepAlivePacket.DECODER,
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),
@ -172,7 +169,7 @@ public enum StateRegistry {
map(0x21, MINECRAFT_1_15, false), map(0x21, MINECRAFT_1_15, false),
map(0x20, MINECRAFT_1_16, false), map(0x20, MINECRAFT_1_16, false),
map(0x1F, MINECRAFT_1_16_2, false)); map(0x1F, MINECRAFT_1_16_2, false));
clientbound.register(JoinGamePacket.class, JoinGamePacket::new, clientbound.register(JoinGamePacket.class, JoinGamePacket.DECODER,
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),
@ -180,7 +177,7 @@ public enum StateRegistry {
map(0x26, MINECRAFT_1_15, false), map(0x26, MINECRAFT_1_15, false),
map(0x25, MINECRAFT_1_16, false), map(0x25, MINECRAFT_1_16, false),
map(0x24, MINECRAFT_1_16_2, false)); map(0x24, MINECRAFT_1_16_2, false));
clientbound.register(RespawnPacket.class, RespawnPacket::new, clientbound.register(RespawnPacket.class, RespawnPacket.DECODER,
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),
@ -190,7 +187,7 @@ public enum StateRegistry {
map(0x3B, MINECRAFT_1_15, true), map(0x3B, MINECRAFT_1_15, true),
map(0x3A, MINECRAFT_1_16, true), map(0x3A, MINECRAFT_1_16, true),
map(0x39, MINECRAFT_1_16_2, true)); map(0x39, MINECRAFT_1_16_2, true));
clientbound.register(ResourcePackRequestPacket.class, ResourcePackRequestPacket::new, clientbound.register(ResourcePackRequestPacket.class, ResourcePackRequestPacket.DECODER,
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),
@ -200,7 +197,7 @@ public enum StateRegistry {
map(0x3A, MINECRAFT_1_15, true), map(0x3A, MINECRAFT_1_15, true),
map(0x39, MINECRAFT_1_16, true), map(0x39, MINECRAFT_1_16, true),
map(0x38, MINECRAFT_1_16_2, true)); map(0x38, MINECRAFT_1_16_2, true));
clientbound.register(HeaderAndFooterPacket.class, HeaderAndFooterPacket::new, clientbound.register(HeaderAndFooterPacket.class, HeaderAndFooterPacket.DECODER,
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),
@ -210,7 +207,7 @@ public enum StateRegistry {
map(0x53, MINECRAFT_1_14, true), map(0x53, MINECRAFT_1_14, true),
map(0x54, MINECRAFT_1_15, true), map(0x54, MINECRAFT_1_15, true),
map(0x53, MINECRAFT_1_16, true)); map(0x53, MINECRAFT_1_16, true));
clientbound.registerNew(TitlePacket.class, TitlePacket.DECODER, clientbound.register(TitlePacket.class, TitlePacket.DECODER,
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),
@ -219,7 +216,7 @@ public enum StateRegistry {
map(0x4F, MINECRAFT_1_14, true), map(0x4F, MINECRAFT_1_14, true),
map(0x50, MINECRAFT_1_15, true), map(0x50, MINECRAFT_1_15, true),
map(0x4F, MINECRAFT_1_16, true)); map(0x4F, MINECRAFT_1_16, true));
clientbound.register(PlayerListItemPacket.class, PlayerListItemPacket::new, clientbound.register(PlayerListItemPacket.class, PlayerListItemPacket.DECODER,
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),
@ -230,31 +227,36 @@ public enum StateRegistry {
map(0x32, MINECRAFT_1_16_2, false)); map(0x32, MINECRAFT_1_16_2, false));
} }
}, },
LOGIN { LOGIN(true) {
{ {
serverbound.register(ServerLoginPacket.class, ServerLoginPacket::new, serverbound.register(ServerLoginPacket.class, ServerLoginPacket.DECODER,
map(0x00, MINECRAFT_1_7_2, false)); map(0x00, MINECRAFT_1_7_2, false));
serverbound.register(EncryptionResponsePacket.class, EncryptionResponsePacket::new, serverbound.register(EncryptionResponsePacket.class, EncryptionResponsePacket.DECODER,
map(0x01, MINECRAFT_1_7_2, false)); map(0x01, MINECRAFT_1_7_2, false));
serverbound.register(LoginPluginResponsePacket.class, LoginPluginResponsePacket::new, serverbound.register(LoginPluginResponsePacket.class, LoginPluginResponsePacket.DECODER,
map(0x02, MINECRAFT_1_13, false)); map(0x02, MINECRAFT_1_13, false));
clientbound.register(DisconnectPacket.class, DisconnectPacket::new, clientbound.register(DisconnectPacket.class, DisconnectPacket.DECODER,
map(0x00, MINECRAFT_1_7_2, false)); map(0x00, MINECRAFT_1_7_2, false));
clientbound.register(EncryptionRequestPacket.class, EncryptionRequestPacket::new, clientbound.register(EncryptionRequestPacket.class, EncryptionRequestPacket.DECODER,
map(0x01, MINECRAFT_1_7_2, false)); map(0x01, MINECRAFT_1_7_2, false));
clientbound.register(ServerLoginSuccessPacket.class, ServerLoginSuccessPacket::new, clientbound.register(ServerLoginSuccessPacket.class, ServerLoginSuccessPacket.DECODER,
map(0x02, MINECRAFT_1_7_2, false)); map(0x02, MINECRAFT_1_7_2, false));
clientbound.registerNew(SetCompressionPacket.class, SetCompressionPacket.DECODER, clientbound.register(SetCompressionPacket.class, SetCompressionPacket.DECODER,
map(0x03, MINECRAFT_1_8, false)); map(0x03, MINECRAFT_1_8, false));
clientbound.register(LoginPluginMessagePacket.class, LoginPluginMessagePacket::new, clientbound.register(LoginPluginMessagePacket.class, LoginPluginMessagePacket.DECODER,
map(0x04, MINECRAFT_1_13, false)); map(0x04, MINECRAFT_1_13, false));
} }
}; };
public static final int STATUS_ID = 1; public static final int STATUS_ID = 1;
public static final int LOGIN_ID = 2; public static final int LOGIN_ID = 2;
public final PacketRegistry clientbound = new PacketRegistry(ProtocolDirection.CLIENTBOUND); public final PacketRegistry clientbound;
public final PacketRegistry serverbound = new PacketRegistry(ProtocolDirection.SERVERBOUND); public final PacketRegistry serverbound;
StateRegistry(boolean fallback) {
this.clientbound = new PacketRegistry(ProtocolDirection.CLIENTBOUND, fallback);
this.serverbound = new PacketRegistry(ProtocolDirection.SERVERBOUND, fallback);
}
public PacketRegistry.ProtocolRegistry getProtocolRegistry(ProtocolDirection direction, public PacketRegistry.ProtocolRegistry getProtocolRegistry(ProtocolDirection direction,
ProtocolVersion version) { ProtocolVersion version) {
@ -266,10 +268,15 @@ public enum StateRegistry {
private final ProtocolDirection direction; private final ProtocolDirection direction;
private final Map<ProtocolVersion, ProtocolRegistry> versions; private final Map<ProtocolVersion, ProtocolRegistry> versions;
private boolean fallback = true; private final boolean fallback;
PacketRegistry(ProtocolDirection direction) { PacketRegistry(ProtocolDirection direction) {
this(direction, true);
}
PacketRegistry(ProtocolDirection direction, boolean fallback) {
this.direction = direction; this.direction = direction;
this.fallback = fallback;
Map<ProtocolVersion, ProtocolRegistry> mutableVersions = new EnumMap<>(ProtocolVersion.class); Map<ProtocolVersion, ProtocolRegistry> mutableVersions = new EnumMap<>(ProtocolVersion.class);
for (ProtocolVersion version : ProtocolVersion.values()) { for (ProtocolVersion version : ProtocolVersion.values()) {
@ -292,7 +299,7 @@ public enum StateRegistry {
return registry; return registry;
} }
<P extends Packet> void registerNew(Class<P> clazz, Packet.Decoder<P> decoder, <P extends Packet> void register(Class<P> clazz, Packet.Decoder<P> decoder,
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.");
@ -338,53 +345,6 @@ public enum StateRegistry {
} }
} }
@Deprecated
<P extends Packet> void register(Class<P> clazz, Supplier<P> packetSupplier,
PacketMapping... mappings) {
if (mappings.length == 0) {
throw new IllegalArgumentException("At least one mapping must be provided.");
}
for (int i = 0; i < mappings.length; i++) {
PacketMapping current = mappings[i];
PacketMapping next = (i + 1 < mappings.length) ? mappings[i + 1] : current;
ProtocolVersion from = current.protocolVersion;
ProtocolVersion to = current == next ? getLast(SUPPORTED_VERSIONS) : next.protocolVersion;
if (from.gte(to) && from != getLast(SUPPORTED_VERSIONS)) {
throw new IllegalArgumentException(String.format(
"Next mapping version (%s) should be lower then current (%s)", to, from));
}
for (ProtocolVersion protocol : EnumSet.range(from, to)) {
if (protocol == to && next != current) {
break;
}
ProtocolRegistry registry = this.versions.get(protocol);
if (registry == null) {
throw new IllegalArgumentException("Unknown protocol version "
+ current.protocolVersion);
}
if (registry.packetIdToSupplier.containsKey(current.id)) {
throw new IllegalArgumentException("Can not register class " + clazz.getSimpleName()
+ " with id " + current.id + " for " + registry.version
+ " because another packet is already registered");
}
if (registry.packetClassToId.containsKey(clazz)) {
throw new IllegalArgumentException(clazz.getSimpleName()
+ " is already registered for version " + registry.version);
}
if (!current.encodeOnly) {
registry.packetIdToSupplier.put(current.id, packetSupplier);
}
registry.packetClassToId.put(clazz, current.id);
}
}
}
public class ProtocolRegistry { public class ProtocolRegistry {
public final ProtocolVersion version; public final ProtocolVersion version;
@ -408,7 +368,7 @@ public enum StateRegistry {
* @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
*/ */
@Deprecated @Deprecated
public @Nullable Packet createPacket(final int id) { @Nullable Packet createPacket(final int id) {
final Supplier<? extends Packet> supplier = this.packetIdToSupplier.get(id); final Supplier<? extends Packet> supplier = this.packetIdToSupplier.get(id);
if (supplier == null) { if (supplier == null) {
return null; return null;
@ -416,13 +376,22 @@ public enum StateRegistry {
return supplier.get(); return supplier.get();
} }
/**
* Attempts to create a packet from the specified {@code id}.
*
* @param id the packet ID
* @param buf the bytebuf
* @param direction the packet direction
* @param version the protocol version
* @return the packet instance, or {@code null} if the ID is not registered
*/
public @Nullable Packet decodePacket(final int id, ByteBuf buf, ProtocolDirection direction, public @Nullable Packet decodePacket(final int id, ByteBuf buf, ProtocolDirection direction,
ProtocolVersion protocolVersion) { ProtocolVersion version) {
final Packet.Decoder<? extends Packet> decoder = this.packetIdToDecoder.get(id); final Packet.Decoder<? extends Packet> decoder = this.packetIdToDecoder.get(id);
if (decoder == null) { if (decoder == null) {
return null; return null;
} }
return decoder.decode(buf, direction, protocolVersion); return decoder.decode(buf, direction, version);
} }
/** /**

Datei anzeigen

@ -53,27 +53,17 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
int originalReaderIndex = buf.readerIndex(); int originalReaderIndex = buf.readerIndex();
int packetId = ProtocolUtils.readVarInt(buf); int packetId = ProtocolUtils.readVarInt(buf);
final boolean decoded; Packet packet = null;
Packet packet = this.registry.decodePacket(packetId, buf, direction, registry.version); try {
if (packet == null) { packet = this.registry.decodePacket(packetId, buf, direction, registry.version);
packet = this.registry.createPacket(packetId); } catch (Exception e) {
decoded = false; throw handleDecodeFailure(e, packet, packetId); // TODO: packet is always null
} else {
decoded = true;
} }
if (packet == null) { if (packet == null) {
buf.readerIndex(originalReaderIndex); buf.readerIndex(originalReaderIndex);
ctx.fireChannelRead(buf); ctx.fireChannelRead(buf);
} else { } else {
try { try {
if (!decoded) {
try {
packet.decode(buf, direction, registry.version);
} catch (Exception e) {
throw handleDecodeFailure(e, packet, packetId);
}
}
if (buf.isReadable()) { if (buf.isReadable()) {
throw handleNotReadEnough(packet, packetId); throw handleNotReadEnough(packet, packetId);
} }

Datei anzeigen

@ -36,6 +36,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class AvailableCommandsPacket implements Packet { public class AvailableCommandsPacket implements Packet {
public static final Decoder<AvailableCommandsPacket> DECODER = Decoder.method(AvailableCommandsPacket::new);
private static final Command<CommandSource> PLACEHOLDER_COMMAND = source -> 0; private static final Command<CommandSource> PLACEHOLDER_COMMAND = source -> 0;
private static final byte NODE_TYPE_ROOT = 0x00; private static final byte NODE_TYPE_ROOT = 0x00;

Datei anzeigen

@ -11,6 +11,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class BossBarPacket implements Packet { public class BossBarPacket implements Packet {
public static final Decoder<BossBarPacket> DECODER = Decoder.method(BossBarPacket::new);
public static final int ADD = 0; public static final int ADD = 0;
public static final int REMOVE = 1; public static final int REMOVE = 1;
public static final int UPDATE_PERCENT = 2; public static final int UPDATE_PERCENT = 2;
@ -87,7 +89,7 @@ public class BossBarPacket implements Packet {
@Override @Override
public String toString() { public String toString() {
return "BossBar{" return "BossBarPacket{"
+ "uuid=" + uuid + "uuid=" + uuid
+ ", action=" + action + ", action=" + action
+ ", name='" + name + '\'' + ", name='" + name + '\''

Datei anzeigen

@ -10,6 +10,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientSettingsPacket implements Packet { public class ClientSettingsPacket implements Packet {
public static final Decoder<ClientSettingsPacket> DECODER = Decoder.method(ClientSettingsPacket::new);
private @Nullable String locale; private @Nullable String locale;
private byte viewDistance; private byte viewDistance;
private int chatVisibility; private int chatVisibility;
@ -84,7 +86,7 @@ public class ClientSettingsPacket implements Packet {
@Override @Override
public String toString() { public String toString() {
return "ClientSettings{" return "ClientSettingsPacket{"
+ "locale='" + locale + '\'' + "locale='" + locale + '\''
+ ", viewDistance=" + viewDistance + ", viewDistance=" + viewDistance
+ ", chatVisibility=" + chatVisibility + ", chatVisibility=" + chatVisibility

Datei anzeigen

@ -12,6 +12,8 @@ import java.util.UUID;
public class ClientboundChatPacket implements Packet { public class ClientboundChatPacket implements Packet {
public static final Decoder<ClientboundChatPacket> DECODER = Decoder.method(ClientboundChatPacket::new);
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;
public static final byte GAME_INFO_TYPE = (byte) 2; public static final byte GAME_INFO_TYPE = (byte) 2;
@ -20,7 +22,7 @@ public class ClientboundChatPacket implements Packet {
private byte type; private byte type;
private @Nullable UUID sender; private @Nullable UUID sender;
public ClientboundChatPacket() { private ClientboundChatPacket() {
} }
public ClientboundChatPacket(String message, byte type, UUID sender) { public ClientboundChatPacket(String message, byte type, UUID sender) {
@ -29,30 +31,6 @@ public class ClientboundChatPacket implements Packet {
this.sender = sender; this.sender = sender;
} }
public String getMessage() {
if (message == null) {
throw new IllegalStateException("Message is not specified");
}
return message;
}
public byte getType() {
return type;
}
public UUID getSenderUuid() {
return sender;
}
@Override
public String toString() {
return "ClientboundChatPacket{"
+ "message='" + message + '\''
+ ", type=" + type
+ ", sender=" + sender
+ '}';
}
@Override @Override
public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
message = ProtocolUtils.readString(buf); message = ProtocolUtils.readString(buf);
@ -82,4 +60,28 @@ public class ClientboundChatPacket implements Packet {
public boolean handle(MinecraftSessionHandler handler) { public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this); return handler.handle(this);
} }
public String getMessage() {
if (message == null) {
throw new IllegalStateException("Message is not specified");
}
return message;
}
public byte getType() {
return type;
}
public UUID getSenderUuid() {
return sender;
}
@Override
public String toString() {
return "ClientboundChatPacket{"
+ "message='" + message + '\''
+ ", type=" + type
+ ", sender=" + sender
+ '}';
}
} }

Datei anzeigen

@ -11,6 +11,7 @@ import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class DisconnectPacket implements Packet { public class DisconnectPacket implements Packet {
public static final Decoder<DisconnectPacket> DECODER = Decoder.method(DisconnectPacket::new);
private @Nullable String reason; private @Nullable String reason;
@ -34,7 +35,7 @@ public class DisconnectPacket implements Packet {
@Override @Override
public String toString() { public String toString() {
return "Disconnect{" return "DisconnectPacket{"
+ "reason='" + reason + '\'' + "reason='" + reason + '\''
+ '}'; + '}';
} }

Datei anzeigen

@ -11,6 +11,7 @@ import io.netty.buffer.ByteBuf;
import java.util.Arrays; import java.util.Arrays;
public class EncryptionRequestPacket implements Packet { public class EncryptionRequestPacket implements Packet {
public static final Decoder<EncryptionRequestPacket> DECODER = Decoder.method(EncryptionRequestPacket::new);
private String serverId = ""; private String serverId = "";
private byte[] publicKey = EMPTY_BYTE_ARRAY; private byte[] publicKey = EMPTY_BYTE_ARRAY;
@ -34,7 +35,7 @@ public class EncryptionRequestPacket implements Packet {
@Override @Override
public String toString() { public String toString() {
return "EncryptionRequest{" return "EncryptionRequestPacket{"
+ "publicKey=" + Arrays.toString(publicKey) + "publicKey=" + Arrays.toString(publicKey)
+ ", verifyToken=" + Arrays.toString(verifyToken) + ", verifyToken=" + Arrays.toString(verifyToken)
+ '}'; + '}';

Datei anzeigen

@ -11,6 +11,7 @@ import io.netty.buffer.ByteBuf;
import java.util.Arrays; import java.util.Arrays;
public class EncryptionResponsePacket implements Packet { public class EncryptionResponsePacket implements Packet {
public static final Decoder<EncryptionResponsePacket> DECODER = Decoder.method(EncryptionResponsePacket::new);
private byte[] sharedSecret = EMPTY_BYTE_ARRAY; private byte[] sharedSecret = EMPTY_BYTE_ARRAY;
private byte[] verifyToken = EMPTY_BYTE_ARRAY; private byte[] verifyToken = EMPTY_BYTE_ARRAY;
@ -25,7 +26,7 @@ public class EncryptionResponsePacket implements Packet {
@Override @Override
public String toString() { public String toString() {
return "EncryptionResponse{" return "EncryptionResponsePacket{"
+ "sharedSecret=" + Arrays.toString(sharedSecret) + "sharedSecret=" + Arrays.toString(sharedSecret)
+ ", verifyToken=" + Arrays.toString(verifyToken) + ", verifyToken=" + Arrays.toString(verifyToken)
+ '}'; + '}';

Datei anzeigen

@ -9,6 +9,8 @@ import io.netty.buffer.ByteBuf;
public class HandshakePacket implements Packet { public class HandshakePacket implements Packet {
public static final Decoder<HandshakePacket> DECODER = Decoder.method(HandshakePacket::new);
private ProtocolVersion protocolVersion; private ProtocolVersion protocolVersion;
private String serverAddress = ""; private String serverAddress = "";
private int port; private int port;
@ -48,7 +50,7 @@ public class HandshakePacket implements Packet {
@Override @Override
public String toString() { public String toString() {
return "Handshake{" return "HandshakePacket{"
+ "protocolVersion=" + protocolVersion + "protocolVersion=" + protocolVersion
+ ", serverAddress='" + serverAddress + '\'' + ", serverAddress='" + serverAddress + '\''
+ ", port=" + port + ", port=" + port

Datei anzeigen

@ -7,11 +7,10 @@ import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.Packet; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
public class HeaderAndFooterPacket implements Packet { public class HeaderAndFooterPacket implements Packet {
public static final Decoder<HeaderAndFooterPacket> DECODER = Decoder.method(HeaderAndFooterPacket::new);
private static final String EMPTY_COMPONENT = "{\"translate\":\"\"}"; private static final String EMPTY_COMPONENT = "{\"translate\":\"\"}";
private static final HeaderAndFooterPacket RESET = new HeaderAndFooterPacket(); private static final HeaderAndFooterPacket RESET = new HeaderAndFooterPacket();
@ -28,19 +27,6 @@ public class HeaderAndFooterPacket implements Packet {
this.footer = Preconditions.checkNotNull(footer, "footer"); this.footer = Preconditions.checkNotNull(footer, "footer");
} }
public String getHeader() {
return header;
}
public String getFooter() {
return footer;
}
@Override
public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
throw new UnsupportedOperationException("Decode is not implemented");
}
@Override @Override
public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
writeString(buf, header); writeString(buf, header);
@ -52,10 +38,12 @@ public class HeaderAndFooterPacket implements Packet {
return handler.handle(this); return handler.handle(this);
} }
public static HeaderAndFooterPacket create(net.kyori.adventure.text.Component header, public String getHeader() {
net.kyori.adventure.text.Component footer, ProtocolVersion protocolVersion) { return header;
GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(protocolVersion); }
return new HeaderAndFooterPacket(serializer.serialize(header), serializer.serialize(footer));
public String getFooter() {
return footer;
} }
public static HeaderAndFooterPacket reset() { public static HeaderAndFooterPacket reset() {

Datei anzeigen

@ -16,6 +16,7 @@ import net.kyori.adventure.nbt.ListBinaryTag;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class JoinGamePacket implements Packet { public class JoinGamePacket implements Packet {
public static final Decoder<JoinGamePacket> DECODER = Decoder.method(JoinGamePacket::new);
private int entityId; private int entityId;
private short gamemode; private short gamemode;
@ -148,7 +149,7 @@ public class JoinGamePacket implements Packet {
@Override @Override
public String toString() { public String toString() {
return "JoinGame{" return "JoinGamePacket{"
+ "entityId=" + entityId + "entityId=" + entityId
+ ", gamemode=" + gamemode + ", gamemode=" + gamemode
+ ", dimension=" + dimension + ", dimension=" + dimension

Datei anzeigen

@ -11,7 +11,7 @@ public class KeepAlivePacket implements Packet {
public static final Decoder<KeepAlivePacket> DECODER = (buf, direction, version) -> { public static final Decoder<KeepAlivePacket> DECODER = (buf, direction, version) -> {
final long randomId; final long randomId;
if (version.compareTo(ProtocolVersion.MINECRAFT_1_12_2) >= 0) { if (version.gte(ProtocolVersion.MINECRAFT_1_12_2)) {
randomId = buf.readLong(); randomId = buf.readLong();
} else if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { } else if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
randomId = ProtocolUtils.readVarInt(buf); randomId = ProtocolUtils.readVarInt(buf);
@ -38,18 +38,18 @@ public class KeepAlivePacket implements Packet {
} }
} }
public long getRandomId() {
return randomId;
}
@Override @Override
public boolean handle(MinecraftSessionHandler handler) { public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this); return handler.handle(this);
} }
public long getRandomId() {
return randomId;
}
@Override @Override
public String toString() { public String toString() {
return "KeepAlive{" return "KeepAlivePacket{"
+ "randomId=" + randomId + "randomId=" + randomId
+ '}'; + '}';
} }

Datei anzeigen

@ -5,19 +5,28 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.Packet; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class LoginPluginMessagePacket extends DeferredByteBufHolder implements Packet { public class LoginPluginMessagePacket extends DefaultByteBufHolder implements Packet {
private int id; public static final Decoder<LoginPluginMessagePacket> DECODER = (buf, direction, version) -> {
private @Nullable String channel; final int id = ProtocolUtils.readVarInt(buf);
final String channel = ProtocolUtils.readString(buf);
public LoginPluginMessagePacket() { final ByteBuf data;
super(null); if (buf.isReadable()) {
data = buf.readSlice(buf.readableBytes());
} else {
data = Unpooled.EMPTY_BUFFER;
} }
return new LoginPluginMessagePacket(id, channel, data);
};
private final int id;
private final @Nullable String channel;
public LoginPluginMessagePacket(int id, @Nullable String channel, ByteBuf data) { public LoginPluginMessagePacket(int id, @Nullable String channel, ByteBuf data) {
super(data); super(data);
@ -25,37 +34,6 @@ public class LoginPluginMessagePacket extends DeferredByteBufHolder implements P
this.channel = channel; this.channel = channel;
} }
public int getId() {
return id;
}
public String getChannel() {
if (channel == null) {
throw new IllegalStateException("Channel is not specified!");
}
return channel;
}
@Override
public String toString() {
return "LoginPluginMessage{"
+ "id=" + id
+ ", channel='" + channel + '\''
+ ", data=" + super.toString()
+ '}';
}
@Override
public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
this.id = ProtocolUtils.readVarInt(buf);
this.channel = ProtocolUtils.readString(buf);
if (buf.isReadable()) {
this.replace(buf.readSlice(buf.readableBytes()));
} else {
this.replace(Unpooled.EMPTY_BUFFER);
}
}
@Override @Override
public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
ProtocolUtils.writeVarInt(buf, id); ProtocolUtils.writeVarInt(buf, id);
@ -70,4 +48,39 @@ public class LoginPluginMessagePacket extends DeferredByteBufHolder implements P
public boolean handle(MinecraftSessionHandler handler) { public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this); return handler.handle(this);
} }
public int getId() {
return id;
}
public String getChannel() {
if (channel == null) {
throw new IllegalStateException("Channel is not specified!");
}
return channel;
}
@Override
public String toString() {
return "LoginPluginMessagePacket{"
+ "id=" + id
+ ", channel='" + channel + '\''
+ ", data=" + super.toString()
+ '}';
}
@Override
public boolean equals(final Object other) {
if(this == other) return true;
if(other == null || this.getClass() != other.getClass()) return false;
final LoginPluginMessagePacket that = (LoginPluginMessagePacket) other;
return this.id == that.id
&& Objects.equals(this.channel, that.channel)
&& super.equals(other);
}
@Override
public int hashCode() {
return Objects.hash(this.id, this.channel, super.hashCode());
}
} }

Datei anzeigen

@ -5,19 +5,28 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.Packet; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
public class LoginPluginResponsePacket extends DeferredByteBufHolder implements Packet { public class LoginPluginResponsePacket extends DefaultByteBufHolder implements Packet {
private int id; public static final Decoder<LoginPluginResponsePacket> DECODER = (buf, direction, version) -> {
private boolean success; final int id = ProtocolUtils.readVarInt(buf);
final boolean success = buf.readBoolean();
public LoginPluginResponsePacket() { final ByteBuf data;
super(Unpooled.EMPTY_BUFFER); if (buf.isReadable()) {
data = buf.readSlice(buf.readableBytes());
} else {
data = Unpooled.EMPTY_BUFFER;
} }
return new LoginPluginResponsePacket(id, success, data);
};
private final int id;
private final boolean success;
public LoginPluginResponsePacket(int id, boolean success, @MonotonicNonNull ByteBuf buf) { public LoginPluginResponsePacket(int id, boolean success, @MonotonicNonNull ByteBuf buf) {
super(buf); super(buf);
@ -25,42 +34,6 @@ public class LoginPluginResponsePacket extends DeferredByteBufHolder implements
this.success = success; this.success = success;
} }
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
@Override
public String toString() {
return "LoginPluginResponse{"
+ "id=" + id
+ ", success=" + success
+ ", data=" + super.toString()
+ '}';
}
@Override
public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
this.id = ProtocolUtils.readVarInt(buf);
this.success = buf.readBoolean();
if (buf.isReadable()) {
this.replace(buf.readSlice(buf.readableBytes()));
} else {
this.replace(Unpooled.EMPTY_BUFFER);
}
}
@Override @Override
public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
ProtocolUtils.writeVarInt(buf, id); ProtocolUtils.writeVarInt(buf, id);
@ -72,4 +45,36 @@ public class LoginPluginResponsePacket extends DeferredByteBufHolder implements
public boolean handle(MinecraftSessionHandler handler) { public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this); return handler.handle(this);
} }
public int getId() {
return id;
}
public boolean isSuccess() {
return success;
}
@Override
public String toString() {
return "LoginPluginResponsePacket{"
+ "id=" + id
+ ", success=" + success
+ ", data=" + super.toString()
+ '}';
}
@Override
public boolean equals(final Object other) {
if(this == other) return true;
if(other == null || this.getClass() != other.getClass()) return false;
final LoginPluginResponsePacket that = (LoginPluginResponsePacket) other;
return this.id == that.id
&& Objects.equals(this.success, that.success)
&& super.equals(other);
}
@Override
public int hashCode() {
return Objects.hash(this.id, this.success, super.hashCode());
}
} }

Datei anzeigen

@ -17,6 +17,7 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class PlayerListItemPacket implements Packet { public class PlayerListItemPacket implements Packet {
public static final Decoder<PlayerListItemPacket> DECODER = Decoder.method(PlayerListItemPacket::new);
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;

Datei anzeigen

@ -7,18 +7,29 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.Packet; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class PluginMessagePacket extends DeferredByteBufHolder implements Packet { public class PluginMessagePacket extends DefaultByteBufHolder implements Packet {
private @Nullable String channel; public static final Decoder<PluginMessagePacket> DECODER = (buf, direction, version) -> {
String channel = ProtocolUtils.readString(buf);
public PluginMessagePacket() { if (version.gte(ProtocolVersion.MINECRAFT_1_13)) {
super(null); channel = transformLegacyToModernChannel(channel);
} }
final ByteBuf data;
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
data = buf.readRetainedSlice(buf.readableBytes());
} else {
data = ProtocolUtils.readRetainedByteBufSlice17(buf);
}
return new PluginMessagePacket(channel, data);
};
private final @Nullable String channel;
public PluginMessagePacket(String channel, public PluginMessagePacket(String channel,
@MonotonicNonNull ByteBuf backing) { @MonotonicNonNull ByteBuf backing) {
@ -26,39 +37,6 @@ public class PluginMessagePacket extends DeferredByteBufHolder implements Packet
this.channel = channel; this.channel = channel;
} }
public String getChannel() {
if (channel == null) {
throw new IllegalStateException("Channel is not specified.");
}
return channel;
}
public void setChannel(String channel) {
this.channel = channel;
}
@Override
public String toString() {
return "PluginMessage{"
+ "channel='" + channel + '\''
+ ", data=" + super.toString()
+ '}';
}
@Override
public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
this.channel = ProtocolUtils.readString(buf);
if (version.gte(ProtocolVersion.MINECRAFT_1_13)) {
this.channel = transformLegacyToModernChannel(this.channel);
}
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
this.replace(buf.readRetainedSlice(buf.readableBytes()));
} else {
this.replace(ProtocolUtils.readRetainedByteBufSlice17(buf));
}
}
@Override @Override
public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (channel == null) { if (channel == null) {
@ -74,7 +52,6 @@ public class PluginMessagePacket extends DeferredByteBufHolder implements Packet
} else { } else {
ProtocolUtils.writeByteBuf17(content(), buf, true); // True for Forge support ProtocolUtils.writeByteBuf17(content(), buf, true); // True for Forge support
} }
} }
@Override @Override
@ -82,24 +59,16 @@ public class PluginMessagePacket extends DeferredByteBufHolder implements Packet
return handler.handle(this); return handler.handle(this);
} }
@Override public String getChannel() {
public PluginMessagePacket copy() { if (channel == null) {
return (PluginMessagePacket) super.copy(); throw new IllegalStateException("Channel is not specified.");
} }
return channel;
@Override
public PluginMessagePacket duplicate() {
return (PluginMessagePacket) super.duplicate();
}
@Override
public PluginMessagePacket retainedDuplicate() {
return (PluginMessagePacket) super.retainedDuplicate();
} }
@Override @Override
public PluginMessagePacket replace(ByteBuf content) { public PluginMessagePacket replace(ByteBuf content) {
return (PluginMessagePacket) super.replace(content); return new PluginMessagePacket(this.channel, content);
} }
@Override @Override
@ -121,4 +90,26 @@ public class PluginMessagePacket extends DeferredByteBufHolder implements Packet
public PluginMessagePacket touch(Object hint) { public PluginMessagePacket touch(Object hint) {
return (PluginMessagePacket) super.touch(hint); return (PluginMessagePacket) super.touch(hint);
} }
@Override
public String toString() {
return "PluginMessagePacket{"
+ "channel='" + channel + '\''
+ ", data=" + super.toString()
+ '}';
}
@Override
public boolean equals(final Object other) {
if(this == other) return true;
if(other == null || this.getClass() != other.getClass()) return false;
final PluginMessagePacket that = (PluginMessagePacket) other;
return Objects.equals(this.channel, that.channel)
&& super.equals(other);
}
@Override
public int hashCode() {
return Objects.hash(this.channel, super.hashCode());
}
} }

Datei anzeigen

@ -10,6 +10,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ResourcePackRequestPacket implements Packet { public class ResourcePackRequestPacket implements Packet {
public static final Decoder<ResourcePackRequestPacket> DECODER = Decoder.method(ResourcePackRequestPacket::new);
private @MonotonicNonNull String url; private @MonotonicNonNull String url;
private @MonotonicNonNull String hash; private @MonotonicNonNull String hash;
@ -52,7 +53,7 @@ public class ResourcePackRequestPacket implements Packet {
@Override @Override
public String toString() { public String toString() {
return "ResourcePackRequest{" return "ResourcePackRequestPacket{"
+ "url='" + url + '\'' + "url='" + url + '\''
+ ", hash='" + hash + '\'' + ", hash='" + hash + '\''
+ '}'; + '}';

Datei anzeigen

@ -11,6 +11,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
public class ResourcePackResponsePacket implements Packet { public class ResourcePackResponsePacket implements Packet {
public static final Decoder<ResourcePackResponsePacket> DECODER = Decoder.method(ResourcePackResponsePacket::new);
private String hash = ""; private String hash = "";
private @MonotonicNonNull Status status; private @MonotonicNonNull Status status;
@ -44,7 +46,7 @@ public class ResourcePackResponsePacket implements Packet {
@Override @Override
public String toString() { public String toString() {
return "ResourcePackResponse{" return "ResourcePackResponsePacket{"
+ "hash=" + hash + ", " + "hash=" + hash + ", "
+ "status=" + status + "status=" + status
+ '}'; + '}';

Datei anzeigen

@ -11,6 +11,7 @@ import io.netty.buffer.ByteBuf;
import net.kyori.adventure.nbt.CompoundBinaryTag; import net.kyori.adventure.nbt.CompoundBinaryTag;
public class RespawnPacket implements Packet { public class RespawnPacket implements Packet {
public static final Decoder<RespawnPacket> DECODER = Decoder.method(RespawnPacket::new);
private int dimension; private int dimension;
private long partialHashedSeed; private long partialHashedSeed;
@ -97,7 +98,7 @@ public class RespawnPacket implements Packet {
@Override @Override
public String toString() { public String toString() {
return "Respawn{" return "RespawnPacket{"
+ "dimension=" + dimension + "dimension=" + dimension
+ ", partialHashedSeed=" + partialHashedSeed + ", partialHashedSeed=" + partialHashedSeed
+ ", difficulty=" + difficulty + ", difficulty=" + difficulty

Datei anzeigen

@ -11,6 +11,7 @@ import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ServerLoginPacket implements Packet { public class ServerLoginPacket implements Packet {
public static final Decoder<ServerLoginPacket> DECODER = Decoder.method(ServerLoginPacket::new);
private static final QuietDecoderException EMPTY_USERNAME = new QuietDecoderException("Empty username!"); private static final QuietDecoderException EMPTY_USERNAME = new QuietDecoderException("Empty username!");
@ -32,7 +33,7 @@ public class ServerLoginPacket implements Packet {
@Override @Override
public String toString() { public String toString() {
return "ServerLogin{" return "ServerLoginPacket{"
+ "username='" + username + '\'' + "username='" + username + '\''
+ '}'; + '}';
} }

Datei anzeigen

@ -11,6 +11,7 @@ import java.util.UUID;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ServerLoginSuccessPacket implements Packet { public class ServerLoginSuccessPacket implements Packet {
public static final Decoder<ServerLoginSuccessPacket> DECODER = Decoder.method(ServerLoginSuccessPacket::new);
private @Nullable UUID uuid; private @Nullable UUID uuid;
private @Nullable String username; private @Nullable String username;
@ -39,7 +40,7 @@ public class ServerLoginSuccessPacket implements Packet {
@Override @Override
public String toString() { public String toString() {
return "ServerLoginSuccess{" return "ServerLoginSuccessPacket{"
+ "uuid=" + uuid + "uuid=" + uuid
+ ", username='" + username + '\'' + ", username='" + username + '\''
+ '}'; + '}';

Datei anzeigen

@ -6,7 +6,6 @@ import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
public class ServerboundChatPacket implements Packet { public class ServerboundChatPacket implements Packet {
@ -17,7 +16,7 @@ public class ServerboundChatPacket implements Packet {
public static final int MAX_MESSAGE_LENGTH = 256; public static final int MAX_MESSAGE_LENGTH = 256;
private final @Nullable String message; private final String message;
public ServerboundChatPacket(String message) { public ServerboundChatPacket(String message) {
this.message = message; this.message = message;
@ -25,27 +24,21 @@ public class ServerboundChatPacket implements Packet {
@Override @Override
public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (message == null) {
throw new IllegalStateException("Message is not specified");
}
ProtocolUtils.writeString(buf, message); ProtocolUtils.writeString(buf, message);
} }
public String getMessage() {
if (message == null) {
throw new IllegalStateException("Message is not specified");
}
return message;
}
@Override @Override
public boolean handle(MinecraftSessionHandler handler) { public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this); return handler.handle(this);
} }
public String getMessage() {
return message;
}
@Override @Override
public String toString() { public String toString() {
return "Chat{" return "ServerboundChatPacket{"
+ "message='" + message + '\'' + "message='" + message + '\''
+ '}'; + '}';
} }

Datei anzeigen

@ -36,7 +36,7 @@ public class SetCompressionPacket implements Packet {
@Override @Override
public String toString() { public String toString() {
return "SetCompression{" return "SetCompressionPacket{"
+ "threshold=" + threshold + "threshold=" + threshold
+ '}'; + '}';
} }

Datei anzeigen

@ -8,7 +8,7 @@ import io.netty.buffer.ByteBuf;
public class StatusPingPacket implements Packet { public class StatusPingPacket implements Packet {
public static Decoder<StatusPingPacket> DECODER = (buf, direction, version) -> { public static final Decoder<StatusPingPacket> DECODER = (buf, direction, version) -> {
final long randomId = buf.readLong(); final long randomId = buf.readLong();
return new StatusPingPacket(randomId); return new StatusPingPacket(randomId);
}; };

Datei anzeigen

@ -9,7 +9,7 @@ import io.netty.buffer.ByteBuf;
public class StatusRequestPacket implements Packet { public class StatusRequestPacket implements Packet {
public static final StatusRequestPacket INSTANCE = new StatusRequestPacket(); public static final StatusRequestPacket INSTANCE = new StatusRequestPacket();
public static Decoder<StatusRequestPacket> DECODER = (buf, direction, version) -> INSTANCE; public static final Decoder<StatusRequestPacket> DECODER = (buf, direction, version) -> INSTANCE;
private StatusRequestPacket() { private StatusRequestPacket() {
} }

Datei anzeigen

@ -10,34 +10,17 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class StatusResponsePacket implements Packet { public class StatusResponsePacket implements Packet {
private @Nullable CharSequence status; public static final Decoder<StatusResponsePacket> DECODER = (buf, direction, version) -> {
final String status = ProtocolUtils.readString(buf, Short.MAX_VALUE);
return new StatusResponsePacket(status);
};
public StatusResponsePacket() { private final @Nullable CharSequence status;
}
public StatusResponsePacket(CharSequence status) { public StatusResponsePacket(CharSequence status) {
this.status = status; this.status = status;
} }
public String getStatus() {
if (status == null) {
throw new IllegalStateException("Status is not specified");
}
return status.toString();
}
@Override
public String toString() {
return "StatusResponse{"
+ "status='" + status + '\''
+ '}';
}
@Override
public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
status = ProtocolUtils.readString(buf, Short.MAX_VALUE);
}
@Override @Override
public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (status == null) { if (status == null) {
@ -50,4 +33,18 @@ public class StatusResponsePacket implements Packet {
public boolean handle(MinecraftSessionHandler handler) { public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this); return handler.handle(this);
} }
public String getStatus() {
if (status == null) {
throw new IllegalStateException("Status is not specified");
}
return status.toString();
}
@Override
public String toString() {
return "StatusResponsePacket{"
+ "status='" + status + '\''
+ '}';
}
} }

Datei anzeigen

@ -15,6 +15,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class TabCompleteRequestPacket implements Packet { public class TabCompleteRequestPacket implements Packet {
public static final Decoder<TabCompleteRequestPacket> DECODER = Decoder.method(TabCompleteRequestPacket::new);
private static final int VANILLA_MAX_TAB_COMPLETE_LEN = 2048; private static final int VANILLA_MAX_TAB_COMPLETE_LEN = 2048;
private @Nullable String command; private @Nullable String command;

Datei anzeigen

@ -16,6 +16,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class TabCompleteResponsePacket implements Packet { public class TabCompleteResponsePacket implements Packet {
public static final Decoder<TabCompleteResponsePacket> DECODER = Decoder.method(TabCompleteResponsePacket::new);
private int transactionId; private int transactionId;
private int start; private int start;
private int length; private int length;
@ -51,7 +53,7 @@ public class TabCompleteResponsePacket implements Packet {
@Override @Override
public String toString() { public String toString() {
return "TabCompleteResponse{" return "TabCompleteResponsePacket{"
+ "transactionId=" + transactionId + "transactionId=" + transactionId
+ ", start=" + start + ", start=" + start
+ ", length=" + length + ", length=" + length

Datei anzeigen

@ -14,9 +14,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class TitlePacket implements Packet { public class TitlePacket implements Packet {
public static final Decoder<TitlePacket> DECODER = (buf, direction, version) -> { public static final Decoder<TitlePacket> DECODER = Decoder.unsupported();
throw new UnsupportedOperationException();
};
public static TitlePacket hide(final ProtocolVersion version) { public static TitlePacket hide(final ProtocolVersion version) {
return version.gte(ProtocolVersion.MINECRAFT_1_11) return version.gte(ProtocolVersion.MINECRAFT_1_11)

Datei anzeigen

@ -8,7 +8,7 @@ import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
public class LegacyDisconnectPacket { public class LegacyDisconnectPacket implements LegacyPacket {
private static final ServerPing.Players FAKE_PLAYERS = new ServerPing.Players(0, 0, private static final ServerPing.Players FAKE_PLAYERS = new ServerPing.Players(0, 0,
ImmutableList.of()); ImmutableList.of());

Datei anzeigen

@ -6,12 +6,7 @@ import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection; import com.velocitypowered.proxy.protocol.ProtocolDirection;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class LegacyHandshakePacket implements Packet { public class LegacyHandshakePacket implements LegacyPacket, Packet {
@Override
public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
throw new UnsupportedOperationException();
}
@Override @Override
public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {

Datei anzeigen

@ -0,0 +1,4 @@
package com.velocitypowered.proxy.protocol.packet.legacy;
public interface LegacyPacket {
}

Datei anzeigen

@ -9,7 +9,7 @@ import io.netty.buffer.ByteBuf;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class LegacyPingPacket implements Packet { public class LegacyPingPacket implements LegacyPacket, Packet {
private final LegacyMinecraftPingVersion version; private final LegacyMinecraftPingVersion version;
private final @Nullable InetSocketAddress vhost; private final @Nullable InetSocketAddress vhost;
@ -24,19 +24,6 @@ public class LegacyPingPacket implements Packet {
this.vhost = vhost; this.vhost = vhost;
} }
public LegacyMinecraftPingVersion getVersion() {
return version;
}
public @Nullable InetSocketAddress getVhost() {
return vhost;
}
@Override
public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
throw new UnsupportedOperationException();
}
@Override @Override
public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
@ -46,4 +33,12 @@ public class LegacyPingPacket implements Packet {
public boolean handle(MinecraftSessionHandler handler) { public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this); return handler.handle(this);
} }
public LegacyMinecraftPingVersion getVersion() {
return version;
}
public @Nullable InetSocketAddress getVhost() {
return vhost;
}
} }

Datei anzeigen

@ -5,6 +5,7 @@ import com.velocitypowered.api.proxy.player.TabList;
import com.velocitypowered.api.proxy.player.TabListEntry; import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.HeaderAndFooterPacket; import com.velocitypowered.proxy.protocol.packet.HeaderAndFooterPacket;
import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket; import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket;
import java.util.ArrayList; import java.util.ArrayList;
@ -15,6 +16,7 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class VelocityTabList implements TabList { public class VelocityTabList implements TabList {
@ -31,7 +33,12 @@ public class VelocityTabList implements TabList {
net.kyori.adventure.text.Component footer) { net.kyori.adventure.text.Component footer) {
Preconditions.checkNotNull(header, "header"); Preconditions.checkNotNull(header, "header");
Preconditions.checkNotNull(footer, "footer"); Preconditions.checkNotNull(footer, "footer");
connection.write(HeaderAndFooterPacket.create(header, footer, connection.getProtocolVersion())); GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(
connection.getProtocolVersion());
connection.write(new HeaderAndFooterPacket(
serializer.serialize(header),
serializer.serialize(footer)
));
} }
@Override @Override

Datei anzeigen

@ -25,7 +25,7 @@ class PacketRegistryTest {
private StateRegistry.PacketRegistry setupRegistry() { private StateRegistry.PacketRegistry setupRegistry() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolDirection.CLIENTBOUND); ProtocolDirection.CLIENTBOUND);
registry.register(HandshakePacket.class, HandshakePacket::new, registry.register(HandshakePacket.class, HandshakePacket.DECODER,
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_8, false), new StateRegistry.PacketMapping(0x01, MINECRAFT_1_8, false),
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false)); new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false));
return registry; return registry;
@ -63,7 +63,7 @@ class PacketRegistryTest {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolDirection.CLIENTBOUND); ProtocolDirection.CLIENTBOUND);
assertThrows(IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> registry.register(HandshakePacket.class, HandshakePacket::new)); () -> registry.register(HandshakePacket.class, HandshakePacket.DECODER));
assertThrows(IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> registry.getProtocolRegistry(ProtocolVersion.UNKNOWN) () -> registry.getProtocolRegistry(ProtocolVersion.UNKNOWN)
.getPacketId(new HandshakePacket())); .getPacketId(new HandshakePacket()));
@ -74,11 +74,11 @@ class PacketRegistryTest {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolDirection.CLIENTBOUND); ProtocolDirection.CLIENTBOUND);
assertThrows(IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> registry.register(HandshakePacket.class, HandshakePacket::new, () -> registry.register(HandshakePacket.class, HandshakePacket.DECODER,
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false), new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false),
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false))); new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false)));
assertThrows(IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> registry.register(HandshakePacket.class, HandshakePacket::new, () -> registry.register(HandshakePacket.class, HandshakePacket.DECODER,
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false), new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false),
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false))); new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false)));
} }
@ -87,13 +87,13 @@ class PacketRegistryTest {
void failOnDuplicate() { void failOnDuplicate() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolDirection.CLIENTBOUND); ProtocolDirection.CLIENTBOUND);
registry.register(HandshakePacket.class, HandshakePacket::new, registry.register(HandshakePacket.class, HandshakePacket.DECODER,
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false)); new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false));
assertThrows(IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> registry.register(HandshakePacket.class, HandshakePacket::new, () -> registry.register(HandshakePacket.class, HandshakePacket.DECODER,
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12, false))); new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12, false)));
assertThrows(IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> registry.registerNew(StatusPingPacket.class, StatusPingPacket.DECODER, () -> registry.register(StatusPingPacket.class, StatusPingPacket.DECODER,
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_13, false))); new StateRegistry.PacketMapping(0x00, MINECRAFT_1_13, false)));
} }
@ -101,7 +101,7 @@ class PacketRegistryTest {
void shouldNotFailWhenRegisterLatestProtocolVersion() { void shouldNotFailWhenRegisterLatestProtocolVersion() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolDirection.CLIENTBOUND); ProtocolDirection.CLIENTBOUND);
assertDoesNotThrow(() -> registry.register(HandshakePacket.class, HandshakePacket::new, assertDoesNotThrow(() -> registry.register(HandshakePacket.class, HandshakePacket.DECODER,
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false), new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false),
new StateRegistry.PacketMapping(0x01, getLast(ProtocolVersion.SUPPORTED_VERSIONS), new StateRegistry.PacketMapping(0x01, getLast(ProtocolVersion.SUPPORTED_VERSIONS),
false))); false)));
@ -111,7 +111,7 @@ class PacketRegistryTest {
void registrySuppliesCorrectPacketsByProtocol() { void registrySuppliesCorrectPacketsByProtocol() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolDirection.CLIENTBOUND); ProtocolDirection.CLIENTBOUND);
registry.register(HandshakePacket.class, HandshakePacket::new, registry.register(HandshakePacket.class, HandshakePacket.DECODER,
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false), new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false),
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12_1, false), new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12_1, false),
new StateRegistry.PacketMapping(0x02, MINECRAFT_1_13, false)); new StateRegistry.PacketMapping(0x02, MINECRAFT_1_13, false));