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

proxy: add 'Packet' suffix to all packets

Dieser Commit ist enthalten in:
Riley Park 2020-11-05 16:21:58 -08:00
Ursprung 02ad6b7e01
Commit b599e7b45c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: D831AF236C834E45
71 geänderte Dateien mit 752 neuen und 721 gelöschten Zeilen

Datei anzeigen

@ -19,7 +19,7 @@ import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler; import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler;
import com.velocitypowered.proxy.connection.client.LoginSessionHandler; import com.velocitypowered.proxy.connection.client.LoginSessionHandler;
import com.velocitypowered.proxy.connection.client.StatusSessionHandler; import com.velocitypowered.proxy.connection.client.StatusSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.netty.MinecraftCipherDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftCipherDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftCipherEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftCipherEncoder;
@ -27,6 +27,7 @@ import com.velocitypowered.proxy.protocol.netty.MinecraftCompressDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftCompressEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftCompressEncoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder;
import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket;
import com.velocitypowered.proxy.util.except.QuietDecoderException; import com.velocitypowered.proxy.util.except.QuietDecoderException;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.Channel;
@ -116,10 +117,10 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
return; return;
} }
if (msg instanceof MinecraftPacket) { if (msg instanceof Packet) {
MinecraftPacket pkt = (MinecraftPacket) msg; Packet pkt = (Packet) msg;
if (!pkt.handle(sessionHandler)) { if (!pkt.handle(sessionHandler)) {
sessionHandler.handleGeneric((MinecraftPacket) msg); sessionHandler.handleGeneric((Packet) msg);
} }
} else if (msg instanceof HAProxyMessage) { } else if (msg instanceof HAProxyMessage) {
HAProxyMessage proxyMessage = (HAProxyMessage) msg; HAProxyMessage proxyMessage = (HAProxyMessage) msg;
@ -368,7 +369,7 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
/** /**
* Sets the compression threshold on the connection. You are responsible for sending * Sets the compression threshold on the connection. You are responsible for sending
* {@link com.velocitypowered.proxy.protocol.packet.SetCompression} beforehand. * {@link SetCompressionPacket} beforehand.
* @param threshold the compression threshold to use * @param threshold the compression threshold to use
*/ */
public void setCompressionThreshold(int threshold) { public void setCompressionThreshold(int threshold) {

Datei anzeigen

@ -1,35 +1,35 @@
package com.velocitypowered.proxy.connection; package com.velocitypowered.proxy.connection;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.packet.AvailableCommands; import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket;
import com.velocitypowered.proxy.protocol.packet.BossBar; import com.velocitypowered.proxy.protocol.packet.BossBarPacket;
import com.velocitypowered.proxy.protocol.packet.Chat; import com.velocitypowered.proxy.protocol.packet.ChatPacket;
import com.velocitypowered.proxy.protocol.packet.ClientSettings; import com.velocitypowered.proxy.protocol.packet.ClientSettingsPacket;
import com.velocitypowered.proxy.protocol.packet.Disconnect; import com.velocitypowered.proxy.protocol.packet.DisconnectPacket;
import com.velocitypowered.proxy.protocol.packet.EncryptionRequest; import com.velocitypowered.proxy.protocol.packet.EncryptionRequestPacket;
import com.velocitypowered.proxy.protocol.packet.EncryptionResponse; import com.velocitypowered.proxy.protocol.packet.EncryptionResponsePacket;
import com.velocitypowered.proxy.protocol.packet.Handshake; import com.velocitypowered.proxy.protocol.packet.HandshakePacket;
import com.velocitypowered.proxy.protocol.packet.HeaderAndFooter; import com.velocitypowered.proxy.protocol.packet.HeaderAndFooterPacket;
import com.velocitypowered.proxy.protocol.packet.JoinGame; import com.velocitypowered.proxy.protocol.packet.JoinGamePacket;
import com.velocitypowered.proxy.protocol.packet.KeepAlive; import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket;
import com.velocitypowered.proxy.protocol.packet.LegacyHandshake; import com.velocitypowered.proxy.protocol.packet.LoginPluginMessagePacket;
import com.velocitypowered.proxy.protocol.packet.LegacyPing; import com.velocitypowered.proxy.protocol.packet.LoginPluginResponsePacket;
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage; import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket;
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse; import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
import com.velocitypowered.proxy.protocol.packet.PlayerListItem; import com.velocitypowered.proxy.protocol.packet.ResourcePackRequestPacket;
import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.ResourcePackResponsePacket;
import com.velocitypowered.proxy.protocol.packet.ResourcePackRequest; import com.velocitypowered.proxy.protocol.packet.RespawnPacket;
import com.velocitypowered.proxy.protocol.packet.ResourcePackResponse; import com.velocitypowered.proxy.protocol.packet.ServerLoginPacket;
import com.velocitypowered.proxy.protocol.packet.Respawn; import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccessPacket;
import com.velocitypowered.proxy.protocol.packet.ServerLogin; import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket;
import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess; import com.velocitypowered.proxy.protocol.packet.StatusPingPacket;
import com.velocitypowered.proxy.protocol.packet.SetCompression; import com.velocitypowered.proxy.protocol.packet.StatusRequestPacket;
import com.velocitypowered.proxy.protocol.packet.StatusPing; import com.velocitypowered.proxy.protocol.packet.StatusResponsePacket;
import com.velocitypowered.proxy.protocol.packet.StatusRequest; import com.velocitypowered.proxy.protocol.packet.TabCompleteRequestPacket;
import com.velocitypowered.proxy.protocol.packet.StatusResponse; import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket;
import com.velocitypowered.proxy.protocol.packet.TabCompleteRequest;
import com.velocitypowered.proxy.protocol.packet.TabCompleteResponse;
import com.velocitypowered.proxy.protocol.packet.TitlePacket; import com.velocitypowered.proxy.protocol.packet.TitlePacket;
import com.velocitypowered.proxy.protocol.packet.legacy.LegacyHandshakePacket;
import com.velocitypowered.proxy.protocol.packet.legacy.LegacyPingPacket;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public interface MinecraftSessionHandler { public interface MinecraftSessionHandler {
@ -38,7 +38,7 @@ public interface MinecraftSessionHandler {
return false; return false;
} }
default void handleGeneric(MinecraftPacket packet) { default void handleGeneric(Packet packet) {
} }
@ -74,103 +74,103 @@ public interface MinecraftSessionHandler {
} }
default boolean handle(AvailableCommands commands) { default boolean handle(AvailableCommandsPacket commands) {
return false; return false;
} }
default boolean handle(BossBar packet) { default boolean handle(BossBarPacket packet) {
return false; return false;
} }
default boolean handle(Chat packet) { default boolean handle(ChatPacket packet) {
return false; return false;
} }
default boolean handle(ClientSettings packet) { default boolean handle(ClientSettingsPacket packet) {
return false; return false;
} }
default boolean handle(Disconnect packet) { default boolean handle(DisconnectPacket packet) {
return false; return false;
} }
default boolean handle(EncryptionRequest packet) { default boolean handle(EncryptionRequestPacket packet) {
return false; return false;
} }
default boolean handle(EncryptionResponse packet) { default boolean handle(EncryptionResponsePacket packet) {
return false; return false;
} }
default boolean handle(Handshake packet) { default boolean handle(HandshakePacket packet) {
return false; return false;
} }
default boolean handle(HeaderAndFooter packet) { default boolean handle(HeaderAndFooterPacket packet) {
return false; return false;
} }
default boolean handle(JoinGame packet) { default boolean handle(JoinGamePacket packet) {
return false; return false;
} }
default boolean handle(KeepAlive packet) { default boolean handle(KeepAlivePacket packet) {
return false; return false;
} }
default boolean handle(LegacyHandshake packet) { default boolean handle(LegacyHandshakePacket packet) {
return false; return false;
} }
default boolean handle(LegacyPing packet) { default boolean handle(LegacyPingPacket packet) {
return false; return false;
} }
default boolean handle(LoginPluginMessage packet) { default boolean handle(LoginPluginMessagePacket packet) {
return false; return false;
} }
default boolean handle(LoginPluginResponse packet) { default boolean handle(LoginPluginResponsePacket packet) {
return false; return false;
} }
default boolean handle(PluginMessage packet) { default boolean handle(PluginMessagePacket packet) {
return false; return false;
} }
default boolean handle(Respawn packet) { default boolean handle(RespawnPacket packet) {
return false; return false;
} }
default boolean handle(ServerLogin packet) { default boolean handle(ServerLoginPacket packet) {
return false; return false;
} }
default boolean handle(ServerLoginSuccess packet) { default boolean handle(ServerLoginSuccessPacket packet) {
return false; return false;
} }
default boolean handle(SetCompression packet) { default boolean handle(SetCompressionPacket packet) {
return false; return false;
} }
default boolean handle(StatusPing packet) { default boolean handle(StatusPingPacket packet) {
return false; return false;
} }
default boolean handle(StatusRequest packet) { default boolean handle(StatusRequestPacket packet) {
return false; return false;
} }
default boolean handle(StatusResponse packet) { default boolean handle(StatusResponsePacket packet) {
return false; return false;
} }
default boolean handle(TabCompleteRequest packet) { default boolean handle(TabCompleteRequestPacket packet) {
return false; return false;
} }
default boolean handle(TabCompleteResponse packet) { default boolean handle(TabCompleteResponsePacket packet) {
return false; return false;
} }
@ -178,15 +178,15 @@ public interface MinecraftSessionHandler {
return false; return false;
} }
default boolean handle(PlayerListItem packet) { default boolean handle(PlayerListItemPacket packet) {
return false; return false;
} }
default boolean handle(ResourcePackRequest packet) { default boolean handle(ResourcePackRequestPacket packet) {
return false; return false;
} }
default boolean handle(ResourcePackResponse packet) { default boolean handle(ResourcePackResponsePacket packet) {
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.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
/** /**
* 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,
PluginMessage message) { PluginMessagePacket 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.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
/** /**
* 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,
PluginMessage message) { PluginMessagePacket 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

@ -16,14 +16,14 @@ import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; 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.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.packet.AvailableCommands; import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket;
import com.velocitypowered.proxy.protocol.packet.BossBar; import com.velocitypowered.proxy.protocol.packet.BossBarPacket;
import com.velocitypowered.proxy.protocol.packet.Disconnect; import com.velocitypowered.proxy.protocol.packet.DisconnectPacket;
import com.velocitypowered.proxy.protocol.packet.KeepAlive; import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket;
import com.velocitypowered.proxy.protocol.packet.PlayerListItem; import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket;
import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
import com.velocitypowered.proxy.protocol.packet.TabCompleteResponse; import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket;
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil; import io.netty.buffer.ByteBufUtil;
@ -79,30 +79,30 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(KeepAlive packet) { public boolean handle(KeepAlivePacket packet) {
serverConn.setLastPingId(packet.getRandomId()); serverConn.setLastPingId(packet.getRandomId());
return false; // forwards on return false; // forwards on
} }
@Override @Override
public boolean handle(Disconnect packet) { public boolean handle(DisconnectPacket packet) {
serverConn.disconnect(); serverConn.disconnect();
serverConn.getPlayer().handleConnectionException(serverConn.getServer(), packet, true); serverConn.getPlayer().handleConnectionException(serverConn.getServer(), packet, true);
return true; return true;
} }
@Override @Override
public boolean handle(BossBar packet) { public boolean handle(BossBarPacket packet) {
if (packet.getAction() == BossBar.ADD) { if (packet.getAction() == BossBarPacket.ADD) {
playerSessionHandler.getServerBossBars().add(packet.getUuid()); playerSessionHandler.getServerBossBars().add(packet.getUuid());
} else if (packet.getAction() == BossBar.REMOVE) { } else if (packet.getAction() == BossBarPacket.REMOVE) {
playerSessionHandler.getServerBossBars().remove(packet.getUuid()); playerSessionHandler.getServerBossBars().remove(packet.getUuid());
} }
return false; // forward return false; // forward
} }
@Override @Override
public boolean handle(PluginMessage packet) { public boolean handle(PluginMessagePacket packet) {
if (bungeecordMessageResponder.process(packet)) { if (bungeecordMessageResponder.process(packet)) {
return true; return true;
} }
@ -123,8 +123,8 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
} }
if (PluginMessageUtil.isMcBrand(packet)) { if (PluginMessageUtil.isMcBrand(packet)) {
PluginMessage rewritten = PluginMessageUtil.rewriteMinecraftBrand(packet, server.getVersion(), PluginMessagePacket rewritten = PluginMessageUtil.rewriteMinecraftBrand(packet,
playerConnection.getProtocolVersion()); server.getVersion(), playerConnection.getProtocolVersion());
playerConnection.write(rewritten); playerConnection.write(rewritten);
return true; return true;
} }
@ -145,7 +145,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()) {
PluginMessage copied = new PluginMessage(packet.getChannel(), PluginMessagePacket copied = new PluginMessagePacket(packet.getChannel(),
Unpooled.wrappedBuffer(copy)); Unpooled.wrappedBuffer(copy));
playerConnection.write(copied); playerConnection.write(copied);
} }
@ -158,19 +158,19 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(TabCompleteResponse packet) { public boolean handle(TabCompleteResponsePacket packet) {
playerSessionHandler.handleTabCompleteResponse(packet); playerSessionHandler.handleTabCompleteResponse(packet);
return true; return true;
} }
@Override @Override
public boolean handle(PlayerListItem packet) { public boolean handle(PlayerListItemPacket packet) {
serverConn.getPlayer().getTabList().processBackendPacket(packet); serverConn.getPlayer().getTabList().processBackendPacket(packet);
return false; //Forward packet to player return false; //Forward packet to player
} }
@Override @Override
public boolean handle(AvailableCommands commands) { public boolean handle(AvailableCommandsPacket commands) {
RootCommandNode<CommandSource> rootNode = commands.getRootNode(); RootCommandNode<CommandSource> rootNode = commands.getRootNode();
if (server.getConfiguration().isAnnounceProxyCommands()) { if (server.getConfiguration().isAnnounceProxyCommands()) {
// Inject commands from the proxy. // Inject commands from the proxy.
@ -243,9 +243,9 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public void handleGeneric(MinecraftPacket packet) { public void handleGeneric(Packet packet) {
if (packet instanceof PluginMessage) { if (packet instanceof PluginMessagePacket) {
((PluginMessage) packet).retain(); ((PluginMessagePacket) packet).retain();
} }
playerConnection.delayedWrite(packet); playerConnection.delayedWrite(packet);
} }
@ -277,7 +277,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
if (!serverConn.isGracefulDisconnect() && !exceptionTriggered) { if (!serverConn.isGracefulDisconnect() && !exceptionTriggered) {
if (server.getConfiguration().isFailoverOnUnexpectedServerDisconnect()) { if (server.getConfiguration().isFailoverOnUnexpectedServerDisconnect()) {
serverConn.getPlayer().handleConnectionException(serverConn.getServer(), serverConn.getPlayer().handleConnectionException(serverConn.getServer(),
Disconnect.create(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR, DisconnectPacket.create(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR,
ProtocolVersion.MINECRAFT_1_16), true); ProtocolVersion.MINECRAFT_1_16), true);
} else { } else {
serverConn.getPlayer().disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); serverConn.getPlayer().disconnect(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR);

Datei anzeigen

@ -9,7 +9,7 @@ import com.velocitypowered.api.util.UuidUtils;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
import com.velocitypowered.proxy.protocol.util.ByteBufDataInput; import com.velocitypowered.proxy.protocol.util.ByteBufDataInput;
import com.velocitypowered.proxy.protocol.util.ByteBufDataOutput; import com.velocitypowered.proxy.protocol.util.ByteBufDataOutput;
import com.velocitypowered.proxy.server.VelocityRegisteredServer; import com.velocitypowered.proxy.server.VelocityRegisteredServer;
@ -45,7 +45,7 @@ public class BungeeCordMessageResponder {
this.player = player; this.player = player;
} }
public static boolean isBungeeCordMessage(PluginMessage message) { public static boolean isBungeeCordMessage(PluginMessagePacket 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 +312,7 @@ public class BungeeCordMessageResponder {
MinecraftConnection serverConnection = player.ensureAndGetCurrentServer().ensureConnected(); MinecraftConnection serverConnection = player.ensureAndGetCurrentServer().ensureConnected();
String chan = getBungeeCordChannel(serverConnection.getProtocolVersion()); String chan = getBungeeCordChannel(serverConnection.getProtocolVersion());
PluginMessage msg = null; PluginMessagePacket msg = null;
boolean released = false; boolean released = false;
try { try {
@ -322,7 +322,7 @@ public class BungeeCordMessageResponder {
} }
MinecraftConnection serverConn = vsc.ensureConnected(); MinecraftConnection serverConn = vsc.ensureConnected();
msg = new PluginMessage(chan, buf); msg = new PluginMessagePacket(chan, buf);
serverConn.write(msg); serverConn.write(msg);
released = true; released = true;
} finally { } finally {
@ -332,7 +332,7 @@ public class BungeeCordMessageResponder {
} }
} }
boolean process(PluginMessage message) { boolean process(PluginMessagePacket 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.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.Disconnect; import com.velocitypowered.proxy.protocol.packet.DisconnectPacket;
import com.velocitypowered.proxy.protocol.packet.EncryptionRequest; import com.velocitypowered.proxy.protocol.packet.EncryptionRequestPacket;
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage; import com.velocitypowered.proxy.protocol.packet.LoginPluginMessagePacket;
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse; import com.velocitypowered.proxy.protocol.packet.LoginPluginResponsePacket;
import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess; import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccessPacket;
import com.velocitypowered.proxy.protocol.packet.SetCompression; import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket;
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;
@ -49,12 +49,12 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(EncryptionRequest packet) { public boolean handle(EncryptionRequestPacket packet) {
throw new IllegalStateException("Backend server is online-mode!"); throw new IllegalStateException("Backend server is online-mode!");
} }
@Override @Override
public boolean handle(LoginPluginMessage packet) { public boolean handle(LoginPluginMessagePacket packet) {
MinecraftConnection mc = serverConn.ensureConnected(); MinecraftConnection mc = serverConn.ensureConnected();
VelocityConfiguration configuration = server.getConfiguration(); VelocityConfiguration configuration = server.getConfiguration();
if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && packet if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && packet
@ -62,31 +62,32 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
ByteBuf forwardingData = createForwardingData(configuration.getForwardingSecret(), ByteBuf forwardingData = createForwardingData(configuration.getForwardingSecret(),
cleanRemoteAddress(serverConn.getPlayer().getRemoteAddress()), cleanRemoteAddress(serverConn.getPlayer().getRemoteAddress()),
serverConn.getPlayer().getGameProfile()); serverConn.getPlayer().getGameProfile());
LoginPluginResponse response = new LoginPluginResponse(packet.getId(), true, forwardingData); LoginPluginResponsePacket response = new LoginPluginResponsePacket(packet.getId(), true,
forwardingData);
mc.write(response); mc.write(response);
informationForwarded = true; informationForwarded = true;
} else { } else {
// Don't understand // Don't understand
mc.write(new LoginPluginResponse(packet.getId(), false, Unpooled.EMPTY_BUFFER)); mc.write(new LoginPluginResponsePacket(packet.getId(), false, Unpooled.EMPTY_BUFFER));
} }
return true; return true;
} }
@Override @Override
public boolean handle(Disconnect packet) { public boolean handle(DisconnectPacket packet) {
resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.getServer())); resultFuture.complete(ConnectionRequestResults.forDisconnect(packet, serverConn.getServer()));
serverConn.disconnect(); serverConn.disconnect();
return true; return true;
} }
@Override @Override
public boolean handle(SetCompression packet) { public boolean handle(SetCompressionPacket packet) {
serverConn.ensureConnected().setCompressionThreshold(packet.getThreshold()); serverConn.ensureConnected().setCompressionThreshold(packet.getThreshold());
return true; return true;
} }
@Override @Override
public boolean handle(ServerLoginSuccess packet) { public boolean handle(ServerLoginSuccessPacket packet) {
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN
&& !informationForwarded) { && !informationForwarded) {
resultFuture.complete(ConnectionRequestResults.forDisconnect(MODERN_IP_FORWARDING_FAILURE, resultFuture.complete(ConnectionRequestResults.forDisconnect(MODERN_IP_FORWARDING_FAILURE,

Datei anzeigen

@ -14,10 +14,10 @@ import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.connection.util.ConnectionMessages; 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.protocol.packet.Disconnect; import com.velocitypowered.proxy.protocol.packet.DisconnectPacket;
import com.velocitypowered.proxy.protocol.packet.JoinGame; import com.velocitypowered.proxy.protocol.packet.JoinGamePacket;
import com.velocitypowered.proxy.protocol.packet.KeepAlive; import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket;
import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -60,13 +60,13 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(KeepAlive packet) { public boolean handle(KeepAlivePacket packet) {
serverConn.ensureConnected().write(packet); serverConn.ensureConnected().write(packet);
return true; return true;
} }
@Override @Override
public boolean handle(JoinGame packet) { public boolean handle(JoinGamePacket packet) {
MinecraftConnection smc = serverConn.ensureConnected(); MinecraftConnection smc = serverConn.ensureConnected();
VelocityServerConnection existingConnection = serverConn.getPlayer().getConnectedServer(); VelocityServerConnection existingConnection = serverConn.getPlayer().getConnectedServer();
@ -132,7 +132,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(Disconnect packet) { public boolean handle(DisconnectPacket packet) {
final MinecraftConnection connection = serverConn.ensureConnected(); final MinecraftConnection connection = serverConn.ensureConnected();
serverConn.disconnect(); serverConn.disconnect();
@ -150,7 +150,7 @@ public class TransitionSessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(PluginMessage packet) { public boolean handle(PluginMessagePacket packet) {
if (!serverConn.getPlayer().canForwardPluginMessage(serverConn.ensureConnected() if (!serverConn.getPlayer().canForwardPluginMessage(serverConn.ensureConnected()
.getProtocolVersion(), packet)) { .getProtocolVersion(), packet)) {
return true; return true;

Datei anzeigen

@ -21,9 +21,10 @@ import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.connection.registry.DimensionRegistry; import com.velocitypowered.proxy.connection.registry.DimensionRegistry;
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.Handshake; import com.velocitypowered.proxy.protocol.packet.HandshakePacket;
import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.JoinGamePacket;
import com.velocitypowered.proxy.protocol.packet.ServerLogin; import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
import com.velocitypowered.proxy.protocol.packet.ServerLoginPacket;
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;
@ -142,7 +143,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
// Initiate the handshake. // Initiate the handshake.
ProtocolVersion protocolVersion = proxyPlayer.getConnection().getProtocolVersion(); ProtocolVersion protocolVersion = proxyPlayer.getConnection().getProtocolVersion();
Handshake handshake = new Handshake(); HandshakePacket handshake = new HandshakePacket();
handshake.setNextStatus(StateRegistry.LOGIN_ID); handshake.setNextStatus(StateRegistry.LOGIN_ID);
handshake.setProtocolVersion(protocolVersion); handshake.setProtocolVersion(protocolVersion);
if (forwardingMode == PlayerInfoForwarding.LEGACY) { if (forwardingMode == PlayerInfoForwarding.LEGACY) {
@ -164,7 +165,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
mc.setProtocolVersion(protocolVersion); mc.setProtocolVersion(protocolVersion);
mc.setState(StateRegistry.LOGIN); mc.setState(StateRegistry.LOGIN);
mc.delayedWrite(new ServerLogin(proxyPlayer.getUsername())); mc.delayedWrite(new ServerLoginPacket(proxyPlayer.getUsername()));
mc.flush(); mc.flush();
} }
@ -233,7 +234,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
MinecraftConnection mc = ensureConnected(); MinecraftConnection mc = ensureConnected();
PluginMessage message = new PluginMessage(identifier.getId(), data); PluginMessagePacket message = new PluginMessagePacket(identifier.getId(), data);
mc.write(message); mc.write(message);
return true; return true;
} }
@ -307,7 +308,7 @@ public class VelocityServerConnection implements MinecraftConnectionAssociation,
} }
/** /**
* Gets whether the {@link com.velocitypowered.proxy.protocol.packet.JoinGame} * Gets whether the {@link JoinGamePacket}
* packet has been sent by this server. * packet has been sent by this server.
* *
* @return Whether the join has been completed. * @return Whether the join has been completed.

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.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
/** /**
* 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,
PluginMessage message, PluginMessagePacket message,
VelocityServerConnection server) { VelocityServerConnection server) {
return false; return false;
} }

Datei anzeigen

@ -19,19 +19,19 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.connection.backend.BackendConnectionPhases; import com.velocitypowered.proxy.connection.backend.BackendConnectionPhases;
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.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.BossBar; import com.velocitypowered.proxy.protocol.packet.BossBarPacket;
import com.velocitypowered.proxy.protocol.packet.Chat; import com.velocitypowered.proxy.protocol.packet.ChatPacket;
import com.velocitypowered.proxy.protocol.packet.ClientSettings; import com.velocitypowered.proxy.protocol.packet.ClientSettingsPacket;
import com.velocitypowered.proxy.protocol.packet.JoinGame; import com.velocitypowered.proxy.protocol.packet.JoinGamePacket;
import com.velocitypowered.proxy.protocol.packet.KeepAlive; import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket;
import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
import com.velocitypowered.proxy.protocol.packet.ResourcePackResponse; import com.velocitypowered.proxy.protocol.packet.ResourcePackResponsePacket;
import com.velocitypowered.proxy.protocol.packet.Respawn; import com.velocitypowered.proxy.protocol.packet.RespawnPacket;
import com.velocitypowered.proxy.protocol.packet.TabCompleteRequest; import com.velocitypowered.proxy.protocol.packet.TabCompleteRequestPacket;
import com.velocitypowered.proxy.protocol.packet.TabCompleteResponse; import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket;
import com.velocitypowered.proxy.protocol.packet.TabCompleteResponse.Offer; import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket.Offer;
import com.velocitypowered.proxy.protocol.packet.TitlePacket; import com.velocitypowered.proxy.protocol.packet.TitlePacket;
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -64,9 +64,9 @@ 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<PluginMessage> loginPluginMessages = new ArrayDeque<>(); private final Queue<PluginMessagePacket> loginPluginMessages = new ArrayDeque<>();
private final VelocityServer server; private final VelocityServer server;
private @Nullable TabCompleteRequest outstandingTabComplete; private @Nullable TabCompleteRequestPacket outstandingTabComplete;
/** /**
* Constructs a client play session handler. * Constructs a client play session handler.
@ -83,7 +83,7 @@ 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()) {
PluginMessage register = constructChannelsPacket(player.getProtocolVersion(), channels); PluginMessagePacket register = constructChannelsPacket(player.getProtocolVersion(), channels);
player.getConnection().write(register); player.getConnection().write(register);
player.getKnownChannels().addAll(channels); player.getKnownChannels().addAll(channels);
} }
@ -91,13 +91,13 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
@Override @Override
public void deactivated() { public void deactivated() {
for (PluginMessage message : loginPluginMessages) { for (PluginMessagePacket message : loginPluginMessages) {
ReferenceCountUtil.release(message); ReferenceCountUtil.release(message);
} }
} }
@Override @Override
public boolean handle(KeepAlive packet) { public boolean handle(KeepAlivePacket packet) {
VelocityServerConnection serverConnection = player.getConnectedServer(); VelocityServerConnection serverConnection = player.getConnectedServer();
if (serverConnection != null && packet.getRandomId() == serverConnection.getLastPingId()) { if (serverConnection != null && packet.getRandomId() == serverConnection.getLastPingId()) {
MinecraftConnection smc = serverConnection.getConnection(); MinecraftConnection smc = serverConnection.getConnection();
@ -111,13 +111,13 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(ClientSettings packet) { public boolean handle(ClientSettingsPacket packet) {
player.setPlayerSettings(packet); player.setPlayerSettings(packet);
return false; // will forward onto the server return false; // will forward onto the server
} }
@Override @Override
public boolean handle(Chat packet) { public boolean handle(ChatPacket packet) {
VelocityServerConnection serverConnection = player.getConnectedServer(); VelocityServerConnection serverConnection = player.getConnectedServer();
if (serverConnection == null) { if (serverConnection == null) {
return true; return true;
@ -154,7 +154,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
if (chatResult.isAllowed()) { if (chatResult.isAllowed()) {
Optional<String> eventMsg = pme.getResult().getMessage(); Optional<String> eventMsg = pme.getResult().getMessage();
if (eventMsg.isPresent()) { if (eventMsg.isPresent()) {
smc.write(Chat.createServerbound(eventMsg.get())); smc.write(ChatPacket.createServerbound(eventMsg.get()));
} else { } else {
smc.write(packet); smc.write(packet);
} }
@ -169,7 +169,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(TabCompleteRequest packet) { public boolean handle(TabCompleteRequestPacket packet) {
boolean isCommand = !packet.isAssumeCommand() && packet.getCommand().startsWith("/"); boolean isCommand = !packet.isAssumeCommand() && packet.getCommand().startsWith("/");
if (isCommand) { if (isCommand) {
@ -180,7 +180,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(PluginMessage packet) { public boolean handle(PluginMessagePacket 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) {
@ -229,7 +229,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()) {
PluginMessage message = new PluginMessage(packet.getChannel(), PluginMessagePacket message = new PluginMessagePacket(packet.getChannel(),
Unpooled.wrappedBuffer(copy)); Unpooled.wrappedBuffer(copy));
backendConn.write(message); backendConn.write(message);
} }
@ -249,14 +249,14 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(ResourcePackResponse packet) { public boolean handle(ResourcePackResponsePacket packet) {
server.getEventManager().fireAndForget(new PlayerResourcePackStatusEvent(player, server.getEventManager().fireAndForget(new PlayerResourcePackStatusEvent(player,
packet.getStatus())); packet.getStatus()));
return false; return false;
} }
@Override @Override
public void handleGeneric(MinecraftPacket packet) { public void handleGeneric(Packet packet) {
VelocityServerConnection serverConnection = player.getConnectedServer(); VelocityServerConnection serverConnection = player.getConnectedServer();
if (serverConnection == null) { if (serverConnection == null) {
// No server connection yet, probably transitioning. // No server connection yet, probably transitioning.
@ -265,8 +265,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 PluginMessage) { if (packet instanceof PluginMessagePacket) {
((PluginMessage) packet).retain(); ((PluginMessagePacket) packet).retain();
} }
smc.write(packet); smc.write(packet);
} }
@ -320,7 +320,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
* @param joinGame the join game packet * @param joinGame the join game packet
* @param destination the new server we are connecting to * @param destination the new server we are connecting to
*/ */
public void handleBackendJoinGame(JoinGame joinGame, VelocityServerConnection destination) { public void handleBackendJoinGame(JoinGamePacket joinGame, VelocityServerConnection destination) {
final MinecraftConnection serverMc = destination.ensureConnected(); final MinecraftConnection serverMc = destination.ensureConnected();
if (!spawned) { if (!spawned) {
@ -345,9 +345,9 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
// Remove previous boss bars. These don't get cleared when sending JoinGame, thus the need to // Remove previous boss bars. These don't get cleared when sending JoinGame, thus the need to
// track them. // track them.
for (UUID serverBossBar : serverBossBars) { for (UUID serverBossBar : serverBossBars) {
BossBar deletePacket = new BossBar(); BossBarPacket deletePacket = new BossBarPacket();
deletePacket.setUuid(serverBossBar); deletePacket.setUuid(serverBossBar);
deletePacket.setAction(BossBar.REMOVE); deletePacket.setAction(BossBarPacket.REMOVE);
player.getConnection().delayedWrite(deletePacket); player.getConnection().delayedWrite(deletePacket);
} }
serverBossBars.clear(); serverBossBars.clear();
@ -359,7 +359,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
} }
// 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.
PluginMessage pm; PluginMessagePacket pm;
while ((pm = loginPluginMessages.poll()) != null) { while ((pm = loginPluginMessages.poll()) != null) {
serverMc.delayedWrite(pm); serverMc.delayedWrite(pm);
} }
@ -376,7 +376,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
destination.completeJoin(); destination.completeJoin();
} }
private void doFastClientServerSwitch(JoinGame joinGame) { private void doFastClientServerSwitch(JoinGamePacket joinGame) {
// In order to handle switching to another server, you will need to send two packets: // In order to handle switching to another server, you will need to send two packets:
// //
// - The join game packet from the backend server, with a different dimension // - The join game packet from the backend server, with a different dimension
@ -395,13 +395,13 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
player.getConnection().delayedWrite(joinGame); player.getConnection().delayedWrite(joinGame);
player.getConnection().delayedWrite( player.getConnection().delayedWrite(
new Respawn(sentOldDim, joinGame.getPartialHashedSeed(), new RespawnPacket(sentOldDim, joinGame.getPartialHashedSeed(),
joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(), joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(),
false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(), false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(),
joinGame.getCurrentDimensionData())); joinGame.getCurrentDimensionData()));
} }
private void doSafeClientServerSwitch(JoinGame joinGame) { private void doSafeClientServerSwitch(JoinGamePacket joinGame) {
// Some clients do not behave well with the "fast" respawn sequence. In this case we will use // Some clients do not behave well with the "fast" respawn sequence. In this case we will use
// a "safe" respawn sequence that involves sending three packets to the client. They have the // a "safe" respawn sequence that involves sending three packets to the client. They have the
// same effect but tend to work better with buggier clients (Forge 1.8 in particular). // same effect but tend to work better with buggier clients (Forge 1.8 in particular).
@ -412,14 +412,14 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
// Send a respawn packet in a different dimension. // Send a respawn packet in a different dimension.
int tempDim = joinGame.getDimension() == 0 ? -1 : 0; int tempDim = joinGame.getDimension() == 0 ? -1 : 0;
player.getConnection().delayedWrite( player.getConnection().delayedWrite(
new Respawn(tempDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(), new RespawnPacket(tempDim, joinGame.getPartialHashedSeed(), joinGame.getDifficulty(),
joinGame.getGamemode(), joinGame.getLevelType(), joinGame.getGamemode(), joinGame.getLevelType(),
false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(), false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(),
joinGame.getCurrentDimensionData())); joinGame.getCurrentDimensionData()));
// Now send a respawn packet in the correct dimension. // Now send a respawn packet in the correct dimension.
player.getConnection().delayedWrite( player.getConnection().delayedWrite(
new Respawn(joinGame.getDimension(), joinGame.getPartialHashedSeed(), new RespawnPacket(joinGame.getDimension(), joinGame.getPartialHashedSeed(),
joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(), joinGame.getDifficulty(), joinGame.getGamemode(), joinGame.getLevelType(),
false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(), false, joinGame.getDimensionInfo(), joinGame.getPreviousGamemode(),
joinGame.getCurrentDimensionData())); joinGame.getCurrentDimensionData()));
@ -429,7 +429,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
return serverBossBars; return serverBossBars;
} }
private boolean handleCommandTabComplete(TabCompleteRequest packet) { private boolean handleCommandTabComplete(TabCompleteRequestPacket packet) {
// In 1.13+, we need to do additional work for the richer suggestions available. // In 1.13+, we need to do additional work for the richer suggestions available.
String command = packet.getCommand().substring(1); String command = packet.getCommand().substring(1);
int commandEndPosition = command.indexOf(' '); int commandEndPosition = command.indexOf(' ');
@ -459,7 +459,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
} }
int startPos = packet.getCommand().lastIndexOf(' ') + 1; int startPos = packet.getCommand().lastIndexOf(' ') + 1;
if (startPos > 0) { if (startPos > 0) {
TabCompleteResponse resp = new TabCompleteResponse(); TabCompleteResponsePacket resp = new TabCompleteResponsePacket();
resp.setTransactionId(packet.getTransactionId()); resp.setTransactionId(packet.getTransactionId());
resp.setStart(startPos); resp.setStart(startPos);
resp.setLength(packet.getCommand().length() - startPos); resp.setLength(packet.getCommand().length() - startPos);
@ -475,7 +475,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
return true; // Sorry, handler; we're just gonna have to lie to you here. return true; // Sorry, handler; we're just gonna have to lie to you here.
} }
private boolean handleRegularTabComplete(TabCompleteRequest packet) { private boolean handleRegularTabComplete(TabCompleteRequestPacket packet) {
if (player.getProtocolVersion().compareTo(MINECRAFT_1_13) < 0) { if (player.getProtocolVersion().compareTo(MINECRAFT_1_13) < 0) {
// Outstanding tab completes are recorded for use with 1.12 clients and below to provide // Outstanding tab completes are recorded for use with 1.12 clients and below to provide
// additional tab completion support. // additional tab completion support.
@ -489,7 +489,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
* *
* @param response the tab complete response from the backend * @param response the tab complete response from the backend
*/ */
public void handleTabCompleteResponse(TabCompleteResponse response) { public void handleTabCompleteResponse(TabCompleteResponsePacket response) {
if (outstandingTabComplete != null && !outstandingTabComplete.isAssumeCommand()) { if (outstandingTabComplete != null && !outstandingTabComplete.isAssumeCommand()) {
if (outstandingTabComplete.getCommand().startsWith("/")) { if (outstandingTabComplete.getCommand().startsWith("/")) {
this.finishCommandTabComplete(outstandingTabComplete, response); this.finishCommandTabComplete(outstandingTabComplete, response);
@ -503,7 +503,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
} }
} }
private void finishCommandTabComplete(TabCompleteRequest request, TabCompleteResponse response) { private void finishCommandTabComplete(TabCompleteRequestPacket request,
TabCompleteResponsePacket response) {
String command = request.getCommand().substring(1); String command = request.getCommand().substring(1);
server.getCommandManager().offerSuggestions(player, command) server.getCommandManager().offerSuggestions(player, command)
.thenAcceptAsync(offers -> { .thenAcceptAsync(offers -> {
@ -532,7 +533,8 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
}); });
} }
private void finishRegularTabComplete(TabCompleteRequest request, TabCompleteResponse response) { private void finishRegularTabComplete(TabCompleteRequestPacket request,
TabCompleteResponsePacket response) {
List<String> offers = new ArrayList<>(); List<String> offers = new ArrayList<>();
for (Offer offer : response.getOffers()) { for (Offer offer : response.getOffers()) {
offers.add(offer.getText()); offers.add(offer.getText());
@ -562,13 +564,13 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
MinecraftConnection smc = player.ensureAndGetCurrentServer().ensureConnected(); MinecraftConnection smc = player.ensureAndGetCurrentServer().ensureConnected();
String commandToRun = result.getCommand().orElse(originalCommand); String commandToRun = result.getCommand().orElse(originalCommand);
if (result.isForwardToServer()) { if (result.isForwardToServer()) {
return CompletableFuture.runAsync(() -> smc.write(Chat.createServerbound("/" return CompletableFuture.runAsync(() -> smc.write(ChatPacket.createServerbound("/"
+ commandToRun)), smc.eventLoop()); + commandToRun)), smc.eventLoop());
} else { } else {
return server.getCommandManager().executeImmediately(player, commandToRun) return server.getCommandManager().executeImmediately(player, commandToRun)
.thenAcceptAsync(hasRun -> { .thenAcceptAsync(hasRun -> {
if (!hasRun) { if (!hasRun) {
smc.write(Chat.createServerbound("/" + commandToRun)); smc.write(ChatPacket.createServerbound("/" + commandToRun));
} }
}, smc.eventLoop()); }, smc.eventLoop());
} }
@ -582,7 +584,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) {
PluginMessage pm; PluginMessagePacket pm;
while ((pm = loginPluginMessages.poll()) != null) { while ((pm = loginPluginMessages.poll()) != null) {
connection.write(pm); connection.write(pm);
} }

Datei anzeigen

@ -2,20 +2,20 @@ package com.velocitypowered.proxy.connection.client;
import com.velocitypowered.api.proxy.player.PlayerSettings; import com.velocitypowered.api.proxy.player.PlayerSettings;
import com.velocitypowered.api.proxy.player.SkinParts; import com.velocitypowered.api.proxy.player.SkinParts;
import com.velocitypowered.proxy.protocol.packet.ClientSettings; import com.velocitypowered.proxy.protocol.packet.ClientSettingsPacket;
import java.util.Locale; import java.util.Locale;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientSettingsWrapper implements PlayerSettings { public class ClientSettingsWrapper implements PlayerSettings {
static final PlayerSettings DEFAULT = new ClientSettingsWrapper( static final PlayerSettings DEFAULT = new ClientSettingsWrapper(
new ClientSettings("en_US", (byte) 10, 0, true, (short) 127, 1)); new ClientSettingsPacket("en_US", (byte) 10, 0, true, (short) 127, 1));
private final ClientSettings settings; private final ClientSettingsPacket settings;
private final SkinParts parts; private final SkinParts parts;
private @Nullable Locale locale; private @Nullable Locale locale;
ClientSettingsWrapper(ClientSettings settings) { ClientSettingsWrapper(ClientSettingsPacket settings) {
this.settings = settings; this.settings = settings;
this.parts = new SkinParts((byte) settings.getSkinParts()); this.parts = new SkinParts((byte) settings.getSkinParts());
} }

Datei anzeigen

@ -38,12 +38,12 @@ import com.velocitypowered.proxy.connection.util.ConnectionMessages;
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl; import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.Chat; import com.velocitypowered.proxy.protocol.packet.ChatPacket;
import com.velocitypowered.proxy.protocol.packet.ClientSettings; import com.velocitypowered.proxy.protocol.packet.ClientSettingsPacket;
import com.velocitypowered.proxy.protocol.packet.Disconnect; import com.velocitypowered.proxy.protocol.packet.DisconnectPacket;
import com.velocitypowered.proxy.protocol.packet.KeepAlive; import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket;
import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
import com.velocitypowered.proxy.protocol.packet.ResourcePackRequest; import com.velocitypowered.proxy.protocol.packet.ResourcePackRequestPacket;
import com.velocitypowered.proxy.protocol.packet.TitlePacket; import com.velocitypowered.proxy.protocol.packet.TitlePacket;
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
import com.velocitypowered.proxy.server.VelocityRegisteredServer; import com.velocitypowered.proxy.server.VelocityRegisteredServer;
@ -186,7 +186,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
return settings == null ? ClientSettingsWrapper.DEFAULT : this.settings; return settings == null ? ClientSettingsWrapper.DEFAULT : this.settings;
} }
void setPlayerSettings(ClientSettings settings) { void setPlayerSettings(ClientSettingsPacket settings) {
ClientSettingsWrapper cs = new ClientSettingsWrapper(settings); ClientSettingsWrapper cs = new ClientSettingsWrapper(settings);
this.settings = cs; this.settings = cs;
server.getEventManager().fireAndForget(new PlayerSettingsChangedEvent(this, cs)); server.getEventManager().fireAndForget(new PlayerSettingsChangedEvent(this, cs));
@ -228,7 +228,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
@Override @Override
public void sendMessage(@NonNull Identity identity, @NonNull Component message) { public void sendMessage(@NonNull Identity identity, @NonNull Component message) {
connection.write(Chat.createClientbound(identity, message, this.getProtocolVersion())); connection.write(ChatPacket.createClientbound(identity, message, this.getProtocolVersion()));
} }
@Override @Override
@ -237,8 +237,8 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
Preconditions.checkNotNull(message, "message"); Preconditions.checkNotNull(message, "message");
Preconditions.checkNotNull(type, "type"); Preconditions.checkNotNull(type, "type");
Chat packet = Chat.createClientbound(identity, message, this.getProtocolVersion()); ChatPacket packet = ChatPacket.createClientbound(identity, message, this.getProtocolVersion());
packet.setType(type == MessageType.CHAT ? Chat.CHAT_TYPE : Chat.SYSTEM_TYPE); packet.setType(type == MessageType.CHAT ? ChatPacket.CHAT_TYPE : ChatPacket.SYSTEM_TYPE);
connection.write(packet); connection.write(packet);
} }
@ -257,9 +257,9 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
// legacy message and then inject the legacy text into a component... yuck! // legacy message and then inject the legacy text into a component... yuck!
JsonObject object = new JsonObject(); JsonObject object = new JsonObject();
object.addProperty("text", LegacyComponentSerializer.legacySection().serialize(message)); object.addProperty("text", LegacyComponentSerializer.legacySection().serialize(message));
Chat chat = new Chat(); ChatPacket chat = new ChatPacket();
chat.setMessage(object.toString()); chat.setMessage(object.toString());
chat.setType(Chat.GAME_INFO_TYPE); chat.setType(ChatPacket.GAME_INFO_TYPE);
connection.write(chat); connection.write(chat);
} }
} }
@ -343,7 +343,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
public void disconnect0(Component reason, boolean duringLogin) { public void disconnect0(Component reason, boolean duringLogin) {
logger.info("{} has disconnected: {}", this, logger.info("{} has disconnected: {}", this,
LegacyComponentSerializer.legacySection().serialize(reason)); LegacyComponentSerializer.legacySection().serialize(reason));
connection.closeWith(Disconnect.create(reason, this.getProtocolVersion())); connection.closeWith(DisconnectPacket.create(reason, this.getProtocolVersion()));
} }
public @Nullable VelocityServerConnection getConnectedServer() { public @Nullable VelocityServerConnection getConnectedServer() {
@ -402,7 +402,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
* @param disconnect the disconnect packet * @param disconnect the disconnect packet
* @param safe whether or not we can safely reconnect to a new server * @param safe whether or not we can safely reconnect to a new server
*/ */
public void handleConnectionException(RegisteredServer server, Disconnect disconnect, public void handleConnectionException(RegisteredServer server, DisconnectPacket disconnect,
boolean safe) { boolean safe) {
if (!isActive()) { if (!isActive()) {
// If the connection is no longer active, it makes no sense to try and recover it. // If the connection is no longer active, it makes no sense to try and recover it.
@ -507,7 +507,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
case SERVER_DISCONNECTED: case SERVER_DISCONNECTED:
Component reason = status.getReason() Component reason = status.getReason()
.orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); .orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR);
handleConnectionException(res.getServer(), Disconnect.create(reason, handleConnectionException(res.getServer(), DisconnectPacket.create(reason,
getProtocolVersion()), ((Impl) status).isSafe()); getProtocolVersion()), ((Impl) status).isSafe());
break; break;
case SUCCESS: case SUCCESS:
@ -664,24 +664,25 @@ 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");
PluginMessage message = new PluginMessage(identifier.getId(), Unpooled.wrappedBuffer(data)); PluginMessagePacket message = new PluginMessagePacket(identifier.getId(),
Unpooled.wrappedBuffer(data));
connection.write(message); connection.write(message);
return true; return true;
} }
@Override @Override
public void spoofChatInput(String input) { public void spoofChatInput(String input) {
Preconditions.checkArgument(input.length() <= Chat.MAX_SERVERBOUND_MESSAGE_LENGTH, Preconditions.checkArgument(input.length() <= ChatPacket.MAX_SERVERBOUND_MESSAGE_LENGTH,
"input cannot be greater than " + Chat.MAX_SERVERBOUND_MESSAGE_LENGTH "input cannot be greater than " + ChatPacket.MAX_SERVERBOUND_MESSAGE_LENGTH
+ " characters in length"); + " characters in length");
ensureBackendConnection().write(Chat.createServerbound(input)); ensureBackendConnection().write(ChatPacket.createServerbound(input));
} }
@Override @Override
public void sendResourcePack(String url) { public void sendResourcePack(String url) {
Preconditions.checkNotNull(url, "url"); Preconditions.checkNotNull(url, "url");
ResourcePackRequest request = new ResourcePackRequest(); ResourcePackRequestPacket request = new ResourcePackRequestPacket();
request.setUrl(url); request.setUrl(url);
request.setHash(""); request.setHash("");
connection.write(request); connection.write(request);
@ -693,20 +694,20 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
Preconditions.checkNotNull(hash, "hash"); Preconditions.checkNotNull(hash, "hash");
Preconditions.checkArgument(hash.length == 20, "Hash length is not 20"); Preconditions.checkArgument(hash.length == 20, "Hash length is not 20");
ResourcePackRequest request = new ResourcePackRequest(); ResourcePackRequestPacket request = new ResourcePackRequestPacket();
request.setUrl(url); request.setUrl(url);
request.setHash(ByteBufUtil.hexDump(hash)); request.setHash(ByteBufUtil.hexDump(hash));
connection.write(request); connection.write(request);
} }
/** /**
* Sends a {@link KeepAlive} packet to the player with a random ID. * Sends a {@link KeepAlivePacket} packet to the player with a random ID.
* The response will be ignored by Velocity as it will not match the * The response will be ignored by Velocity as it will not match the
* ID last sent by the server. * ID last sent by the server.
*/ */
public void sendKeepAlive() { public void sendKeepAlive() {
if (connection.getState() == StateRegistry.PLAY) { if (connection.getState() == StateRegistry.PLAY) {
KeepAlive keepAlive = new KeepAlive(); KeepAlivePacket keepAlive = new KeepAlivePacket();
keepAlive.setRandomId(ThreadLocalRandom.current().nextLong()); keepAlive.setRandomId(ThreadLocalRandom.current().nextLong());
connection.write(keepAlive); connection.write(keepAlive);
} }
@ -746,7 +747,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, PluginMessage message) { public boolean canForwardPluginMessage(ProtocolVersion version, PluginMessagePacket 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.
@ -879,7 +880,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
case SERVER_DISCONNECTED: case SERVER_DISCONNECTED:
Component reason = status.getReason() Component reason = status.getReason()
.orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR); .orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR);
handleConnectionException(toConnect, Disconnect.create(reason, handleConnectionException(toConnect, DisconnectPacket.create(reason,
getProtocolVersion()), status.isSafe()); getProtocolVersion()), status.isSafe());
break; break;
default: default:

Datei anzeigen

@ -12,12 +12,12 @@ import com.velocitypowered.proxy.connection.ConnectionTypes;
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.connection.forge.legacy.LegacyForgeConstants; import com.velocitypowered.proxy.connection.forge.legacy.LegacyForgeConstants;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.Handshake; import com.velocitypowered.proxy.protocol.packet.HandshakePacket;
import com.velocitypowered.proxy.protocol.packet.LegacyDisconnect; import com.velocitypowered.proxy.protocol.packet.legacy.LegacyDisconnectPacket;
import com.velocitypowered.proxy.protocol.packet.LegacyHandshake; import com.velocitypowered.proxy.protocol.packet.legacy.LegacyHandshakePacket;
import com.velocitypowered.proxy.protocol.packet.LegacyPing; import com.velocitypowered.proxy.protocol.packet.legacy.LegacyPingPacket;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -41,7 +41,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(LegacyPing packet) { public boolean handle(LegacyPingPacket packet) {
connection.setProtocolVersion(ProtocolVersion.LEGACY); connection.setProtocolVersion(ProtocolVersion.LEGACY);
StatusSessionHandler handler = new StatusSessionHandler(server, connection, StatusSessionHandler handler = new StatusSessionHandler(server, connection,
new LegacyInboundConnection(connection, packet)); new LegacyInboundConnection(connection, packet));
@ -51,14 +51,14 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(LegacyHandshake packet) { public boolean handle(LegacyHandshakePacket packet) {
connection.closeWith(LegacyDisconnect connection.closeWith(LegacyDisconnectPacket
.from(Component.text("Your client is old, please upgrade!", NamedTextColor.RED))); .from(Component.text("Your client is old, please upgrade!", NamedTextColor.RED)));
return true; return true;
} }
@Override @Override
public boolean handle(Handshake handshake) { public boolean handle(HandshakePacket handshake) {
InitialInboundConnection ic = new InitialInboundConnection(connection, InitialInboundConnection ic = new InitialInboundConnection(connection,
cleanVhost(handshake.getServerAddress()), handshake); cleanVhost(handshake.getServerAddress()), handshake);
StateRegistry nextState = getStateForProtocol(handshake.getNextStatus()); StateRegistry nextState = getStateForProtocol(handshake.getNextStatus());
@ -97,7 +97,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
} }
} }
private void handleLogin(Handshake handshake, InitialInboundConnection ic) { private void handleLogin(HandshakePacket handshake, InitialInboundConnection ic) {
if (!ProtocolVersion.isSupported(handshake.getProtocolVersion())) { if (!ProtocolVersion.isSupported(handshake.getProtocolVersion())) {
ic.disconnectQuietly(Component.translatable("multiplayer.disconnect.outdated_client")); ic.disconnectQuietly(Component.translatable("multiplayer.disconnect.outdated_client"));
return; return;
@ -123,7 +123,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
connection.setSessionHandler(new LoginSessionHandler(server, connection, ic)); connection.setSessionHandler(new LoginSessionHandler(server, connection, ic));
} }
private ConnectionType getHandshakeConnectionType(Handshake handshake) { private ConnectionType getHandshakeConnectionType(HandshakePacket handshake) {
// Determine if we're using Forge (1.8 to 1.12, may not be the case in 1.13). // Determine if we're using Forge (1.8 to 1.12, may not be the case in 1.13).
if (handshake.getServerAddress().endsWith(LegacyForgeConstants.HANDSHAKE_HOSTNAME_TOKEN) if (handshake.getServerAddress().endsWith(LegacyForgeConstants.HANDSHAKE_HOSTNAME_TOKEN)
&& handshake.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) { && handshake.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_13) < 0) {
@ -164,7 +164,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public void handleGeneric(MinecraftPacket packet) { public void handleGeneric(Packet packet) {
// Unknown packet received. Better to close the connection. // Unknown packet received. Better to close the connection.
connection.close(true); connection.close(true);
} }
@ -178,10 +178,10 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
private static class LegacyInboundConnection implements InboundConnection { private static class LegacyInboundConnection implements InboundConnection {
private final MinecraftConnection connection; private final MinecraftConnection connection;
private final LegacyPing ping; private final LegacyPingPacket ping;
private LegacyInboundConnection(MinecraftConnection connection, private LegacyInboundConnection(MinecraftConnection connection,
LegacyPing ping) { LegacyPingPacket ping) {
this.connection = connection; this.connection = connection;
this.ping = ping; this.ping = ping;
} }

Datei anzeigen

@ -3,7 +3,7 @@ package com.velocitypowered.proxy.connection.client;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; 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.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil; import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
public class InitialConnectSessionHandler implements MinecraftSessionHandler { public class InitialConnectSessionHandler implements MinecraftSessionHandler {
@ -15,7 +15,7 @@ public class InitialConnectSessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(PluginMessage packet) { public boolean handle(PluginMessagePacket 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.protocol.packet.Disconnect; import com.velocitypowered.proxy.protocol.packet.DisconnectPacket;
import com.velocitypowered.proxy.protocol.packet.Handshake; import com.velocitypowered.proxy.protocol.packet.HandshakePacket;
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;
@ -20,10 +20,10 @@ public final class InitialInboundConnection implements InboundConnection,
private final MinecraftConnection connection; private final MinecraftConnection connection;
private final String cleanedAddress; private final String cleanedAddress;
private final Handshake handshake; private final HandshakePacket handshake;
InitialInboundConnection(MinecraftConnection connection, String cleanedAddress, InitialInboundConnection(MinecraftConnection connection, String cleanedAddress,
Handshake handshake) { HandshakePacket handshake) {
this.connection = connection; this.connection = connection;
this.cleanedAddress = cleanedAddress; this.cleanedAddress = cleanedAddress;
this.handshake = handshake; this.handshake = handshake;
@ -61,7 +61,7 @@ public final class InitialInboundConnection implements InboundConnection,
public void disconnect(Component reason) { public void disconnect(Component reason) {
logger.info("{} has disconnected: {}", this, logger.info("{} has disconnected: {}", this,
LegacyComponentSerializer.legacySection().serialize(reason)); LegacyComponentSerializer.legacySection().serialize(reason));
connection.closeWith(Disconnect.create(reason, getProtocolVersion())); connection.closeWith(DisconnectPacket.create(reason, getProtocolVersion()));
} }
/** /**
@ -69,6 +69,6 @@ public final class InitialInboundConnection implements InboundConnection,
* @param reason the reason for disconnecting * @param reason the reason for disconnecting
*/ */
public void disconnectQuietly(Component reason) { public void disconnectQuietly(Component reason) {
connection.closeWith(Disconnect.create(reason, getProtocolVersion())); connection.closeWith(DisconnectPacket.create(reason, getProtocolVersion()));
} }
} }

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.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.Disconnect; import com.velocitypowered.proxy.protocol.packet.DisconnectPacket;
import com.velocitypowered.proxy.protocol.packet.EncryptionRequest; import com.velocitypowered.proxy.protocol.packet.EncryptionRequestPacket;
import com.velocitypowered.proxy.protocol.packet.EncryptionResponse; import com.velocitypowered.proxy.protocol.packet.EncryptionResponsePacket;
import com.velocitypowered.proxy.protocol.packet.ServerLogin; import com.velocitypowered.proxy.protocol.packet.ServerLoginPacket;
import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess; import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccessPacket;
import com.velocitypowered.proxy.protocol.packet.SetCompression; import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket;
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;
@ -58,7 +58,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
private final VelocityServer server; private final VelocityServer server;
private final MinecraftConnection mcConnection; private final MinecraftConnection mcConnection;
private final InitialInboundConnection inbound; private final InitialInboundConnection inbound;
private @MonotonicNonNull ServerLogin login; private @MonotonicNonNull ServerLoginPacket login;
private byte[] verify = EMPTY_BYTE_ARRAY; private byte[] verify = EMPTY_BYTE_ARRAY;
private @MonotonicNonNull ConnectedPlayer connectedPlayer; private @MonotonicNonNull ConnectedPlayer connectedPlayer;
@ -70,15 +70,15 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(ServerLogin packet) { public boolean handle(ServerLoginPacket packet) {
this.login = packet; this.login = packet;
beginPreLogin(); beginPreLogin();
return true; return true;
} }
@Override @Override
public boolean handle(EncryptionResponse packet) { public boolean handle(EncryptionResponsePacket packet) {
ServerLogin login = this.login; ServerLoginPacket login = this.login;
if (login == null) { if (login == null) {
throw new IllegalStateException("No ServerLogin packet received yet."); throw new IllegalStateException("No ServerLogin packet received yet.");
} }
@ -153,7 +153,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
} }
private void beginPreLogin() { private void beginPreLogin() {
ServerLogin login = this.login; ServerLoginPacket login = this.login;
if (login == null) { if (login == null) {
throw new IllegalStateException("No ServerLogin packet received yet."); throw new IllegalStateException("No ServerLogin packet received yet.");
} }
@ -169,7 +169,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
Optional<Component> disconnectReason = result.getReason(); Optional<Component> disconnectReason = result.getReason();
if (disconnectReason.isPresent()) { if (disconnectReason.isPresent()) {
// The component is guaranteed to be provided if the connection was denied. // The component is guaranteed to be provided if the connection was denied.
mcConnection.closeWith(Disconnect.create(disconnectReason.get(), mcConnection.closeWith(DisconnectPacket.create(disconnectReason.get(),
inbound.getProtocolVersion())); inbound.getProtocolVersion()));
return; return;
} }
@ -177,7 +177,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
if (!result.isForceOfflineMode() && (server.getConfiguration().isOnlineMode() || result if (!result.isForceOfflineMode() && (server.getConfiguration().isOnlineMode() || result
.isOnlineModeAllowed())) { .isOnlineModeAllowed())) {
// Request encryption. // Request encryption.
EncryptionRequest request = generateEncryptionRequest(); EncryptionRequestPacket request = generateEncryptionRequest();
this.verify = Arrays.copyOf(request.getVerifyToken(), 4); this.verify = Arrays.copyOf(request.getVerifyToken(), 4);
mcConnection.write(request); mcConnection.write(request);
} else { } else {
@ -190,11 +190,11 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
}); });
} }
private EncryptionRequest generateEncryptionRequest() { private EncryptionRequestPacket generateEncryptionRequest() {
byte[] verify = new byte[4]; byte[] verify = new byte[4];
ThreadLocalRandom.current().nextBytes(verify); ThreadLocalRandom.current().nextBytes(verify);
EncryptionRequest request = new EncryptionRequest(); EncryptionRequestPacket request = new EncryptionRequestPacket();
request.setPublicKey(server.getServerKeyPair().getPublic().getEncoded()); request.setPublicKey(server.getServerKeyPair().getPublic().getEncoded());
request.setVerifyToken(verify); request.setVerifyToken(verify);
return request; return request;
@ -243,7 +243,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
private void completeLoginProtocolPhaseAndInitialize(ConnectedPlayer player) { private void completeLoginProtocolPhaseAndInitialize(ConnectedPlayer player) {
int threshold = server.getConfiguration().getCompressionThreshold(); int threshold = server.getConfiguration().getCompressionThreshold();
if (threshold >= 0 && mcConnection.getProtocolVersion().compareTo(MINECRAFT_1_8) >= 0) { if (threshold >= 0 && mcConnection.getProtocolVersion().compareTo(MINECRAFT_1_8) >= 0) {
mcConnection.write(new SetCompression(threshold)); mcConnection.write(new SetCompressionPacket(threshold));
mcConnection.setCompressionThreshold(threshold); mcConnection.setCompressionThreshold(threshold);
} }
VelocityConfiguration configuration = server.getConfiguration(); VelocityConfiguration configuration = server.getConfiguration();
@ -251,7 +251,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) { if (configuration.getPlayerInfoForwardingMode() == PlayerInfoForwarding.NONE) {
playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername()); playerUniqueId = UuidUtils.generateOfflinePlayerUuid(player.getUsername());
} }
ServerLoginSuccess success = new ServerLoginSuccess(); ServerLoginSuccessPacket success = new ServerLoginSuccessPacket();
success.setUsername(player.getUsername()); success.setUsername(player.getUsername());
success.setUuid(playerUniqueId); success.setUuid(playerUniqueId);
mcConnection.write(success); mcConnection.write(success);

Datei anzeigen

@ -13,11 +13,11 @@ import com.velocitypowered.proxy.config.PingPassthroughMode;
import com.velocitypowered.proxy.config.VelocityConfiguration; import com.velocitypowered.proxy.config.VelocityConfiguration;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.packet.LegacyDisconnect; import com.velocitypowered.proxy.protocol.packet.StatusPingPacket;
import com.velocitypowered.proxy.protocol.packet.LegacyPing; import com.velocitypowered.proxy.protocol.packet.StatusRequestPacket;
import com.velocitypowered.proxy.protocol.packet.StatusPing; import com.velocitypowered.proxy.protocol.packet.StatusResponsePacket;
import com.velocitypowered.proxy.protocol.packet.StatusRequest; import com.velocitypowered.proxy.protocol.packet.legacy.LegacyDisconnectPacket;
import com.velocitypowered.proxy.protocol.packet.StatusResponse; import com.velocitypowered.proxy.protocol.packet.legacy.LegacyPingPacket;
import com.velocitypowered.proxy.server.VelocityRegisteredServer; import com.velocitypowered.proxy.server.VelocityRegisteredServer;
import com.velocitypowered.proxy.util.except.QuietRuntimeException; import com.velocitypowered.proxy.util.except.QuietRuntimeException;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@ -158,7 +158,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(LegacyPing packet) { public boolean handle(LegacyPingPacket packet) {
if (this.pingReceived) { if (this.pingReceived) {
throw EXPECTED_AWAITING_REQUEST; throw EXPECTED_AWAITING_REQUEST;
} }
@ -166,7 +166,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
getInitialPing() getInitialPing()
.thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping))) .thenCompose(ping -> server.getEventManager().fire(new ProxyPingEvent(inbound, ping)))
.thenAcceptAsync(event -> connection.closeWith( .thenAcceptAsync(event -> connection.closeWith(
LegacyDisconnect.fromServerPing(event.getPing(), packet.getVersion())), LegacyDisconnectPacket.fromServerPing(event.getPing(), packet.getVersion())),
connection.eventLoop()) connection.eventLoop())
.exceptionally((ex) -> { .exceptionally((ex) -> {
logger.error("Exception while handling legacy ping {}", packet, ex); logger.error("Exception while handling legacy ping {}", packet, ex);
@ -176,13 +176,13 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
} }
@Override @Override
public boolean handle(StatusPing packet) { public boolean handle(StatusPingPacket packet) {
connection.closeWith(packet); connection.closeWith(packet);
return true; return true;
} }
@Override @Override
public boolean handle(StatusRequest packet) { public boolean handle(StatusRequestPacket packet) {
if (this.pingReceived) { if (this.pingReceived) {
throw EXPECTED_AWAITING_REQUEST; throw EXPECTED_AWAITING_REQUEST;
} }
@ -195,7 +195,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
StringBuilder json = new StringBuilder(); StringBuilder json = new StringBuilder();
VelocityServer.getPingGsonInstance(connection.getProtocolVersion()) VelocityServer.getPingGsonInstance(connection.getProtocolVersion())
.toJson(event.getPing(), json); .toJson(event.getPing(), json);
connection.write(new StatusResponse(json)); connection.write(new StatusResponsePacket(json));
}, },
connection.eventLoop()) connection.eventLoop())
.exceptionally((ex) -> { .exceptionally((ex) -> {

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.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
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,
PluginMessage message) { PluginMessagePacket 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,
PluginMessage packet) { PluginMessagePacket 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.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
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,
PluginMessage message, PluginMessagePacket 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,
PluginMessage message, PluginMessagePacket 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,
PluginMessage message, PluginMessagePacket 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,
PluginMessage message, PluginMessagePacket 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,
PluginMessage message, PluginMessagePacket 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(PluginMessage packet) { private LegacyForgeHandshakeClientPhase getNewPhase(PluginMessagePacket packet) {
if (packetToAdvanceOn != null if (packetToAdvanceOn != null
&& LegacyForgeUtil.getHandshakePacketDiscriminator(packet) == packetToAdvanceOn) { && LegacyForgeUtil.getHandshakePacketDiscriminator(packet) == packetToAdvanceOn) {
return nextPhase(); return nextPhase();

Datei anzeigen

@ -8,7 +8,7 @@ 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.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
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 +25,7 @@ class LegacyForgeUtil {
* @param message The message to analyse * @param message The message to analyse
* @return The discriminator * @return The discriminator
*/ */
static byte getHandshakePacketDiscriminator(PluginMessage message) { static byte getHandshakePacketDiscriminator(PluginMessagePacket 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 +37,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(PluginMessage message) { static List<ModInfo.Mod> readModList(PluginMessagePacket 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 +71,8 @@ class LegacyForgeUtil {
* *
* @return A copy of the reset packet * @return A copy of the reset packet
*/ */
static PluginMessage resetPacket() { static PluginMessagePacket resetPacket() {
PluginMessage msg = new PluginMessage(); PluginMessagePacket msg = new PluginMessagePacket();
msg.setChannel(FORGE_LEGACY_HANDSHAKE_CHANNEL); msg.setChannel(FORGE_LEGACY_HANDSHAKE_CHANNEL);
msg.replace(Unpooled.wrappedBuffer(FORGE_LEGACY_HANDSHAKE_RESET_DATA.clone())); msg.replace(Unpooled.wrappedBuffer(FORGE_LEGACY_HANDSHAKE_RESET_DATA.clone()));
return msg; return msg;

Datei anzeigen

@ -3,7 +3,7 @@ package com.velocitypowered.proxy.connection.util;
import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder; import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder;
import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder.Status; import com.velocitypowered.api.proxy.player.ConnectionRequestBuilder.Status;
import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.proxy.protocol.packet.Disconnect; import com.velocitypowered.proxy.protocol.packet.DisconnectPacket;
import java.util.Optional; import java.util.Optional;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -41,12 +41,12 @@ public class ConnectionRequestResults {
return new Impl(Status.SERVER_DISCONNECTED, component, server, true); return new Impl(Status.SERVER_DISCONNECTED, component, server, true);
} }
public static Impl forDisconnect(Disconnect disconnect, RegisteredServer server) { public static Impl forDisconnect(DisconnectPacket disconnect, RegisteredServer server) {
Component deserialized = GsonComponentSerializer.gson().deserialize(disconnect.getReason()); Component deserialized = GsonComponentSerializer.gson().deserialize(disconnect.getReason());
return forDisconnect(deserialized, server); return forDisconnect(deserialized, server);
} }
public static Impl forUnsafeDisconnect(Disconnect disconnect, RegisteredServer server) { public static Impl forUnsafeDisconnect(DisconnectPacket disconnect, RegisteredServer server) {
Component deserialized = GsonComponentSerializer.gson().deserialize(disconnect.getReason()); Component deserialized = GsonComponentSerializer.gson().deserialize(disconnect.getReason());
return new Impl(Status.SERVER_DISCONNECTED, deserialized, server, false); return new Impl(Status.SERVER_DISCONNECTED, deserialized, server, false);
} }

Datei anzeigen

@ -8,7 +8,7 @@ import static com.velocitypowered.proxy.network.Connections.MINECRAFT_ENCODER;
import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT; import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.netty.AutoReadHolderHandler; import com.velocitypowered.proxy.protocol.netty.AutoReadHolderHandler;
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder;
@ -37,9 +37,9 @@ public class BackendChannelInitializer extends ChannelInitializer<Channel> {
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
.addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE)
.addLast(MINECRAFT_DECODER, .addLast(MINECRAFT_DECODER,
new MinecraftDecoder(ProtocolUtils.Direction.CLIENTBOUND)) new MinecraftDecoder(ProtocolDirection.CLIENTBOUND))
.addLast(FLOW_HANDLER, new AutoReadHolderHandler()) .addLast(FLOW_HANDLER, new AutoReadHolderHandler())
.addLast(MINECRAFT_ENCODER, .addLast(MINECRAFT_ENCODER,
new MinecraftEncoder(ProtocolUtils.Direction.SERVERBOUND)); new MinecraftEncoder(ProtocolDirection.SERVERBOUND));
} }
} }

Datei anzeigen

@ -11,7 +11,7 @@ import static com.velocitypowered.proxy.network.Connections.READ_TIMEOUT;
import com.velocitypowered.proxy.VelocityServer; import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler; import com.velocitypowered.proxy.connection.client.HandshakeSessionHandler;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.netty.LegacyPingDecoder; import com.velocitypowered.proxy.protocol.netty.LegacyPingDecoder;
import com.velocitypowered.proxy.protocol.netty.LegacyPingEncoder; import com.velocitypowered.proxy.protocol.netty.LegacyPingEncoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
@ -43,8 +43,8 @@ public class ServerChannelInitializer extends ChannelInitializer<Channel> {
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
.addLast(LEGACY_PING_ENCODER, LegacyPingEncoder.INSTANCE) .addLast(LEGACY_PING_ENCODER, LegacyPingEncoder.INSTANCE)
.addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE)
.addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolUtils.Direction.SERVERBOUND)) .addLast(MINECRAFT_DECODER, new MinecraftDecoder(ProtocolDirection.SERVERBOUND))
.addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolUtils.Direction.CLIENTBOUND)); .addLast(MINECRAFT_ENCODER, new MinecraftEncoder(ProtocolDirection.CLIENTBOUND));
final MinecraftConnection connection = new MinecraftConnection(ch, this.server); final MinecraftConnection connection = new MinecraftConnection(ch, this.server);
connection.setSessionHandler(new HandshakeSessionHandler(connection, this.server)); connection.setSessionHandler(new HandshakeSessionHandler(connection, this.server));

Datei anzeigen

@ -4,11 +4,11 @@ import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public interface MinecraftPacket { public interface Packet {
void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion); void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion);
void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion protocolVersion); void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion);
boolean handle(MinecraftSessionHandler handler); boolean handle(MinecraftSessionHandler handler);
} }

Datei anzeigen

@ -0,0 +1,6 @@
package com.velocitypowered.proxy.protocol;
public enum ProtocolDirection {
SERVERBOUND,
CLIENTBOUND;
}

Datei anzeigen

@ -465,14 +465,4 @@ public enum ProtocolUtils {
return PRE_1_16_SERIALIZER; return PRE_1_16_SERIALIZER;
} }
public enum Direction {
SERVERBOUND,
CLIENTBOUND;
public StateRegistry.PacketRegistry.ProtocolRegistry getProtocolRegistry(StateRegistry state,
ProtocolVersion version) {
return (this == SERVERBOUND ? state.serverbound : state.clientbound)
.getProtocolRegistry(version);
}
}
} }

Datei anzeigen

@ -14,35 +14,34 @@ import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9;
import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9_4; import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9_4;
import static com.velocitypowered.api.network.ProtocolVersion.MINIMUM_VERSION; import static com.velocitypowered.api.network.ProtocolVersion.MINIMUM_VERSION;
import static com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS; import static com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS;
import static com.velocitypowered.proxy.protocol.ProtocolUtils.Direction;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.packet.AvailableCommands; import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket;
import com.velocitypowered.proxy.protocol.packet.BossBar; import com.velocitypowered.proxy.protocol.packet.BossBarPacket;
import com.velocitypowered.proxy.protocol.packet.Chat; import com.velocitypowered.proxy.protocol.packet.ChatPacket;
import com.velocitypowered.proxy.protocol.packet.ClientSettings; import com.velocitypowered.proxy.protocol.packet.ClientSettingsPacket;
import com.velocitypowered.proxy.protocol.packet.Disconnect; import com.velocitypowered.proxy.protocol.packet.DisconnectPacket;
import com.velocitypowered.proxy.protocol.packet.EncryptionRequest; import com.velocitypowered.proxy.protocol.packet.EncryptionRequestPacket;
import com.velocitypowered.proxy.protocol.packet.EncryptionResponse; import com.velocitypowered.proxy.protocol.packet.EncryptionResponsePacket;
import com.velocitypowered.proxy.protocol.packet.Handshake; import com.velocitypowered.proxy.protocol.packet.HandshakePacket;
import com.velocitypowered.proxy.protocol.packet.HeaderAndFooter; import com.velocitypowered.proxy.protocol.packet.HeaderAndFooterPacket;
import com.velocitypowered.proxy.protocol.packet.JoinGame; import com.velocitypowered.proxy.protocol.packet.JoinGamePacket;
import com.velocitypowered.proxy.protocol.packet.KeepAlive; import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket;
import com.velocitypowered.proxy.protocol.packet.LoginPluginMessage; import com.velocitypowered.proxy.protocol.packet.LoginPluginMessagePacket;
import com.velocitypowered.proxy.protocol.packet.LoginPluginResponse; import com.velocitypowered.proxy.protocol.packet.LoginPluginResponsePacket;
import com.velocitypowered.proxy.protocol.packet.PlayerListItem; import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket;
import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
import com.velocitypowered.proxy.protocol.packet.ResourcePackRequest; import com.velocitypowered.proxy.protocol.packet.ResourcePackRequestPacket;
import com.velocitypowered.proxy.protocol.packet.ResourcePackResponse; import com.velocitypowered.proxy.protocol.packet.ResourcePackResponsePacket;
import com.velocitypowered.proxy.protocol.packet.Respawn; import com.velocitypowered.proxy.protocol.packet.RespawnPacket;
import com.velocitypowered.proxy.protocol.packet.ServerLogin; import com.velocitypowered.proxy.protocol.packet.ServerLoginPacket;
import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccess; import com.velocitypowered.proxy.protocol.packet.ServerLoginSuccessPacket;
import com.velocitypowered.proxy.protocol.packet.SetCompression; import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket;
import com.velocitypowered.proxy.protocol.packet.StatusPing; import com.velocitypowered.proxy.protocol.packet.StatusPingPacket;
import com.velocitypowered.proxy.protocol.packet.StatusRequest; import com.velocitypowered.proxy.protocol.packet.StatusRequestPacket;
import com.velocitypowered.proxy.protocol.packet.StatusResponse; import com.velocitypowered.proxy.protocol.packet.StatusResponsePacket;
import com.velocitypowered.proxy.protocol.packet.TabCompleteRequest; import com.velocitypowered.proxy.protocol.packet.TabCompleteRequestPacket;
import com.velocitypowered.proxy.protocol.packet.TabCompleteResponse; import com.velocitypowered.proxy.protocol.packet.TabCompleteResponsePacket;
import com.velocitypowered.proxy.protocol.packet.TitlePacket; import com.velocitypowered.proxy.protocol.packet.TitlePacket;
import io.netty.util.collection.IntObjectHashMap; import io.netty.util.collection.IntObjectHashMap;
import io.netty.util.collection.IntObjectMap; import io.netty.util.collection.IntObjectMap;
@ -60,20 +59,20 @@ public enum StateRegistry {
HANDSHAKE { HANDSHAKE {
{ {
serverbound.register(Handshake.class, Handshake::new, serverbound.register(HandshakePacket.class, HandshakePacket::new,
map(0x00, MINECRAFT_1_7_2, false)); map(0x00, MINECRAFT_1_7_2, false));
} }
}, },
STATUS { STATUS {
{ {
serverbound.register(StatusRequest.class, () -> StatusRequest.INSTANCE, serverbound.register(StatusRequestPacket.class, () -> StatusRequestPacket.INSTANCE,
map(0x00, MINECRAFT_1_7_2, false)); map(0x00, MINECRAFT_1_7_2, false));
serverbound.register(StatusPing.class, StatusPing::new, serverbound.register(StatusPingPacket.class, StatusPingPacket::new,
map(0x01, MINECRAFT_1_7_2, false)); map(0x01, MINECRAFT_1_7_2, false));
clientbound.register(StatusResponse.class, StatusResponse::new, clientbound.register(StatusResponsePacket.class, StatusResponsePacket::new,
map(0x00, MINECRAFT_1_7_2, false)); map(0x00, MINECRAFT_1_7_2, false));
clientbound.register(StatusPing.class, StatusPing::new, clientbound.register(StatusPingPacket.class, StatusPingPacket::new,
map(0x01, MINECRAFT_1_7_2, false)); map(0x01, MINECRAFT_1_7_2, false));
} }
}, },
@ -82,33 +81,33 @@ public enum StateRegistry {
serverbound.fallback = false; serverbound.fallback = false;
clientbound.fallback = false; clientbound.fallback = false;
serverbound.register(TabCompleteRequest.class, TabCompleteRequest::new, serverbound.register(TabCompleteRequestPacket.class, TabCompleteRequestPacket::new,
map(0x14, MINECRAFT_1_7_2, false), map(0x14, MINECRAFT_1_7_2, false),
map(0x01, MINECRAFT_1_9, false), map(0x01, MINECRAFT_1_9, false),
map(0x02, MINECRAFT_1_12, false), map(0x02, MINECRAFT_1_12, false),
map(0x01, MINECRAFT_1_12_1, false), map(0x01, MINECRAFT_1_12_1, false),
map(0x05, MINECRAFT_1_13, false), map(0x05, MINECRAFT_1_13, false),
map(0x06, MINECRAFT_1_14, false)); map(0x06, MINECRAFT_1_14, false));
serverbound.register(Chat.class, Chat::new, serverbound.register(ChatPacket.class, ChatPacket::new,
map(0x01, MINECRAFT_1_7_2, false), map(0x01, MINECRAFT_1_7_2, false),
map(0x02, MINECRAFT_1_9, false), map(0x02, MINECRAFT_1_9, false),
map(0x03, MINECRAFT_1_12, false), map(0x03, MINECRAFT_1_12, false),
map(0x02, MINECRAFT_1_12_1, false), map(0x02, MINECRAFT_1_12_1, false),
map(0x03, MINECRAFT_1_14, false)); map(0x03, MINECRAFT_1_14, false));
serverbound.register(ClientSettings.class, ClientSettings::new, serverbound.register(ClientSettingsPacket.class, ClientSettingsPacket::new,
map(0x15, MINECRAFT_1_7_2, false), map(0x15, MINECRAFT_1_7_2, false),
map(0x04, MINECRAFT_1_9, false), map(0x04, MINECRAFT_1_9, false),
map(0x05, MINECRAFT_1_12, false), map(0x05, MINECRAFT_1_12, false),
map(0x04, MINECRAFT_1_12_1, false), map(0x04, MINECRAFT_1_12_1, false),
map(0x05, MINECRAFT_1_14, false)); map(0x05, MINECRAFT_1_14, false));
serverbound.register(PluginMessage.class, PluginMessage::new, serverbound.register(PluginMessagePacket.class, PluginMessagePacket::new,
map(0x17, MINECRAFT_1_7_2, false), map(0x17, MINECRAFT_1_7_2, false),
map(0x09, MINECRAFT_1_9, false), map(0x09, MINECRAFT_1_9, false),
map(0x0A, MINECRAFT_1_12, false), map(0x0A, MINECRAFT_1_12, false),
map(0x09, MINECRAFT_1_12_1, false), map(0x09, MINECRAFT_1_12_1, false),
map(0x0A, MINECRAFT_1_13, false), map(0x0A, MINECRAFT_1_13, false),
map(0x0B, MINECRAFT_1_14, false)); map(0x0B, MINECRAFT_1_14, false));
serverbound.register(KeepAlive.class, KeepAlive::new, serverbound.register(KeepAlivePacket.class, KeepAlivePacket::new,
map(0x00, MINECRAFT_1_7_2, false), map(0x00, MINECRAFT_1_7_2, false),
map(0x0B, MINECRAFT_1_9, false), map(0x0B, MINECRAFT_1_9, false),
map(0x0C, MINECRAFT_1_12, false), map(0x0C, MINECRAFT_1_12, false),
@ -116,7 +115,7 @@ public enum StateRegistry {
map(0x0E, MINECRAFT_1_13, false), map(0x0E, MINECRAFT_1_13, false),
map(0x0F, MINECRAFT_1_14, false), map(0x0F, MINECRAFT_1_14, false),
map(0x10, MINECRAFT_1_16, false)); map(0x10, MINECRAFT_1_16, false));
serverbound.register(ResourcePackResponse.class, ResourcePackResponse::new, serverbound.register(ResourcePackResponsePacket.class, ResourcePackResponsePacket::new,
map(0x19, MINECRAFT_1_8, false), map(0x19, MINECRAFT_1_8, false),
map(0x16, MINECRAFT_1_9, false), map(0x16, MINECRAFT_1_9, false),
map(0x18, MINECRAFT_1_12, false), map(0x18, MINECRAFT_1_12, false),
@ -125,29 +124,29 @@ public enum StateRegistry {
map(0x20, MINECRAFT_1_16, false), map(0x20, MINECRAFT_1_16, false),
map(0x21, MINECRAFT_1_16_2, false)); map(0x21, MINECRAFT_1_16_2, false));
clientbound.register(BossBar.class, BossBar::new, clientbound.register(BossBarPacket.class, BossBarPacket::new,
map(0x0C, MINECRAFT_1_9, false), map(0x0C, MINECRAFT_1_9, false),
map(0x0D, MINECRAFT_1_15, false), map(0x0D, MINECRAFT_1_15, false),
map(0x0C, MINECRAFT_1_16, false)); map(0x0C, MINECRAFT_1_16, false));
clientbound.register(Chat.class, Chat::new, clientbound.register(ChatPacket.class, ChatPacket::new,
map(0x02, MINECRAFT_1_7_2, true), map(0x02, MINECRAFT_1_7_2, true),
map(0x0F, MINECRAFT_1_9, true), map(0x0F, MINECRAFT_1_9, true),
map(0x0E, MINECRAFT_1_13, true), map(0x0E, MINECRAFT_1_13, true),
map(0x0F, MINECRAFT_1_15, true), map(0x0F, MINECRAFT_1_15, true),
map(0x0E, MINECRAFT_1_16, true)); map(0x0E, MINECRAFT_1_16, true));
clientbound.register(TabCompleteResponse.class, TabCompleteResponse::new, clientbound.register(TabCompleteResponsePacket.class, TabCompleteResponsePacket::new,
map(0x3A, MINECRAFT_1_7_2, false), map(0x3A, MINECRAFT_1_7_2, false),
map(0x0E, MINECRAFT_1_9, false), map(0x0E, MINECRAFT_1_9, false),
map(0x10, MINECRAFT_1_13, false), map(0x10, MINECRAFT_1_13, false),
map(0x11, MINECRAFT_1_15, false), map(0x11, MINECRAFT_1_15, false),
map(0x10, MINECRAFT_1_16, false), map(0x10, MINECRAFT_1_16, false),
map(0x0F, MINECRAFT_1_16_2, false)); map(0x0F, MINECRAFT_1_16_2, false));
clientbound.register(AvailableCommands.class, AvailableCommands::new, clientbound.register(AvailableCommandsPacket.class, AvailableCommandsPacket::new,
map(0x11, MINECRAFT_1_13, false), map(0x11, MINECRAFT_1_13, false),
map(0x12, MINECRAFT_1_15, false), map(0x12, MINECRAFT_1_15, false),
map(0x11, MINECRAFT_1_16, false), map(0x11, MINECRAFT_1_16, false),
map(0x10, MINECRAFT_1_16_2, false)); map(0x10, MINECRAFT_1_16_2, false));
clientbound.register(PluginMessage.class, PluginMessage::new, clientbound.register(PluginMessagePacket.class, PluginMessagePacket::new,
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),
@ -155,7 +154,7 @@ public enum StateRegistry {
map(0x19, MINECRAFT_1_15, false), map(0x19, MINECRAFT_1_15, false),
map(0x18, MINECRAFT_1_16, false), map(0x18, MINECRAFT_1_16, false),
map(0x17, MINECRAFT_1_16_2, false)); map(0x17, MINECRAFT_1_16_2, false));
clientbound.register(Disconnect.class, Disconnect::new, clientbound.register(DisconnectPacket.class, DisconnectPacket::new,
map(0x40, MINECRAFT_1_7_2, false), map(0x40, MINECRAFT_1_7_2, false),
map(0x1A, MINECRAFT_1_9, false), map(0x1A, MINECRAFT_1_9, false),
map(0x1B, MINECRAFT_1_13, false), map(0x1B, MINECRAFT_1_13, false),
@ -163,7 +162,7 @@ public enum StateRegistry {
map(0x1B, MINECRAFT_1_15, false), map(0x1B, MINECRAFT_1_15, false),
map(0x1A, MINECRAFT_1_16, false), map(0x1A, MINECRAFT_1_16, false),
map(0x19, MINECRAFT_1_16_2, false)); map(0x19, MINECRAFT_1_16_2, false));
clientbound.register(KeepAlive.class, KeepAlive::new, clientbound.register(KeepAlivePacket.class, KeepAlivePacket::new,
map(0x00, MINECRAFT_1_7_2, false), map(0x00, MINECRAFT_1_7_2, false),
map(0x1F, MINECRAFT_1_9, false), map(0x1F, MINECRAFT_1_9, false),
map(0x21, MINECRAFT_1_13, false), map(0x21, MINECRAFT_1_13, false),
@ -171,7 +170,7 @@ public enum StateRegistry {
map(0x21, MINECRAFT_1_15, false), map(0x21, MINECRAFT_1_15, false),
map(0x20, MINECRAFT_1_16, false), map(0x20, MINECRAFT_1_16, false),
map(0x1F, MINECRAFT_1_16_2, false)); map(0x1F, MINECRAFT_1_16_2, false));
clientbound.register(JoinGame.class, JoinGame::new, clientbound.register(JoinGamePacket.class, JoinGamePacket::new,
map(0x01, MINECRAFT_1_7_2, false), map(0x01, MINECRAFT_1_7_2, false),
map(0x23, MINECRAFT_1_9, false), map(0x23, MINECRAFT_1_9, false),
map(0x25, MINECRAFT_1_13, false), map(0x25, MINECRAFT_1_13, false),
@ -179,7 +178,7 @@ public enum StateRegistry {
map(0x26, MINECRAFT_1_15, false), map(0x26, MINECRAFT_1_15, false),
map(0x25, MINECRAFT_1_16, false), map(0x25, MINECRAFT_1_16, false),
map(0x24, MINECRAFT_1_16_2, false)); map(0x24, MINECRAFT_1_16_2, false));
clientbound.register(Respawn.class, Respawn::new, clientbound.register(RespawnPacket.class, RespawnPacket::new,
map(0x07, MINECRAFT_1_7_2, true), map(0x07, MINECRAFT_1_7_2, true),
map(0x33, MINECRAFT_1_9, true), map(0x33, MINECRAFT_1_9, true),
map(0x34, MINECRAFT_1_12, true), map(0x34, MINECRAFT_1_12, true),
@ -189,7 +188,7 @@ public enum StateRegistry {
map(0x3B, MINECRAFT_1_15, true), map(0x3B, MINECRAFT_1_15, true),
map(0x3A, MINECRAFT_1_16, true), map(0x3A, MINECRAFT_1_16, true),
map(0x39, MINECRAFT_1_16_2, true)); map(0x39, MINECRAFT_1_16_2, true));
clientbound.register(ResourcePackRequest.class, ResourcePackRequest::new, clientbound.register(ResourcePackRequestPacket.class, ResourcePackRequestPacket::new,
map(0x48, MINECRAFT_1_8, true), map(0x48, MINECRAFT_1_8, true),
map(0x32, MINECRAFT_1_9, true), map(0x32, MINECRAFT_1_9, true),
map(0x33, MINECRAFT_1_12, true), map(0x33, MINECRAFT_1_12, true),
@ -199,7 +198,7 @@ public enum StateRegistry {
map(0x3A, MINECRAFT_1_15, true), map(0x3A, MINECRAFT_1_15, true),
map(0x39, MINECRAFT_1_16, true), map(0x39, MINECRAFT_1_16, true),
map(0x38, MINECRAFT_1_16_2, true)); map(0x38, MINECRAFT_1_16_2, true));
clientbound.register(HeaderAndFooter.class, HeaderAndFooter::new, clientbound.register(HeaderAndFooterPacket.class, HeaderAndFooterPacket::new,
map(0x47, MINECRAFT_1_8, true), map(0x47, MINECRAFT_1_8, true),
map(0x48, MINECRAFT_1_9, true), map(0x48, MINECRAFT_1_9, true),
map(0x47, MINECRAFT_1_9_4, true), map(0x47, MINECRAFT_1_9_4, true),
@ -218,7 +217,7 @@ public enum StateRegistry {
map(0x4F, MINECRAFT_1_14, true), map(0x4F, MINECRAFT_1_14, true),
map(0x50, MINECRAFT_1_15, true), map(0x50, MINECRAFT_1_15, true),
map(0x4F, MINECRAFT_1_16, true)); map(0x4F, MINECRAFT_1_16, true));
clientbound.register(PlayerListItem.class, PlayerListItem::new, clientbound.register(PlayerListItemPacket.class, PlayerListItemPacket::new,
map(0x38, MINECRAFT_1_7_2, false), map(0x38, MINECRAFT_1_7_2, false),
map(0x2D, MINECRAFT_1_9, false), map(0x2D, MINECRAFT_1_9, false),
map(0x2E, MINECRAFT_1_12_1, false), map(0x2E, MINECRAFT_1_12_1, false),
@ -231,37 +230,43 @@ public enum StateRegistry {
}, },
LOGIN { LOGIN {
{ {
serverbound.register(ServerLogin.class, ServerLogin::new, serverbound.register(ServerLoginPacket.class, ServerLoginPacket::new,
map(0x00, MINECRAFT_1_7_2, false)); map(0x00, MINECRAFT_1_7_2, false));
serverbound.register(EncryptionResponse.class, EncryptionResponse::new, serverbound.register(EncryptionResponsePacket.class, EncryptionResponsePacket::new,
map(0x01, MINECRAFT_1_7_2, false)); map(0x01, MINECRAFT_1_7_2, false));
serverbound.register(LoginPluginResponse.class, LoginPluginResponse::new, serverbound.register(LoginPluginResponsePacket.class, LoginPluginResponsePacket::new,
map(0x02, MINECRAFT_1_13, false)); map(0x02, MINECRAFT_1_13, false));
clientbound.register(Disconnect.class, Disconnect::new, clientbound.register(DisconnectPacket.class, DisconnectPacket::new,
map(0x00, MINECRAFT_1_7_2, false)); map(0x00, MINECRAFT_1_7_2, false));
clientbound.register(EncryptionRequest.class, EncryptionRequest::new, clientbound.register(EncryptionRequestPacket.class, EncryptionRequestPacket::new,
map(0x01, MINECRAFT_1_7_2, false)); map(0x01, MINECRAFT_1_7_2, false));
clientbound.register(ServerLoginSuccess.class, ServerLoginSuccess::new, clientbound.register(ServerLoginSuccessPacket.class, ServerLoginSuccessPacket::new,
map(0x02, MINECRAFT_1_7_2, false)); map(0x02, MINECRAFT_1_7_2, false));
clientbound.register(SetCompression.class, SetCompression::new, clientbound.register(SetCompressionPacket.class, SetCompressionPacket::new,
map(0x03, MINECRAFT_1_8, false)); map(0x03, MINECRAFT_1_8, false));
clientbound.register(LoginPluginMessage.class, LoginPluginMessage::new, clientbound.register(LoginPluginMessagePacket.class, LoginPluginMessagePacket::new,
map(0x04, MINECRAFT_1_13, false)); map(0x04, MINECRAFT_1_13, false));
} }
}; };
public static final int STATUS_ID = 1; public static final int STATUS_ID = 1;
public static final int LOGIN_ID = 2; public static final int LOGIN_ID = 2;
public final PacketRegistry clientbound = new PacketRegistry(Direction.CLIENTBOUND); public final PacketRegistry clientbound = new PacketRegistry(ProtocolDirection.CLIENTBOUND);
public final PacketRegistry serverbound = new PacketRegistry(Direction.SERVERBOUND); public final PacketRegistry serverbound = new PacketRegistry(ProtocolDirection.SERVERBOUND);
public PacketRegistry.ProtocolRegistry getProtocolRegistry(ProtocolDirection direction,
ProtocolVersion version) {
return (direction == ProtocolDirection.SERVERBOUND ? this.serverbound : this.clientbound)
.getProtocolRegistry(version);
}
public static class PacketRegistry { public static class PacketRegistry {
private final Direction direction; private final ProtocolDirection direction;
private final Map<ProtocolVersion, ProtocolRegistry> versions; private final Map<ProtocolVersion, ProtocolRegistry> versions;
private boolean fallback = true; private boolean fallback = true;
PacketRegistry(Direction direction) { PacketRegistry(ProtocolDirection direction) {
this.direction = direction; this.direction = direction;
Map<ProtocolVersion, ProtocolRegistry> mutableVersions = new EnumMap<>(ProtocolVersion.class); Map<ProtocolVersion, ProtocolRegistry> mutableVersions = new EnumMap<>(ProtocolVersion.class);
@ -285,7 +290,7 @@ public enum StateRegistry {
return registry; return registry;
} }
<P extends MinecraftPacket> void register(Class<P> clazz, Supplier<P> packetSupplier, <P extends Packet> void register(Class<P> clazz, Supplier<P> packetSupplier,
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.");
@ -334,9 +339,9 @@ public enum StateRegistry {
public class ProtocolRegistry { public class ProtocolRegistry {
public final ProtocolVersion version; public final ProtocolVersion version;
final IntObjectMap<Supplier<? extends MinecraftPacket>> packetIdToSupplier = final IntObjectMap<Supplier<? extends Packet>> packetIdToSupplier =
new IntObjectHashMap<>(16, 0.5f); new IntObjectHashMap<>(16, 0.5f);
final Object2IntMap<Class<? extends MinecraftPacket>> packetClassToId = final Object2IntMap<Class<? extends Packet>> packetClassToId =
new Object2IntOpenHashMap<>(16, 0.5f); new Object2IntOpenHashMap<>(16, 0.5f);
ProtocolRegistry(final ProtocolVersion version) { ProtocolRegistry(final ProtocolVersion version) {
@ -350,8 +355,8 @@ public enum StateRegistry {
* @param id the packet ID * @param id the packet ID
* @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 MinecraftPacket createPacket(final int id) { public @Nullable Packet createPacket(final int id) {
final Supplier<? extends MinecraftPacket> supplier = this.packetIdToSupplier.get(id); final Supplier<? extends Packet> supplier = this.packetIdToSupplier.get(id);
if (supplier == null) { if (supplier == null) {
return null; return null;
} }
@ -365,7 +370,7 @@ public enum StateRegistry {
* @return the packet ID * @return the packet ID
* @throws IllegalArgumentException if the packet ID is not found * @throws IllegalArgumentException if the packet ID is not found
*/ */
public int getPacketId(final MinecraftPacket packet) { public int getPacketId(final Packet packet) {
final int id = this.packetClassToId.getInt(packet.getClass()); final int id = this.packetClassToId.getInt(packet.getClass());
if (id == Integer.MIN_VALUE) { if (id == Integer.MIN_VALUE) {
throw new IllegalArgumentException(String.format( throw new IllegalArgumentException(String.format(

Datei anzeigen

@ -2,8 +2,8 @@ package com.velocitypowered.proxy.protocol.netty;
import static com.velocitypowered.proxy.protocol.util.NettyPreconditions.checkFrame; import static com.velocitypowered.proxy.protocol.util.NettyPreconditions.checkFrame;
import com.velocitypowered.proxy.protocol.packet.LegacyHandshake; import com.velocitypowered.proxy.protocol.packet.legacy.LegacyHandshakePacket;
import com.velocitypowered.proxy.protocol.packet.LegacyPing; import com.velocitypowered.proxy.protocol.packet.legacy.LegacyPingPacket;
import com.velocitypowered.proxy.protocol.packet.legacyping.LegacyMinecraftPingVersion; import com.velocitypowered.proxy.protocol.packet.legacyping.LegacyMinecraftPingVersion;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -32,13 +32,13 @@ public class LegacyPingDecoder extends ByteToMessageDecoder {
if (first == 0xfe) { if (first == 0xfe) {
// possibly a ping // possibly a ping
if (!in.isReadable()) { if (!in.isReadable()) {
out.add(new LegacyPing(LegacyMinecraftPingVersion.MINECRAFT_1_3)); out.add(new LegacyPingPacket(LegacyMinecraftPingVersion.MINECRAFT_1_3));
return; return;
} }
short next = in.readUnsignedByte(); short next = in.readUnsignedByte();
if (next == 1 && !in.isReadable()) { if (next == 1 && !in.isReadable()) {
out.add(new LegacyPing(LegacyMinecraftPingVersion.MINECRAFT_1_4)); out.add(new LegacyPingPacket(LegacyMinecraftPingVersion.MINECRAFT_1_4));
return; return;
} }
@ -46,14 +46,14 @@ public class LegacyPingDecoder extends ByteToMessageDecoder {
out.add(readExtended16Data(in)); out.add(readExtended16Data(in));
} else if (first == 0x02 && in.isReadable()) { } else if (first == 0x02 && in.isReadable()) {
in.skipBytes(in.readableBytes()); in.skipBytes(in.readableBytes());
out.add(new LegacyHandshake()); out.add(new LegacyHandshakePacket());
} else { } else {
in.readerIndex(originalReaderIndex); in.readerIndex(originalReaderIndex);
ctx.pipeline().remove(this); ctx.pipeline().remove(this);
} }
} }
private static LegacyPing readExtended16Data(ByteBuf in) { private static LegacyPingPacket readExtended16Data(ByteBuf in) {
in.skipBytes(1); in.skipBytes(1);
String channelName = readLegacyString(in); String channelName = readLegacyString(in);
if (!channelName.equals(MC_1_6_CHANNEL)) { if (!channelName.equals(MC_1_6_CHANNEL)) {
@ -63,7 +63,7 @@ public class LegacyPingDecoder extends ByteToMessageDecoder {
String hostname = readLegacyString(in); String hostname = readLegacyString(in);
int port = in.readInt(); int port = in.readInt();
return new LegacyPing(LegacyMinecraftPingVersion.MINECRAFT_1_6, InetSocketAddress return new LegacyPingPacket(LegacyMinecraftPingVersion.MINECRAFT_1_6, InetSocketAddress
.createUnresolved(hostname, port)); .createUnresolved(hostname, port));
} }

Datei anzeigen

@ -1,6 +1,6 @@
package com.velocitypowered.proxy.protocol.netty; package com.velocitypowered.proxy.protocol.netty;
import com.velocitypowered.proxy.protocol.packet.LegacyDisconnect; import com.velocitypowered.proxy.protocol.packet.legacy.LegacyDisconnectPacket;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -8,7 +8,7 @@ import io.netty.handler.codec.MessageToByteEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ChannelHandler.Sharable @ChannelHandler.Sharable
public class LegacyPingEncoder extends MessageToByteEncoder<LegacyDisconnect> { public class LegacyPingEncoder extends MessageToByteEncoder<LegacyDisconnectPacket> {
public static final LegacyPingEncoder INSTANCE = new LegacyPingEncoder(); public static final LegacyPingEncoder INSTANCE = new LegacyPingEncoder();
@ -16,7 +16,7 @@ public class LegacyPingEncoder extends MessageToByteEncoder<LegacyDisconnect> {
} }
@Override @Override
protected void encode(ChannelHandlerContext ctx, LegacyDisconnect msg, ByteBuf out) protected void encode(ChannelHandlerContext ctx, LegacyDisconnectPacket msg, ByteBuf out)
throws Exception { throws Exception {
out.writeByte(0xff); out.writeByte(0xff);
writeLegacyString(out, msg.getReason()); writeLegacyString(out, msg.getReason());

Datei anzeigen

@ -2,7 +2,8 @@ package com.velocitypowered.proxy.protocol.netty;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.util.except.QuietDecoderException; import com.velocitypowered.proxy.util.except.QuietDecoderException;
@ -18,7 +19,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
new QuietDecoderException("A packet did not decode successfully (invalid data). If you are a " new QuietDecoderException("A packet did not decode successfully (invalid data). If you are a "
+ "developer, launch Velocity with -Dvelocity.packet-decode-logging=true to see more."); + "developer, launch Velocity with -Dvelocity.packet-decode-logging=true to see more.");
private final ProtocolUtils.Direction direction; private final ProtocolDirection direction;
private StateRegistry state; private StateRegistry state;
private StateRegistry.PacketRegistry.ProtocolRegistry registry; private StateRegistry.PacketRegistry.ProtocolRegistry registry;
@ -27,9 +28,9 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
* *
* @param direction the direction from which we decode from * @param direction the direction from which we decode from
*/ */
public MinecraftDecoder(ProtocolUtils.Direction direction) { public MinecraftDecoder(ProtocolDirection direction) {
this.direction = Preconditions.checkNotNull(direction, "direction"); this.direction = Preconditions.checkNotNull(direction, "direction");
this.registry = direction.getProtocolRegistry(StateRegistry.HANDSHAKE, this.registry = StateRegistry.HANDSHAKE.getProtocolRegistry(direction,
ProtocolVersion.MINIMUM_VERSION); ProtocolVersion.MINIMUM_VERSION);
this.state = StateRegistry.HANDSHAKE; this.state = StateRegistry.HANDSHAKE;
} }
@ -52,7 +53,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
int originalReaderIndex = buf.readerIndex(); int originalReaderIndex = buf.readerIndex();
int packetId = ProtocolUtils.readVarInt(buf); int packetId = ProtocolUtils.readVarInt(buf);
MinecraftPacket packet = this.registry.createPacket(packetId); Packet packet = this.registry.createPacket(packetId);
if (packet == null) { if (packet == null) {
buf.readerIndex(originalReaderIndex); buf.readerIndex(originalReaderIndex);
ctx.fireChannelRead(buf); ctx.fireChannelRead(buf);
@ -74,7 +75,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
} }
} }
private Exception handleNotReadEnough(MinecraftPacket packet, int packetId) { private Exception handleNotReadEnough(Packet packet, int packetId) {
if (DEBUG) { if (DEBUG) {
return new CorruptedFrameException("Did not read full packet for " + packet.getClass() + " " return new CorruptedFrameException("Did not read full packet for " + packet.getClass() + " "
+ getExtraConnectionDetail(packetId)); + getExtraConnectionDetail(packetId));
@ -83,7 +84,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
} }
} }
private Exception handleDecodeFailure(Exception cause, MinecraftPacket packet, int packetId) { private Exception handleDecodeFailure(Exception cause, Packet packet, int packetId) {
if (DEBUG) { if (DEBUG) {
return new CorruptedFrameException( return new CorruptedFrameException(
"Error decoding " + packet.getClass() + " " + getExtraConnectionDetail(packetId), cause); "Error decoding " + packet.getClass() + " " + getExtraConnectionDetail(packetId), cause);
@ -98,7 +99,7 @@ public class MinecraftDecoder extends ChannelInboundHandlerAdapter {
} }
public void setProtocolVersion(ProtocolVersion protocolVersion) { public void setProtocolVersion(ProtocolVersion protocolVersion) {
this.registry = direction.getProtocolRegistry(state, protocolVersion); this.registry = state.getProtocolRegistry(direction, protocolVersion);
} }
public void setState(StateRegistry state) { public void setState(StateRegistry state) {

Datei anzeigen

@ -2,16 +2,17 @@ package com.velocitypowered.proxy.protocol.netty;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToByteEncoder;
public class MinecraftEncoder extends MessageToByteEncoder<MinecraftPacket> { public class MinecraftEncoder extends MessageToByteEncoder<Packet> {
private final ProtocolUtils.Direction direction; private final ProtocolDirection direction;
private StateRegistry state; private StateRegistry state;
private StateRegistry.PacketRegistry.ProtocolRegistry registry; private StateRegistry.PacketRegistry.ProtocolRegistry registry;
@ -20,22 +21,22 @@ public class MinecraftEncoder extends MessageToByteEncoder<MinecraftPacket> {
* *
* @param direction the direction to encode to * @param direction the direction to encode to
*/ */
public MinecraftEncoder(ProtocolUtils.Direction direction) { public MinecraftEncoder(ProtocolDirection direction) {
this.direction = Preconditions.checkNotNull(direction, "direction"); this.direction = Preconditions.checkNotNull(direction, "direction");
this.registry = direction this.registry = StateRegistry.HANDSHAKE
.getProtocolRegistry(StateRegistry.HANDSHAKE, ProtocolVersion.MINIMUM_VERSION); .getProtocolRegistry(direction, ProtocolVersion.MINIMUM_VERSION);
this.state = StateRegistry.HANDSHAKE; this.state = StateRegistry.HANDSHAKE;
} }
@Override @Override
protected void encode(ChannelHandlerContext ctx, MinecraftPacket msg, ByteBuf out) { protected void encode(ChannelHandlerContext ctx, Packet msg, ByteBuf out) {
int packetId = this.registry.getPacketId(msg); int packetId = this.registry.getPacketId(msg);
ProtocolUtils.writeVarInt(out, packetId); ProtocolUtils.writeVarInt(out, packetId);
msg.encode(out, direction, registry.version); msg.encode(out, direction, registry.version);
} }
public void setProtocolVersion(final ProtocolVersion protocolVersion) { public void setProtocolVersion(final ProtocolVersion protocolVersion) {
this.registry = direction.getProtocolRegistry(state, protocolVersion); this.registry = state.getProtocolRegistry(direction, protocolVersion);
} }
public void setState(StateRegistry state) { public void setState(StateRegistry state) {

Datei anzeigen

@ -19,9 +19,9 @@ import com.mojang.brigadier.tree.RootCommandNode;
import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.ProtocolUtils.Direction; import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.packet.brigadier.ArgumentPropertyRegistry; import com.velocitypowered.proxy.protocol.packet.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;
@ -35,7 +35,7 @@ import java.util.concurrent.CompletableFuture;
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 AvailableCommands implements MinecraftPacket { public class AvailableCommandsPacket implements Packet {
private static final Command<CommandSource> PLACEHOLDER_COMMAND = source -> 0; private static final Command<CommandSource> PLACEHOLDER_COMMAND = source -> 0;
private static final byte NODE_TYPE_ROOT = 0x00; private static final byte NODE_TYPE_ROOT = 0x00;
@ -61,7 +61,7 @@ public class AvailableCommands implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) {
int commands = ProtocolUtils.readVarInt(buf); int commands = ProtocolUtils.readVarInt(buf);
WireNode[] wireNodes = new WireNode[commands]; WireNode[] wireNodes = new WireNode[commands];
for (int i = 0; i < commands; i++) { for (int i = 0; i < commands; i++) {
@ -93,7 +93,7 @@ public class AvailableCommands implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) {
// Assign all the children an index. // Assign all the children an index.
Deque<CommandNode<CommandSource>> childrenQueue = new ArrayDeque<>(ImmutableList.of(rootNode)); Deque<CommandNode<CommandSource>> childrenQueue = new ArrayDeque<>(ImmutableList.of(rootNode));
Object2IntMap<CommandNode<CommandSource>> idMappings = new Object2IntLinkedOpenHashMap<>(); Object2IntMap<CommandNode<CommandSource>> idMappings = new Object2IntLinkedOpenHashMap<>();

Datei anzeigen

@ -2,13 +2,14 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.UUID; import java.util.UUID;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class BossBar implements MinecraftPacket { public class BossBarPacket implements Packet {
public static final int ADD = 0; public static final int ADD = 0;
public static final int REMOVE = 1; public static final int REMOVE = 1;
@ -16,6 +17,7 @@ public class BossBar implements MinecraftPacket {
public static final int UPDATE_NAME = 3; public static final int UPDATE_NAME = 3;
public static final int UPDATE_STYLE = 4; public static final int UPDATE_STYLE = 4;
public static final int UPDATE_PROPERTIES = 5; public static final int UPDATE_PROPERTIES = 5;
private @Nullable UUID uuid; private @Nullable UUID uuid;
private int action; private int action;
private @Nullable String name; private @Nullable String name;
@ -97,7 +99,7 @@ public class BossBar implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
this.uuid = ProtocolUtils.readUuid(buf); this.uuid = ProtocolUtils.readUuid(buf);
this.action = ProtocolUtils.readVarInt(buf); this.action = ProtocolUtils.readVarInt(buf);
switch (action) { switch (action) {
@ -129,7 +131,7 @@ public class BossBar implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (uuid == null) { if (uuid == null) {
throw new IllegalStateException("No boss bar UUID specified"); throw new IllegalStateException("No boss bar UUID specified");
} }
@ -174,8 +176,8 @@ public class BossBar implements MinecraftPacket {
return handler.handle(this); return handler.handle(this);
} }
public static BossBar createRemovePacket(UUID id) { public static BossBarPacket createRemovePacket(UUID id) {
BossBar packet = new BossBar(); BossBarPacket packet = new BossBarPacket();
packet.setUuid(id); packet.setUuid(id);
packet.setAction(REMOVE); packet.setAction(REMOVE);
return packet; return packet;

Datei anzeigen

@ -3,7 +3,8 @@ package com.velocitypowered.proxy.protocol.packet;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.kyori.adventure.identity.Identity; import net.kyori.adventure.identity.Identity;
@ -12,7 +13,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.UUID; import java.util.UUID;
public class Chat implements MinecraftPacket { public class ChatPacket implements Packet {
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;
@ -25,10 +26,10 @@ public class Chat implements MinecraftPacket {
private byte type; private byte type;
private @Nullable UUID sender; private @Nullable UUID sender;
public Chat() { public ChatPacket() {
} }
public Chat(String message, byte type, UUID sender) { public ChatPacket(String message, byte type, UUID sender) {
this.message = message; this.message = message;
this.type = type; this.type = type;
this.sender = sender; this.sender = sender;
@ -71,9 +72,9 @@ public class Chat implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
message = ProtocolUtils.readString(buf); message = ProtocolUtils.readString(buf);
if (direction == ProtocolUtils.Direction.CLIENTBOUND && version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (direction == ProtocolDirection.CLIENTBOUND && version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
type = buf.readByte(); type = buf.readByte();
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
sender = ProtocolUtils.readUuid(buf); sender = ProtocolUtils.readUuid(buf);
@ -82,12 +83,12 @@ public class Chat implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (message == null) { if (message == null) {
throw new IllegalStateException("Message is not specified"); throw new IllegalStateException("Message is not specified");
} }
ProtocolUtils.writeString(buf, message); ProtocolUtils.writeString(buf, message);
if (direction == ProtocolUtils.Direction.CLIENTBOUND && version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (direction == ProtocolDirection.CLIENTBOUND && version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
buf.writeByte(type); buf.writeByte(type);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
ProtocolUtils.writeUuid(buf, sender == null ? EMPTY_SENDER : sender); ProtocolUtils.writeUuid(buf, sender == null ? EMPTY_SENDER : sender);
@ -100,19 +101,19 @@ public class Chat implements MinecraftPacket {
return handler.handle(this); return handler.handle(this);
} }
public static Chat createClientbound(Identity identity, public static ChatPacket createClientbound(Identity identity,
Component component, ProtocolVersion version) { Component component, ProtocolVersion version) {
return createClientbound(component, CHAT_TYPE, identity.uuid(), version); return createClientbound(component, CHAT_TYPE, identity.uuid(), version);
} }
public static Chat createClientbound(Component component, byte type, public static ChatPacket createClientbound(Component component, byte type,
UUID sender, ProtocolVersion version) { UUID sender, ProtocolVersion version) {
Preconditions.checkNotNull(component, "component"); Preconditions.checkNotNull(component, "component");
return new Chat(ProtocolUtils.getJsonChatSerializer(version).serialize(component), type, return new ChatPacket(ProtocolUtils.getJsonChatSerializer(version).serialize(component), type,
sender); sender);
} }
public static Chat createServerbound(String message) { public static ChatPacket createServerbound(String message) {
return new Chat(message, CHAT_TYPE, EMPTY_SENDER); return new ChatPacket(message, CHAT_TYPE, EMPTY_SENDER);
} }
} }

Datei anzeigen

@ -2,12 +2,13 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ClientSettings implements MinecraftPacket { public class ClientSettingsPacket implements Packet {
private @Nullable String locale; private @Nullable String locale;
private byte viewDistance; private byte viewDistance;
@ -17,10 +18,10 @@ public class ClientSettings implements MinecraftPacket {
private short skinParts; private short skinParts;
private int mainHand; private int mainHand;
public ClientSettings() { public ClientSettingsPacket() {
} }
public ClientSettings(String locale, byte viewDistance, int chatVisibility, boolean chatColors, public ClientSettingsPacket(String locale, byte viewDistance, int chatVisibility, boolean chatColors,
short skinParts, int mainHand) { short skinParts, int mainHand) {
this.locale = locale; this.locale = locale;
this.viewDistance = viewDistance; this.viewDistance = viewDistance;
@ -94,7 +95,7 @@ public class ClientSettings implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
this.locale = ProtocolUtils.readString(buf, 16); this.locale = ProtocolUtils.readString(buf, 16);
this.viewDistance = buf.readByte(); this.viewDistance = buf.readByte();
this.chatVisibility = ProtocolUtils.readVarInt(buf); this.chatVisibility = ProtocolUtils.readVarInt(buf);
@ -112,7 +113,7 @@ public class ClientSettings implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (locale == null) { if (locale == null) {
throw new IllegalStateException("No locale specified"); throw new IllegalStateException("No locale specified");
} }

Datei anzeigen

@ -3,20 +3,21 @@ package com.velocitypowered.proxy.protocol.packet;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import 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 Disconnect implements MinecraftPacket { public class DisconnectPacket implements Packet {
private @Nullable String reason; private @Nullable String reason;
public Disconnect() { public DisconnectPacket() {
} }
public Disconnect(String reason) { public DisconnectPacket(String reason) {
this.reason = Preconditions.checkNotNull(reason, "reason"); this.reason = Preconditions.checkNotNull(reason, "reason");
} }
@ -39,12 +40,12 @@ public class Disconnect implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
reason = ProtocolUtils.readString(buf); reason = ProtocolUtils.readString(buf);
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (reason == null) { if (reason == null) {
throw new IllegalStateException("No reason specified."); throw new IllegalStateException("No reason specified.");
} }
@ -56,8 +57,8 @@ public class Disconnect implements MinecraftPacket {
return handler.handle(this); return handler.handle(this);
} }
public static Disconnect create(Component component, ProtocolVersion version) { public static DisconnectPacket create(Component component, ProtocolVersion version) {
Preconditions.checkNotNull(component, "component"); Preconditions.checkNotNull(component, "component");
return new Disconnect(ProtocolUtils.getJsonChatSerializer(version).serialize(component)); return new DisconnectPacket(ProtocolUtils.getJsonChatSerializer(version).serialize(component));
} }
} }

Datei anzeigen

@ -4,12 +4,13 @@ import static com.velocitypowered.proxy.connection.VelocityConstants.EMPTY_BYTE_
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.Arrays; import java.util.Arrays;
public class EncryptionRequest implements MinecraftPacket { public class EncryptionRequestPacket implements Packet {
private String serverId = ""; private String serverId = "";
private byte[] publicKey = EMPTY_BYTE_ARRAY; private byte[] publicKey = EMPTY_BYTE_ARRAY;
@ -40,7 +41,7 @@ public class EncryptionRequest implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
this.serverId = ProtocolUtils.readString(buf, 20); this.serverId = ProtocolUtils.readString(buf, 20);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
@ -53,7 +54,7 @@ public class EncryptionRequest implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
ProtocolUtils.writeString(buf, this.serverId); ProtocolUtils.writeString(buf, this.serverId);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {

Datei anzeigen

@ -4,12 +4,13 @@ import static com.velocitypowered.proxy.connection.VelocityConstants.EMPTY_BYTE_
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.Arrays; import java.util.Arrays;
public class EncryptionResponse implements MinecraftPacket { public class EncryptionResponsePacket implements Packet {
private byte[] sharedSecret = EMPTY_BYTE_ARRAY; private byte[] sharedSecret = EMPTY_BYTE_ARRAY;
private byte[] verifyToken = EMPTY_BYTE_ARRAY; private byte[] verifyToken = EMPTY_BYTE_ARRAY;
@ -31,7 +32,7 @@ public class EncryptionResponse implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
this.sharedSecret = ProtocolUtils.readByteArray(buf, 256); this.sharedSecret = ProtocolUtils.readByteArray(buf, 256);
this.verifyToken = ProtocolUtils.readByteArray(buf, 128); this.verifyToken = ProtocolUtils.readByteArray(buf, 128);
@ -42,7 +43,7 @@ public class EncryptionResponse implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
ProtocolUtils.writeByteArray(buf, sharedSecret); ProtocolUtils.writeByteArray(buf, sharedSecret);
ProtocolUtils.writeByteArray(buf, verifyToken); ProtocolUtils.writeByteArray(buf, verifyToken);

Datei anzeigen

@ -2,11 +2,12 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class Handshake implements MinecraftPacket { public class HandshakePacket implements Packet {
private ProtocolVersion protocolVersion; private ProtocolVersion protocolVersion;
private String serverAddress = ""; private String serverAddress = "";
@ -56,7 +57,7 @@ public class Handshake implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion ignored) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion ignored) {
int realProtocolVersion = ProtocolUtils.readVarInt(buf); int realProtocolVersion = ProtocolUtils.readVarInt(buf);
this.protocolVersion = ProtocolVersion.getProtocolVersion(realProtocolVersion); this.protocolVersion = ProtocolVersion.getProtocolVersion(realProtocolVersion);
this.serverAddress = ProtocolUtils.readString(buf); this.serverAddress = ProtocolUtils.readString(buf);
@ -65,7 +66,7 @@ public class Handshake implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion ignored) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion ignored) {
ProtocolUtils.writeVarInt(buf, this.protocolVersion.getProtocol()); ProtocolUtils.writeVarInt(buf, this.protocolVersion.getProtocol());
ProtocolUtils.writeString(buf, this.serverAddress); ProtocolUtils.writeString(buf, this.serverAddress);
buf.writeShort(this.port); buf.writeShort(this.port);

Datei anzeigen

@ -5,24 +5,25 @@ import static com.velocitypowered.proxy.protocol.ProtocolUtils.writeString;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
public class HeaderAndFooter implements MinecraftPacket { public class HeaderAndFooterPacket implements Packet {
private static final String EMPTY_COMPONENT = "{\"translate\":\"\"}"; private static final String EMPTY_COMPONENT = "{\"translate\":\"\"}";
private static final HeaderAndFooter RESET = new HeaderAndFooter(); private static final HeaderAndFooterPacket RESET = new HeaderAndFooterPacket();
private final String header; private final String header;
private final String footer; private final String footer;
public HeaderAndFooter() { public HeaderAndFooterPacket() {
this(EMPTY_COMPONENT, EMPTY_COMPONENT); this(EMPTY_COMPONENT, EMPTY_COMPONENT);
} }
public HeaderAndFooter(String header, String footer) { public HeaderAndFooterPacket(String header, String footer) {
this.header = Preconditions.checkNotNull(header, "header"); this.header = Preconditions.checkNotNull(header, "header");
this.footer = Preconditions.checkNotNull(footer, "footer"); this.footer = Preconditions.checkNotNull(footer, "footer");
} }
@ -36,12 +37,12 @@ public class HeaderAndFooter implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
throw new UnsupportedOperationException("Decode is not implemented"); throw new UnsupportedOperationException("Decode is not implemented");
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
writeString(buf, header); writeString(buf, header);
writeString(buf, footer); writeString(buf, footer);
} }
@ -51,13 +52,13 @@ public class HeaderAndFooter implements MinecraftPacket {
return handler.handle(this); return handler.handle(this);
} }
public static HeaderAndFooter create(net.kyori.adventure.text.Component header, public static HeaderAndFooterPacket create(net.kyori.adventure.text.Component header,
net.kyori.adventure.text.Component footer, ProtocolVersion protocolVersion) { net.kyori.adventure.text.Component footer, ProtocolVersion protocolVersion) {
GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(protocolVersion); GsonComponentSerializer serializer = ProtocolUtils.getJsonChatSerializer(protocolVersion);
return new HeaderAndFooter(serializer.serialize(header), serializer.serialize(footer)); return new HeaderAndFooterPacket(serializer.serialize(header), serializer.serialize(footer));
} }
public static HeaderAndFooter reset() { public static HeaderAndFooterPacket reset() {
return RESET; return RESET;
} }
} }

Datei anzeigen

@ -6,14 +6,16 @@ import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.connection.registry.DimensionData; import com.velocitypowered.proxy.connection.registry.DimensionData;
import com.velocitypowered.proxy.connection.registry.DimensionInfo; import com.velocitypowered.proxy.connection.registry.DimensionInfo;
import com.velocitypowered.proxy.connection.registry.DimensionRegistry; import com.velocitypowered.proxy.connection.registry.DimensionRegistry;
import com.velocitypowered.proxy.protocol.*; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.kyori.adventure.nbt.BinaryTagTypes; import net.kyori.adventure.nbt.BinaryTagTypes;
import net.kyori.adventure.nbt.CompoundBinaryTag; import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.kyori.adventure.nbt.ListBinaryTag; import net.kyori.adventure.nbt.ListBinaryTag;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class JoinGame implements MinecraftPacket { public class JoinGamePacket implements Packet {
private int entityId; private int entityId;
private short gamemode; private short gamemode;
@ -163,7 +165,7 @@ public class JoinGame implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
this.entityId = buf.readInt(); this.entityId = buf.readInt();
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
this.isHardcore = buf.readBoolean(); this.isHardcore = buf.readBoolean();
@ -236,7 +238,7 @@ public class JoinGame implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
buf.writeInt(entityId); buf.writeInt(entityId);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
buf.writeBoolean(isHardcore); buf.writeBoolean(isHardcore);

Datei anzeigen

@ -2,11 +2,12 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class KeepAlive implements MinecraftPacket { public class KeepAlivePacket implements Packet {
private long randomId; private long randomId;
@ -26,7 +27,7 @@ public class KeepAlive implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_12_2) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_12_2) >= 0) {
randomId = buf.readLong(); randomId = buf.readLong();
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
@ -37,7 +38,7 @@ public class KeepAlive implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_12_2) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_12_2) >= 0) {
buf.writeLong(randomId); buf.writeLong(randomId);
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {

Datei anzeigen

@ -1,25 +0,0 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf;
public class LegacyHandshake implements MinecraftPacket {
@Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
throw new UnsupportedOperationException();
}
@Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) {
throw new UnsupportedOperationException();
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -2,23 +2,24 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder; import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class LoginPluginMessage extends DeferredByteBufHolder implements MinecraftPacket { public class LoginPluginMessagePacket extends DeferredByteBufHolder implements Packet {
private int id; private int id;
private @Nullable String channel; private @Nullable String channel;
public LoginPluginMessage() { public LoginPluginMessagePacket() {
super(null); super(null);
} }
public LoginPluginMessage(int id, @Nullable String channel, ByteBuf data) { public LoginPluginMessagePacket(int id, @Nullable String channel, ByteBuf data) {
super(data); super(data);
this.id = id; this.id = id;
this.channel = channel; this.channel = channel;
@ -45,7 +46,7 @@ public class LoginPluginMessage extends DeferredByteBufHolder implements Minecra
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
this.id = ProtocolUtils.readVarInt(buf); this.id = ProtocolUtils.readVarInt(buf);
this.channel = ProtocolUtils.readString(buf); this.channel = ProtocolUtils.readString(buf);
if (buf.isReadable()) { if (buf.isReadable()) {
@ -56,7 +57,7 @@ public class LoginPluginMessage extends DeferredByteBufHolder implements Minecra
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
ProtocolUtils.writeVarInt(buf, id); ProtocolUtils.writeVarInt(buf, id);
if (channel == null) { if (channel == null) {
throw new IllegalStateException("Channel is not specified!"); throw new IllegalStateException("Channel is not specified!");

Datei anzeigen

@ -2,23 +2,24 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder; import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
public class LoginPluginResponse extends DeferredByteBufHolder implements MinecraftPacket { public class LoginPluginResponsePacket extends DeferredByteBufHolder implements Packet {
private int id; private int id;
private boolean success; private boolean success;
public LoginPluginResponse() { public LoginPluginResponsePacket() {
super(Unpooled.EMPTY_BUFFER); super(Unpooled.EMPTY_BUFFER);
} }
public LoginPluginResponse(int id, boolean success, @MonotonicNonNull ByteBuf buf) { public LoginPluginResponsePacket(int id, boolean success, @MonotonicNonNull ByteBuf buf) {
super(buf); super(buf);
this.id = id; this.id = id;
this.success = success; this.success = success;
@ -50,7 +51,7 @@ public class LoginPluginResponse extends DeferredByteBufHolder implements Minecr
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
this.id = ProtocolUtils.readVarInt(buf); this.id = ProtocolUtils.readVarInt(buf);
this.success = buf.readBoolean(); this.success = buf.readBoolean();
if (buf.isReadable()) { if (buf.isReadable()) {
@ -61,7 +62,7 @@ public class LoginPluginResponse extends DeferredByteBufHolder implements Minecr
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
ProtocolUtils.writeVarInt(buf, id); ProtocolUtils.writeVarInt(buf, id);
buf.writeBoolean(success); buf.writeBoolean(success);
buf.writeBytes(content()); buf.writeBytes(content());

Datei anzeigen

@ -5,7 +5,8 @@ import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.player.TabListEntry; import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
@ -15,7 +16,7 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class PlayerListItem implements MinecraftPacket { public class PlayerListItemPacket implements Packet {
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;
@ -25,12 +26,12 @@ public class PlayerListItem implements MinecraftPacket {
private int action; private int action;
private final List<Item> items = new ArrayList<>(); private final List<Item> items = new ArrayList<>();
public PlayerListItem(int action, List<Item> items) { public PlayerListItemPacket(int action, List<Item> items) {
this.action = action; this.action = action;
this.items.addAll(items); this.items.addAll(items);
} }
public PlayerListItem() { public PlayerListItemPacket() {
} }
public int getAction() { public int getAction() {
@ -42,7 +43,7 @@ public class PlayerListItem implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
action = ProtocolUtils.readVarInt(buf); action = ProtocolUtils.readVarInt(buf);
int length = ProtocolUtils.readVarInt(buf); int length = ProtocolUtils.readVarInt(buf);
@ -92,7 +93,7 @@ public class PlayerListItem implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_8) >= 0) {
ProtocolUtils.writeVarInt(buf, action); ProtocolUtils.writeVarInt(buf, action);
ProtocolUtils.writeVarInt(buf, items.size()); ProtocolUtils.writeVarInt(buf, items.size());

Datei anzeigen

@ -4,22 +4,23 @@ import static com.velocitypowered.proxy.protocol.util.PluginMessageUtil.transfor
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder; import com.velocitypowered.proxy.protocol.util.DeferredByteBufHolder;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
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 PluginMessage extends DeferredByteBufHolder implements MinecraftPacket { public class PluginMessagePacket extends DeferredByteBufHolder implements Packet {
private @Nullable String channel; private @Nullable String channel;
public PluginMessage() { public PluginMessagePacket() {
super(null); super(null);
} }
public PluginMessage(String channel, public PluginMessagePacket(String channel,
@MonotonicNonNull ByteBuf backing) { @MonotonicNonNull ByteBuf backing) {
super(backing); super(backing);
this.channel = channel; this.channel = channel;
@ -45,7 +46,7 @@ public class PluginMessage extends DeferredByteBufHolder implements MinecraftPac
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
this.channel = ProtocolUtils.readString(buf); this.channel = ProtocolUtils.readString(buf);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_13) >= 0) {
this.channel = transformLegacyToModernChannel(this.channel); this.channel = transformLegacyToModernChannel(this.channel);
@ -59,7 +60,7 @@ public class PluginMessage extends DeferredByteBufHolder implements MinecraftPac
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (channel == null) { if (channel == null) {
throw new IllegalStateException("Channel is not specified."); throw new IllegalStateException("Channel is not specified.");
} }
@ -82,42 +83,42 @@ public class PluginMessage extends DeferredByteBufHolder implements MinecraftPac
} }
@Override @Override
public PluginMessage copy() { public PluginMessagePacket copy() {
return (PluginMessage) super.copy(); return (PluginMessagePacket) super.copy();
} }
@Override @Override
public PluginMessage duplicate() { public PluginMessagePacket duplicate() {
return (PluginMessage) super.duplicate(); return (PluginMessagePacket) super.duplicate();
} }
@Override @Override
public PluginMessage retainedDuplicate() { public PluginMessagePacket retainedDuplicate() {
return (PluginMessage) super.retainedDuplicate(); return (PluginMessagePacket) super.retainedDuplicate();
} }
@Override @Override
public PluginMessage replace(ByteBuf content) { public PluginMessagePacket replace(ByteBuf content) {
return (PluginMessage) super.replace(content); return (PluginMessagePacket) super.replace(content);
} }
@Override @Override
public PluginMessage retain() { public PluginMessagePacket retain() {
return (PluginMessage) super.retain(); return (PluginMessagePacket) super.retain();
} }
@Override @Override
public PluginMessage retain(int increment) { public PluginMessagePacket retain(int increment) {
return (PluginMessage) super.retain(increment); return (PluginMessagePacket) super.retain(increment);
} }
@Override @Override
public PluginMessage touch() { public PluginMessagePacket touch() {
return (PluginMessage) super.touch(); return (PluginMessagePacket) super.touch();
} }
@Override @Override
public PluginMessage touch(Object hint) { public PluginMessagePacket touch(Object hint) {
return (PluginMessage) super.touch(hint); return (PluginMessagePacket) super.touch(hint);
} }
} }

Datei anzeigen

@ -2,14 +2,14 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.ProtocolUtils.Direction; import com.velocitypowered.proxy.protocol.ProtocolDirection;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
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 ResourcePackRequest implements MinecraftPacket { public class ResourcePackRequestPacket implements Packet {
private @MonotonicNonNull String url; private @MonotonicNonNull String url;
private @MonotonicNonNull String hash; private @MonotonicNonNull String hash;
@ -31,13 +31,13 @@ public class ResourcePackRequest implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) {
this.url = ProtocolUtils.readString(buf); this.url = ProtocolUtils.readString(buf);
this.hash = ProtocolUtils.readString(buf); this.hash = ProtocolUtils.readString(buf);
} }
@Override @Override
public void encode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) {
if (url == null || hash == null) { if (url == null || hash == null) {
throw new IllegalStateException("Packet not fully filled in yet!"); throw new IllegalStateException("Packet not fully filled in yet!");
} }

Datei anzeigen

@ -3,13 +3,13 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent.Status; import com.velocitypowered.api.event.player.PlayerResourcePackStatusEvent.Status;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.ProtocolUtils.Direction; import com.velocitypowered.proxy.protocol.ProtocolDirection;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
public class ResourcePackResponse implements MinecraftPacket { public class ResourcePackResponsePacket implements Packet {
private String hash = ""; private String hash = "";
private @MonotonicNonNull Status status; private @MonotonicNonNull Status status;
@ -22,7 +22,7 @@ public class ResourcePackResponse implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) {
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_4) <= 0) { if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_4) <= 0) {
this.hash = ProtocolUtils.readString(buf); this.hash = ProtocolUtils.readString(buf);
} }
@ -30,7 +30,7 @@ public class ResourcePackResponse implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, Direction direction, ProtocolVersion protocolVersion) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion protocolVersion) {
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_4) <= 0) { if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_9_4) <= 0) {
ProtocolUtils.writeString(buf, hash); ProtocolUtils.writeString(buf, hash);
} }

Datei anzeigen

@ -4,12 +4,13 @@ import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.connection.registry.DimensionData; import com.velocitypowered.proxy.connection.registry.DimensionData;
import com.velocitypowered.proxy.connection.registry.DimensionInfo; import com.velocitypowered.proxy.connection.registry.DimensionInfo;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.kyori.adventure.nbt.CompoundBinaryTag; import net.kyori.adventure.nbt.CompoundBinaryTag;
public class Respawn implements MinecraftPacket { public class RespawnPacket implements Packet {
private int dimension; private int dimension;
private long partialHashedSeed; private long partialHashedSeed;
@ -21,10 +22,10 @@ public class Respawn implements MinecraftPacket {
private short previousGamemode; // 1.16+ private short previousGamemode; // 1.16+
private DimensionData currentDimensionData; // 1.16.2+ private DimensionData currentDimensionData; // 1.16.2+
public Respawn() { public RespawnPacket() {
} }
public Respawn(int dimension, long partialHashedSeed, short difficulty, short gamemode, public RespawnPacket(int dimension, long partialHashedSeed, short difficulty, short gamemode,
String levelType, boolean shouldKeepPlayerData, DimensionInfo dimensionInfo, String levelType, boolean shouldKeepPlayerData, DimensionInfo dimensionInfo,
short previousGamemode, DimensionData currentDimensionData) { short previousGamemode, DimensionData currentDimensionData) {
this.dimension = dimension; this.dimension = dimension;
@ -111,7 +112,7 @@ public class Respawn implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
String dimensionIdentifier = null; String dimensionIdentifier = null;
String levelName = null; String levelName = null;
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
@ -146,7 +147,7 @@ public class Respawn implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16_2) >= 0) {
ProtocolUtils.writeCompoundTag(buf, currentDimensionData.serializeDimensionDetails()); ProtocolUtils.writeCompoundTag(buf, currentDimensionData.serializeDimensionDetails());

Datei anzeigen

@ -3,22 +3,23 @@ package com.velocitypowered.proxy.protocol.packet;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
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 org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ServerLogin implements MinecraftPacket { public class ServerLoginPacket implements Packet {
private static final QuietDecoderException EMPTY_USERNAME = new QuietDecoderException("Empty username!"); private static final QuietDecoderException EMPTY_USERNAME = new QuietDecoderException("Empty username!");
private @Nullable String username; private @Nullable String username;
public ServerLogin() { public ServerLoginPacket() {
} }
public ServerLogin(String username) { public ServerLoginPacket(String username) {
this.username = Preconditions.checkNotNull(username, "username"); this.username = Preconditions.checkNotNull(username, "username");
} }
@ -37,7 +38,7 @@ public class ServerLogin implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
username = ProtocolUtils.readString(buf, 16); username = ProtocolUtils.readString(buf, 16);
if (username.isEmpty()) { if (username.isEmpty()) {
throw EMPTY_USERNAME; throw EMPTY_USERNAME;
@ -45,7 +46,7 @@ public class ServerLogin implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (username == null) { if (username == null) {
throw new IllegalStateException("No username found!"); throw new IllegalStateException("No username found!");
} }

Datei anzeigen

@ -3,13 +3,14 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.util.UuidUtils; import com.velocitypowered.api.util.UuidUtils;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.UUID; import java.util.UUID;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class ServerLoginSuccess implements MinecraftPacket { public class ServerLoginSuccessPacket implements Packet {
private @Nullable UUID uuid; private @Nullable UUID uuid;
private @Nullable String username; private @Nullable String username;
@ -45,7 +46,7 @@ public class ServerLoginSuccess implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
uuid = ProtocolUtils.readUuidIntArray(buf); uuid = ProtocolUtils.readUuidIntArray(buf);
} else if (version.compareTo(ProtocolVersion.MINECRAFT_1_7_6) >= 0) { } else if (version.compareTo(ProtocolVersion.MINECRAFT_1_7_6) >= 0) {
@ -57,7 +58,7 @@ public class ServerLoginSuccess implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (uuid == null) { if (uuid == null) {
throw new IllegalStateException("No UUID specified!"); throw new IllegalStateException("No UUID specified!");
} }

Datei anzeigen

@ -2,18 +2,19 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class SetCompression implements MinecraftPacket { public class SetCompressionPacket implements Packet {
private int threshold; private int threshold;
public SetCompression() { public SetCompressionPacket() {
} }
public SetCompression(int threshold) { public SetCompressionPacket(int threshold) {
this.threshold = threshold; this.threshold = threshold;
} }
@ -33,12 +34,12 @@ public class SetCompression implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
this.threshold = ProtocolUtils.readVarInt(buf); this.threshold = ProtocolUtils.readVarInt(buf);
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
ProtocolUtils.writeVarInt(buf, threshold); ProtocolUtils.writeVarInt(buf, threshold);
} }

Datei anzeigen

@ -2,21 +2,21 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolDirection;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class StatusPing implements MinecraftPacket { public class StatusPingPacket implements Packet {
private long randomId; private long randomId;
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
randomId = buf.readLong(); randomId = buf.readLong();
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
buf.writeLong(randomId); buf.writeLong(randomId);
} }

Datei anzeigen

@ -2,25 +2,25 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolDirection;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class StatusRequest implements MinecraftPacket { public class StatusRequestPacket implements Packet {
public static final StatusRequest INSTANCE = new StatusRequest(); public static final StatusRequestPacket INSTANCE = new StatusRequestPacket();
private StatusRequest() { private StatusRequestPacket() {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
// There is no additional data to decode. // There is no additional data to decode.
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
// There is no data to decode. // There is no data to decode.
} }

Datei anzeigen

@ -2,19 +2,20 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class StatusResponse implements MinecraftPacket { public class StatusResponsePacket implements Packet {
private @Nullable CharSequence status; private @Nullable CharSequence status;
public StatusResponse() { public StatusResponsePacket() {
} }
public StatusResponse(CharSequence status) { public StatusResponsePacket(CharSequence status) {
this.status = status; this.status = status;
} }
@ -33,12 +34,12 @@ public class StatusResponse implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
status = ProtocolUtils.readString(buf, Short.MAX_VALUE); status = ProtocolUtils.readString(buf, Short.MAX_VALUE);
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (status == null) { if (status == null) {
throw new IllegalStateException("Status is not specified"); throw new IllegalStateException("Status is not specified");
} }

Datei anzeigen

@ -7,12 +7,13 @@ import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_9;
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.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class TabCompleteRequest implements MinecraftPacket { public class TabCompleteRequestPacket implements Packet {
private static final int VANILLA_MAX_TAB_COMPLETE_LEN = 2048; private static final int VANILLA_MAX_TAB_COMPLETE_LEN = 2048;
@ -77,7 +78,7 @@ public class TabCompleteRequest implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (version.compareTo(MINECRAFT_1_13) >= 0) { if (version.compareTo(MINECRAFT_1_13) >= 0) {
this.transactionId = ProtocolUtils.readVarInt(buf); this.transactionId = ProtocolUtils.readVarInt(buf);
this.command = ProtocolUtils.readString(buf, VANILLA_MAX_TAB_COMPLETE_LEN); this.command = ProtocolUtils.readString(buf, VANILLA_MAX_TAB_COMPLETE_LEN);
@ -96,7 +97,7 @@ public class TabCompleteRequest implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (command == null) { if (command == null) {
throw new IllegalStateException("Command is not specified"); throw new IllegalStateException("Command is not specified");
} }

Datei anzeigen

@ -5,7 +5,8 @@ import static com.velocitypowered.api.network.ProtocolVersion.MINECRAFT_1_13;
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.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.ArrayList; import java.util.ArrayList;
@ -13,7 +14,7 @@ import java.util.List;
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 TabCompleteResponse implements MinecraftPacket { public class TabCompleteResponsePacket implements Packet {
private int transactionId; private int transactionId;
private int start; private int start;
@ -59,7 +60,7 @@ public class TabCompleteResponse implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (version.compareTo(MINECRAFT_1_13) >= 0) { if (version.compareTo(MINECRAFT_1_13) >= 0) {
this.transactionId = ProtocolUtils.readVarInt(buf); this.transactionId = ProtocolUtils.readVarInt(buf);
this.start = ProtocolUtils.readVarInt(buf); this.start = ProtocolUtils.readVarInt(buf);
@ -80,7 +81,7 @@ public class TabCompleteResponse implements MinecraftPacket {
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
if (version.compareTo(MINECRAFT_1_13) >= 0) { if (version.compareTo(MINECRAFT_1_13) >= 0) {
ProtocolUtils.writeVarInt(buf, this.transactionId); ProtocolUtils.writeVarInt(buf, this.transactionId);
ProtocolUtils.writeVarInt(buf, this.start); ProtocolUtils.writeVarInt(buf, this.start);

Datei anzeigen

@ -2,12 +2,13 @@ package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class TitlePacket implements MinecraftPacket { public class TitlePacket implements Packet {
public static final int SET_TITLE = 0; public static final int SET_TITLE = 0;
public static final int SET_SUBTITLE = 1; public static final int SET_SUBTITLE = 1;
@ -26,12 +27,12 @@ public class TitlePacket implements MinecraftPacket {
private int fadeOut; private int fadeOut;
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
throw new UnsupportedOperationException(); // encode only throw new UnsupportedOperationException(); // encode only
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
ProtocolUtils.writeVarInt(buf, action); ProtocolUtils.writeVarInt(buf, action);
if (version.compareTo(ProtocolVersion.MINECRAFT_1_11) >= 0) { if (version.compareTo(ProtocolVersion.MINECRAFT_1_11) >= 0) {
// 1.11+ shifted the action enum by 1 to handle the action bar // 1.11+ shifted the action enum by 1 to handle the action bar

Datei anzeigen

@ -1,4 +1,4 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet.legacy;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.proxy.server.ServerPing; import com.velocitypowered.api.proxy.server.ServerPing;
@ -8,7 +8,7 @@ import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer; import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
public class LegacyDisconnect { public class LegacyDisconnectPacket {
private static final ServerPing.Players FAKE_PLAYERS = new ServerPing.Players(0, 0, private static final ServerPing.Players FAKE_PLAYERS = new ServerPing.Players(0, 0,
ImmutableList.of()); ImmutableList.of());
@ -17,7 +17,7 @@ public class LegacyDisconnect {
private final String reason; private final String reason;
private LegacyDisconnect(String reason) { private LegacyDisconnectPacket(String reason) {
this.reason = reason; this.reason = reason;
} }
@ -27,7 +27,7 @@ public class LegacyDisconnect {
* @param version the requesting clients' version * @param version the requesting clients' version
* @return the disconnect packet * @return the disconnect packet
*/ */
public static LegacyDisconnect fromServerPing(ServerPing response, public static LegacyDisconnectPacket fromServerPing(ServerPing response,
LegacyMinecraftPingVersion version) { LegacyMinecraftPingVersion version) {
Players players = response.getPlayers().orElse(FAKE_PLAYERS); Players players = response.getPlayers().orElse(FAKE_PLAYERS);
@ -36,7 +36,7 @@ public class LegacyDisconnect {
// Minecraft 1.3 and below use the section symbol as a delimiter. Accordingly, we must // Minecraft 1.3 and below use the section symbol as a delimiter. Accordingly, we must
// remove all section symbols, along with fetching just the first line of an (unformatted) // remove all section symbols, along with fetching just the first line of an (unformatted)
// MOTD. // MOTD.
return new LegacyDisconnect(String.join(LEGACY_COLOR_CODE, return new LegacyDisconnectPacket(String.join(LEGACY_COLOR_CODE,
cleanSectionSymbol(getFirstLine(PlainComponentSerializer.plain().serialize( cleanSectionSymbol(getFirstLine(PlainComponentSerializer.plain().serialize(
response.getDescription()))), response.getDescription()))),
Integer.toString(players.getOnline()), Integer.toString(players.getOnline()),
@ -44,7 +44,7 @@ public class LegacyDisconnect {
case MINECRAFT_1_4: case MINECRAFT_1_4:
case MINECRAFT_1_6: case MINECRAFT_1_6:
// Minecraft 1.4-1.6 provide support for more fields, and additionally support color codes. // Minecraft 1.4-1.6 provide support for more fields, and additionally support color codes.
return new LegacyDisconnect(String.join("\0", return new LegacyDisconnectPacket(String.join("\0",
LEGACY_COLOR_CODE + "1", LEGACY_COLOR_CODE + "1",
Integer.toString(response.getVersion().getProtocol()), Integer.toString(response.getVersion().getProtocol()),
response.getVersion().getName(), response.getVersion().getName(),
@ -72,10 +72,10 @@ public class LegacyDisconnect {
* @param component the component to convert * @param component the component to convert
* @return the disconnect packet * @return the disconnect packet
*/ */
public static LegacyDisconnect from(TextComponent component) { public static LegacyDisconnectPacket from(TextComponent component) {
// We intentionally use the legacy serializers, because the old clients can't understand JSON. // We intentionally use the legacy serializers, because the old clients can't understand JSON.
String serialized = LegacyComponentSerializer.legacySection().serialize(component); String serialized = LegacyComponentSerializer.legacySection().serialize(component);
return new LegacyDisconnect(serialized); return new LegacyDisconnectPacket(serialized);
} }
public String getReason() { public String getReason() {

Datei anzeigen

@ -0,0 +1,25 @@
package com.velocitypowered.proxy.protocol.packet.legacy;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolDirection;
import io.netty.buffer.ByteBuf;
public class LegacyHandshakePacket implements Packet {
@Override
public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
throw new UnsupportedOperationException();
}
@Override
public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
throw new UnsupportedOperationException();
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,25 +1,25 @@
package com.velocitypowered.proxy.protocol.packet; package com.velocitypowered.proxy.protocol.packet.legacy;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler; import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket; import com.velocitypowered.proxy.protocol.Packet;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.packet.legacyping.LegacyMinecraftPingVersion; import com.velocitypowered.proxy.protocol.packet.legacyping.LegacyMinecraftPingVersion;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
public class LegacyPing implements MinecraftPacket { public class LegacyPingPacket implements Packet {
private final LegacyMinecraftPingVersion version; private final LegacyMinecraftPingVersion version;
private final @Nullable InetSocketAddress vhost; private final @Nullable InetSocketAddress vhost;
public LegacyPing(LegacyMinecraftPingVersion version) { public LegacyPingPacket(LegacyMinecraftPingVersion version) {
this.version = version; this.version = version;
this.vhost = null; this.vhost = null;
} }
public LegacyPing(LegacyMinecraftPingVersion version, InetSocketAddress vhost) { public LegacyPingPacket(LegacyMinecraftPingVersion version, InetSocketAddress vhost) {
this.version = version; this.version = version;
this.vhost = vhost; this.vhost = vhost;
} }
@ -33,12 +33,12 @@ public class LegacyPing implements MinecraftPacket {
} }
@Override @Override
public void decode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void decode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override @Override
public void encode(ByteBuf buf, ProtocolUtils.Direction direction, ProtocolVersion version) { public void encode(ByteBuf buf, ProtocolDirection direction, ProtocolVersion version) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

Datei anzeigen

@ -7,7 +7,7 @@ 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.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.PluginMessage; import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
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;
@ -34,7 +34,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(PluginMessage message) { public static boolean isMcBrand(PluginMessagePacket 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);
@ -45,7 +45,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(PluginMessage message) { public static boolean isRegister(PluginMessagePacket 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);
@ -56,7 +56,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(PluginMessage message) { public static boolean isUnregister(PluginMessagePacket 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);
@ -67,7 +67,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(PluginMessage message) { public static boolean isLegacyRegister(PluginMessagePacket message) {
checkNotNull(message, "message"); checkNotNull(message, "message");
return message.getChannel().equals(REGISTER_CHANNEL_LEGACY); return message.getChannel().equals(REGISTER_CHANNEL_LEGACY);
} }
@ -78,7 +78,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(PluginMessage message) { public static boolean isLegacyUnregister(PluginMessagePacket message) {
checkNotNull(message, "message"); checkNotNull(message, "message");
return message.getChannel().equals(UNREGISTER_CHANNEL_LEGACY); return message.getChannel().equals(UNREGISTER_CHANNEL_LEGACY);
} }
@ -88,7 +88,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(PluginMessage message) { public static List<String> getChannels(PluginMessagePacket 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());
@ -107,7 +107,7 @@ 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 PluginMessage constructChannelsPacket(ProtocolVersion protocolVersion, public static PluginMessagePacket constructChannelsPacket(ProtocolVersion protocolVersion,
Collection<String> channels) { Collection<String> channels) {
checkNotNull(channels, "channels"); checkNotNull(channels, "channels");
checkArgument(!channels.isEmpty(), "no channels specified"); checkArgument(!channels.isEmpty(), "no channels specified");
@ -115,7 +115,7 @@ public final class PluginMessageUtil {
? 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 PluginMessage(channelName, contents); return new PluginMessagePacket(channelName, contents);
} }
/** /**
@ -124,7 +124,8 @@ 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 PluginMessage rewriteMinecraftBrand(PluginMessage message, ProxyVersion version, public static PluginMessagePacket rewriteMinecraftBrand(PluginMessagePacket message,
ProxyVersion version,
ProtocolVersion protocolVersion) { ProtocolVersion protocolVersion) {
checkNotNull(message, "message"); checkNotNull(message, "message");
checkNotNull(version, "version"); checkNotNull(version, "version");
@ -140,7 +141,7 @@ public final class PluginMessageUtil {
rewrittenBuf.writeCharSequence(rewrittenBrand, StandardCharsets.UTF_8); rewrittenBuf.writeCharSequence(rewrittenBrand, StandardCharsets.UTF_8);
} }
return new PluginMessage(message.getChannel(), rewrittenBuf); return new PluginMessagePacket(message.getChannel(), rewrittenBuf);
} }
private static String readBrandMessage(ByteBuf content) { private static String readBrandMessage(ByteBuf content) {

Datei anzeigen

@ -7,9 +7,9 @@ import com.velocitypowered.proxy.VelocityServer;
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.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.Handshake; import com.velocitypowered.proxy.protocol.packet.HandshakePacket;
import com.velocitypowered.proxy.protocol.packet.StatusRequest; import com.velocitypowered.proxy.protocol.packet.StatusRequestPacket;
import com.velocitypowered.proxy.protocol.packet.StatusResponse; import com.velocitypowered.proxy.protocol.packet.StatusResponsePacket;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
@ -33,7 +33,7 @@ public class PingSessionHandler implements MinecraftSessionHandler {
@Override @Override
public void activated() { public void activated() {
Handshake handshake = new Handshake(); HandshakePacket handshake = new HandshakePacket();
handshake.setNextStatus(StateRegistry.STATUS_ID); handshake.setNextStatus(StateRegistry.STATUS_ID);
SocketAddress address = server.getServerInfo().getAddress(); SocketAddress address = server.getServerInfo().getAddress();
@ -49,13 +49,13 @@ public class PingSessionHandler implements MinecraftSessionHandler {
connection.delayedWrite(handshake); connection.delayedWrite(handshake);
connection.setState(StateRegistry.STATUS); connection.setState(StateRegistry.STATUS);
connection.delayedWrite(StatusRequest.INSTANCE); connection.delayedWrite(StatusRequestPacket.INSTANCE);
connection.flush(); connection.flush();
} }
@Override @Override
public boolean handle(StatusResponse packet) { public boolean handle(StatusResponsePacket packet) {
// All good! // All good!
completed = true; completed = true;
connection.close(true); connection.close(true);

Datei anzeigen

@ -19,7 +19,7 @@ import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
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.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolDirection;
import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftDecoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder; import com.velocitypowered.proxy.protocol.netty.MinecraftEncoder;
import com.velocitypowered.proxy.protocol.netty.MinecraftVarintFrameDecoder; import com.velocitypowered.proxy.protocol.netty.MinecraftVarintFrameDecoder;
@ -90,9 +90,9 @@ public class VelocityRegisteredServer implements RegisteredServer, ForwardingAud
.addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder()) .addLast(FRAME_DECODER, new MinecraftVarintFrameDecoder())
.addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE) .addLast(FRAME_ENCODER, MinecraftVarintLengthEncoder.INSTANCE)
.addLast(MINECRAFT_DECODER, .addLast(MINECRAFT_DECODER,
new MinecraftDecoder(ProtocolUtils.Direction.CLIENTBOUND)) new MinecraftDecoder(ProtocolDirection.CLIENTBOUND))
.addLast(MINECRAFT_ENCODER, .addLast(MINECRAFT_ENCODER,
new MinecraftEncoder(ProtocolUtils.Direction.SERVERBOUND)); new MinecraftEncoder(ProtocolDirection.SERVERBOUND));
ch.pipeline().addLast(HANDLER, new MinecraftConnection(ch, server)); ch.pipeline().addLast(HANDLER, new MinecraftConnection(ch, server));
} }

Datei anzeigen

@ -5,8 +5,8 @@ import com.velocitypowered.api.proxy.player.TabList;
import com.velocitypowered.api.proxy.player.TabListEntry; import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.protocol.packet.HeaderAndFooter; import com.velocitypowered.proxy.protocol.packet.HeaderAndFooterPacket;
import com.velocitypowered.proxy.protocol.packet.PlayerListItem; import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -31,12 +31,12 @@ public class VelocityTabList implements TabList {
net.kyori.adventure.text.Component footer) { net.kyori.adventure.text.Component footer) {
Preconditions.checkNotNull(header, "header"); Preconditions.checkNotNull(header, "header");
Preconditions.checkNotNull(footer, "footer"); Preconditions.checkNotNull(footer, "footer");
connection.write(HeaderAndFooter.create(header, footer, connection.getProtocolVersion())); connection.write(HeaderAndFooterPacket.create(header, footer, connection.getProtocolVersion()));
} }
@Override @Override
public void clearHeaderAndFooter() { public void clearHeaderAndFooter() {
connection.write(HeaderAndFooter.reset()); connection.write(HeaderAndFooterPacket.reset());
} }
@Override @Override
@ -49,9 +49,9 @@ public class VelocityTabList implements TabList {
Preconditions.checkArgument(entry instanceof VelocityTabListEntry, Preconditions.checkArgument(entry instanceof VelocityTabListEntry,
"Not a Velocity tab list entry"); "Not a Velocity tab list entry");
PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry); PlayerListItemPacket.Item packetItem = PlayerListItemPacket.Item.from(entry);
connection.write( connection.write(new PlayerListItemPacket(PlayerListItemPacket.ADD_PLAYER,
new PlayerListItem(PlayerListItem.ADD_PLAYER, Collections.singletonList(packetItem))); Collections.singletonList(packetItem)));
entries.put(entry.getProfile().getId(), (VelocityTabListEntry) entry); entries.put(entry.getProfile().getId(), (VelocityTabListEntry) entry);
} }
@ -61,9 +61,9 @@ public class VelocityTabList implements TabList {
TabListEntry entry = entries.remove(uuid); TabListEntry entry = entries.remove(uuid);
if (entry != null) { if (entry != null) {
PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry); PlayerListItemPacket.Item packetItem = PlayerListItemPacket.Item.from(entry);
connection.write( connection.write(new PlayerListItemPacket(PlayerListItemPacket.REMOVE_PLAYER,
new PlayerListItem(PlayerListItem.REMOVE_PLAYER, Collections.singletonList(packetItem))); Collections.singletonList(packetItem)));
} }
return Optional.ofNullable(entry); return Optional.ofNullable(entry);
@ -85,12 +85,12 @@ public class VelocityTabList implements TabList {
if (listEntries.isEmpty()) { if (listEntries.isEmpty()) {
return; return;
} }
List<PlayerListItem.Item> items = new ArrayList<>(listEntries.size()); List<PlayerListItemPacket.Item> items = new ArrayList<>(listEntries.size());
for (TabListEntry value : listEntries) { for (TabListEntry value : listEntries) {
items.add(PlayerListItem.Item.from(value)); items.add(PlayerListItemPacket.Item.from(value));
} }
entries.clear(); entries.clear();
connection.delayedWrite(new PlayerListItem(PlayerListItem.REMOVE_PLAYER, items)); connection.delayedWrite(new PlayerListItemPacket(PlayerListItemPacket.REMOVE_PLAYER, items));
} }
@Override @Override
@ -109,19 +109,19 @@ public class VelocityTabList implements TabList {
* *
* @param packet the packet to process * @param packet the packet to process
*/ */
public void processBackendPacket(PlayerListItem packet) { public void processBackendPacket(PlayerListItemPacket packet) {
// Packets are already forwarded on, so no need to do that here // Packets are already forwarded on, so no need to do that here
for (PlayerListItem.Item item : packet.getItems()) { for (PlayerListItemPacket.Item item : packet.getItems()) {
UUID uuid = item.getUuid(); UUID uuid = item.getUuid();
assert uuid != null : "1.7 tab list entry given to modern tab list handler!"; assert uuid != null : "1.7 tab list entry given to modern tab list handler!";
if (packet.getAction() != PlayerListItem.ADD_PLAYER && !entries.containsKey(uuid)) { if (packet.getAction() != PlayerListItemPacket.ADD_PLAYER && !entries.containsKey(uuid)) {
// Sometimes UPDATE_GAMEMODE is sent before ADD_PLAYER so don't want to warn here // Sometimes UPDATE_GAMEMODE is sent before ADD_PLAYER so don't want to warn here
continue; continue;
} }
switch (packet.getAction()) { switch (packet.getAction()) {
case PlayerListItem.ADD_PLAYER: { case PlayerListItemPacket.ADD_PLAYER: {
// ensure that name and properties are available // ensure that name and properties are available
String name = item.getName(); String name = item.getName();
List<GameProfile.Property> properties = item.getProperties(); List<GameProfile.Property> properties = item.getProperties();
@ -137,24 +137,24 @@ public class VelocityTabList implements TabList {
.build()); .build());
break; break;
} }
case PlayerListItem.REMOVE_PLAYER: case PlayerListItemPacket.REMOVE_PLAYER:
entries.remove(uuid); entries.remove(uuid);
break; break;
case PlayerListItem.UPDATE_DISPLAY_NAME: { case PlayerListItemPacket.UPDATE_DISPLAY_NAME: {
VelocityTabListEntry entry = entries.get(uuid); VelocityTabListEntry entry = entries.get(uuid);
if (entry != null) { if (entry != null) {
entry.setDisplayNameInternal(item.getDisplayName()); entry.setDisplayNameInternal(item.getDisplayName());
} }
break; break;
} }
case PlayerListItem.UPDATE_LATENCY: { case PlayerListItemPacket.UPDATE_LATENCY: {
VelocityTabListEntry entry = entries.get(uuid); VelocityTabListEntry entry = entries.get(uuid);
if (entry != null) { if (entry != null) {
entry.setLatencyInternal(item.getLatency()); entry.setLatencyInternal(item.getLatency());
} }
break; break;
} }
case PlayerListItem.UPDATE_GAMEMODE: { case PlayerListItemPacket.UPDATE_GAMEMODE: {
VelocityTabListEntry entry = entries.get(uuid); VelocityTabListEntry entry = entries.get(uuid);
if (entry != null) { if (entry != null) {
entry.setGameModeInternal(item.getGameMode()); entry.setGameModeInternal(item.getGameMode());
@ -170,8 +170,8 @@ public class VelocityTabList implements TabList {
void updateEntry(int action, TabListEntry entry) { void updateEntry(int action, TabListEntry entry) {
if (entries.containsKey(entry.getProfile().getId())) { if (entries.containsKey(entry.getProfile().getId())) {
PlayerListItem.Item packetItem = PlayerListItem.Item.from(entry); PlayerListItemPacket.Item packetItem = PlayerListItemPacket.Item.from(entry);
connection.write(new PlayerListItem(action, Collections.singletonList(packetItem))); connection.write(new PlayerListItemPacket(action, Collections.singletonList(packetItem)));
} }
} }
} }

Datei anzeigen

@ -3,7 +3,7 @@ package com.velocitypowered.proxy.tablist;
import com.velocitypowered.api.proxy.player.TabList; import com.velocitypowered.api.proxy.player.TabList;
import com.velocitypowered.api.proxy.player.TabListEntry; import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.proxy.protocol.packet.PlayerListItem; import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket;
import java.util.Optional; import java.util.Optional;
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;
@ -43,7 +43,7 @@ public class VelocityTabListEntry implements TabListEntry {
@Override @Override
public TabListEntry setDisplayName(net.kyori.adventure.text.@Nullable Component displayName) { public TabListEntry setDisplayName(net.kyori.adventure.text.@Nullable Component displayName) {
this.displayName = displayName; this.displayName = displayName;
tabList.updateEntry(PlayerListItem.UPDATE_DISPLAY_NAME, this); tabList.updateEntry(PlayerListItemPacket.UPDATE_DISPLAY_NAME, this);
return this; return this;
} }
@ -59,7 +59,7 @@ public class VelocityTabListEntry implements TabListEntry {
@Override @Override
public TabListEntry setLatency(int latency) { public TabListEntry setLatency(int latency) {
this.latency = latency; this.latency = latency;
tabList.updateEntry(PlayerListItem.UPDATE_LATENCY, this); tabList.updateEntry(PlayerListItemPacket.UPDATE_LATENCY, this);
return this; return this;
} }
@ -75,7 +75,7 @@ public class VelocityTabListEntry implements TabListEntry {
@Override @Override
public TabListEntry setGameMode(int gameMode) { public TabListEntry setGameMode(int gameMode) {
this.gameMode = gameMode; this.gameMode = gameMode;
tabList.updateEntry(PlayerListItem.UPDATE_GAMEMODE, this); tabList.updateEntry(PlayerListItemPacket.UPDATE_GAMEMODE, this);
return this; return this;
} }

Datei anzeigen

@ -4,8 +4,8 @@ import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.proxy.player.TabListEntry; import com.velocitypowered.api.proxy.player.TabListEntry;
import com.velocitypowered.api.util.GameProfile; import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.proxy.connection.MinecraftConnection; import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.protocol.packet.PlayerListItem; import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket;
import com.velocitypowered.proxy.protocol.packet.PlayerListItem.Item; import com.velocitypowered.proxy.protocol.packet.PlayerListItemPacket.Item;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
@ -46,19 +46,19 @@ public class VelocityTabListLegacy extends VelocityTabList {
@Override @Override
public void clearAll() { public void clearAll() {
for (TabListEntry value : entries.values()) { for (TabListEntry value : entries.values()) {
connection.delayedWrite(new PlayerListItem(PlayerListItem.REMOVE_PLAYER, connection.delayedWrite(new PlayerListItemPacket(PlayerListItemPacket.REMOVE_PLAYER,
Collections.singletonList(PlayerListItem.Item.from(value)))); Collections.singletonList(PlayerListItemPacket.Item.from(value))));
} }
entries.clear(); entries.clear();
nameMapping.clear(); nameMapping.clear();
} }
@Override @Override
public void processBackendPacket(PlayerListItem packet) { public void processBackendPacket(PlayerListItemPacket packet) {
Item item = packet.getItems().get(0); // Only one item per packet in 1.7 Item item = packet.getItems().get(0); // Only one item per packet in 1.7
switch (packet.getAction()) { switch (packet.getAction()) {
case PlayerListItem.ADD_PLAYER: case PlayerListItemPacket.ADD_PLAYER:
if (nameMapping.containsKey(item.getName())) { // ADD_PLAYER also used for updating ping if (nameMapping.containsKey(item.getName())) { // ADD_PLAYER also used for updating ping
VelocityTabListEntry entry = entries.get(nameMapping.get(item.getName())); VelocityTabListEntry entry = entries.get(nameMapping.get(item.getName()));
if (entry != null) { if (entry != null) {
@ -74,7 +74,7 @@ public class VelocityTabListLegacy extends VelocityTabList {
.build()); .build());
} }
break; break;
case PlayerListItem.REMOVE_PLAYER: case PlayerListItemPacket.REMOVE_PLAYER:
UUID removedUuid = nameMapping.remove(item.getName()); UUID removedUuid = nameMapping.remove(item.getName());
if (removedUuid != null) { if (removedUuid != null) {
entries.remove(removedUuid); entries.remove(removedUuid);
@ -91,11 +91,12 @@ public class VelocityTabListLegacy extends VelocityTabList {
void updateEntry(int action, TabListEntry entry) { void updateEntry(int action, TabListEntry entry) {
if (entries.containsKey(entry.getProfile().getId())) { if (entries.containsKey(entry.getProfile().getId())) {
switch (action) { switch (action) {
case PlayerListItem.UPDATE_LATENCY: case PlayerListItemPacket.UPDATE_LATENCY:
case PlayerListItem.UPDATE_DISPLAY_NAME: // Add here because we removed beforehand case PlayerListItemPacket.UPDATE_DISPLAY_NAME: // Add here because we removed beforehand
connection connection
.write(new PlayerListItem(PlayerListItem.ADD_PLAYER, // ADD_PLAYER also updates ping // ADD_PLAYER also updates ping
Collections.singletonList(PlayerListItem.Item.from(entry)))); .write(new PlayerListItemPacket(PlayerListItemPacket.ADD_PLAYER,
Collections.singletonList(PlayerListItemPacket.Item.from(entry))));
break; break;
default: default:
// Can't do anything else // Can't do anything else

Datei anzeigen

@ -4,6 +4,7 @@ import com.google.common.collect.MapMaker;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer; import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
import com.velocitypowered.proxy.protocol.ProtocolUtils; import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.packet.BossBarPacket;
import com.velocitypowered.proxy.util.collect.Enum2IntMap; import com.velocitypowered.proxy.util.collect.Enum2IntMap;
import com.velocitypowered.proxy.util.concurrent.Once; import com.velocitypowered.proxy.util.concurrent.Once;
import java.util.Collections; import java.util.Collections;
@ -106,9 +107,9 @@ public class AdventureBossBarManager implements BossBar.Listener {
if (holder == null) { if (holder == null) {
return; return;
} }
com.velocitypowered.proxy.protocol.packet.BossBar pre116Packet = holder.createTitleUpdate( BossBarPacket pre116Packet = holder.createTitleUpdate(
newName, ProtocolVersion.MINECRAFT_1_15_2); newName, ProtocolVersion.MINECRAFT_1_15_2);
com.velocitypowered.proxy.protocol.packet.BossBar rgbPacket = holder.createTitleUpdate( BossBarPacket rgbPacket = holder.createTitleUpdate(
newName, ProtocolVersion.MINECRAFT_1_16); newName, ProtocolVersion.MINECRAFT_1_16);
for (ConnectedPlayer player : holder.subscribers) { for (ConnectedPlayer player : holder.subscribers) {
if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) { if (player.getProtocolVersion().compareTo(ProtocolVersion.MINECRAFT_1_16) >= 0) {
@ -125,7 +126,7 @@ public class AdventureBossBarManager implements BossBar.Listener {
if (holder == null) { if (holder == null) {
return; return;
} }
com.velocitypowered.proxy.protocol.packet.BossBar packet = holder BossBarPacket packet = holder
.createPercentUpdate(newPercent); .createPercentUpdate(newPercent);
for (ConnectedPlayer player : holder.subscribers) { for (ConnectedPlayer player : holder.subscribers) {
player.getConnection().write(packet); player.getConnection().write(packet);
@ -139,7 +140,7 @@ public class AdventureBossBarManager implements BossBar.Listener {
if (holder == null) { if (holder == null) {
return; return;
} }
com.velocitypowered.proxy.protocol.packet.BossBar packet = holder.createColorUpdate(newColor); BossBarPacket packet = holder.createColorUpdate(newColor);
for (ConnectedPlayer player : holder.subscribers) { for (ConnectedPlayer player : holder.subscribers) {
player.getConnection().write(packet); player.getConnection().write(packet);
} }
@ -152,7 +153,7 @@ public class AdventureBossBarManager implements BossBar.Listener {
if (holder == null) { if (holder == null) {
return; return;
} }
com.velocitypowered.proxy.protocol.packet.BossBar packet = holder BossBarPacket packet = holder
.createOverlayUpdate(newOverlay); .createOverlayUpdate(newOverlay);
for (ConnectedPlayer player : holder.subscribers) { for (ConnectedPlayer player : holder.subscribers) {
player.getConnection().write(packet); player.getConnection().write(packet);
@ -166,7 +167,7 @@ public class AdventureBossBarManager implements BossBar.Listener {
if (holder == null) { if (holder == null) {
return; return;
} }
com.velocitypowered.proxy.protocol.packet.BossBar packet = holder.createFlagsUpdate(); BossBarPacket packet = holder.createFlagsUpdate();
for (ConnectedPlayer player : holder.subscribers) { for (ConnectedPlayer player : holder.subscribers) {
player.getConnection().write(packet); player.getConnection().write(packet);
} }
@ -187,15 +188,14 @@ public class AdventureBossBarManager implements BossBar.Listener {
registrationOnce.run(() -> this.bar.addListener(AdventureBossBarManager.this)); registrationOnce.run(() -> this.bar.addListener(AdventureBossBarManager.this));
} }
com.velocitypowered.proxy.protocol.packet.BossBar createRemovePacket() { BossBarPacket createRemovePacket() {
return com.velocitypowered.proxy.protocol.packet.BossBar.createRemovePacket(this.id); return BossBarPacket.createRemovePacket(this.id);
} }
com.velocitypowered.proxy.protocol.packet.BossBar createAddPacket(ProtocolVersion version) { BossBarPacket createAddPacket(ProtocolVersion version) {
com.velocitypowered.proxy.protocol.packet.BossBar packet = new com.velocitypowered BossBarPacket packet = new BossBarPacket();
.proxy.protocol.packet.BossBar();
packet.setUuid(this.id); packet.setUuid(this.id);
packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.ADD); packet.setAction(BossBarPacket.ADD);
packet.setName(ProtocolUtils.getJsonChatSerializer(version).serialize(bar.name())); packet.setName(ProtocolUtils.getJsonChatSerializer(version).serialize(bar.name()));
packet.setColor(COLORS_TO_PROTOCOL.get(bar.color())); packet.setColor(COLORS_TO_PROTOCOL.get(bar.color()));
packet.setOverlay(bar.overlay().ordinal()); packet.setOverlay(bar.overlay().ordinal());
@ -204,54 +204,49 @@ public class AdventureBossBarManager implements BossBar.Listener {
return packet; return packet;
} }
com.velocitypowered.proxy.protocol.packet.BossBar createPercentUpdate(float newPercent) { BossBarPacket createPercentUpdate(float newPercent) {
com.velocitypowered.proxy.protocol.packet.BossBar packet = new com.velocitypowered BossBarPacket packet = new BossBarPacket();
.proxy.protocol.packet.BossBar();
packet.setUuid(this.id); packet.setUuid(this.id);
packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.UPDATE_PERCENT); packet.setAction(BossBarPacket.UPDATE_PERCENT);
packet.setPercent(newPercent); packet.setPercent(newPercent);
return packet; return packet;
} }
com.velocitypowered.proxy.protocol.packet.BossBar createColorUpdate(Color color) { BossBarPacket createColorUpdate(Color color) {
com.velocitypowered.proxy.protocol.packet.BossBar packet = new com.velocitypowered BossBarPacket packet = new BossBarPacket();
.proxy.protocol.packet.BossBar();
packet.setUuid(this.id); packet.setUuid(this.id);
packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.UPDATE_NAME); packet.setAction(BossBarPacket.UPDATE_NAME);
packet.setColor(COLORS_TO_PROTOCOL.get(color)); packet.setColor(COLORS_TO_PROTOCOL.get(color));
packet.setFlags(serializeFlags(bar.flags())); packet.setFlags(serializeFlags(bar.flags()));
return packet; return packet;
} }
com.velocitypowered.proxy.protocol.packet.BossBar createTitleUpdate(Component name, BossBarPacket createTitleUpdate(Component name,
ProtocolVersion version) { ProtocolVersion version) {
com.velocitypowered.proxy.protocol.packet.BossBar packet = new com.velocitypowered BossBarPacket packet = new BossBarPacket();
.proxy.protocol.packet.BossBar();
packet.setUuid(this.id); packet.setUuid(this.id);
packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.UPDATE_NAME); packet.setAction(BossBarPacket.UPDATE_NAME);
packet.setName(ProtocolUtils.getJsonChatSerializer(version).serialize(name)); packet.setName(ProtocolUtils.getJsonChatSerializer(version).serialize(name));
return packet; return packet;
} }
com.velocitypowered.proxy.protocol.packet.BossBar createFlagsUpdate() { BossBarPacket createFlagsUpdate() {
return createFlagsUpdate(bar.flags()); return createFlagsUpdate(bar.flags());
} }
com.velocitypowered.proxy.protocol.packet.BossBar createFlagsUpdate(Set<Flag> newFlags) { BossBarPacket createFlagsUpdate(Set<Flag> newFlags) {
com.velocitypowered.proxy.protocol.packet.BossBar packet = new com.velocitypowered BossBarPacket packet = new BossBarPacket();
.proxy.protocol.packet.BossBar();
packet.setUuid(this.id); packet.setUuid(this.id);
packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.UPDATE_PROPERTIES); packet.setAction(BossBarPacket.UPDATE_PROPERTIES);
packet.setColor(COLORS_TO_PROTOCOL.get(this.bar.color())); packet.setColor(COLORS_TO_PROTOCOL.get(this.bar.color()));
packet.setFlags(this.serializeFlags(newFlags)); packet.setFlags(this.serializeFlags(newFlags));
return packet; return packet;
} }
com.velocitypowered.proxy.protocol.packet.BossBar createOverlayUpdate(Overlay overlay) { BossBarPacket createOverlayUpdate(Overlay overlay) {
com.velocitypowered.proxy.protocol.packet.BossBar packet = new com.velocitypowered BossBarPacket packet = new BossBarPacket();
.proxy.protocol.packet.BossBar();
packet.setUuid(this.id); packet.setUuid(this.id);
packet.setAction(com.velocitypowered.proxy.protocol.packet.BossBar.UPDATE_PROPERTIES); packet.setAction(BossBarPacket.UPDATE_PROPERTIES);
packet.setOverlay(OVERLAY_TO_PROTOCOL.get(overlay)); packet.setOverlay(OVERLAY_TO_PROTOCOL.get(overlay));
return packet; return packet;
} }

Datei anzeigen

@ -15,8 +15,8 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import com.velocitypowered.api.network.ProtocolVersion; import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.packet.Handshake; import com.velocitypowered.proxy.protocol.packet.HandshakePacket;
import com.velocitypowered.proxy.protocol.packet.StatusPing; import com.velocitypowered.proxy.protocol.packet.StatusPingPacket;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -24,8 +24,8 @@ class PacketRegistryTest {
private StateRegistry.PacketRegistry setupRegistry() { private StateRegistry.PacketRegistry setupRegistry() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolUtils.Direction.CLIENTBOUND); ProtocolDirection.CLIENTBOUND);
registry.register(Handshake.class, Handshake::new, registry.register(HandshakePacket.class, HandshakePacket::new,
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_8, false), new StateRegistry.PacketMapping(0x01, MINECRAFT_1_8, false),
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false)); new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false));
return registry; return registry;
@ -34,9 +34,9 @@ class PacketRegistryTest {
@Test @Test
void packetRegistryWorks() { void packetRegistryWorks() {
StateRegistry.PacketRegistry registry = setupRegistry(); StateRegistry.PacketRegistry registry = setupRegistry();
MinecraftPacket packet = registry.getProtocolRegistry(MINECRAFT_1_12).createPacket(0); Packet packet = registry.getProtocolRegistry(MINECRAFT_1_12).createPacket(0);
assertNotNull(packet, "Packet was not found in registry"); assertNotNull(packet, "Packet was not found in registry");
assertEquals(Handshake.class, packet.getClass(), "Registry returned wrong class"); assertEquals(HandshakePacket.class, packet.getClass(), "Registry returned wrong class");
assertEquals(0, registry.getProtocolRegistry(MINECRAFT_1_12).getPacketId(packet), assertEquals(0, registry.getProtocolRegistry(MINECRAFT_1_12).getPacketId(packet),
"Registry did not return the correct packet ID"); "Registry did not return the correct packet ID");
@ -45,9 +45,9 @@ class PacketRegistryTest {
@Test @Test
void packetRegistryLinkingWorks() { void packetRegistryLinkingWorks() {
StateRegistry.PacketRegistry registry = setupRegistry(); StateRegistry.PacketRegistry registry = setupRegistry();
MinecraftPacket packet = registry.getProtocolRegistry(MINECRAFT_1_12_1).createPacket(0); Packet packet = registry.getProtocolRegistry(MINECRAFT_1_12_1).createPacket(0);
assertNotNull(packet, "Packet was not found in registry"); assertNotNull(packet, "Packet was not found in registry");
assertEquals(Handshake.class, packet.getClass(), "Registry returned wrong class"); assertEquals(HandshakePacket.class, packet.getClass(), "Registry returned wrong class");
assertEquals(0, registry.getProtocolRegistry(MINECRAFT_1_12_1).getPacketId(packet), assertEquals(0, registry.getProtocolRegistry(MINECRAFT_1_12_1).getPacketId(packet),
"Registry did not return the correct packet ID"); "Registry did not return the correct packet ID");
assertEquals(0, registry.getProtocolRegistry(MINECRAFT_1_14_2).getPacketId(packet), assertEquals(0, registry.getProtocolRegistry(MINECRAFT_1_14_2).getPacketId(packet),
@ -61,23 +61,24 @@ class PacketRegistryTest {
@Test @Test
void failOnNoMappings() { void failOnNoMappings() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolUtils.Direction.CLIENTBOUND); ProtocolDirection.CLIENTBOUND);
assertThrows(IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> registry.register(Handshake.class, Handshake::new)); () -> registry.register(HandshakePacket.class, HandshakePacket::new));
assertThrows(IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> registry.getProtocolRegistry(ProtocolVersion.UNKNOWN).getPacketId(new Handshake())); () -> registry.getProtocolRegistry(ProtocolVersion.UNKNOWN)
.getPacketId(new HandshakePacket()));
} }
@Test @Test
void failOnWrongOrder() { void failOnWrongOrder() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolUtils.Direction.CLIENTBOUND); ProtocolDirection.CLIENTBOUND);
assertThrows(IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> registry.register(Handshake.class, Handshake::new, () -> registry.register(HandshakePacket.class, HandshakePacket::new,
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false), new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false),
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false))); new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false)));
assertThrows(IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> registry.register(Handshake.class, Handshake::new, () -> registry.register(HandshakePacket.class, HandshakePacket::new,
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false), new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false),
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false))); new StateRegistry.PacketMapping(0x01, MINECRAFT_1_13, false)));
} }
@ -85,22 +86,22 @@ class PacketRegistryTest {
@Test @Test
void failOnDuplicate() { void failOnDuplicate() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolUtils.Direction.CLIENTBOUND); ProtocolDirection.CLIENTBOUND);
registry.register(Handshake.class, Handshake::new, registry.register(HandshakePacket.class, HandshakePacket::new,
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false)); new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false));
assertThrows(IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> registry.register(Handshake.class, Handshake::new, () -> registry.register(HandshakePacket.class, HandshakePacket::new,
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12, false))); new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12, false)));
assertThrows(IllegalArgumentException.class, assertThrows(IllegalArgumentException.class,
() -> registry.register(StatusPing.class, StatusPing::new, () -> registry.register(StatusPingPacket.class, StatusPingPacket::new,
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_13, false))); new StateRegistry.PacketMapping(0x00, MINECRAFT_1_13, false)));
} }
@Test @Test
void shouldNotFailWhenRegisterLatestProtocolVersion() { void shouldNotFailWhenRegisterLatestProtocolVersion() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolUtils.Direction.CLIENTBOUND); ProtocolDirection.CLIENTBOUND);
assertDoesNotThrow(() -> registry.register(Handshake.class, Handshake::new, assertDoesNotThrow(() -> registry.register(HandshakePacket.class, HandshakePacket::new,
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false), new StateRegistry.PacketMapping(0x00, MINECRAFT_1_8, false),
new StateRegistry.PacketMapping(0x01, getLast(ProtocolVersion.SUPPORTED_VERSIONS), new StateRegistry.PacketMapping(0x01, getLast(ProtocolVersion.SUPPORTED_VERSIONS),
false))); false)));
@ -109,20 +110,20 @@ class PacketRegistryTest {
@Test @Test
void registrySuppliesCorrectPacketsByProtocol() { void registrySuppliesCorrectPacketsByProtocol() {
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry( StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(
ProtocolUtils.Direction.CLIENTBOUND); ProtocolDirection.CLIENTBOUND);
registry.register(Handshake.class, Handshake::new, registry.register(HandshakePacket.class, HandshakePacket::new,
new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false), new StateRegistry.PacketMapping(0x00, MINECRAFT_1_12, false),
new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12_1, false), new StateRegistry.PacketMapping(0x01, MINECRAFT_1_12_1, false),
new StateRegistry.PacketMapping(0x02, MINECRAFT_1_13, false)); new StateRegistry.PacketMapping(0x02, MINECRAFT_1_13, false));
assertEquals(Handshake.class, assertEquals(HandshakePacket.class,
registry.getProtocolRegistry(MINECRAFT_1_12).createPacket(0x00).getClass()); registry.getProtocolRegistry(MINECRAFT_1_12).createPacket(0x00).getClass());
assertEquals(Handshake.class, assertEquals(HandshakePacket.class,
registry.getProtocolRegistry(MINECRAFT_1_12_1).createPacket(0x01).getClass()); registry.getProtocolRegistry(MINECRAFT_1_12_1).createPacket(0x01).getClass());
assertEquals(Handshake.class, assertEquals(HandshakePacket.class,
registry.getProtocolRegistry(MINECRAFT_1_12_2).createPacket(0x01).getClass()); registry.getProtocolRegistry(MINECRAFT_1_12_2).createPacket(0x01).getClass());
assertEquals(Handshake.class, assertEquals(HandshakePacket.class,
registry.getProtocolRegistry(MINECRAFT_1_13).createPacket(0x02).getClass()); registry.getProtocolRegistry(MINECRAFT_1_13).createPacket(0x02).getClass());
assertEquals(Handshake.class, assertEquals(HandshakePacket.class,
registry.getProtocolRegistry(MINECRAFT_1_14_2).createPacket(0x02).getClass()); registry.getProtocolRegistry(MINECRAFT_1_14_2).createPacket(0x02).getClass());
} }
} }