Skip to content

Commit

Permalink
build: build against velocity build 371
Browse files Browse the repository at this point in the history
Fixes #47
  • Loading branch information
ishland committed Mar 24, 2024
1 parent bdd358b commit 94669fd
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion velocity/build.gradle
Expand Up @@ -40,7 +40,7 @@ dependencies {
// api 'com.velocitypowered:velocity-api:3.1.1'
// annotationProcessor 'com.velocitypowered:velocity-api:3.1.1'

implementation 'velocity:3.2.0-SNAPSHOT:296'
implementation 'velocity:3.3.0-SNAPSHOT:371'
// annotationProcessor 'velocity:3.1.2-SNAPSHOT:139'

shadowInclude implementation(project(":common"))
Expand Down
Expand Up @@ -59,6 +59,7 @@ public static void launch() {
private static boolean isCompatible() {
try {
Class.forName("com.velocitypowered.proxy.crypto.EncryptionUtils");
Class.forName("com.velocitypowered.proxy.protocol.packet.PluginMessagePacket");
return true;
} catch (ClassNotFoundException e) {
return false;
Expand Down
Expand Up @@ -31,13 +31,13 @@
import com.velocitypowered.proxy.crypto.EncryptionUtils;
import com.velocitypowered.proxy.network.Connections;
import com.velocitypowered.proxy.protocol.VelocityConnectionEvent;
import com.velocitypowered.proxy.protocol.packet.AvailableCommands;
import com.velocitypowered.proxy.protocol.packet.EncryptionResponse;
import com.velocitypowered.proxy.protocol.packet.JoinGame;
import com.velocitypowered.proxy.protocol.packet.Respawn;
import com.velocitypowered.proxy.protocol.packet.SetCompression;
import com.velocitypowered.proxy.protocol.packet.config.FinishedUpdate;
import com.velocitypowered.proxy.protocol.packet.config.StartUpdate;
import com.velocitypowered.proxy.protocol.packet.AvailableCommandsPacket;
import com.velocitypowered.proxy.protocol.packet.EncryptionResponsePacket;
import com.velocitypowered.proxy.protocol.packet.JoinGamePacket;
import com.velocitypowered.proxy.protocol.packet.RespawnPacket;
import com.velocitypowered.proxy.protocol.packet.SetCompressionPacket;
import com.velocitypowered.proxy.protocol.packet.config.FinishedUpdatePacket;
import com.velocitypowered.proxy.protocol.packet.config.StartUpdatePacket;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
Expand All @@ -53,18 +53,18 @@ public class RakNetVelocityChannelEventListener extends ChannelDuplexHandler {

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
if (msg instanceof SetCompression) {
if (msg instanceof SetCompressionPacket) {
final MultiChannelingStreamingCompression compression = ctx.channel().pipeline().get(MultiChannelingStreamingCompression.class);
if (compression != null && compression.isActive()) {
RaknetifyVelocityPlugin.LOGGER.info("Preventing vanilla compression as streaming compression is enabled");
promise.setSuccess(); // swallow SetCompression packet
return;
}
} else if (msg instanceof Respawn || msg instanceof JoinGame || msg instanceof StartUpdate || msg instanceof FinishedUpdate) {
} else if (msg instanceof RespawnPacket || msg instanceof JoinGamePacket || msg instanceof StartUpdatePacket || msg instanceof FinishedUpdatePacket) {
ctx.write(SynchronizationLayer.SYNC_REQUEST_OBJECT); // sync
super.write(ctx, msg, promise);
return;
} else if (msg instanceof AvailableCommands) {
} else if (msg instanceof AvailableCommandsPacket) {
ctx.write(RakNetSimpleMultiChannelCodec.SIGNAL_START_MULTICHANNEL);
super.write(ctx, msg, promise);
return;
Expand All @@ -74,7 +74,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof EncryptionResponse packet) {
if (msg instanceof EncryptionResponsePacket packet) {
try {
byte[] secret = EncryptionUtils.decryptRsa(((VelocityServer) RaknetifyVelocityPlugin.PROXY).getServerKeyPair(), packet.getSharedSecret());
this.encryptionKey = new SecretKeySpec(secret, "AES");
Expand Down
Expand Up @@ -37,7 +37,7 @@
import com.velocitypowered.proxy.network.Connections;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
import com.velocitypowered.proxy.protocol.packet.PluginMessagePacket;
import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.handler.codec.haproxy.HAProxyMessageDecoder;
Expand Down Expand Up @@ -86,7 +86,7 @@ public static void onPlayerLogin(LoginEvent evt) {
if (versionMapping != null) {

// handle custom payload separately
final int pluginMessageId = StateRegistry.PLAY.getProtocolRegistry(ProtocolUtils.Direction.CLIENTBOUND, protocolVersion).getPacketId(new PluginMessage());
final int pluginMessageId = StateRegistry.PLAY.getProtocolRegistry(ProtocolUtils.Direction.CLIENTBOUND, protocolVersion).getPacketId(new PluginMessagePacket());
if (Constants.DEBUG) RaknetifyVelocityPlugin.LOGGER.info("PluginMessage packetId=%d at version=%d".formatted(pluginMessageId, protocolVersion.getProtocol()));
multiChannelCodec.addHandler(new CustomPayloadChannel.OverrideHandler(value -> value == pluginMessageId));

Expand Down
Expand Up @@ -23,7 +23,7 @@
import com.google.common.base.Preconditions;
import com.ishland.raknetify.common.Constants;
import com.ishland.raknetify.velocity.RaknetifyVelocityPlugin;
import com.velocitypowered.proxy.protocol.packet.KeepAlive;
import com.velocitypowered.proxy.protocol.packet.KeepAlivePacket;
import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandler;
Expand All @@ -46,7 +46,7 @@ public RakNetVelocityServerChannelEventListener(Channel clientChannel) {

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof KeepAlive) {
if (msg instanceof KeepAlivePacket) {
if (Constants.DEBUG) RaknetifyVelocityPlugin.LOGGER.info("Received downstream keepalive, swallowing it");
final long rttNanos = RakNet.config(clientChannel).getRTTNanos();
// RaknetifyVelocityPlugin.PROXY.getScheduler().buildTask(RaknetifyVelocityPlugin.INSTANCE, () -> ctx.write(msg))
Expand Down
Expand Up @@ -23,7 +23,7 @@
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.MinecraftPacket;
import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.packet.Respawn;
import com.velocitypowered.proxy.protocol.packet.RespawnPacket;
import io.netty.util.collection.IntObjectMap;
import it.unimi.dsi.fastutil.objects.Object2IntMap;

Expand All @@ -45,10 +45,10 @@ public static void inject() {
accessible(StateRegistry.PacketRegistry.ProtocolRegistry.class.getDeclaredField("packetClassToId")).get(value);
final var packetIdToSupplier = (IntObjectMap<Supplier<? extends MinecraftPacket>>)
accessible(StateRegistry.PacketRegistry.ProtocolRegistry.class.getDeclaredField("packetIdToSupplier")).get(value);
if (packetClassToId.containsKey(Respawn.class)) {
final int packetId = packetClassToId.getInt(Respawn.class);
if (packetClassToId.containsKey(RespawnPacket.class)) {
final int packetId = packetClassToId.getInt(RespawnPacket.class);
if (!packetIdToSupplier.containsKey(packetId)) {
packetIdToSupplier.put(packetId, Respawn::new); // make respawn packet no longer encodeOnly
packetIdToSupplier.put(packetId, RespawnPacket::new); // make respawn packet no longer encodeOnly
}
}
}
Expand Down

0 comments on commit 94669fd

Please sign in to comment.