use of org.spongepowered.api.network.channel.NoResponseException 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.api.network.channel.NoResponseException in project SpongeCommon by SpongePowered.
the class SpongePacketChannel method handleTransactionResponse.
@Override
protected void handleTransactionResponse(final EngineConnection connection, final Object stored, final TransactionResult result) {
if (result.isSuccess()) {
final ChannelBuf payload = result.getPayload();
final long typeAndValue = payload.readVarLong();
final int type = SpongePacketChannel.extractType(typeAndValue);
final int value = SpongePacketChannel.extractValue(typeAndValue);
if (type == SpongePacketChannel.TYPE_RESPONSE || type == SpongePacketChannel.TYPE_NO_RESPONSE || type == SpongePacketChannel.TYPE_DYNAMIC_RESPONSE) {
final TransactionData<RequestPacket<Packet>, Packet> transactionData = (TransactionData<RequestPacket<Packet>, Packet>) stored;
if (type == SpongePacketChannel.TYPE_RESPONSE) {
this.handleTransactionResponse(connection, transactionData, result, SpongePacketChannel.NO_DYNAMIC_OPCODE);
} else if (type == SpongePacketChannel.TYPE_NO_RESPONSE) {
this.handleTransactionResponse(connection, transactionData, TransactionResult.failure(new NoResponseException()), SpongePacketChannel.NO_DYNAMIC_OPCODE);
} else {
this.handleTransactionResponse(connection, transactionData, result, value);
}
} else {
this.handleException(connection, new ChannelIOException("Unknown packet type: " + type), null);
}
}
}
use of org.spongepowered.api.network.channel.NoResponseException in project SpongeCommon by SpongePowered.
the class VelocityForwardingInfo method sendQuery.
public static void sendQuery(final ServerLoginPacketListenerImpl mcConn) {
final EngineConnection conn = (EngineConnection) mcConn;
VelocityChannel.CHANNEL.sendTo(conn, cbuf -> {
}).whenComplete((response, error) -> {
if (error != null) {
if (error instanceof NoResponseException) {
conn.close(Component.text("This server requires you to connect with Velocity."));
}
return;
}
if (!VelocityForwardingInfo.checkIntegrity(response)) {
conn.close(Component.text("Unable to verify player details. Is your forwarding secret correct?"));
return;
}
final ConnectionAccessor connectionAccessor = (ConnectionAccessor) mcConn.getConnection();
connectionAccessor.accessor$address(new InetSocketAddress(VelocityForwardingInfo.readAddress(response), ((InetSocketAddress) mcConn.getConnection().getRemoteAddress()).getPort()));
((ServerLoginPacketListenerImplAccessor) mcConn).accessor$gameProfile(VelocityForwardingInfo.createProfile(response));
}).exceptionally(err -> {
if (!(err instanceof NoResponseException)) {
// Handled above
VelocityForwardingInfo.LOGGER.error("Failed to process velocity forwarding info", err);
conn.close(Component.text("Invalid forwarding information received!"));
}
return null;
});
}
use of org.spongepowered.api.network.channel.NoResponseException in project SpongeCommon by SpongePowered.
the class SpongeChannelManager method handleLoginResponsePayload.
private void handleLoginResponsePayload(final EngineConnection connection, final int transactionId, @Nullable final ChannelBuf payload) {
// Sponge magic... Allows normal packets to be send during the login phase from the client to server
if (transactionId == Constants.Channels.LOGIN_PAYLOAD_IGNORED_TRANSACTION_ID) {
return;
}
if (transactionId == Constants.Channels.LOGIN_PAYLOAD_TRANSACTION_ID) {
if (payload != null) {
final ResourceKey channelKey = ResourceKey.resolve(payload.readString());
this.handlePlayPayload(connection, channelKey, payload);
}
return;
}
// Normal handling
final TransactionStore transactionStore = ConnectionUtil.getTransactionStore(connection);
final TransactionStore.Entry entry = transactionStore.remove(transactionId);
if (entry == null) {
return;
}
if (entry.getData() instanceof ClientTypeSyncFuture) {
if (payload != null) {
this.handleClientType(connection, payload);
}
((ClientTypeSyncFuture) entry.getData()).future.complete(null);
return;
}
if (entry.getData() instanceof ChannelRegistrySyncFuture) {
if (payload != null) {
this.handleChannelRegistry(connection, payload);
}
((ChannelRegistrySyncFuture) entry.getData()).future.complete(null);
return;
}
final TransactionResult result = payload == null ? TransactionResult.failure(new NoResponseException()) : TransactionResult.success(payload);
entry.getChannel().handleTransactionResponse(connection, entry.getData(), result);
}
use of org.spongepowered.api.network.channel.NoResponseException in project SpongeCommon by SpongePowered.
the class ChannelTest method onRegisterChannel.
@Listener
public void onRegisterChannel(final RegisterChannelEvent event) {
this.channel = event.register(ResourceKey.of("channeltest", "default"), PacketChannel.class);
this.channel.register(PrintTextPacket.class, 0).addHandler((packet, connection) -> {
this.logReceived(this.channel, packet, connection);
this.plugin.logger().info(packet.getText());
});
this.channel.registerTransactional(PingPacket.class, PongPacket.class, 1).setRequestHandler((requestPacket, connection, response) -> {
this.logReceived(this.channel, requestPacket, connection);
response.success(new PongPacket(requestPacket.getId()));
});
this.basicChannel = event.register(ResourceKey.of("channeltest", "basic"), BasicPacketChannel.class);
this.basicChannel.register(PrintTextPacket.class, 0).addHandler((packet, connection) -> {
this.logReceived(this.basicChannel, packet, connection);
this.plugin.logger().info(packet.getText());
});
this.basicChannel.registerTransactional(PingPacket.class, PongPacket.class, 1).setRequestHandler((requestPacket, connection, response) -> {
this.logReceived(this.basicChannel, requestPacket, connection);
response.success(new PongPacket(requestPacket.getId()));
});
this.rawChannel = event.register(ResourceKey.of("channeltest", "raw"), RawDataChannel.class);
this.rawChannel.handshake().setRequestHandler((request, connection, response) -> {
final int value = request.readVarInt();
this.logReceived(this.rawChannel, value, connection);
if (value == 0) {
response.fail(new NoResponseException());
} else {
response.success(buf -> buf.writeVarInt(value * 2));
}
});
}
Aggregations