Search in sources :

Example 6 with NoResponseException

use of org.spongepowered.api.network.channel.NoResponseException in project SpongeCommon by SpongePowered.

the class ChannelTest method onConnectionHandshake.

@Listener
public void onConnectionHandshake(final ServerSideConnectionEvent.Handshake event) {
    this.plugin.logger().info("Starting handshake phase.");
    final PingPacket pingPacket1 = new PingPacket(123);
    final ServerSideConnection connection = event.connection();
    this.channel.sendTo(connection, pingPacket1).thenAccept(response1 -> {
        this.logReceived(this.channel, response1, connection);
        final PingPacket pingPacket2 = new PingPacket(456);
        this.channel.sendTo(connection, pingPacket2).thenAccept(response2 -> {
            this.logReceived(this.channel, response2, connection);
            this.channel.sendTo(connection, new PrintTextPacket("Finished handshake phase."));
            this.plugin.logger().info("Finished handshake phase.");
        }).exceptionally(cause -> {
            this.plugin.logger().error("Failed to get a response to {}", pingPacket2, cause);
            return null;
        });
    }).exceptionally(cause -> {
        this.plugin.logger().error("Failed to get a response to {}", pingPacket1, cause);
        return null;
    });
    final PingPacket basicPingPacket1 = new PingPacket(1123);
    this.basicChannel.handshake().sendTo(connection, basicPingPacket1).thenAccept(response1 -> {
        this.logReceived(this.basicChannel, response1, connection);
        final PingPacket basicPingPacket2 = new PingPacket(1456);
        this.basicChannel.handshake().sendTo(connection, basicPingPacket2).thenAccept(response2 -> {
            this.logReceived(this.channel, response2, connection);
            this.basicChannel.handshake().sendTo(connection, new PrintTextPacket("Finished handshake phase for basic channel."));
            this.plugin.logger().info("Finished handshake phase for basic channel.");
        }).exceptionally(cause -> {
            this.plugin.logger().error("Failed to get a response to {}", basicPingPacket2, cause);
            return null;
        });
    }).exceptionally(cause -> {
        this.plugin.logger().error("Failed to get a response to {}", pingPacket1, cause);
        return null;
    });
    this.rawChannel.handshake().sendTo(connection, buf -> buf.writeVarInt(200)).thenAccept(response -> this.logReceived(this.rawChannel, response.readVarInt(), connection)).exceptionally(cause -> {
        this.plugin.logger().error("Failed to get a response to raw 200 value", cause);
        return null;
    });
    this.rawChannel.handshake().sendTo(connection, buf -> buf.writeVarInt(0)).thenAccept(response -> this.logReceived(this.rawChannel, response.readVarInt(), connection)).exceptionally(cause -> {
        if (cause instanceof CompletionException) {
            cause = cause.getCause();
        }
        if (cause instanceof NoResponseException) {
            this.plugin.logger().error("Successfully received no response exception");
        } else {
            this.plugin.logger().error("Failed to get a response to raw 0 value", cause);
        }
        return null;
    });
}
Also used : Channel(org.spongepowered.api.network.channel.Channel) BasicPacketChannel(org.spongepowered.api.network.channel.packet.basic.BasicPacketChannel) Plugin(org.spongepowered.plugin.builtin.jvm.Plugin) ServerSideConnection(org.spongepowered.api.network.ServerSideConnection) ServerSideConnectionEvent(org.spongepowered.api.event.network.ServerSideConnectionEvent) Inject(com.google.inject.Inject) EngineConnection(org.spongepowered.api.network.EngineConnection) NoResponseException(org.spongepowered.api.network.channel.NoResponseException) EngineConnectionSide(org.spongepowered.api.network.EngineConnectionSide) CompletionException(java.util.concurrent.CompletionException) RawDataChannel(org.spongepowered.api.network.channel.raw.RawDataChannel) PluginContainer(org.spongepowered.plugin.PluginContainer) RegisterChannelEvent(org.spongepowered.api.event.lifecycle.RegisterChannelEvent) ResourceKey(org.spongepowered.api.ResourceKey) PacketChannel(org.spongepowered.api.network.channel.packet.PacketChannel) Listener(org.spongepowered.api.event.Listener) CompletionException(java.util.concurrent.CompletionException) ServerSideConnection(org.spongepowered.api.network.ServerSideConnection) NoResponseException(org.spongepowered.api.network.channel.NoResponseException) Listener(org.spongepowered.api.event.Listener)

Aggregations

NoResponseException (org.spongepowered.api.network.channel.NoResponseException)6 ResourceKey (org.spongepowered.api.ResourceKey)3 RawDataChannel (org.spongepowered.api.network.channel.raw.RawDataChannel)3 Listener (org.spongepowered.api.event.Listener)2 EngineConnection (org.spongepowered.api.network.EngineConnection)2 ChannelBuf (org.spongepowered.api.network.channel.ChannelBuf)2 Packet (org.spongepowered.api.network.channel.packet.Packet)2 PacketChannel (org.spongepowered.api.network.channel.packet.PacketChannel)2 RequestPacket (org.spongepowered.api.network.channel.packet.RequestPacket)2 BasicPacketChannel (org.spongepowered.api.network.channel.packet.basic.BasicPacketChannel)2 InetAddresses (com.google.common.net.InetAddresses)1 Inject (com.google.inject.Inject)1 GameProfile (com.mojang.authlib.GameProfile)1 Property (com.mojang.authlib.properties.Property)1 ByteBuf (io.netty.buffer.ByteBuf)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 StandardCharsets (java.nio.charset.StandardCharsets)1 InvalidKeyException (java.security.InvalidKeyException)1 MessageDigest (java.security.MessageDigest)1