use of org.spongepowered.api.network.channel.ChannelBuf in project SpongeCommon by SpongePowered.
the class SpongeChannelManager method handleLoginRequestPayload.
private boolean handleLoginRequestPayload(final EngineConnection connection, final ResourceKey channelKey, final int transactionId, final ChannelBuf payload) {
if (channelKey.equals(Constants.Channels.SPONGE_CLIENT_TYPE)) {
final ClientType clientType = ((MinecraftBridge) Sponge.client()).bridge$getClientType();
final ChannelBuf responsePayload = this.bufferAllocator.buffer();
responsePayload.writeString(clientType.getName());
final Packet<?> mcPacket = PacketUtil.createLoginPayloadResponse(responsePayload, transactionId);
PacketSender.sendTo(connection, mcPacket);
return true;
}
if (channelKey.equals(Constants.Channels.SPONGE_CHANNEL_REGISTRY)) {
this.handleChannelRegistry(connection, payload);
// Respond with registered channels
final ChannelBuf responsePayload = this.encodeChannelRegistry();
final Packet<?> mcPacket = PacketUtil.createLoginPayloadResponse(responsePayload, transactionId);
PacketSender.sendTo(connection, mcPacket);
return true;
}
ResourceKey actualChannelKey = channelKey;
ChannelBuf actualPayload = payload;
if (channelKey.equals(Constants.Channels.FML_LOGIN_WRAPPER_CHANNEL)) {
actualChannelKey = ResourceKey.resolve(payload.readString());
final int length = payload.readVarInt();
actualPayload = payload.readSlice(length);
}
final SpongeChannel channel = this.channels.get(actualChannelKey);
if (channel != null) {
channel.handleLoginRequestPayload(connection, transactionId, actualPayload);
return true;
}
return false;
}
use of org.spongepowered.api.network.channel.ChannelBuf in project SpongeCommon by SpongePowered.
the class SpongeChannelManager method sendLoginChannelRegistry.
/**
* Sends the login channel registrations. The client will respond back with
* the registrations and the returned future will be completed.
*
* @param connection The connection to send the registrations to
*/
public CompletableFuture<Void> sendLoginChannelRegistry(final EngineConnection connection) {
final CompletableFuture<Void> future = new CompletableFuture<>();
final TransactionStore store = ConnectionUtil.getTransactionStore(connection);
final int transactionId = store.nextId();
store.put(transactionId, null, new ChannelRegistrySyncFuture(future));
final ChannelBuf payload = this.encodeChannelRegistry();
final Packet<?> mcPacket = PacketUtil.createLoginPayloadRequest(Constants.Channels.SPONGE_CHANNEL_REGISTRY, payload, transactionId);
PacketSender.sendTo(connection, mcPacket, sendFuture -> {
if (!sendFuture.isSuccess()) {
future.completeExceptionally(sendFuture.cause());
}
});
return future;
}
use of org.spongepowered.api.network.channel.ChannelBuf in project SpongeCommon by SpongePowered.
the class SpongeChannelManager method handleLoginRequestPayload.
public boolean handleLoginRequestPayload(final EngineConnection connection, final ClientboundCustomQueryPacket packet) {
// Server -> Client request
final ClientboundCustomQueryPacketAccessor accessor = (ClientboundCustomQueryPacketAccessor) packet;
final ResourceKey channel = (ResourceKey) (Object) accessor.accessor$identifier();
final int transactionId = accessor.accessor$transactionId();
final ChannelBuf payload = (ChannelBuf) accessor.accessor$data();
try {
return this.handleLoginRequestPayload(connection, channel, transactionId, payload);
} finally {
ChannelBuffers.release(payload);
}
}
use of org.spongepowered.api.network.channel.ChannelBuf in project SpongeCommon by SpongePowered.
the class SpongeChannelManager method handlePlayPayload.
public boolean handlePlayPayload(final EngineConnection connection, final ClientboundCustomPayloadPacket packet) {
final ClientboundCustomPayloadPacketAccessor accessor = (ClientboundCustomPayloadPacketAccessor) packet;
final ResourceKey channel = (ResourceKey) (Object) accessor.accessor$identifier();
final ChannelBuf payload = (ChannelBuf) accessor.accessor$data();
return this.handlePlayPayload(connection, channel, payload);
}
use of org.spongepowered.api.network.channel.ChannelBuf in project SpongeCommon by SpongePowered.
the class SpongeChannelManager method requestClientType.
public CompletableFuture<Void> requestClientType(final EngineConnection connection) {
final CompletableFuture<Void> future = new CompletableFuture<>();
final TransactionStore store = ConnectionUtil.getTransactionStore(connection);
final int transactionId = store.nextId();
store.put(transactionId, null, new ClientTypeSyncFuture(future));
final ChannelBuf payload = this.bufferAllocator.buffer();
final Packet<?> mcPacket = PacketUtil.createLoginPayloadRequest(Constants.Channels.SPONGE_CLIENT_TYPE, payload, transactionId);
PacketSender.sendTo(connection, mcPacket, sendFuture -> {
if (!sendFuture.isSuccess()) {
future.completeExceptionally(sendFuture.cause());
}
});
return future;
}
Aggregations