3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-09-29 06:30:16 +02: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.forge.legacy.LegacyForgeHandshakeBackendPhase;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket;
import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
/**
* Provides connection phase specific actions.
@ -21,7 +21,7 @@ public interface BackendConnectionPhase {
*/
default boolean handle(VelocityServerConnection server,
ConnectedPlayer player,
PluginMessagePacket message) {
AbstractPluginMessagePacket<?> message) {
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.forge.legacy.LegacyForgeHandshakeBackendPhase;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket;
import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
/**
* Contains Vanilla {@link BackendConnectionPhase}s.
@ -29,7 +29,7 @@ public final class BackendConnectionPhases {
@Override
public boolean handle(VelocityServerConnection serverConn,
ConnectedPlayer player,
PluginMessagePacket message) {
AbstractPluginMessagePacket<?> message) {
// The connection may be legacy forge. If so, the Forge handler will deal with this
// for us. Otherwise, we have nothing to do.
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.util.ConnectionMessages;
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.clientbound.ClientboundAvailableCommandsPacket;
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.ClientboundPlayerListItemPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundPluginMessagePacket;
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.ByteBufUtil;
import io.netty.buffer.Unpooled;
@ -64,7 +65,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
serverConn.getServer().addPlayer(serverConn.getPlayer());
MinecraftConnection serverMc = serverConn.ensureConnected();
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
public boolean handle(PluginMessagePacket packet) {
public boolean handle(ClientboundPluginMessagePacket packet) {
if (bungeecordMessageResponder.process(packet)) {
return true;
}
@ -123,8 +124,8 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
}
if (PluginMessageUtil.isMcBrand(packet)) {
PluginMessagePacket rewritten = PluginMessageUtil.rewriteMinecraftBrand(packet,
server.getVersion(), playerConnection.getProtocolVersion());
AbstractPluginMessagePacket<?> rewritten = PluginMessageUtil.rewriteMinecraftBrand(packet,
server.getVersion(), playerConnection.getProtocolVersion(), ClientboundPluginMessagePacket.FACTORY);
playerConnection.write(rewritten);
return true;
}
@ -145,7 +146,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
server.getEventManager().fire(event)
.thenAcceptAsync(pme -> {
if (pme.getResult().isAllowed() && !playerConnection.isClosed()) {
PluginMessagePacket copied = new PluginMessagePacket(packet.getChannel(),
ClientboundPluginMessagePacket copied = new ClientboundPluginMessagePacket(packet.getChannel(),
Unpooled.wrappedBuffer(copy));
playerConnection.write(copied);
}
@ -244,8 +245,8 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
@Override
public void handleGeneric(Packet packet) {
if (packet instanceof PluginMessagePacket) {
((PluginMessagePacket) packet).retain();
if (packet instanceof AbstractPluginMessagePacket<?>) {
((AbstractPluginMessagePacket<?>) packet).retain();
}
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.network.buffer.ByteBufDataInput;
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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import io.netty.buffer.ByteBuf;
@ -45,7 +46,7 @@ public class BungeeCordMessageResponder {
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()
.equals(message.getChannel());
}
@ -312,7 +313,7 @@ public class BungeeCordMessageResponder {
MinecraftConnection serverConnection = player.ensureAndGetCurrentServer().ensureConnected();
String chan = getBungeeCordChannel(serverConnection.getProtocolVersion());
PluginMessagePacket msg = null;
ServerboundPluginMessagePacket msg = null;
boolean released = false;
try {
@ -322,7 +323,7 @@ public class BungeeCordMessageResponder {
}
MinecraftConnection serverConn = vsc.ensureConnected();
msg = new PluginMessagePacket(chan, buf);
msg = new ServerboundPluginMessagePacket(chan, buf);
serverConn.write(msg);
released = true;
} finally {
@ -332,7 +333,7 @@ public class BungeeCordMessageResponder {
}
}
boolean process(PluginMessagePacket message) {
boolean process(AbstractPluginMessagePacket<?> message) {
if (!proxy.getConfiguration().isBungeePluginChannelEnabled()) {
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.network.ProtocolUtils;
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.ClientboundLoginPluginMessagePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundServerLoginSuccessPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundLoginPluginResponsePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import com.velocitypowered.proxy.util.except.QuietRuntimeException;
import io.netty.buffer.ByteBuf;
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.Impl;
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.ClientboundJoinGamePacket;
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.util.concurrent.CompletableFuture;
import org.apache.logging.log4j.LogManager;
@ -150,7 +150,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
}
@Override
public boolean handle(PluginMessagePacket packet) {
public boolean handle(ClientboundPluginMessagePacket packet) {
if (!serverConn.getPlayer().canForwardPluginMessage(serverConn.ensureConnected()
.getProtocolVersion(), packet)) {
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.packet.clientbound.ClientboundJoinGamePacket;
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.shared.PluginMessagePacket;
import com.velocitypowered.proxy.server.VelocityRegisteredServer;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@ -234,7 +234,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
MinecraftConnection mc = ensureConnected();
PluginMessagePacket message = new PluginMessagePacket(identifier.getId(), data);
ServerboundPluginMessagePacket message = new ServerboundPluginMessagePacket(identifier.getId(), data);
mc.write(message);
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.forge.legacy.LegacyForgeHandshakeClientPhase;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket;
import com.velocitypowered.proxy.network.packet.AbstractPluginMessagePacket;
/**
* Provides connection phase specific actions.
@ -22,7 +22,7 @@ public interface ClientConnectionPhase {
* @return true if handled, false otherwise.
*/
default boolean handle(ConnectedPlayer player,
PluginMessagePacket message,
AbstractPluginMessagePacket<?> message,
VelocityServerConnection server) {
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.network.PluginMessageUtil;
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.clientbound.ClientboundBossBarPacket;
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.ClientboundTabCompleteResponsePacket;
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.ServerboundClientSettingsPacket;
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.ServerboundTabCompleteRequestPacket;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
@ -64,7 +66,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
private final ConnectedPlayer player;
private boolean spawned = false;
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 @Nullable ServerboundTabCompleteRequestPacket outstandingTabComplete;
@ -83,7 +85,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
Collection<String> channels = server.getChannelRegistrar().getChannelsForProtocol(player
.getProtocolVersion());
if (!channels.isEmpty()) {
PluginMessagePacket register = constructChannelsPacket(player.getProtocolVersion(), channels);
AbstractPluginMessagePacket<?> register = constructChannelsPacket(player.getProtocolVersion(),
channels, ClientboundPluginMessagePacket.FACTORY);
player.getConnection().write(register);
player.getKnownChannels().addAll(channels);
}
@ -91,7 +94,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
@Override
public void deactivated() {
for (PluginMessagePacket message : loginPluginMessages) {
for (ServerboundPluginMessagePacket message : loginPluginMessages) {
ReferenceCountUtil.release(message);
}
}
@ -180,7 +183,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
}
@Override
public boolean handle(PluginMessagePacket packet) {
public boolean handle(ServerboundPluginMessagePacket packet) {
VelocityServerConnection serverConn = player.getConnectedServer();
MinecraftConnection backendConn = serverConn != null ? serverConn.getConnection() : null;
if (serverConn != null && backendConn != null) {
@ -195,7 +198,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
backendConn.write(packet.retain());
} else if (PluginMessageUtil.isMcBrand(packet)) {
backendConn.write(PluginMessageUtil
.rewriteMinecraftBrand(packet, server.getVersion(), player.getProtocolVersion()));
.rewriteMinecraftBrand(packet, server.getVersion(), player.getProtocolVersion(), ServerboundPluginMessagePacket.FACTORY));
} else if (BungeeCordMessageResponder.isBungeeCordMessage(packet)) {
return true;
} else {
@ -229,7 +232,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
ByteBufUtil.getBytes(packet.content()));
server.getEventManager().fire(event).thenAcceptAsync(pme -> {
if (pme.getResult().isAllowed()) {
PluginMessagePacket message = new PluginMessagePacket(packet.getChannel(),
ServerboundPluginMessagePacket message = new ServerboundPluginMessagePacket(packet.getChannel(),
Unpooled.wrappedBuffer(copy));
backendConn.write(message);
}
@ -265,8 +268,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
MinecraftConnection smc = serverConnection.getConnection();
if (smc != null && serverConnection.getPhase().consideredComplete()) {
if (packet instanceof PluginMessagePacket) {
((PluginMessagePacket) packet).retain();
if (packet instanceof AbstractPluginMessagePacket<?>) {
((AbstractPluginMessagePacket<?>) packet).retain();
}
smc.write(packet);
}
@ -356,11 +359,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
// Tell the server about this client's plugin message channels.
ProtocolVersion serverVersion = serverMc.getProtocolVersion();
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.
PluginMessagePacket pm;
ServerboundPluginMessagePacket pm;
while ((pm = loginPluginMessages.poll()) != null) {
serverMc.delayedWrite(pm);
}
@ -585,7 +588,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
if (serverConnection != null) {
MinecraftConnection connection = serverConnection.getConnection();
if (connection != null) {
PluginMessagePacket pm;
ServerboundPluginMessagePacket pm;
while ((pm = loginPluginMessages.poll()) != null) {
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.ProtocolUtils;
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.ClientboundDisconnectPacket;
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.ClientboundTitlePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundChatPacket;
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.tablist.VelocityTabList;
import com.velocitypowered.proxy.tablist.VelocityTabListLegacy;
@ -659,7 +660,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
public boolean sendPluginMessage(ChannelIdentifier identifier, byte[] data) {
Preconditions.checkNotNull(identifier, "identifier");
Preconditions.checkNotNull(data, "data");
PluginMessagePacket message = new PluginMessagePacket(identifier.getId(),
ClientboundPluginMessagePacket message = new ClientboundPluginMessagePacket(identifier.getId(),
Unpooled.wrappedBuffer(data));
connection.write(message);
return true;
@ -734,7 +735,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
* @param message the plugin message to forward to the client
* @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;
// 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.VelocityServerConnection;
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 {
@ -15,7 +15,7 @@ public class InitialConnectSessionHandler implements MinecraftSessionHandler {
}
@Override
public boolean handle(PluginMessagePacket packet) {
public boolean handle(ServerboundPluginMessagePacket packet) {
VelocityServerConnection serverConn = player.getConnectionInFlight();
if (serverConn != null) {
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.proxy.connection.MinecraftConnection;
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.serverbound.ServerboundHandshakePacket;
import java.net.InetSocketAddress;
import java.util.Optional;
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.MinecraftSessionHandler;
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.ClientboundServerLoginSuccessPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundSetCompressionPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundEncryptionResponsePacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundServerLoginPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundDisconnectPacket;
import io.netty.buffer.ByteBuf;
import java.net.InetSocketAddress;
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.VelocityServerConnection;
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;
/**
@ -107,7 +107,7 @@ public enum LegacyForgeHandshakeBackendPhase implements BackendConnectionPhase {
@Override
public final boolean handle(VelocityServerConnection serverConnection,
ConnectedPlayer player,
PluginMessagePacket message) {
AbstractPluginMessagePacket<?> message) {
if (message.getChannel().equals(LegacyForgeConstants.FORGE_LEGACY_HANDSHAKE_CHANNEL)) {
// Get the phase and check if we need to start the next phase.
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.
*/
private LegacyForgeHandshakeBackendPhase getNewPhase(VelocityServerConnection serverConnection,
PluginMessagePacket packet) {
AbstractPluginMessagePacket<?> packet) {
if (packetToAdvanceOn != null
&& LegacyForgeUtil.getHandshakePacketDiscriminator(packet) == packetToAdvanceOn) {
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.ClientPlaySessionHandler;
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 javax.annotation.Nullable;
@ -39,7 +39,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase {
@Override
boolean onHandle(ConnectedPlayer player,
PluginMessagePacket message,
AbstractPluginMessagePacket<?> message,
MinecraftConnection backendConn) {
// If we stay in this phase, we do nothing because it means the packet wasn't handled.
// Returning false indicates this
@ -73,7 +73,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase {
@Override
boolean onHandle(ConnectedPlayer player,
PluginMessagePacket message,
AbstractPluginMessagePacket<?> message,
MinecraftConnection backendConn) {
// Read the mod list if we haven't already.
if (!player.getModInfo().isPresent()) {
@ -147,7 +147,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase {
@Override
boolean onHandle(ConnectedPlayer player,
PluginMessagePacket message,
AbstractPluginMessagePacket<?> message,
MinecraftConnection backendConn) {
super.onHandle(player, message, backendConn);
@ -180,7 +180,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase {
@Override
public final boolean handle(ConnectedPlayer player,
PluginMessagePacket message,
AbstractPluginMessagePacket<?> message,
VelocityServerConnection server) {
if (server != null) {
MinecraftConnection backendConn = server.getConnection();
@ -211,7 +211,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase {
* @return true if handled, false otherwise.
*/
boolean onHandle(ConnectedPlayer player,
PluginMessagePacket message,
AbstractPluginMessagePacket<?> message,
MinecraftConnection backendConn) {
// Send the packet on to the server.
backendConn.write(message.retain());
@ -241,7 +241,7 @@ public enum LegacyForgeHandshakeClientPhase implements ClientConnectionPhase {
* @param packet The packet
* @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
&& LegacyForgeUtil.getHandshakePacketDiscriminator(packet) == packetToAdvanceOn) {
return nextPhase();

Datei anzeigen

@ -8,7 +8,8 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.util.ModInfo;
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.Unpooled;
import java.util.List;
@ -25,7 +26,7 @@ class LegacyForgeUtil {
* @param message The message to analyse
* @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.content().isReadable());
return message.content().getByte(0);
@ -37,7 +38,7 @@ class LegacyForgeUtil {
* @param message The message
* @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
.checkArgument(message.getChannel().equals(FORGE_LEGACY_HANDSHAKE_CHANNEL),
@ -71,8 +72,8 @@ class LegacyForgeUtil {
*
* @return A copy of the reset packet
*/
static PluginMessagePacket resetPacket() {
return new PluginMessagePacket(
static AbstractPluginMessagePacket<?> resetPacket() {
return new ClientboundPluginMessagePacket(
FORGE_LEGACY_HANDSHAKE_CHANNEL,
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.velocitypowered.api.network.ProtocolVersion;
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.Unpooled;
import java.nio.charset.StandardCharsets;
@ -33,7 +33,7 @@ public final class PluginMessageUtil {
* @param message the 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");
return message.getChannel().equals(BRAND_CHANNEL_LEGACY) || message.getChannel()
.equals(BRAND_CHANNEL);
@ -44,7 +44,7 @@ public final class PluginMessageUtil {
* @param message the plugin message
* @return whether we are registering plugin channels or not
*/
public static boolean isRegister(PluginMessagePacket message) {
public static boolean isRegister(AbstractPluginMessagePacket<?> message) {
checkNotNull(message, "message");
return message.getChannel().equals(REGISTER_CHANNEL_LEGACY) || message.getChannel()
.equals(REGISTER_CHANNEL);
@ -55,7 +55,7 @@ public final class PluginMessageUtil {
* @param message the plugin message
* @return whether we are unregistering plugin channels or not
*/
public static boolean isUnregister(PluginMessagePacket message) {
public static boolean isUnregister(AbstractPluginMessagePacket<?> message) {
checkNotNull(message, "message");
return message.getChannel().equals(UNREGISTER_CHANNEL_LEGACY) || message.getChannel()
.equals(UNREGISTER_CHANNEL);
@ -66,7 +66,7 @@ public final class PluginMessageUtil {
* @param message the plugin message
* @return whether this is a legacy register message
*/
public static boolean isLegacyRegister(PluginMessagePacket message) {
public static boolean isLegacyRegister(AbstractPluginMessagePacket<?> message) {
checkNotNull(message, "message");
return message.getChannel().equals(REGISTER_CHANNEL_LEGACY);
}
@ -77,7 +77,7 @@ public final class PluginMessageUtil {
* @param message the plugin message
* @return whether this is a legacy unregister message
*/
public static boolean isLegacyUnregister(PluginMessagePacket message) {
public static boolean isLegacyUnregister(AbstractPluginMessagePacket<?> message) {
checkNotNull(message, "message");
return message.getChannel().equals(UNREGISTER_CHANNEL_LEGACY);
}
@ -87,7 +87,7 @@ public final class PluginMessageUtil {
* @param message the message to get the channels from
* @return the channels, as an immutable list
*/
public static List<String> getChannels(PluginMessagePacket message) {
public static List<String> getChannels(AbstractPluginMessagePacket<?> message) {
checkNotNull(message, "message");
checkArgument(isRegister(message) || isUnregister(message), "Unknown channel type %s",
message.getChannel());
@ -106,15 +106,16 @@ public final class PluginMessageUtil {
* @param channels the channels to register
* @return the plugin message to send
*/
public static PluginMessagePacket constructChannelsPacket(ProtocolVersion protocolVersion,
Collection<String> channels) {
public static AbstractPluginMessagePacket<?> constructChannelsPacket(ProtocolVersion protocolVersion,
Collection<String> channels,
AbstractPluginMessagePacket.Factory<?> factory) {
checkNotNull(channels, "channels");
checkArgument(!channels.isEmpty(), "no channels specified");
String channelName = protocolVersion.gte(ProtocolVersion.MINECRAFT_1_13)
? REGISTER_CHANNEL : REGISTER_CHANNEL_LEGACY;
ByteBuf contents = Unpooled.buffer();
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
* @return the rewritten plugin message
*/
public static PluginMessagePacket rewriteMinecraftBrand(PluginMessagePacket message,
public static AbstractPluginMessagePacket<?> rewriteMinecraftBrand(AbstractPluginMessagePacket<?> message,
ProxyVersion version,
ProtocolVersion protocolVersion) {
ProtocolVersion protocolVersion,
AbstractPluginMessagePacket.Factory<?> factory) {
checkNotNull(message, "message");
checkNotNull(version, "version");
checkArgument(isMcBrand(message), "message is not a brand plugin message");
@ -140,7 +142,7 @@ public final class PluginMessageUtil {
rewrittenBuf.writeCharSequence(rewrittenBrand, StandardCharsets.UTF_8);
}
return new PluginMessagePacket(message.getChannel(), rewrittenBuf);
return factory.create(message.getChannel(), rewrittenBuf);
}
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.proxy.network.packet.Packet;
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.ClientboundBossBarPacket;
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.ClientboundHeaderAndFooterPacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundJoinGamePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundKeepAlivePacket;
import com.velocitypowered.proxy.network.packet.clientbound.ClientboundLoginPluginMessagePacket;
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.ClientboundRespawnPacket;
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.ServerboundKeepAlivePacket;
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.ServerboundServerLoginPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusPingPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusRequestPacket;
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.util.collection.IntObjectHashMap;
import io.netty.util.collection.IntObjectMap;
@ -58,7 +60,6 @@ import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Map;
import java.util.Objects;
import java.util.function.Supplier;
import org.checkerframework.checker.nullness.qual.Nullable;
public enum StateRegistry {
@ -128,8 +129,8 @@ public enum StateRegistry {
map(0x05, MINECRAFT_1_14, false)
);
serverbound.register(
PluginMessagePacket.class,
PluginMessagePacket.DECODER,
ServerboundPluginMessagePacket.class,
ServerboundPluginMessagePacket.DECODER,
map(0x17, MINECRAFT_1_7_2, false),
map(0x09, MINECRAFT_1_9, false),
map(0x0A, MINECRAFT_1_12, false),
@ -195,8 +196,8 @@ public enum StateRegistry {
map(0x10, MINECRAFT_1_16_2, false)
);
clientbound.register(
PluginMessagePacket.class,
PluginMessagePacket.DECODER,
ClientboundPluginMessagePacket.class,
ClientboundPluginMessagePacket.DECODER,
map(0x3F, MINECRAFT_1_7_2, false),
map(0x18, MINECRAFT_1_9, false),
map(0x19, MINECRAFT_1_13, false),
@ -400,7 +401,7 @@ public enum StateRegistry {
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) {
if (mappings.length == 0) {
throw new IllegalArgumentException("At least one mapping must be provided.");
@ -427,7 +428,7 @@ public enum StateRegistry {
+ current.protocolVersion);
}
if (registry.packetIdToSupplier.containsKey(current.id)) {
if (registry.packetIdToReader.containsKey(current.id)) {
throw new IllegalArgumentException("Can not register class " + clazz.getSimpleName()
+ " with id " + current.id + " for " + registry.version
+ " because another packet is already registered");
@ -439,7 +440,7 @@ public enum StateRegistry {
}
if (!current.encodeOnly) {
registry.packetIdToDecoder.put(current.id, decoder);
registry.packetIdToReader.put(current.id, decoder);
}
registry.packetClassToId.put(clazz, current.id);
}
@ -449,10 +450,7 @@ public enum StateRegistry {
public class ProtocolRegistry {
public final ProtocolVersion version;
@Deprecated
final IntObjectMap<Supplier<? extends Packet>> packetIdToSupplier =
new IntObjectHashMap<>(16, 0.5f);
final IntObjectMap<Packet.Decoder<? extends Packet>> packetIdToDecoder =
final IntObjectMap<PacketReader<? extends Packet>> packetIdToReader =
new IntObjectHashMap<>(16, 0.5f);
final Object2IntMap<Class<? extends Packet>> packetClassToId =
new Object2IntOpenHashMap<>(16, 0.5f);
@ -462,21 +460,6 @@ public enum StateRegistry {
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}.
*
@ -486,13 +469,13 @@ public enum StateRegistry {
* @param version the protocol version
* @return the packet instance, or {@code null} if the ID is not registered
*/
public @Nullable Packet decodePacket(final int id, ByteBuf buf, PacketDirection direction,
ProtocolVersion version) {
final Packet.Decoder<? extends Packet> decoder = this.packetIdToDecoder.get(id);
public @Nullable Packet readPacket(final int id, ByteBuf buf, PacketDirection direction,
ProtocolVersion version) {
final PacketReader<? extends Packet> decoder = this.packetIdToReader.get(id);
if (decoder == 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 {
private final int id;
private final ProtocolVersion protocolVersion;
private final boolean encodeOnly;
final int id;
final ProtocolVersion protocolVersion;
final boolean encodeOnly;
PacketMapping(int id, ProtocolVersion protocolVersion, boolean packetDecoding) {
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;
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) -> {
final long randomId;
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 com.google.common.base.MoreObjects;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.network.ProtocolUtils;
import com.velocitypowered.proxy.network.packet.Packet;
import com.velocitypowered.proxy.network.packet.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.buffer.TypedDefaultByteBufHolder;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder;
import java.util.Objects;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
public class PluginMessagePacket extends DefaultByteBufHolder implements Packet {
public static final Decoder<PluginMessagePacket> DECODER = (buf, direction, version) -> {
String channel = ProtocolUtils.readString(buf);
if (version.gte(ProtocolVersion.MINECRAFT_1_13)) {
channel = transformLegacyToModernChannel(channel);
}
final ByteBuf data;
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
data = buf.readRetainedSlice(buf.readableBytes());
} else {
data = ProtocolUtils.readRetainedByteBufSlice17(buf);
}
return new PluginMessagePacket(channel, data);
};
public abstract class AbstractPluginMessagePacket<S extends AbstractPluginMessagePacket<S>> extends TypedDefaultByteBufHolder<S> implements Packet {
protected static <P extends AbstractPluginMessagePacket<P>> PacketReader<P> decoder(final Factory<P> factory) {
return (buf, direction, version) -> {
String channel = ProtocolUtils.readString(buf);
if (version.gte(ProtocolVersion.MINECRAFT_1_13)) {
channel = transformLegacyToModernChannel(channel);
}
final ByteBuf data;
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
data = buf.readRetainedSlice(buf.readableBytes());
} else {
data = ProtocolUtils.readRetainedByteBufSlice17(buf);
}
return factory.create(channel, data);
};
}
private final @Nullable String channel;
protected final @Nullable String channel;
public PluginMessagePacket(String channel,
@MonotonicNonNull ByteBuf backing) {
protected AbstractPluginMessagePacket(String channel,
@MonotonicNonNull ByteBuf backing) {
super(backing);
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() {
if (channel == null) {
throw new IllegalStateException("Channel is not specified.");
@ -66,31 +60,6 @@ public class PluginMessagePacket extends DefaultByteBufHolder implements Packet
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
public boolean equals(final Object other) {
if (this == other) {
@ -99,7 +68,7 @@ public class PluginMessagePacket extends DefaultByteBufHolder implements Packet
if (other == null || this.getClass() != other.getClass()) {
return false;
}
final PluginMessagePacket that = (PluginMessagePacket) other;
final AbstractPluginMessagePacket<?> that = (AbstractPluginMessagePacket<?>) other;
return Objects.equals(this.channel, that.channel)
&& super.equals(other);
}
@ -116,4 +85,8 @@ public class PluginMessagePacket extends DefaultByteBufHolder implements Packet
.add("data", this.contentToString())
.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;
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) -> {
final long randomId = buf.readLong();
return factory.apply(randomId);

Datei anzeigen

@ -15,26 +15,4 @@ public interface Packet {
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.ClientboundLoginPluginMessagePacket;
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.ClientboundRespawnPacket;
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.ServerboundKeepAlivePacket;
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.ServerboundServerLoginPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusPingPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundStatusRequestPacket;
import com.velocitypowered.proxy.network.packet.serverbound.ServerboundTabCompleteRequestPacket;
import com.velocitypowered.proxy.network.packet.shared.PluginMessagePacket;
public interface PacketHandler {
default boolean handle(PluginMessagePacket packet) {
return false;
}
/*
* Clientbound
*/
@ -82,6 +79,10 @@ public interface PacketHandler {
return false;
}
default boolean handle(ClientboundPluginMessagePacket packet) {
return false;
}
default boolean handle(ClientboundResourcePackRequestPacket packet) {
return false;
}
@ -142,6 +143,10 @@ public interface PacketHandler {
return false;
}
default boolean handle(ServerboundPluginMessagePacket packet) {
return false;
}
default boolean handle(ServerboundResourcePackResponsePacket packet) {
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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.network.serialization.brigadier.ArgumentPropertyRegistry;
import io.netty.buffer.ByteBuf;
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;
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;

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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
import java.util.UUID;
import org.checkerframework.checker.nullness.qual.Nullable;
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 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
import java.util.UUID;
import org.checkerframework.checker.nullness.qual.Nullable;
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 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientboundDisconnectPacket implements Packet {
public static final Decoder<ClientboundDisconnectPacket> DECODER = Decoder.method(ClientboundDisconnectPacket::new);
public static final PacketReader<ClientboundDisconnectPacket> DECODER = PacketReader.method(ClientboundDisconnectPacket::new);
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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
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 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
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 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
import net.kyori.adventure.nbt.BinaryTagTypes;
import net.kyori.adventure.nbt.CompoundBinaryTag;
@ -17,7 +18,7 @@ import net.kyori.adventure.nbt.ListBinaryTag;
import org.checkerframework.checker.nullness.qual.Nullable;
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 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.Packet;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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) {
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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder;
import io.netty.buffer.Unpooled;
@ -13,7 +14,7 @@ import java.util.Objects;
import org.checkerframework.checker.nullness.qual.Nullable;
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 String channel = ProtocolUtils.readString(buf);
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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.List;
@ -18,7 +19,7 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable;
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 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
import java.util.Objects;
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 hash = ProtocolUtils.readString(buf);
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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
import net.kyori.adventure.nbt.CompoundBinaryTag;
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 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
import java.util.Objects;
import java.util.UUID;
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;
if (version.gte(ProtocolVersion.MINECRAFT_1_16)) {
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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
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);
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.Packet;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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) {
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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
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);
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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.List;
@ -13,7 +14,7 @@ import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
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 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.util.DurationUtils;
import io.netty.buffer.ByteBuf;
import java.util.Arrays;
@ -14,7 +15,7 @@ import net.kyori.adventure.title.Title;
import org.checkerframework.checker.nullness.qual.Nullable;
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) {
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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
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);
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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
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 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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
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[] verifyToken;
if (version.gte(ProtocolVersion.MINECRAFT_1_8)) {
@ -25,7 +26,7 @@ public class ServerboundEncryptionResponsePacket implements Packet {
private final byte[] sharedSecret;
private final byte[] verifyToken;
public ServerboundEncryptionResponsePacket(final byte[] sharedSecret, final byte[] verifyToken) {
private ServerboundEncryptionResponsePacket(final byte[] sharedSecret, final byte[] verifyToken) {
this.sharedSecret = sharedSecret;
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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
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);
final ProtocolVersion protocolVersion = ProtocolVersion.getProtocolVersion(realProtocolVersion);
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.Packet;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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) {
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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.DefaultByteBufHolder;
import io.netty.buffer.Unpooled;
@ -13,7 +14,7 @@ import java.util.Objects;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
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 boolean success = buf.readBoolean();
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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
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;
if (version.lte(ProtocolVersion.MINECRAFT_1_9_4)) {
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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import com.velocitypowered.proxy.util.except.QuietDecoderException;
import io.netty.buffer.ByteBuf;
import java.util.Objects;
@ -13,7 +14,7 @@ import java.util.Objects;
public class ServerboundServerLoginPacket implements Packet {
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);
if (username.isEmpty()) {
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.Packet;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
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) {
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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
public class ServerboundStatusRequestPacket implements Packet {
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() {
}

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.PacketDirection;
import com.velocitypowered.proxy.network.packet.PacketHandler;
import com.velocitypowered.proxy.network.packet.PacketReader;
import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable;
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;

Datei anzeigen

@ -55,7 +55,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
int packetId = ProtocolUtils.readVarInt(buf);
Packet packet = null;
try {
packet = this.registry.decodePacket(packetId, buf, direction, registry.version);
packet = this.registry.readPacket(packetId, buf, direction, registry.version);
} catch (Exception e) {
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.ServerboundStatusPingPacket;
import io.netty.buffer.Unpooled;
import org.junit.jupiter.api.Test;
class PacketRegistryTest {
@ -36,7 +37,7 @@ class PacketRegistryTest {
@Test
void packetRegistryWorks() {
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");
assertEquals(ServerboundHandshakePacket.class,
packet.getClass(), "Registry returned wrong class");
@ -48,7 +49,7 @@ class PacketRegistryTest {
@Test
void packetRegistryLinkingWorks() {
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");
assertEquals(ServerboundHandshakePacket.class,
packet.getClass(), "Registry returned wrong class");
@ -58,7 +59,7 @@ class PacketRegistryTest {
"Registry did not return the correct packet ID");
assertEquals(1, registry.getProtocolRegistry(MINECRAFT_1_11).getPacketId(packet),
"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");
}
@ -126,14 +127,19 @@ class PacketRegistryTest {
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12_1, false),
new StateRegistry.PacketMapping(0x02, MINECRAFT_1_13, false));
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,
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,
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,
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,
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());
}
}