Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.cloudburstmc.netty.handler.codec.raknet.client;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import io.netty.util.concurrent.Promise;

public class RakClientFirstPacketHandler extends ChannelOutboundHandlerAdapter {
public static final String NAME = "rak-client-first-packet-handler";

private final Promise<Object> packetPromise;

public RakClientFirstPacketHandler(Promise<Object> packetPromise) {
this.packetPromise = packetPromise;
}

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
ctx.channel().pipeline().remove(RakClientFirstPacketHandler.NAME);
this.packetPromise.setSuccess(msg);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.cloudburstmc.netty.channel.raknet.RakChannel;
import org.cloudburstmc.netty.channel.raknet.RakOfflineState;
import org.cloudburstmc.netty.channel.raknet.config.RakChannelOption;
import org.cloudburstmc.netty.channel.raknet.packet.RakMessage;
import org.cloudburstmc.netty.handler.codec.raknet.common.*;
import org.cloudburstmc.netty.util.RakUtils;

Expand All @@ -31,18 +30,18 @@ void onRetryAttempt(Channel channel) {
@Override
void onSuccess(ChannelHandlerContext ctx) {
RakSessionCodec sessionCodec = new RakSessionCodecCompatible(this.rakChannel());
Promise<RakMessage> networkSettingsPacketPromise = ctx.executor().newPromise();
Promise<Object> packetPromise = ctx.executor().newPromise();
ctx.pipeline().addAfter(NAME, RakDatagramCodec.NAME, new RakDatagramCodec());
ctx.pipeline().addAfter(RakDatagramCodec.NAME, RakAcknowledgeHandler.NAME, new RakAcknowledgeHandler(sessionCodec));
ctx.pipeline().addAfter(RakAcknowledgeHandler.NAME, RakSessionCodec.NAME, sessionCodec);
// Ensure new incoming connection batches with request network settings game packet
ctx.pipeline().addAfter(RakSessionCodec.NAME, RakClientNetworkSettingsHandler.NAME, new RakClientNetworkSettingsHandler(this.rakChannel(), networkSettingsPacketPromise));
// Ensure new incoming connection batches with first game packet (request network settings)
ctx.pipeline().addAfter(RakSessionCodec.NAME, RakClientFirstPacketHandler.NAME, new RakClientFirstPacketHandler(packetPromise));
ctx.pipeline().addAfter(RakSessionCodec.NAME, ConnectedPingHandler.NAME, new ConnectedPingHandler());
ctx.pipeline().addAfter(ConnectedPingHandler.NAME, ConnectedPongHandler.NAME, new ConnectedPongHandler(sessionCodec));
ctx.pipeline().addAfter(ConnectedPongHandler.NAME, DisconnectNotificationHandler.NAME, DisconnectNotificationHandler.INSTANCE);
// Replicate server behavior, and transform unhandled encapsulated packets to rakMessage
ctx.pipeline().addAfter(DisconnectNotificationHandler.NAME, EncapsulatedToMessageHandler.NAME, EncapsulatedToMessageHandler.INSTANCE);
ctx.pipeline().addAfter(DisconnectNotificationHandler.NAME, RakClientOnlineInitialHandlerCompatible.NAME, new RakClientOnlineInitialHandlerCompatible(this.rakChannel(), this.successPromise(), networkSettingsPacketPromise));
ctx.pipeline().addAfter(DisconnectNotificationHandler.NAME, RakClientOnlineInitialHandlerCompatible.NAME, new RakClientOnlineInitialHandlerCompatible(this.rakChannel(), this.successPromise(), packetPromise));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@
public class RakClientOnlineInitialHandlerCompatible extends RakClientOnlineInitialHandler {
public static final String NAME = "rak-client-online-initial-handler";

private final Promise<RakMessage> networkSettingsPacketPromise;
private final Promise<Object> packetPromise;
private long pingTime = 0;

public RakClientOnlineInitialHandlerCompatible(RakChannel rakChannel, ChannelPromise successPromise, Promise<RakMessage> networkSettingsPacketPromise) {
public RakClientOnlineInitialHandlerCompatible(RakChannel rakChannel, ChannelPromise successPromise, Promise<Object> packetPromise) {
super(rakChannel, successPromise);
this.networkSettingsPacketPromise = networkSettingsPacketPromise;
this.packetPromise = packetPromise;
}

@Override
void onSuccess(ChannelHandlerContext ctx) {
super.onSuccess(ctx);

// Wait for the RequestNetworkSettings packet before sending the final batch
this.networkSettingsPacketPromise.addListener(future -> {
// Wait for the first game packet (request network settings) before sending the final batch
this.packetPromise.addListener(future -> {
ByteBuf incomingBuffer = ctx.alloc().ioBuffer();
this.writeIncomingConnection(ctx, incomingBuffer, pingTime);
ctx.write(new RakMessage(incomingBuffer, RakReliability.RELIABLE_ORDERED, RakPriority.NORMAL));
Expand Down