use of org.spongepowered.common.network.channel.TransactionResult in project SpongeCommon by SpongePowered.
the class SpongePacketChannel method handleResponsePacket.
private void handleResponsePacket(final EngineConnection connection, final int transactionId, @Nullable final ChannelBuf payload, final int dynamicOpcode) {
final TransactionStore store = ConnectionUtil.getTransactionStore(connection);
final TransactionStore.Entry stored = store.remove(transactionId);
if (stored == null) {
return;
}
final TransactionData<RequestPacket<Packet>, Packet> transactionData = (TransactionData<RequestPacket<Packet>, Packet>) stored.getData();
final TransactionResult result = payload == null ? TransactionResult.failure(new NoResponseException()) : TransactionResult.success(payload);
this.handleTransactionResponse(connection, transactionData, result, dynamicOpcode);
}
use of org.spongepowered.common.network.channel.TransactionResult in project SpongeCommon by SpongePowered.
the class SpongeRawLoginDataChannel method sendTo.
@Override
public CompletableFuture<ChannelBuf> sendTo(final EngineConnection connection, final Consumer<ChannelBuf> payload) {
ConnectionUtil.checkHandshakePhase(connection);
final CompletableFuture<ChannelBuf> future = new CompletableFuture<>();
final ChannelBuf buf;
try {
buf = this.parent.encodePayload(payload);
} catch (final Throwable t) {
this.parent.handleException(connection, t, future);
return future;
}
final TransactionStore transactionStore = ConnectionUtil.getTransactionStore(connection);
final int transactionId = transactionStore.nextId();
final Consumer<TransactionResult> resultConsumer = result -> {
if (result.isSuccess()) {
future.complete(result.getPayload());
} else {
this.parent.handleException(connection, result.getCause(), future);
}
};
final Packet<?> mcPacket = PacketUtil.createLoginPayloadRequest(this.parent.key(), buf, transactionId);
PacketSender.sendTo(connection, mcPacket, sendFuture -> {
if (sendFuture.isSuccess()) {
transactionStore.put(transactionId, this.parent, resultConsumer);
} else {
// The packet already failed before it could reach the client
future.completeExceptionally(sendFuture.cause());
}
});
return future;
}
Aggregations