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

Started refactoring session handlers

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-09-29 02:16:34 -04:00
Ursprung 6cd0a6b148
Commit c7bd0d100e
36 geänderte Dateien mit 229 neuen und 48 gelöschten Zeilen

Datei anzeigen

@ -69,7 +69,10 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof MinecraftPacket) {
sessionHandler.handle((MinecraftPacket) msg);
MinecraftPacket pkt = (MinecraftPacket) msg;
if (!pkt.handle(sessionHandler)) {
sessionHandler.handleGeneric((MinecraftPacket) msg);
}
} else if (msg instanceof ByteBuf) {
try {
sessionHandler.handleUnknown((ByteBuf) msg);

Datei anzeigen

@ -1,10 +1,11 @@
package com.velocitypowered.proxy.connection;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.packet.*;
import io.netty.buffer.ByteBuf;
public interface MinecraftSessionHandler {
void handle(MinecraftPacket packet);
void handleGeneric(MinecraftPacket packet);
default void handleUnknown(ByteBuf buf) {
// No-op: we'll release the buffer later.
@ -33,4 +34,30 @@ public interface MinecraftSessionHandler {
default void writabilityChanged() {
}
default boolean handle(BossBar packet) { return false; }
default boolean handle(Chat packet) { return false; }
default boolean handle(ClientSettings packet) { return false; }
default boolean handle(Disconnect packet) { return false; }
default boolean handle(EncryptionRequest packet) { return false; }
default boolean handle(EncryptionResponse packet) { return false; }
default boolean handle(Handshake packet) { return false; }
default boolean handle(HeaderAndFooter packet) { return false; }
default boolean handle(JoinGame packet) { return false; }
default boolean handle(KeepAlive packet) { return false; }
default boolean handle(LegacyHandshake packet) { return false; }
default boolean handle(LegacyPing packet) { return false; }
default boolean handle(LoginPluginMessage packet) { return false; }
default boolean handle(LoginPluginResponse packet) { return false; }
default boolean handle(PluginMessage packet) { return false; }
default boolean handle(Respawn packet) { return false; }
default boolean handle(ServerLogin packet) { return false; }
default boolean handle(ServerLoginSuccess packet) { return false; }
default boolean handle(SetCompression packet) { return false; }
default boolean handle(StatusPing packet) { return false; }
default boolean handle(StatusRequest packet) { return false; }
default boolean handle(StatusResponse packet) { return false; }
default boolean handle(TabCompleteRequest packet) { return false; }
default boolean handle(TabCompleteResponse packet) { return false; }
default boolean handle(TitlePacket packet) { return false; }
}

Datei anzeigen

@ -30,7 +30,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
}
@Override
public void handle(MinecraftPacket packet) {
public void handleGeneric(MinecraftPacket packet) {
if (!serverConn.getPlayer().isActive()) {
// Connection was left open accidentally. Close it so as to avoid "You logged in from another location"
// errors.

Datei anzeigen

@ -36,7 +36,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
}
@Override
public void handle(MinecraftPacket packet) {
public void handleGeneric(MinecraftPacket packet) {
if (packet instanceof EncryptionRequest) {
throw new IllegalStateException("Backend server is online-mode!");
} else if (packet instanceof LoginPluginMessage) {

Datei anzeigen

@ -49,7 +49,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
}
@Override
public void handle(MinecraftPacket packet) {
public void handleGeneric(MinecraftPacket packet) {
VelocityServerConnection serverConnection = player.getConnectedServer();
if (serverConnection == null) {
// No server connection yet, probably transitioning.

Datei anzeigen

@ -35,74 +35,8 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
}
@Override
public void handle(MinecraftPacket packet) {
if (packet instanceof LegacyPing || packet instanceof LegacyHandshake) {
public boolean handle(LegacyPing packet) {
connection.setProtocolVersion(ProtocolConstants.LEGACY);
handleLegacy(packet);
return;
}
if (!(packet instanceof Handshake)) {
throw new IllegalArgumentException("Did not expect packet " + packet.getClass().getName());
}
InitialInboundConnection ic = new InitialInboundConnection(connection, (Handshake) packet);
Handshake handshake = (Handshake) packet;
switch (handshake.getNextStatus()) {
case StateRegistry.STATUS_ID:
connection.setState(StateRegistry.STATUS);
connection.setProtocolVersion(handshake.getProtocolVersion());
connection.setSessionHandler(new StatusSessionHandler(server, connection, ic));
break;
case StateRegistry.LOGIN_ID:
connection.setState(StateRegistry.LOGIN);
connection.setProtocolVersion(handshake.getProtocolVersion());
if (!ProtocolConstants.isSupported(handshake.getProtocolVersion())) {
connection.closeWith(Disconnect.create(TranslatableComponent.of("multiplayer.disconnect.outdated_client")));
return;
}
InetAddress address = ((InetSocketAddress) connection.getChannel().remoteAddress()).getAddress();
if (!server.getIpAttemptLimiter().attempt(address)) {
connection.closeWith(Disconnect.create(TextComponent.of("You are logging in too fast, try again later.")));
return;
}
// Determine if we're using Forge (1.8 to 1.12, may not be the case in 1.13) and store that in the connection
boolean isForge = handshake.getServerAddress().endsWith("\0FML\0");
connection.setLegacyForge(isForge);
// Make sure legacy forwarding is not in use on this connection. Make sure that we do _not_ reject Forge
if (handshake.getServerAddress().contains("\0") && !isForge) {
connection.closeWith(Disconnect.create(TextComponent.of("Running Velocity behind Velocity is unsupported.")));
return;
}
// If the proxy is configured for modern forwarding, we must deny connections from 1.12.2 and lower,
// otherwise IP information will never get forwarded.
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && handshake.getProtocolVersion() <
ProtocolConstants.MINECRAFT_1_13) {
connection.closeWith(Disconnect.create(TextComponent.of("This server is only compatible with 1.13 and above.")));
return;
}
server.getEventManager().fireAndForget(new ConnectionHandshakeEvent(ic));
connection.setSessionHandler(new LoginSessionHandler(server, connection, ic));
break;
default:
throw new IllegalArgumentException("Invalid state " + handshake.getNextStatus());
}
}
@Override
public void handleUnknown(ByteBuf buf) {
throw new IllegalStateException("Unknown data " + ByteBufUtil.hexDump(buf));
}
private void handleLegacy(MinecraftPacket packet) {
if (packet instanceof LegacyPing) {
VelocityConfiguration configuration = server.getConfiguration();
ServerPing ping = new ServerPing(
new ServerPing.Version(ProtocolConstants.MAXIMUM_GENERIC_VERSION, "Velocity " + ProtocolConstants.SUPPORTED_GENERIC_VERSION_STRING),
@ -117,9 +51,73 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
// The disconnect packet is the same as the server response one.
connection.closeWith(LegacyDisconnect.fromPingResponse(LegacyPingResponse.from(event.getPing())));
}, connection.eventLoop());
} else if (packet instanceof LegacyHandshake) {
connection.closeWith(LegacyDisconnect.from(TextComponent.of("Your client is old, please upgrade!", TextColor.RED)));
return true;
}
@Override
public boolean handle(LegacyHandshake packet) {
connection.closeWith(LegacyDisconnect.from(TextComponent.of("Your client is old, please upgrade!", TextColor.RED)));
return true;
}
@Override
public boolean handle(Handshake handshake) {
InitialInboundConnection ic = new InitialInboundConnection(connection, handshake);
switch (handshake.getNextStatus()) {
case StateRegistry.STATUS_ID:
connection.setState(StateRegistry.STATUS);
connection.setProtocolVersion(handshake.getProtocolVersion());
connection.setSessionHandler(new StatusSessionHandler(server, connection, ic));
return true;
case StateRegistry.LOGIN_ID:
connection.setState(StateRegistry.LOGIN);
connection.setProtocolVersion(handshake.getProtocolVersion());
if (!ProtocolConstants.isSupported(handshake.getProtocolVersion())) {
connection.closeWith(Disconnect.create(TranslatableComponent.of("multiplayer.disconnect.outdated_client")));
return true;
}
InetAddress address = ((InetSocketAddress) connection.getChannel().remoteAddress()).getAddress();
if (!server.getIpAttemptLimiter().attempt(address)) {
connection.closeWith(Disconnect.create(TextComponent.of("You are logging in too fast, try again later.")));
return true;
}
// Determine if we're using Forge (1.8 to 1.12, may not be the case in 1.13) and store that in the connection
boolean isForge = handshake.getServerAddress().endsWith("\0FML\0");
connection.setLegacyForge(isForge);
// Make sure legacy forwarding is not in use on this connection. Make sure that we do _not_ reject Forge
if (handshake.getServerAddress().contains("\0") && !isForge) {
connection.closeWith(Disconnect.create(TextComponent.of("Running Velocity behind Velocity is unsupported.")));
return true;
}
// If the proxy is configured for modern forwarding, we must deny connections from 1.12.2 and lower,
// otherwise IP information will never get forwarded.
if (server.getConfiguration().getPlayerInfoForwardingMode() == PlayerInfoForwarding.MODERN && handshake.getProtocolVersion() <
ProtocolConstants.MINECRAFT_1_13) {
connection.closeWith(Disconnect.create(TextComponent.of("This server is only compatible with 1.13 and above.")));
return true;
}
server.getEventManager().fireAndForget(new ConnectionHandshakeEvent(ic));
connection.setSessionHandler(new LoginSessionHandler(server, connection, ic));
return true;
default:
throw new IllegalArgumentException("Invalid state " + handshake.getNextStatus());
}
}
@Override
public void handleGeneric(MinecraftPacket packet) {
}
@Override
public void handleUnknown(ByteBuf buf) {
throw new IllegalStateException("Unknown data " + ByteBufUtil.hexDump(buf));
}
private static class LegacyInboundConnection implements InboundConnection {

Datei anzeigen

@ -11,7 +11,7 @@ public class InitialConnectSessionHandler implements MinecraftSessionHandler {
}
@Override
public void handle(MinecraftPacket packet) {
public void handleGeneric(MinecraftPacket packet) {
// No-op: will never handle packets
}

Datei anzeigen

@ -59,7 +59,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
}
@Override
public void handle(MinecraftPacket packet) {
public void handleGeneric(MinecraftPacket packet) {
if (packet instanceof LoginPluginResponse) {
LoginPluginResponse lpr = (LoginPluginResponse) packet;
if (lpr.getId() == playerInfoId) {

Datei anzeigen

@ -29,7 +29,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
}
@Override
public void handle(MinecraftPacket packet) {
public void handleGeneric(MinecraftPacket packet) {
Preconditions.checkArgument(packet instanceof StatusPing || packet instanceof StatusRequest,
"Unrecognized packet type " + packet.getClass().getName());

Datei anzeigen

@ -1,9 +1,12 @@
package com.velocitypowered.proxy.protocol;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import io.netty.buffer.ByteBuf;
public interface MinecraftPacket {
void decode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion);
void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion);
boolean handle(MinecraftSessionHandler handler);
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -150,4 +151,9 @@ public class BossBar implements MinecraftPacket {
break;
}
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,6 +1,7 @@
package com.velocitypowered.proxy.protocol.packet;
import com.google.common.base.Preconditions;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -63,6 +64,11 @@ public class Chat implements MinecraftPacket {
}
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
public static Chat createClientbound(Component component) {
return createClientbound(component, CHAT);
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -111,4 +112,9 @@ public class ClientSettings implements MinecraftPacket {
ProtocolUtils.writeVarInt(buf, mainHand);
}
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,6 +1,7 @@
package com.velocitypowered.proxy.protocol.packet;
import com.google.common.base.Preconditions;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -43,6 +44,11 @@ public class Disconnect implements MinecraftPacket {
ProtocolUtils.writeString(buf, reason);
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
public static Disconnect create(Component component) {
Preconditions.checkNotNull(component, "component");
return new Disconnect(ComponentSerializers.JSON.serialize(component));

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -48,4 +49,9 @@ public class EncryptionRequest implements MinecraftPacket {
ProtocolUtils.writeByteArray(buf, publicKey);
ProtocolUtils.writeByteArray(buf, verifyToken);
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -46,4 +47,9 @@ public class EncryptionResponse implements MinecraftPacket {
ProtocolUtils.writeByteArray(buf, sharedSecret);
ProtocolUtils.writeByteArray(buf, verifyToken);
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -68,4 +69,9 @@ public class Handshake implements MinecraftPacket {
buf.writeShort(this.port);
ProtocolUtils.writeVarInt(buf, this.nextStatus);
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants.Direction;
import io.netty.buffer.ByteBuf;
@ -51,6 +52,11 @@ public class HeaderAndFooter implements MinecraftPacket {
writeString(buf, footer);
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
public static HeaderAndFooter create(Component header, Component footer) {
ComponentSerializer<Component, Component, String> json = ComponentSerializers.JSON;
return new HeaderAndFooter(json.serialize(header), json.serialize(footer));

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -112,4 +113,9 @@ public class JoinGame implements MinecraftPacket {
ProtocolUtils.writeString(buf, levelType);
buf.writeBoolean(reducedDebugInfo);
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -42,4 +43,9 @@ public class KeepAlive implements MinecraftPacket {
ProtocolUtils.writeVarInt(buf, (int) randomId);
}
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import io.netty.buffer.ByteBuf;
@ -14,4 +15,9 @@ public class LegacyHandshake implements MinecraftPacket {
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
throw new UnsupportedOperationException();
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import io.netty.buffer.ByteBuf;
@ -14,4 +15,9 @@ public class LegacyPing implements MinecraftPacket {
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
throw new UnsupportedOperationException();
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -61,4 +62,9 @@ public class LoginPluginMessage implements MinecraftPacket {
ProtocolUtils.writeString(buf, channel);
buf.writeBytes(data);
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -61,4 +62,9 @@ public class LoginPluginResponse implements MinecraftPacket {
buf.writeBoolean(success);
buf.writeBytes(data);
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -46,4 +47,9 @@ public class PluginMessage implements MinecraftPacket {
ProtocolUtils.writeString(buf, channel);
buf.writeBytes(data);
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -78,4 +79,9 @@ public class Respawn implements MinecraftPacket {
buf.writeByte(gamemode);
ProtocolUtils.writeString(buf, levelType);
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -32,4 +33,9 @@ public class ServerLogin implements MinecraftPacket {
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
ProtocolUtils.writeString(buf, username);
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -46,4 +47,9 @@ public class ServerLoginSuccess implements MinecraftPacket {
ProtocolUtils.writeString(buf, uuid.toString());
ProtocolUtils.writeString(buf, username);
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -38,4 +39,9 @@ public class SetCompression implements MinecraftPacket {
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
ProtocolUtils.writeVarInt(buf, threshold);
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import io.netty.buffer.ByteBuf;
@ -16,4 +17,9 @@ public class StatusPing implements MinecraftPacket {
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
buf.writeLong(randomId);
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import io.netty.buffer.ByteBuf;
@ -25,4 +26,9 @@ public class StatusRequest implements MinecraftPacket {
public String toString() {
return "StatusRequest";
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -32,4 +33,9 @@ public class StatusResponse implements MinecraftPacket {
public void encode(ByteBuf buf, ProtocolConstants.Direction direction, int protocolVersion) {
ProtocolUtils.writeString(buf, status);
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -79,4 +80,9 @@ public class TabCompleteRequest implements MinecraftPacket {
buf.writeLong(position);
}
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.proxy.protocol.packet;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -37,4 +38,9 @@ public class TabCompleteResponse implements MinecraftPacket {
ProtocolUtils.writeString(buf, offer);
}
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -1,6 +1,7 @@
package com.velocitypowered.proxy.protocol.packet;
import com.google.common.base.Preconditions;
import com.velocitypowered.proxy.connection.MinecraftSessionHandler;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
@ -134,4 +135,9 @@ public class TitlePacket implements MinecraftPacket {
", fadeOut=" + fadeOut +
'}';
}
@Override
public boolean handle(MinecraftSessionHandler handler) {
return handler.handle(this);
}
}

Datei anzeigen

@ -42,7 +42,7 @@ public class PingSessionHandler implements MinecraftSessionHandler {
}
@Override
public void handle(MinecraftPacket packet) {
public void handleGeneric(MinecraftPacket packet) {
Preconditions.checkState(packet instanceof StatusResponse, "Did not get status response back from connection");
// All good!