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

and then there was more

Dieser Commit ist enthalten in:
Riley Park 2020-11-08 17:12:05 -08:00
Ursprung 7ca40094cb
Commit 2f9bda99fb
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: D831AF236C834E45
59 geänderte Dateien mit 331 neuen und 367 gelöschten Zeilen

Datei anzeigen

@ -2,7 +2,7 @@ package com.velocitypowered.proxy.connection.backend;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeBackendPhase; import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeBackendPhase;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
/** /**
* Provides connection phase specific actions. * Provides connection phase specific actions.
@ -21,7 +21,7 @@ public interface BackendConnectionPhase {
*/ */
default boolean handle(VelocityServerConnection server, default boolean handle(VelocityServerConnection server,
ConnectedPlayer player, ConnectedPlayer player,
PluginMessagePacket message) { AbstractPluginMessagePacket<?> message) {
return false; return false;
} }

Datei anzeigen

@ -2,7 +2,7 @@ package com.velocitypowered.proxy.connection.backend;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeBackendPhase; import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeBackendPhase;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
/** /**
* Contains Vanilla {@link BackendConnectionPhase}s. * Contains Vanilla {@link BackendConnectionPhase}s.
@ -29,7 +29,7 @@ public final class BackendConnectionPhases {
@Override @Override
public boolean handle(VelocityServerConnection serverConn, public boolean handle(VelocityServerConnection serverConn,
ConnectedPlayer player, ConnectedPlayer player,
PluginMessagePacket message) { AbstractPluginMessagePacket<?> message) {
// The connection may be legacy forge. If so, the Forge handler will deal with this // The connection may be legacy forge. If so, the Forge handler will deal with this
// for us. Otherwise, we have nothing to do. // for us. Otherwise, we have nothing to do.
return LegacyForgeHandshakeBackendPhase.NOT_STARTED.handle(serverConn, player, message); return LegacyForgeHandshakeBackendPhase.NOT_STARTED.handle(serverConn, player, message);

Datei anzeigen

@ -17,14 +17,15 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler; import com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler;
import com.velocitypowered.proxy.connection.util.ConnectionMessages; import com.velocitypowered.proxy.connection.util.ConnectionMessages;
import com.velocitypowered.proxy.network.PluginMessageUtil; import com.velocitypowered.proxy.network.PluginMessageUtil;
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.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.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTabCompleteResponsePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTabCompleteResponsePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil; import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -64,7 +65,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
serverConn.getServer().addPlayer(serverConn.getPlayer()); serverConn.getServer().addPlayer(serverConn.getPlayer());
MinecraftConnection serverMc = serverConn.ensureConnected(); MinecraftConnection serverMc = serverConn.ensureConnected();
serverMc.write(PluginMessageUtil.constructChannelsPacket(serverMc.getProtocolVersion(), serverMc.write(PluginMessageUtil.constructChannelsPacket(serverMc.getProtocolVersion(),
ImmutableList.of(getBungeeCordChannel(serverMc.getProtocolVersion())) ImmutableList.of(getBungeeCordChannel(serverMc.getProtocolVersion())), ClientboundPluginMessagePacket.FACTORY
)); ));
} }
@ -102,7 +103,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(PluginMessagePacket packet) { public boolean handle(ClientboundPluginMessagePacket packet) {
if (bungeecordMessageResponder.process(packet)) { if (bungeecordMessageResponder.process(packet)) {
return true; return true;
} }
@ -123,8 +124,8 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
} }
if (PluginMessageUtil.isMcBrand(packet)) { if (PluginMessageUtil.isMcBrand(packet)) {
PluginMessagePacket rewritten = PluginMessageUtil.rewriteMinecraftBrand(packet, AbstractPluginMessagePacket<?> rewritten = PluginMessageUtil.rewriteMinecraftBrand(packet,
server.getVersion(), playerConnection.getProtocolVersion()); server.getVersion(), playerConnection.getProtocolVersion(), ClientboundPluginMessagePacket.FACTORY);
playerConnection.write(rewritten); playerConnection.write(rewritten);
return true; return true;
} }
@ -145,7 +146,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
server.getEventManager().fire(event) server.getEventManager().fire(event)
.thenAcceptAsync(pme -> { .thenAcceptAsync(pme -> {
if (pme.getResult().isAllowed() && !playerConnection.isClosed()) { if (pme.getResult().isAllowed() && !playerConnection.isClosed()) {
PluginMessagePacket copied = new PluginMessagePacket(packet.getChannel(), ClientboundPluginMessagePacket copied = new ClientboundPluginMessagePacket(packet.getChannel(),
Unpooled.wrappedBuffer(copy)); Unpooled.wrappedBuffer(copy));
playerConnection.write(copied); playerConnection.write(copied);
} }
@ -244,8 +245,8 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
@Override @Override
public void handleGeneric(Packet packet) { public void handleGeneric(Packet packet) {
if (packet instanceof PluginMessagePacket) { if (packet instanceof AbstractPluginMessagePacket<?>) {
((PluginMessagePacket) packet).retain(); ((AbstractPluginMessagePacket<?>) packet).retain();
} }
playerConnection.delayedWrite(packet); playerConnection.delayedWrite(packet);
} }

Datei anzeigen

@ -11,7 +11,8 @@ import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.network.buffer.ByteBufDataInput; import com.velocitypowered.proxy.network.buffer.ByteBufDataInput;
import com.velocitypowered.proxy.network.buffer.ByteBufDataOutput; import com.velocitypowered.proxy.network.buffer.ByteBufDataOutput;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundPluginMessagePacket;
import com.velocitypowered.proxy.server.VelocityRegisteredServer; import com.velocitypowered.proxy.server.VelocityRegisteredServer;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -45,7 +46,7 @@ public class BungeeCordMessageResponder {
this.player = player; this.player = player;
} }
public static boolean isBungeeCordMessage(PluginMessagePacket message) { public static boolean isBungeeCordMessage(AbstractPluginMessagePacket<?> message) {
return MODERN_CHANNEL.getId().equals(message.getChannel()) || LEGACY_CHANNEL.getId() return MODERN_CHANNEL.getId().equals(message.getChannel()) || LEGACY_CHANNEL.getId()
.equals(message.getChannel()); .equals(message.getChannel());
} }
@ -312,7 +313,7 @@ public class BungeeCordMessageResponder {
MinecraftConnection serverConnection = player.ensureAndGetCurrentServer().ensureConnected(); MinecraftConnection serverConnection = player.ensureAndGetCurrentServer().ensureConnected();
String chan = getBungeeCordChannel(serverConnection.getProtocolVersion()); String chan = getBungeeCordChannel(serverConnection.getProtocolVersion());
PluginMessagePacket msg = null; ServerboundPluginMessagePacket msg = null;
boolean released = false; boolean released = false;
try { try {
@ -322,7 +323,7 @@ public class BungeeCordMessageResponder {
} }
MinecraftConnection serverConn = vsc.ensureConnected(); MinecraftConnection serverConn = vsc.ensureConnected();
msg = new PluginMessagePacket(chan, buf); msg = new ServerboundPluginMessagePacket(chan, buf);
serverConn.write(msg); serverConn.write(msg);
released = true; released = true;
} finally { } finally {
@ -332,7 +333,7 @@ public class BungeeCordMessageResponder {
} }
} }
boolean process(PluginMessagePacket message) { boolean process(AbstractPluginMessagePacket<?> message) {
if (!proxy.getConfiguration().isBungeePluginChannelEnabled()) { if (!proxy.getConfiguration().isBungeePluginChannelEnabled()) {
return false; return false;
} }

Datei anzeigen

@ -11,12 +11,12 @@ import com.velocitypowered.proxy.connection.util.ConnectionRequestResults;
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.StateRegistry; import com.velocitypowered.proxy.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundLoginPluginMessagePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundLoginPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundLoginPluginResponsePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundLoginPluginResponsePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
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.buffer.Unpooled; import io.netty.buffer.Unpooled;

Datei anzeigen

@ -15,10 +15,10 @@ import com.velocitypowered.proxy.connection.util.ConnectionMessages;
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults;
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
import com.velocitypowered.proxy.network.PluginMessageUtil; import com.velocitypowered.proxy.network.PluginMessageUtil;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPluginMessagePacket;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -150,7 +150,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(PluginMessagePacket packet) { public boolean handle(ClientboundPluginMessagePacket packet) {
if (!serverConn.getPlayer().canForwardPluginMessage(serverConn.ensureConnected() if (!serverConn.getPlayer().canForwardPluginMessage(serverConn.ensureConnected()
.getProtocolVersion(), packet)) { .getProtocolVersion(), packet)) {
return true; return true;

Datei anzeigen

@ -23,8 +23,8 @@ import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
import com.velocitypowered.proxy.network.StateRegistry; import com.velocitypowered.proxy.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket;
import com.velocitypowered.proxy.server.VelocityRegisteredServer; import com.velocitypowered.proxy.server.VelocityRegisteredServer;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -234,7 +234,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
MinecraftConnection mc = ensureConnected(); MinecraftConnection mc = ensureConnected();
PluginMessagePacket message = new PluginMessagePacket(identifier.getId(), data); ServerboundPluginMessagePacket message = new ServerboundPluginMessagePacket(identifier.getId(), data);
mc.write(message); mc.write(message);
return true; return true;
} }

Datei anzeigen

@ -2,7 +2,7 @@ package com.velocitypowered.proxy.connection.client;
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeClientPhase; import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeHandshakeClientPhase;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
/** /**
* Provides connection phase specific actions. * Provides connection phase specific actions.
@ -22,7 +22,7 @@ public interface ClientConnectionPhase {
* @return true if handled, false otherwise. * @return true if handled, false otherwise.
*/ */
default boolean handle(ConnectedPlayer player, default boolean handle(ConnectedPlayer player,
PluginMessagePacket message, AbstractPluginMessagePacket<?> message,
VelocityServerConnection server) { VelocityServerConnection server) {
return false; return false;
} }

Datei anzeigen

@ -21,9 +21,11 @@ import com.velocitypowered.proxy.connection.backend.BungeeCordMessageResponder;
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
import com.velocitypowered.proxy.network.PluginMessageUtil; import com.velocitypowered.proxy.network.PluginMessageUtil;
import com.velocitypowered.proxy.network.StateRegistry; import com.velocitypowered.proxy.network.StateRegistry;
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.clientbound.ClientboundBossBarPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundBossBarPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundRespawnPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundRespawnPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTabCompleteResponsePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTabCompleteResponsePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTabCompleteResponsePacket.Offer; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTabCompleteResponsePacket.Offer;
@ -31,9 +33,9 @@ import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTitlePack
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundChatPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundChatPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundClientSettingsPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundClientSettingsPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundKeepAlivePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundKeepAlivePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundResourcePackResponsePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundResourcePackResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundTabCompleteRequestPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundTabCompleteRequestPacket;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil; import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -64,7 +66,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
private final ConnectedPlayer player; private final ConnectedPlayer player;
private boolean spawned = false; private boolean spawned = false;
private final List<UUID> serverBossBars = new ArrayList<>(); private final List<UUID> serverBossBars = new ArrayList<>();
private final Queue<PluginMessagePacket> loginPluginMessages = new ArrayDeque<>(); private final Queue<ServerboundPluginMessagePacket> loginPluginMessages = new ArrayDeque<>();
private final VelocityServer server; private final VelocityServer server;
private @Nullable ServerboundTabCompleteRequestPacket outstandingTabComplete; private @Nullable ServerboundTabCompleteRequestPacket outstandingTabComplete;
@ -83,7 +85,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
Collection<String> channels = server.getChannelRegistrar().getChannelsForProtocol(player Collection<String> channels = server.getChannelRegistrar().getChannelsForProtocol(player
.getProtocolVersion()); .getProtocolVersion());
if (!channels.isEmpty()) { if (!channels.isEmpty()) {
PluginMessagePacket register = constructChannelsPacket(player.getProtocolVersion(), channels); AbstractPluginMessagePacket<?> register = constructChannelsPacket(player.getProtocolVersion(),
channels, ClientboundPluginMessagePacket.FACTORY);
player.getConnection().write(register); player.getConnection().write(register);
player.getKnownChannels().addAll(channels); player.getKnownChannels().addAll(channels);
} }
@ -91,7 +94,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
@Override @Override
public void deactivated() { public void deactivated() {
for (PluginMessagePacket message : loginPluginMessages) { for (ServerboundPluginMessagePacket message : loginPluginMessages) {
ReferenceCountUtil.release(message); ReferenceCountUtil.release(message);
} }
} }
@ -180,7 +183,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(PluginMessagePacket packet) { public boolean handle(ServerboundPluginMessagePacket packet) {
VelocityServerConnection serverConn = player.getConnectedServer(); VelocityServerConnection serverConn = player.getConnectedServer();
MinecraftConnection backendConn = serverConn != null ? serverConn.getConnection() : null; MinecraftConnection backendConn = serverConn != null ? serverConn.getConnection() : null;
if (serverConn != null && backendConn != null) { if (serverConn != null && backendConn != null) {
@ -195,7 +198,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
backendConn.write(packet.retain()); backendConn.write(packet.retain());
} else if (PluginMessageUtil.isMcBrand(packet)) { } else if (PluginMessageUtil.isMcBrand(packet)) {
backendConn.write(PluginMessageUtil backendConn.write(PluginMessageUtil
.rewriteMinecraftBrand(packet, server.getVersion(), player.getProtocolVersion())); .rewriteMinecraftBrand(packet, server.getVersion(), player.getProtocolVersion(), ServerboundPluginMessagePacket.FACTORY));
} else if (BungeeCordMessageResponder.isBungeeCordMessage(packet)) { } else if (BungeeCordMessageResponder.isBungeeCordMessage(packet)) {
return true; return true;
} else { } else {
@ -229,7 +232,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
ByteBufUtil.getBytes(packet.content())); ByteBufUtil.getBytes(packet.content()));
server.getEventManager().fire(event).thenAcceptAsync(pme -> { server.getEventManager().fire(event).thenAcceptAsync(pme -> {
if (pme.getResult().isAllowed()) { if (pme.getResult().isAllowed()) {
PluginMessagePacket message = new PluginMessagePacket(packet.getChannel(), ServerboundPluginMessagePacket message = new ServerboundPluginMessagePacket(packet.getChannel(),
Unpooled.wrappedBuffer(copy)); Unpooled.wrappedBuffer(copy));
backendConn.write(message); backendConn.write(message);
} }
@ -265,8 +268,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
MinecraftConnection smc = serverConnection.getConnection(); MinecraftConnection smc = serverConnection.getConnection();
if (smc != null && serverConnection.getPhase().consideredComplete()) { if (smc != null && serverConnection.getPhase().consideredComplete()) {
if (packet instanceof PluginMessagePacket) { if (packet instanceof AbstractPluginMessagePacket<?>) {
((PluginMessagePacket) packet).retain(); ((AbstractPluginMessagePacket<?>) packet).retain();
} }
smc.write(packet); smc.write(packet);
} }
@ -356,11 +359,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
// Tell the server about this client's plugin message channels. // Tell the server about this client's plugin message channels.
ProtocolVersion serverVersion = serverMc.getProtocolVersion(); ProtocolVersion serverVersion = serverMc.getProtocolVersion();
if (!player.getKnownChannels().isEmpty()) { if (!player.getKnownChannels().isEmpty()) {
serverMc.delayedWrite(constructChannelsPacket(serverVersion, player.getKnownChannels())); serverMc.delayedWrite(constructChannelsPacket(serverVersion, player.getKnownChannels(), ServerboundPluginMessagePacket.FACTORY));
} }
// If we had plugin messages queued during login/FML handshake, send them now. // If we had plugin messages queued during login/FML handshake, send them now.
PluginMessagePacket pm; ServerboundPluginMessagePacket pm;
while ((pm = loginPluginMessages.poll()) != null) { while ((pm = loginPluginMessages.poll()) != null) {
serverMc.delayedWrite(pm); serverMc.delayedWrite(pm);
} }
@ -585,7 +588,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
if (serverConnection != null) { if (serverConnection != null) {
MinecraftConnection connection = serverConnection.getConnection(); MinecraftConnection connection = serverConnection.getConnection();
if (connection != null) { if (connection != null) {
PluginMessagePacket pm; ServerboundPluginMessagePacket pm;
while ((pm = loginPluginMessages.poll()) != null) { while ((pm = loginPluginMessages.poll()) != null) {
connection.write(pm); connection.write(pm);
} }

Datei anzeigen

@ -39,14 +39,15 @@ import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
import com.velocitypowered.proxy.network.PluginMessageUtil; import com.velocitypowered.proxy.network.PluginMessageUtil;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.StateRegistry; import com.velocitypowered.proxy.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundChatPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundChatPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundResourcePackRequestPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundResourcePackRequestPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTitlePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundTitlePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundChatPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundChatPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundClientSettingsPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundClientSettingsPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket;
import com.velocitypowered.proxy.server.VelocityRegisteredServer; import com.velocitypowered.proxy.server.VelocityRegisteredServer;
import com.velocitypowered.proxy.tablist.VelocityTabList; import com.velocitypowered.proxy.tablist.VelocityTabList;
import com.velocitypowered.proxy.tablist.VelocityTabListLegacy; import com.velocitypowered.proxy.tablist.VelocityTabListLegacy;
@ -659,7 +660,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
public boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data) { public boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data) {
Preconditions.checkNotNull(identifier, "identifier"); Preconditions.checkNotNull(identifier, "identifier");
Preconditions.checkNotNull(data, "data"); Preconditions.checkNotNull(data, "data");
PluginMessagePacket message = new PluginMessagePacket(identifier.getId(), ClientboundPluginMessagePacket message = new ClientboundPluginMessagePacket(identifier.getId(),
Unpooled.wrappedBuffer(data)); Unpooled.wrappedBuffer(data));
connection.write(message); connection.write(message);
return true; return true;
@ -734,7 +735,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
* @param message the plugin message to forward to the client * @param message the plugin message to forward to the client
* @return {@code true} if the message can be forwarded, {@code false} otherwise * @return {@code true} if the message can be forwarded, {@code false} otherwise
*/ */
public boolean canForwardPluginMessage(ProtocolVersion version, PluginMessagePacket message) { public boolean canForwardPluginMessage(ProtocolVersion version, AbstractPluginMessagePacket<?> message) {
boolean minecraftOrFmlMessage; boolean minecraftOrFmlMessage;
// By default, all internal Minecraft and Forge channels are forwarded from the server. // By default, all internal Minecraft and Forge channels are forwarded from the server.

Datei anzeigen

@ -4,7 +4,7 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.connection.backend.BungeeCordMessageResponder; import com.velocitypowered.proxy.connection.backend.BungeeCordMessageResponder;
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
import com.velocitypowered.proxy.network.PluginMessageUtil; import com.velocitypowered.proxy.network.PluginMessageUtil;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundPluginMessagePacket;
public class InitialConnectSessionHandler implements MinecraftSessionHandler { public class InitialConnectSessionHandler implements MinecraftSessionHandler {
@ -15,7 +15,7 @@ public class InitialConnectSessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(PluginMessagePacket packet) { public boolean handle(ServerboundPluginMessagePacket packet) {
VelocityServerConnection serverConn = player.getConnectionInFlight(); VelocityServerConnection serverConn = player.getConnectionInFlight();
if (serverConn != null) { if (serverConn != null) {
if (player.getPhase().handle(player, packet, serverConn)) { if (player.getPhase().handle(player, packet, serverConn)) {

Datei anzeigen

@ -4,8 +4,8 @@ import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.connection.InboundConnection; import com.velocitypowered.api.proxy.connection.InboundConnection;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation; import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Optional; import java.util.Optional;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;

Datei anzeigen

@ -26,12 +26,12 @@ 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.StateRegistry; import com.velocitypowered.proxy.network.StateRegistry;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundEncryptionResponsePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundEncryptionResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;

Datei anzeigen

@ -6,7 +6,7 @@ import com.velocitypowered.proxy.connection.backend.BackendConnectionPhase;
import com.velocitypowered.proxy.connection.backend.BackendConnectionPhases; import com.velocitypowered.proxy.connection.backend.BackendConnectionPhases;
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection; import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
import javax.annotation.Nullable; import javax.annotation.Nullable;
/** /**
@ -107,7 +107,7 @@ public enum LegacyForgeHandshakeBackendPhase implements BackendConnectionPhase {
@Override @Override
public final boolean handle(VelocityServerConnection serverConnection, public final boolean handle(VelocityServerConnection serverConnection,
ConnectedPlayer player, ConnectedPlayer player,
PluginMessagePacket message) { AbstractPluginMessagePacket<?> message) {
if (message.getChannel().equals(LegacyForgeConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL)) { if (message.getChannel().equals(LegacyForgeConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL)) {
// Get the phase and check if we need to start the next phase. // Get the phase and check if we need to start the next phase.
LegacyForgeHandshakeBackendPhase newPhase = getNewPhase(serverConnection, message); LegacyForgeHandshakeBackendPhase newPhase = getNewPhase(serverConnection, message);
@ -162,7 +162,7 @@ public enum LegacyForgeHandshakeBackendPhase implements BackendConnectionPhase {
* @return The phase to transition to, which may be the same as before. * @return The phase to transition to, which may be the same as before.
*/ */
private LegacyForgeHandshakeBackendPhase getNewPhase(VelocityServerConnection serverConnection, private LegacyForgeHandshakeBackendPhase getNewPhase(VelocityServerConnection serverConnection,
PluginMessagePacket packet) { AbstractPluginMessagePacket<?> packet) {
if (packetToAdvanceOn != null if (packetToAdvanceOn != null
&& LegacyForgeUtil.getHandshakePacketDiscriminator(packet) == packetToAdvanceOn) { && LegacyForgeUtil.getHandshakePacketDiscriminator(packet) == packetToAdvanceOn) {
LegacyForgeHandshakeBackendPhase phaseToTransitionTo = nextPhase(); LegacyForgeHandshakeBackendPhase phaseToTransitionTo = nextPhase();

Datei anzeigen

@ -7,7 +7,7 @@ import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
import com.velocitypowered.proxy.connection.client.ClientConnectionPhase; import com.velocitypowered.proxy.connection.client.ClientConnectionPhase;
import com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler; import com.velocitypowered.proxy.connection.client.ClientPlaySessionHandler;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
import java.util.List; import java.util.List;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -39,7 +39,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase {
@Override @Override
boolean onHandle(ConnectedPlayer player, boolean onHandle(ConnectedPlayer player,
PluginMessagePacket message, AbstractPluginMessagePacket<?> message,
MinecraftConnection backendConn) { MinecraftConnection backendConn) {
// If we stay in this phase, we do nothing because it means the packet wasn't handled. // If we stay in this phase, we do nothing because it means the packet wasn't handled.
// Returning false indicates this // Returning false indicates this
@ -73,7 +73,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase {
@Override @Override
boolean onHandle(ConnectedPlayer player, boolean onHandle(ConnectedPlayer player,
PluginMessagePacket message, AbstractPluginMessagePacket<?> message,
MinecraftConnection backendConn) { MinecraftConnection backendConn) {
// Read the mod list if we haven't already. // Read the mod list if we haven't already.
if (!player.getModInfo().isPresent()) { if (!player.getModInfo().isPresent()) {
@ -147,7 +147,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase {
@Override @Override
boolean onHandle(ConnectedPlayer player, boolean onHandle(ConnectedPlayer player,
PluginMessagePacket message, AbstractPluginMessagePacket<?> message,
MinecraftConnection backendConn) { MinecraftConnection backendConn) {
super.onHandle(player, message, backendConn); super.onHandle(player, message, backendConn);
@ -180,7 +180,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase {
@Override @Override
public final boolean handle(ConnectedPlayer player, public final boolean handle(ConnectedPlayer player,
PluginMessagePacket message, AbstractPluginMessagePacket<?> message,
VelocityServerConnection server) { VelocityServerConnection server) {
if (server != null) { if (server != null) {
MinecraftConnection backendConn = server.getConnection(); MinecraftConnection backendConn = server.getConnection();
@ -211,7 +211,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase {
* @return true if handled, false otherwise. * @return true if handled, false otherwise.
*/ */
boolean onHandle(ConnectedPlayer player, boolean onHandle(ConnectedPlayer player,
PluginMessagePacket message, AbstractPluginMessagePacket<?> message,
MinecraftConnection backendConn) { MinecraftConnection backendConn) {
// Send the packet on to the server. // Send the packet on to the server.
backendConn.write(message.retain()); backendConn.write(message.retain());
@ -241,7 +241,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase {
* @param packet The packet * @param packet The packet
* @return The phase to transition to, which may be the same as before. * @return The phase to transition to, which may be the same as before.
*/ */
private LegacyForgeHandshakeClientPhase getNewPhase(PluginMessagePacket packet) { private LegacyForgeHandshakeClientPhase getNewPhase(AbstractPluginMessagePacket<?> packet) {
if (packetToAdvanceOn != null if (packetToAdvanceOn != null
&& LegacyForgeUtil.getHandshakePacketDiscriminator(packet) == packetToAdvanceOn) { && LegacyForgeUtil.getHandshakePacketDiscriminator(packet) == packetToAdvanceOn) {
return nextPhase(); return nextPhase();

Datei anzeigen

@ -8,7 +8,8 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.util.ModInfo; import com.velocitypowered.api.util.ModInfo;
import com.velocitypowered.proxy.network.ProtocolUtils; import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPluginMessagePacket;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import java.util.List; import java.util.List;
@ -25,7 +26,7 @@ class LegacyForgeUtil {
* @param message The message to analyse * @param message The message to analyse
* @return The discriminator * @return The discriminator
*/ */
static byte getHandshakePacketDiscriminator(PluginMessagePacket message) { static byte getHandshakePacketDiscriminator(AbstractPluginMessagePacket<?> message) {
Preconditions.checkArgument(message.getChannel().equals(FORGE_LEGACY_HANDSHAKE_CHANNEL)); Preconditions.checkArgument(message.getChannel().equals(FORGE_LEGACY_HANDSHAKE_CHANNEL));
Preconditions.checkArgument(message.content().isReadable()); Preconditions.checkArgument(message.content().isReadable());
return message.content().getByte(0); return message.content().getByte(0);
@ -37,7 +38,7 @@ class LegacyForgeUtil {
* @param message The message * @param message The message
* @return The list of mods. May be empty. * @return The list of mods. May be empty.
*/ */
static List<ModInfo.Mod> readModList(PluginMessagePacket message) { static List<ModInfo.Mod> readModList(AbstractPluginMessagePacket<?> message) {
Preconditions.checkNotNull(message, "message"); Preconditions.checkNotNull(message, "message");
Preconditions Preconditions
.checkArgument(message.getChannel().equals(FORGE_LEGACY_HANDSHAKE_CHANNEL), .checkArgument(message.getChannel().equals(FORGE_LEGACY_HANDSHAKE_CHANNEL),
@ -71,8 +72,8 @@ class LegacyForgeUtil {
* *
* @return A copy of the reset packet * @return A copy of the reset packet
*/ */
static PluginMessagePacket resetPacket() { static AbstractPluginMessagePacket<?> resetPacket() {
return new PluginMessagePacket( return new ClientboundPluginMessagePacket(
FORGE_LEGACY_HANDSHAKE_CHANNEL, FORGE_LEGACY_HANDSHAKE_CHANNEL,
Unpooled.wrappedBuffer(FORGE_LEGACY_HANDSHAKE_RESET_DATA.clone()) Unpooled.wrappedBuffer(FORGE_LEGACY_HANDSHAKE_RESET_DATA.clone())
); );

Datei anzeigen

@ -6,7 +6,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.util.ProxyVersion; import com.velocitypowered.api.util.ProxyVersion;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket; import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -33,7 +33,7 @@ public final class PluginMessageUtil {
* @param message the plugin message * @param message the plugin message
* @return whether or not this is a brand plugin message * @return whether or not this is a brand plugin message
*/ */
public static boolean isMcBrand(PluginMessagePacket message) { public static boolean isMcBrand(AbstractPluginMessagePacket<?> message) {
checkNotNull(message, "message"); checkNotNull(message, "message");
return message.getChannel().equals(BRAND_CHANNEL_LEGACY) || message.getChannel() return message.getChannel().equals(BRAND_CHANNEL_LEGACY) || message.getChannel()
.equals(BRAND_CHANNEL); .equals(BRAND_CHANNEL);
@ -44,7 +44,7 @@ public final class PluginMessageUtil {
* @param message the plugin message * @param message the plugin message
* @return whether we are registering plugin channels or not * @return whether we are registering plugin channels or not
*/ */
public static boolean isRegister(PluginMessagePacket message) { public static boolean isRegister(AbstractPluginMessagePacket<?> message) {
checkNotNull(message, "message"); checkNotNull(message, "message");
return message.getChannel().equals(REGISTER_CHANNEL_LEGACY) || message.getChannel() return message.getChannel().equals(REGISTER_CHANNEL_LEGACY) || message.getChannel()
.equals(REGISTER_CHANNEL); .equals(REGISTER_CHANNEL);
@ -55,7 +55,7 @@ public final class PluginMessageUtil {
* @param message the plugin message * @param message the plugin message
* @return whether we are unregistering plugin channels or not * @return whether we are unregistering plugin channels or not
*/ */
public static boolean isUnregister(PluginMessagePacket message) { public static boolean isUnregister(AbstractPluginMessagePacket<?> message) {
checkNotNull(message, "message"); checkNotNull(message, "message");
return message.getChannel().equals(UNREGISTER_CHANNEL_LEGACY) || message.getChannel() return message.getChannel().equals(UNREGISTER_CHANNEL_LEGACY) || message.getChannel()
.equals(UNREGISTER_CHANNEL); .equals(UNREGISTER_CHANNEL);
@ -66,7 +66,7 @@ public final class PluginMessageUtil {
* @param message the plugin message * @param message the plugin message
* @return whether this is a legacy register message * @return whether this is a legacy register message
*/ */
public static boolean isLegacyRegister(PluginMessagePacket message) { public static boolean isLegacyRegister(AbstractPluginMessagePacket<?> message) {
checkNotNull(message, "message"); checkNotNull(message, "message");
return message.getChannel().equals(REGISTER_CHANNEL_LEGACY); return message.getChannel().equals(REGISTER_CHANNEL_LEGACY);
} }
@ -77,7 +77,7 @@ public final class PluginMessageUtil {
* @param message the plugin message * @param message the plugin message
* @return whether this is a legacy unregister message * @return whether this is a legacy unregister message
*/ */
public static boolean isLegacyUnregister(PluginMessagePacket message) { public static boolean isLegacyUnregister(AbstractPluginMessagePacket<?> message) {
checkNotNull(message, "message"); checkNotNull(message, "message");
return message.getChannel().equals(UNREGISTER_CHANNEL_LEGACY); return message.getChannel().equals(UNREGISTER_CHANNEL_LEGACY);
} }
@ -87,7 +87,7 @@ public final class PluginMessageUtil {
* @param message the message to get the channels from * @param message the message to get the channels from
* @return the channels, as an immutable list * @return the channels, as an immutable list
*/ */
public static List<String> getChannels(PluginMessagePacket message) { public static List<String> getChannels(AbstractPluginMessagePacket<?> message) {
checkNotNull(message, "message"); checkNotNull(message, "message");
checkArgument(isRegister(message) || isUnregister(message), "Unknown channel type %s", checkArgument(isRegister(message) || isUnregister(message), "Unknown channel type %s",
message.getChannel()); message.getChannel());
@ -106,15 +106,16 @@ public final class PluginMessageUtil {
* @param channels the channels to register * @param channels the channels to register
* @return the plugin message to send * @return the plugin message to send
*/ */
public static PluginMessagePacket constructChannelsPacket(ProtocolVersion protocolVersion, public static AbstractPluginMessagePacket<?> constructChannelsPacket(ProtocolVersion protocolVersion,
Collection<String> channels) { Collection<String> channels,
AbstractPluginMessagePacket.Factory<?> factory) {
checkNotNull(channels, "channels"); checkNotNull(channels, "channels");
checkArgument(!channels.isEmpty(), "no channels specified"); checkArgument(!channels.isEmpty(), "no channels specified");
String channelName = protocolVersion.gte(ProtocolVersion.MINECRAFT_1_13) String channelName = protocolVersion.gte(ProtocolVersion.MINECRAFT_1_13)
? REGISTER_CHANNEL : REGISTER_CHANNEL_LEGACY; ? REGISTER_CHANNEL : REGISTER_CHANNEL_LEGACY;
ByteBuf contents = Unpooled.buffer(); ByteBuf contents = Unpooled.buffer();
contents.writeCharSequence(String.join("\0", channels), StandardCharsets.UTF_8); contents.writeCharSequence(String.join("\0", channels), StandardCharsets.UTF_8);
return new PluginMessagePacket(channelName, contents); return factory.create(channelName, contents);
} }
/** /**
@ -123,9 +124,10 @@ public final class PluginMessageUtil {
* @param version the proxy version * @param version the proxy version
* @return the rewritten plugin message * @return the rewritten plugin message
*/ */
public static PluginMessagePacket rewriteMinecraftBrand(PluginMessagePacket message, public static AbstractPluginMessagePacket<?> rewriteMinecraftBrand(AbstractPluginMessagePacket<?> message,
ProxyVersion version, ProxyVersion version,
ProtocolVersion protocolVersion) { ProtocolVersion protocolVersion,
AbstractPluginMessagePacket.Factory<?> factory) {
checkNotNull(message, "message"); checkNotNull(message, "message");
checkNotNull(version, "version"); checkNotNull(version, "version");
checkArgument(isMcBrand(message), "message is not a brand plugin message"); checkArgument(isMcBrand(message), "message is not a brand plugin message");
@ -140,7 +142,7 @@ public final class PluginMessageUtil {
rewrittenBuf.writeCharSequence(rewrittenBrand, StandardCharsets.UTF_8); rewrittenBuf.writeCharSequence(rewrittenBrand, StandardCharsets.UTF_8);
} }
return new PluginMessagePacket(message.getChannel(), rewrittenBuf); return factory.create(message.getChannel(), rewrittenBuf);
} }
private static String readBrandMessage(ByteBuf content) { private static String readBrandMessage(ByteBuf content) {

Datei anzeigen

@ -18,15 +18,18 @@ import static com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS
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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketReader;
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;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundEncryptionRequestPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundHeaderAndFooterPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundHeaderAndFooterPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundLoginPluginMessagePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundLoginPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundResourcePackRequestPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundResourcePackRequestPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundRespawnPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundRespawnPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket;
@ -41,13 +44,12 @@ import com.velocitypowered.proxy.network.packet.serverbound.ServerboundEncryptio
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundKeepAlivePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundKeepAlivePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundLoginPluginResponsePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundLoginPluginResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundResourcePackResponsePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundResourcePackResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusPingPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusPingPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusRequestPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusRequestPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundTabCompleteRequestPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundTabCompleteRequestPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.util.collection.IntObjectHashMap; import io.netty.util.collection.IntObjectHashMap;
import io.netty.util.collection.IntObjectMap; import io.netty.util.collection.IntObjectMap;
@ -58,7 +60,6 @@ import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.function.Supplier;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public enum StateRegistry { public enum StateRegistry {
@ -128,8 +129,8 @@ public enum StateRegistry {
map(0x05, MINECRAFT_1_14, false) map(0x05, MINECRAFT_1_14, false)
); );
serverbound.register( serverbound.register(
PluginMessagePacket.class, ServerboundPluginMessagePacket.class,
PluginMessagePacket.DECODER, ServerboundPluginMessagePacket.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),
@ -195,8 +196,8 @@ public enum StateRegistry {
map(0x10, MINECRAFT_1_16_2, false) map(0x10, MINECRAFT_1_16_2, false)
); );
clientbound.register( clientbound.register(
PluginMessagePacket.class, ClientboundPluginMessagePacket.class,
PluginMessagePacket.DECODER, ClientboundPluginMessagePacket.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),
@ -400,7 +401,7 @@ public enum StateRegistry {
return registry; return registry;
} }
<P extends Packet> void register(Class<P> clazz, Packet.Decoder<P> decoder, <P extends Packet> void register(Class<P> clazz, PacketReader<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.");
@ -427,7 +428,7 @@ public enum StateRegistry {
+ current.protocolVersion); + current.protocolVersion);
} }
if (registry.packetIdToSupplier.containsKey(current.id)) { if (registry.packetIdToReader.containsKey(current.id)) {
throw new IllegalArgumentException("Can not register class " + clazz.getSimpleName() throw new IllegalArgumentException("Can not register class " + clazz.getSimpleName()
+ " with id " + current.id + " for " + registry.version + " with id " + current.id + " for " + registry.version
+ " because another packet is already registered"); + " because another packet is already registered");
@ -439,7 +440,7 @@ public enum StateRegistry {
} }
if (!current.encodeOnly) { if (!current.encodeOnly) {
registry.packetIdToDecoder.put(current.id, decoder); registry.packetIdToReader.put(current.id, decoder);
} }
registry.packetClassToId.put(clazz, current.id); registry.packetClassToId.put(clazz, current.id);
} }
@ -449,10 +450,7 @@ public enum StateRegistry {
public class ProtocolRegistry { public class ProtocolRegistry {
public final ProtocolVersion version; public final ProtocolVersion version;
@Deprecated final IntObjectMap<PacketReader<? extends Packet>> packetIdToReader =
final IntObjectMap<Supplier<? extends Packet>> packetIdToSupplier =
new IntObjectHashMap<>(16, 0.5f);
final IntObjectMap<Packet.Decoder<? extends Packet>> packetIdToDecoder =
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);
@ -462,21 +460,6 @@ public enum StateRegistry {
this.packetClassToId.defaultReturnValue(Integer.MIN_VALUE); this.packetClassToId.defaultReturnValue(Integer.MIN_VALUE);
} }
/**
* Attempts to create a packet from the specified {@code id}.
*
* @param id the packet ID
* @return the packet instance, or {@code null} if the ID is not registered
*/
@Deprecated
@Nullable Packet createPacket(final int id) {
final Supplier<? extends Packet> supplier = this.packetIdToSupplier.get(id);
if (supplier == null) {
return null;
}
return supplier.get();
}
/** /**
* Attempts to create a packet from the specified {@code id}. * Attempts to create a packet from the specified {@code id}.
* *
@ -486,13 +469,13 @@ public enum StateRegistry {
* @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 decodePacket(final int id, ByteBuf buf, PacketDirection direction, public @Nullable Packet readPacket(final int id, ByteBuf buf, PacketDirection direction,
ProtocolVersion version) { ProtocolVersion version) {
final Packet.Decoder<? extends Packet> decoder = this.packetIdToDecoder.get(id); final PacketReader<? extends Packet> decoder = this.packetIdToReader.get(id);
if (decoder == null) { if (decoder == null) {
return null; return null;
} }
return decoder.decode(buf, direction, version); return decoder.read(buf, direction, version);
} }
/** /**
@ -517,9 +500,9 @@ public enum StateRegistry {
public static final class PacketMapping { public static final class PacketMapping {
private final int id; final int id;
private final ProtocolVersion protocolVersion; final ProtocolVersion protocolVersion;
private final boolean encodeOnly; final boolean encodeOnly;
PacketMapping(int id, ProtocolVersion protocolVersion, boolean packetDecoding) { PacketMapping(int id, ProtocolVersion protocolVersion, boolean packetDecoding) {
this.id = id; this.id = id;

Datei anzeigen

@ -1,136 +0,0 @@
package com.velocitypowered.proxy.network.buffer;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufHolder;
import io.netty.util.IllegalReferenceCountException;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/**
* A special-purpose implementation of {@code ByteBufHolder} that can defer accepting its buffer.
* This is required because Velocity packets are, for better or worse, mutable.
*/
public class DeferredByteBufHolder implements ByteBufHolder {
@MonotonicNonNull
private ByteBuf backing;
public DeferredByteBufHolder(
@MonotonicNonNull ByteBuf backing) {
this.backing = backing;
}
@Override
public ByteBuf content() {
if (backing == null) {
throw new IllegalStateException("Trying to obtain contents of holder with a null buffer");
}
if (backing.refCnt() <= 0) {
throw new IllegalReferenceCountException(backing.refCnt());
}
return backing;
}
@Override
public ByteBufHolder copy() {
if (backing == null) {
throw new IllegalStateException("Trying to obtain contents of holder with a null buffer");
}
return new DeferredByteBufHolder(backing.copy());
}
@Override
public ByteBufHolder duplicate() {
if (backing == null) {
throw new IllegalStateException("Trying to obtain contents of holder with a null buffer");
}
return new DeferredByteBufHolder(backing.duplicate());
}
@Override
public ByteBufHolder retainedDuplicate() {
if (backing == null) {
throw new IllegalStateException("Trying to obtain contents of holder with a null buffer");
}
return new DeferredByteBufHolder(backing.retainedDuplicate());
}
@Override
public ByteBufHolder replace(ByteBuf content) {
if (content == null) {
throw new NullPointerException("content");
}
this.backing = content;
return this;
}
@Override
public int refCnt() {
if (backing == null) {
throw new IllegalStateException("Trying to obtain contents of holder with a null buffer");
}
return backing.refCnt();
}
@Override
public ByteBufHolder retain() {
if (backing == null) {
throw new IllegalStateException("Trying to obtain contents of holder with a null buffer");
}
backing.retain();
return this;
}
@Override
public ByteBufHolder retain(int increment) {
if (backing == null) {
throw new IllegalStateException("Trying to obtain contents of holder with a null buffer");
}
backing.retain(increment);
return this;
}
@Override
public ByteBufHolder touch() {
if (backing == null) {
throw new IllegalStateException("Trying to obtain contents of holder with a null buffer");
}
backing.touch();
return this;
}
@Override
public ByteBufHolder touch(Object hint) {
if (backing == null) {
throw new IllegalStateException("Trying to obtain contents of holder with a null buffer");
}
backing.touch(hint);
return this;
}
@Override
public boolean release() {
if (backing == null) {
throw new IllegalStateException("Trying to obtain contents of holder with a null buffer");
}
return backing.release();
}
@Override
public boolean release(int decrement) {
if (backing == null) {
throw new IllegalStateException("Trying to obtain contents of holder with a null buffer");
}
return backing.release(decrement);
}
@Override
public String toString() {
String str = "DeferredByteBufHolder[";
if (backing == null) {
str += "null";
} else {
str += backing.toString();
}
return str + "]";
}
}

Datei anzeigen

@ -0,0 +1,37 @@
package com.velocitypowered.proxy.network.buffer;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder;
public abstract class TypedDefaultByteBufHolder<S extends TypedDefaultByteBufHolder<S>> extends DefaultByteBufHolder {
protected TypedDefaultByteBufHolder(final ByteBuf data) {
super(data);
}
@Override
public abstract S replace(final ByteBuf content);
@Override
@SuppressWarnings("unchecked")
public S retain() {
return (S) super.retain();
}
@Override
@SuppressWarnings("unchecked")
public S retain(final int increment) {
return (S) super.retain(increment);
}
@Override
@SuppressWarnings("unchecked")
public S touch() {
return (S) super.touch();
}
@Override
@SuppressWarnings("unchecked")
public S touch(final Object hint) {
return (S) super.touch(hint);
}
}

Datei anzeigen

@ -7,7 +7,7 @@ import io.netty.buffer.ByteBuf;
import java.util.function.LongFunction; import java.util.function.LongFunction;
public abstract class AbstractKeepAlivePacket implements Packet { public abstract class AbstractKeepAlivePacket implements Packet {
protected static <P extends AbstractKeepAlivePacket> Decoder<P> decoder(final LongFunction<P> factory) { protected static <P extends AbstractKeepAlivePacket> PacketReader<P> decoder(final LongFunction<P> factory) {
return (buf, direction, version) -> { return (buf, direction, version) -> {
final long randomId; final long randomId;
if (version.gte(ProtocolVersion.MINECRAFT_1_12_2)) { if (version.gte(ProtocolVersion.MINECRAFT_1_12_2)) {

Datei anzeigen

@ -1,38 +1,37 @@
package com.velocitypowered.proxy.network.packet.shared; package com.velocitypowered.proxy.network.packet;
import static com.velocitypowered.proxy.network.PluginMessageUtil.transformLegacyToModernChannel; import static com.velocitypowered.proxy.network.PluginMessageUtil.transformLegacyToModernChannel;
import com.google.common.base.MoreObjects; 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.buffer.TypedDefaultByteBufHolder;
import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder;
import java.util.Objects; 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 DefaultByteBufHolder implements Packet { public abstract class AbstractPluginMessagePacket<S extends AbstractPluginMessagePacket<S>> extends TypedDefaultByteBufHolder<S> implements Packet {
public static final Decoder<PluginMessagePacket> DECODER = (buf, direction, version) -> { protected static <P extends AbstractPluginMessagePacket<P>> PacketReader<P> decoder(final Factory<P> factory) {
String channel = ProtocolUtils.readString(buf); return (buf, direction, version) -> {
if (version.gte(ProtocolVersion.MINECRAFT_1_13)) { String channel = ProtocolUtils.readString(buf);
channel = transformLegacyToModernChannel(channel); if (version.gte(ProtocolVersion.MINECRAFT_1_13)) {
} channel = transformLegacyToModernChannel(channel);
final ByteBuf data; }
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) { final ByteBuf data;
data = buf.readRetainedSlice(buf.readableBytes()); if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
} else { data = buf.readRetainedSlice(buf.readableBytes());
data = ProtocolUtils.readRetainedByteBufSlice17(buf); } else {
} data = ProtocolUtils.readRetainedByteBufSlice17(buf);
return new PluginMessagePacket(channel, data); }
}; return factory.create(channel, data);
};
}
private final @Nullable String channel; protected final @Nullable String channel;
public PluginMessagePacket(String channel, protected AbstractPluginMessagePacket(String channel,
@MonotonicNonNull ByteBuf backing) { @MonotonicNonNull ByteBuf backing) {
super(backing); super(backing);
this.channel = channel; this.channel = channel;
} }
@ -54,11 +53,6 @@ public class PluginMessagePacket extends DefaultByteBufHolder implements Packet
} }
} }
@Override
public boolean handle(PacketHandler handler) {
return handler.handle(this);
}
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.");
@ -66,31 +60,6 @@ public class PluginMessagePacket extends DefaultByteBufHolder implements Packet
return channel; return channel;
} }
@Override
public PluginMessagePacket replace(ByteBuf content) {
return new PluginMessagePacket(this.channel, content);
}
@Override
public PluginMessagePacket retain() {
return (PluginMessagePacket) super.retain();
}
@Override
public PluginMessagePacket retain(int increment) {
return (PluginMessagePacket) super.retain(increment);
}
@Override
public PluginMessagePacket touch() {
return (PluginMessagePacket) super.touch();
}
@Override
public PluginMessagePacket touch(Object hint) {
return (PluginMessagePacket) super.touch(hint);
}
@Override @Override
public boolean equals(final Object other) { public boolean equals(final Object other) {
if (this == other) { if (this == other) {
@ -99,7 +68,7 @@ public class PluginMessagePacket extends DefaultByteBufHolder implements Packet
if (other == null || this.getClass() != other.getClass()) { if (other == null || this.getClass() != other.getClass()) {
return false; return false;
} }
final PluginMessagePacket that = (PluginMessagePacket) other; final AbstractPluginMessagePacket<?> that = (AbstractPluginMessagePacket<?>) other;
return Objects.equals(this.channel, that.channel) return Objects.equals(this.channel, that.channel)
&& super.equals(other); && super.equals(other);
} }
@ -116,4 +85,8 @@ public class PluginMessagePacket extends DefaultByteBufHolder implements Packet
.add("data", this.contentToString()) .add("data", this.contentToString())
.toString(); .toString();
} }
public interface Factory<P extends AbstractPluginMessagePacket<P>> {
P create(final String channel, final ByteBuf data);
}
} }

Datei anzeigen

@ -6,7 +6,7 @@ import io.netty.buffer.ByteBuf;
import java.util.function.LongFunction; import java.util.function.LongFunction;
public abstract class AbstractStatusPingPacket implements Packet { public abstract class AbstractStatusPingPacket implements Packet {
protected static <P extends AbstractStatusPingPacket> Decoder<P> decoder(final LongFunction<P> factory) { protected static <P extends AbstractStatusPingPacket> PacketReader<P> decoder(final LongFunction<P> factory) {
return (buf, direction, version) -> { return (buf, direction, version) -> {
final long randomId = buf.readLong(); final long randomId = buf.readLong();
return factory.apply(randomId); return factory.apply(randomId);

Datei anzeigen

@ -15,26 +15,4 @@ public interface Packet {
boolean handle(PacketHandler handler); boolean handle(PacketHandler handler);
interface Decoder<P extends Packet> {
P decode(final ByteBuf buf, final PacketDirection direction, final ProtocolVersion version);
static <P extends Packet> Decoder<P> unsupported() {
return (buf, direction, version) -> {
throw new UnsupportedOperationException();
};
}
static <P extends Packet> Decoder<P> instance(final P packet) {
return (buf, direction, version) -> packet;
}
@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

@ -10,6 +10,7 @@ import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGameP
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundLoginPluginMessagePacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundLoginPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPlayerListItemPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundResourcePackRequestPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundResourcePackRequestPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundRespawnPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundRespawnPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket; import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket;
@ -26,18 +27,14 @@ import com.velocitypowered.proxy.network.packet.serverbound.ServerboundEncryptio
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundKeepAlivePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundKeepAlivePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundLoginPluginResponsePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundLoginPluginResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundResourcePackResponsePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundResourcePackResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusPingPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusPingPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusRequestPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusRequestPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundTabCompleteRequestPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundTabCompleteRequestPacket;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket;
public interface PacketHandler { public interface PacketHandler {
default boolean handle(PluginMessagePacket packet) {
return false;
}
/* /*
* Clientbound * Clientbound
*/ */
@ -82,6 +79,10 @@ public interface PacketHandler {
return false; return false;
} }
default boolean handle(ClientboundPluginMessagePacket packet) {
return false;
}
default boolean handle(ClientboundResourcePackRequestPacket packet) { default boolean handle(ClientboundResourcePackRequestPacket packet) {
return false; return false;
} }
@ -142,6 +143,10 @@ public interface PacketHandler {
return false; return false;
} }
default boolean handle(ServerboundPluginMessagePacket packet) {
return false;
}
default boolean handle(ServerboundResourcePackResponsePacket packet) { default boolean handle(ServerboundResourcePackResponsePacket packet) {
return false; return false;
} }

Datei anzeigen

@ -0,0 +1,28 @@
package com.velocitypowered.proxy.network.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import io.netty.buffer.ByteBuf;
import java.util.function.Supplier;
public interface PacketReader<P extends Packet> {
P read(final ByteBuf buf, final PacketDirection direction, final ProtocolVersion version);
static <P extends Packet> PacketReader<P> unsupported() {
return (buf, direction, version) -> {
throw new UnsupportedOperationException();
};
}
static <P extends Packet> PacketReader<P> instance(final P packet) {
return (buf, direction, version) -> packet;
}
@Deprecated
static <P extends Packet> PacketReader<P> method(final Supplier<P> factory) {
return (buf, direction, version) -> {
final P packet = factory.get();
packet.decode(buf, direction, version);
return packet;
};
}
}

Datei anzeigen

@ -22,6 +22,7 @@ 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.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.serialization.brigadier.ArgumentPropertyRegistry; import com.velocitypowered.proxy.network.serialization.brigadier.ArgumentPropertyRegistry;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap;
@ -36,7 +37,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundAvailableCommandsPacket implements Packet { public class ClientboundAvailableCommandsPacket implements Packet {
public static final Decoder<ClientboundAvailableCommandsPacket> DECODER = Decoder.method(ClientboundAvailableCommandsPacket::new); public static final PacketReader<ClientboundAvailableCommandsPacket> DECODER = PacketReader.method(ClientboundAvailableCommandsPacket::new);
private static final Command<CommandSource> PLACEHOLDER_COMMAND = source -> 0; private static final Command<CommandSource> PLACEHOLDER_COMMAND = source -> 0;

Datei anzeigen

@ -6,13 +6,14 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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 ClientboundBossBarPacket implements Packet { public class ClientboundBossBarPacket implements Packet {
public static final Decoder<ClientboundBossBarPacket> DECODER = Decoder.method(ClientboundBossBarPacket::new); public static final PacketReader<ClientboundBossBarPacket> DECODER = PacketReader.method(ClientboundBossBarPacket::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;

Datei anzeigen

@ -6,12 +6,13 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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 Decoder<ClientboundChatPacket> DECODER = Decoder.method(ClientboundChatPacket::new); public static final PacketReader<ClientboundChatPacket> DECODER = PacketReader.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;

Datei anzeigen

@ -7,12 +7,13 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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 Decoder<ClientboundDisconnectPacket> DECODER = Decoder.method(ClientboundDisconnectPacket::new); public static final PacketReader<ClientboundDisconnectPacket> DECODER = PacketReader.method(ClientboundDisconnectPacket::new);
private @Nullable String reason; private @Nullable String reason;

Datei anzeigen

@ -8,10 +8,11 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ClientboundEncryptionRequestPacket implements Packet { public class ClientboundEncryptionRequestPacket implements Packet {
public static final Decoder<ClientboundEncryptionRequestPacket> DECODER = Decoder.method(ClientboundEncryptionRequestPacket::new); public static final PacketReader<ClientboundEncryptionRequestPacket> DECODER = PacketReader.method(ClientboundEncryptionRequestPacket::new);
private String serverId = ""; private String serverId = "";
private byte[] publicKey = EMPTY_BYTE_ARRAY; private byte[] publicKey = EMPTY_BYTE_ARRAY;

Datei anzeigen

@ -8,10 +8,11 @@ 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.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ClientboundHeaderAndFooterPacket implements Packet { public class ClientboundHeaderAndFooterPacket implements Packet {
public static final Decoder<ClientboundHeaderAndFooterPacket> DECODER = Decoder.method(ClientboundHeaderAndFooterPacket::new); public static final PacketReader<ClientboundHeaderAndFooterPacket> DECODER = PacketReader.method(ClientboundHeaderAndFooterPacket::new);
private static final String EMPTY_COMPONENT = "{\"translate\":\"\"}"; private static final String EMPTY_COMPONENT = "{\"translate\":\"\"}";
private static final ClientboundHeaderAndFooterPacket RESET private static final ClientboundHeaderAndFooterPacket RESET

Datei anzeigen

@ -10,6 +10,7 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.kyori.adventure.nbt.BinaryTagTypes; import net.kyori.adventure.nbt.BinaryTagTypes;
import net.kyori.adventure.nbt.CompoundBinaryTag; import net.kyori.adventure.nbt.CompoundBinaryTag;
@ -17,7 +18,7 @@ import net.kyori.adventure.nbt.ListBinaryTag;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundJoinGamePacket implements Packet { public class ClientboundJoinGamePacket implements Packet {
public static final Decoder<ClientboundJoinGamePacket> DECODER = Decoder.method(ClientboundJoinGamePacket::new); public static final PacketReader<ClientboundJoinGamePacket> DECODER = PacketReader.method(ClientboundJoinGamePacket::new);
private int entityId; private int entityId;
private short gamemode; private short gamemode;

Datei anzeigen

@ -3,9 +3,10 @@ package com.velocitypowered.proxy.network.packet.clientbound;
import com.velocitypowered.proxy.network.packet.AbstractKeepAlivePacket; 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;
public class ClientboundKeepAlivePacket extends AbstractKeepAlivePacket implements Packet { public class ClientboundKeepAlivePacket extends AbstractKeepAlivePacket implements Packet {
public static final Decoder<ClientboundKeepAlivePacket> DECODER = decoder(ClientboundKeepAlivePacket::new); public static final PacketReader<ClientboundKeepAlivePacket> DECODER = decoder(ClientboundKeepAlivePacket::new);
public ClientboundKeepAlivePacket(final long randomId) { public ClientboundKeepAlivePacket(final long randomId) {
super(randomId); super(randomId);

Datei anzeigen

@ -6,6 +6,7 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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;
@ -13,7 +14,7 @@ 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 Decoder<ClientboundLoginPluginMessagePacket> DECODER = (buf, direction, version) -> { public static final PacketReader<ClientboundLoginPluginMessagePacket> DECODER = (buf, direction, 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;

Datei anzeigen

@ -9,6 +9,7 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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;
@ -18,7 +19,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 ClientboundPlayerListItemPacket implements Packet { public class ClientboundPlayerListItemPacket implements Packet {
public static final Decoder<ClientboundPlayerListItemPacket> DECODER = Decoder.method(ClientboundPlayerListItemPacket::new); public static final PacketReader<ClientboundPlayerListItemPacket> DECODER = PacketReader.method(ClientboundPlayerListItemPacket::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

@ -0,0 +1,26 @@
package com.velocitypowered.proxy.network.packet.clientbound;
import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
public class ClientboundPluginMessagePacket extends AbstractPluginMessagePacket<ClientboundPluginMessagePacket> implements Packet {
public static final Factory<ClientboundPluginMessagePacket> FACTORY = ClientboundPluginMessagePacket::new;
public static final PacketReader<ClientboundPluginMessagePacket> DECODER = decoder(FACTORY);
public ClientboundPluginMessagePacket(final String channel, final ByteBuf backing) {
super(channel, backing);
}
@Override
public boolean handle(PacketHandler handler) {
return handler.handle(this);
}
@Override
public ClientboundPluginMessagePacket replace(ByteBuf content) {
return new ClientboundPluginMessagePacket(this.channel, content);
}
}

Datei anzeigen

@ -6,11 +6,12 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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 Decoder<ClientboundResourcePackRequestPacket> DECODER = (buf, direction, version) -> { public static final PacketReader<ClientboundResourcePackRequestPacket> DECODER = (buf, direction, 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);

Datei anzeigen

@ -8,11 +8,12 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
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 Decoder<ClientboundRespawnPacket> DECODER = Decoder.method(ClientboundRespawnPacket::new); public static final PacketReader<ClientboundRespawnPacket> DECODER = PacketReader.method(ClientboundRespawnPacket::new);
private int dimension; private int dimension;
private long partialHashedSeed; private long partialHashedSeed;

Datei anzeigen

@ -7,12 +7,13 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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 Decoder<ClientboundServerLoginSuccessPacket> DECODER = (buf, direction, version) -> { public static final PacketReader<ClientboundServerLoginSuccessPacket> DECODER = (buf, direction, 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);

Datei anzeigen

@ -6,10 +6,11 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ClientboundSetCompressionPacket implements Packet { public class ClientboundSetCompressionPacket implements Packet {
public static final Decoder<ClientboundSetCompressionPacket> DECODER = (buf, direction, version) -> { public static final PacketReader<ClientboundSetCompressionPacket> DECODER = (buf, direction, version) -> {
final int threshold = ProtocolUtils.readVarInt(buf); final int threshold = ProtocolUtils.readVarInt(buf);
return new ClientboundSetCompressionPacket(threshold); return new ClientboundSetCompressionPacket(threshold);
}; };

Datei anzeigen

@ -3,9 +3,10 @@ package com.velocitypowered.proxy.network.packet.clientbound;
import com.velocitypowered.proxy.network.packet.AbstractStatusPingPacket; 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;
public class ClientboundStatusPingPacket extends AbstractStatusPingPacket implements Packet { public class ClientboundStatusPingPacket extends AbstractStatusPingPacket implements Packet {
public static final Decoder<ClientboundStatusPingPacket> DECODER = decoder(ClientboundStatusPingPacket::new); public static final PacketReader<ClientboundStatusPingPacket> DECODER = decoder(ClientboundStatusPingPacket::new);
public ClientboundStatusPingPacket(final long randomId) { public ClientboundStatusPingPacket(final long randomId) {
super(randomId); super(randomId);

Datei anzeigen

@ -6,11 +6,12 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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 Decoder<ClientboundStatusResponsePacket> DECODER = (buf, direction, version) -> { public static final PacketReader<ClientboundStatusResponsePacket> DECODER = (buf, direction, 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);
}; };

Datei anzeigen

@ -6,6 +6,7 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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;
@ -13,7 +14,7 @@ import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundTabCompleteResponsePacket implements Packet { public class ClientboundTabCompleteResponsePacket implements Packet {
public static final Decoder<ClientboundTabCompleteResponsePacket> DECODER = Decoder.method(ClientboundTabCompleteResponsePacket::new); public static final PacketReader<ClientboundTabCompleteResponsePacket> DECODER = PacketReader.method(ClientboundTabCompleteResponsePacket::new);
private int transactionId; private int transactionId;
private int start; private int start;

Datei anzeigen

@ -7,6 +7,7 @@ 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.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.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;
@ -14,7 +15,7 @@ import net.kyori.adventure.title.Title;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundTitlePacket implements Packet { public class ClientboundTitlePacket implements Packet {
public static final Decoder<ClientboundTitlePacket> DECODER = Decoder.unsupported(); public static final PacketReader<ClientboundTitlePacket> DECODER = PacketReader.unsupported();
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)

Datei anzeigen

@ -6,10 +6,11 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ServerboundChatPacket implements Packet { public class ServerboundChatPacket implements Packet {
public static final Decoder<ServerboundChatPacket> DECODER = (buf, direction, version) -> { public static final PacketReader<ServerboundChatPacket> DECODER = (buf, direction, version) -> {
final String message = ProtocolUtils.readString(buf); final String message = ProtocolUtils.readString(buf);
return new ServerboundChatPacket(message); return new ServerboundChatPacket(message);
}; };

Datei anzeigen

@ -6,11 +6,12 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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 Decoder<ServerboundClientSettingsPacket> DECODER = Decoder.method(ServerboundClientSettingsPacket::new); public static final PacketReader<ServerboundClientSettingsPacket> DECODER = PacketReader.method(ServerboundClientSettingsPacket::new);
private @Nullable String locale; private @Nullable String locale;
private byte viewDistance; private byte viewDistance;

Datei anzeigen

@ -6,10 +6,11 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ServerboundEncryptionResponsePacket implements Packet { public class ServerboundEncryptionResponsePacket implements Packet {
public static final Decoder<ServerboundEncryptionResponsePacket> DECODER = (buf, direction, version) -> { public static final PacketReader<ServerboundEncryptionResponsePacket> DECODER = (buf, direction, 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)) {
@ -25,7 +26,7 @@ public class ServerboundEncryptionResponsePacket implements Packet {
private final byte[] sharedSecret; private final byte[] sharedSecret;
private final byte[] verifyToken; private final byte[] verifyToken;
public ServerboundEncryptionResponsePacket(final byte[] sharedSecret, final byte[] verifyToken) { private ServerboundEncryptionResponsePacket(final byte[] sharedSecret, final byte[] verifyToken) {
this.sharedSecret = sharedSecret; this.sharedSecret = sharedSecret;
this.verifyToken = verifyToken; this.verifyToken = verifyToken;
} }

Datei anzeigen

@ -6,10 +6,11 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class ServerboundHandshakePacket implements Packet { public class ServerboundHandshakePacket implements Packet {
public static final Decoder<ServerboundHandshakePacket> DECODER = (buf, direction, version) -> { public static final PacketReader<ServerboundHandshakePacket> DECODER = (buf, direction, 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);

Datei anzeigen

@ -3,9 +3,10 @@ package com.velocitypowered.proxy.network.packet.serverbound;
import com.velocitypowered.proxy.network.packet.AbstractKeepAlivePacket; 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;
public class ServerboundKeepAlivePacket extends AbstractKeepAlivePacket implements Packet { public class ServerboundKeepAlivePacket extends AbstractKeepAlivePacket implements Packet {
public static final Decoder<ServerboundKeepAlivePacket> DECODER = decoder(ServerboundKeepAlivePacket::new); public static final PacketReader<ServerboundKeepAlivePacket> DECODER = decoder(ServerboundKeepAlivePacket::new);
public ServerboundKeepAlivePacket(final long randomId) { public ServerboundKeepAlivePacket(final long randomId) {
super(randomId); super(randomId);

Datei anzeigen

@ -6,6 +6,7 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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;
@ -13,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 Decoder<ServerboundLoginPluginResponsePacket> DECODER = (buf, direction, version) -> { public static final PacketReader<ServerboundLoginPluginResponsePacket> DECODER = (buf, direction, 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;

Datei anzeigen

@ -0,0 +1,26 @@
package com.velocitypowered.proxy.network.packet.serverbound;
import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
public class ServerboundPluginMessagePacket extends AbstractPluginMessagePacket<ServerboundPluginMessagePacket> implements Packet {
public static final Factory<ServerboundPluginMessagePacket> FACTORY = ServerboundPluginMessagePacket::new;
public static final PacketReader<ServerboundPluginMessagePacket> DECODER = decoder(FACTORY);
public ServerboundPluginMessagePacket(final String channel, final ByteBuf backing) {
super(channel, backing);
}
@Override
public boolean handle(PacketHandler handler) {
return handler.handle(this);
}
@Override
public ServerboundPluginMessagePacket replace(ByteBuf content) {
return new ServerboundPluginMessagePacket(this.channel, content);
}
}

Datei anzeigen

@ -7,11 +7,12 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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 Decoder<ServerboundResourcePackResponsePacket> DECODER = (buf, direction, version) -> { public static final PacketReader<ServerboundResourcePackResponsePacket> DECODER = (buf, direction, 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);

Datei anzeigen

@ -6,6 +6,7 @@ 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.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.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;
@ -13,7 +14,7 @@ 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 Decoder<ServerboundServerLoginPacket> DECODER = (buf, direction, version) -> { public static final PacketReader<ServerboundServerLoginPacket> DECODER = (buf, direction, 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;

Datei anzeigen

@ -3,9 +3,10 @@ package com.velocitypowered.proxy.network.packet.serverbound;
import com.velocitypowered.proxy.network.packet.AbstractStatusPingPacket; 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;
public class ServerboundStatusPingPacket extends AbstractStatusPingPacket implements Packet { public class ServerboundStatusPingPacket extends AbstractStatusPingPacket implements Packet {
public static final Decoder<ServerboundStatusPingPacket> DECODER = decoder(ServerboundStatusPingPacket::new); public static final PacketReader<ServerboundStatusPingPacket> DECODER = decoder(ServerboundStatusPingPacket::new);
public ServerboundStatusPingPacket(final long randomId) { public ServerboundStatusPingPacket(final long randomId) {
super(randomId); super(randomId);

Datei anzeigen

@ -4,11 +4,12 @@ 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.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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 Decoder<ServerboundStatusRequestPacket> DECODER = Decoder.instance(INSTANCE); public static final PacketReader<ServerboundStatusRequestPacket> DECODER = PacketReader.instance(INSTANCE);
private ServerboundStatusRequestPacket() { private ServerboundStatusRequestPacket() {
} }

Datei anzeigen

@ -10,11 +10,12 @@ 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler; import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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 Decoder<ServerboundTabCompleteRequestPacket> DECODER = Decoder.method(ServerboundTabCompleteRequestPacket::new); public static final PacketReader<ServerboundTabCompleteRequestPacket> DECODER = PacketReader.method(ServerboundTabCompleteRequestPacket::new);
private static final int VANILLA_MAX_TAB_COMPLETE_LEN = 2048; private static final int VANILLA_MAX_TAB_COMPLETE_LEN = 2048;

Datei anzeigen

@ -55,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.decodePacket(packetId, buf, direction, registry.version); packet = this.registry.readPacket(packetId, buf, direction, 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
} }

Datei anzeigen

@ -20,6 +20,7 @@ import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundHandshakePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusPingPacket; import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusPingPacket;
import io.netty.buffer.Unpooled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
class PacketRegistryTest { class PacketRegistryTest {
@ -36,7 +37,7 @@ class PacketRegistryTest {
@Test @Test
void packetRegistryWorks() { void packetRegistryWorks() {
StateRegistry.PacketRegistry registry = setupRegistry(); StateRegistry.PacketRegistry registry = setupRegistry();
Packet packet = registry.getProtocolRegistry(MINECRAFT_1_12).createPacket(0); Packet packet = registry.getProtocolRegistry(MINECRAFT_1_12).readPacket(0, Unpooled.EMPTY_BUFFER, PacketDirection.SERVERBOUND, MINECRAFT_1_12);
assertNotNull(packet, "Packet was not found in registry"); assertNotNull(packet, "Packet was not found in registry");
assertEquals(ServerboundHandshakePacket.class, assertEquals(ServerboundHandshakePacket.class,
packet.getClass(), "Registry returned wrong class"); packet.getClass(), "Registry returned wrong class");
@ -48,7 +49,7 @@ class PacketRegistryTest {
@Test @Test
void packetRegistryLinkingWorks() { void packetRegistryLinkingWorks() {
StateRegistry.PacketRegistry registry = setupRegistry(); StateRegistry.PacketRegistry registry = setupRegistry();
Packet packet = registry.getProtocolRegistry(MINECRAFT_1_12_1).createPacket(0); Packet packet = registry.getProtocolRegistry(MINECRAFT_1_12_1).readPacket(0, Unpooled.EMPTY_BUFFER, PacketDirection.SERVERBOUND, MINECRAFT_1_12);
assertNotNull(packet, "Packet was not found in registry"); assertNotNull(packet, "Packet was not found in registry");
assertEquals(ServerboundHandshakePacket.class, assertEquals(ServerboundHandshakePacket.class,
packet.getClass(), "Registry returned wrong class"); packet.getClass(), "Registry returned wrong class");
@ -58,7 +59,7 @@ class PacketRegistryTest {
"Registry did not return the correct packet ID"); "Registry did not return the correct packet ID");
assertEquals(1, registry.getProtocolRegistry(MINECRAFT_1_11).getPacketId(packet), assertEquals(1, registry.getProtocolRegistry(MINECRAFT_1_11).getPacketId(packet),
"Registry did not return the correct packet ID"); "Registry did not return the correct packet ID");
assertNull(registry.getProtocolRegistry(MINECRAFT_1_14_2).createPacket(0x01), assertNull(registry.getProtocolRegistry(MINECRAFT_1_14_2).readPacket(0x01, Unpooled.EMPTY_BUFFER, PacketDirection.SERVERBOUND, MINECRAFT_1_12),
"Registry should return a null"); "Registry should return a null");
} }
@ -126,14 +127,19 @@ class PacketRegistryTest {
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));
assertEquals(ServerboundHandshakePacket.class, assertEquals(ServerboundHandshakePacket.class,
registry.getProtocolRegistry(MINECRAFT_1_12).createPacket(0x00).getClass()); registry.getProtocolRegistry(MINECRAFT_1_12).readPacket(0x00, Unpooled.EMPTY_BUFFER,
PacketDirection.SERVERBOUND, MINECRAFT_1_12).getClass());
assertEquals(ServerboundHandshakePacket.class, assertEquals(ServerboundHandshakePacket.class,
registry.getProtocolRegistry(MINECRAFT_1_12_1).createPacket(0x01).getClass()); registry.getProtocolRegistry(MINECRAFT_1_12_1).readPacket(0x01, Unpooled.EMPTY_BUFFER,
PacketDirection.SERVERBOUND, MINECRAFT_1_12).getClass());
assertEquals(ServerboundHandshakePacket.class, assertEquals(ServerboundHandshakePacket.class,
registry.getProtocolRegistry(MINECRAFT_1_12_2).createPacket(0x01).getClass()); registry.getProtocolRegistry(MINECRAFT_1_12_2).readPacket(0x01, Unpooled.EMPTY_BUFFER,
PacketDirection.SERVERBOUND, MINECRAFT_1_12).getClass());
assertEquals(ServerboundHandshakePacket.class, assertEquals(ServerboundHandshakePacket.class,
registry.getProtocolRegistry(MINECRAFT_1_13).createPacket(0x02).getClass()); registry.getProtocolRegistry(MINECRAFT_1_13).readPacket(0x02, Unpooled.EMPTY_BUFFER,
PacketDirection.SERVERBOUND, MINECRAFT_1_12).getClass());
assertEquals(ServerboundHandshakePacket.class, assertEquals(ServerboundHandshakePacket.class,
registry.getProtocolRegistry(MINECRAFT_1_14_2).createPacket(0x02).getClass()); registry.getProtocolRegistry(MINECRAFT_1_14_2).readPacket(0x02, Unpooled.EMPTY_BUFFER,
PacketDirection.SERVERBOUND, MINECRAFT_1_12).getClass());
} }
} }