Search in sources :

Example 1 with Callback

use of com.github.dirtpowered.dirtmv.data.interfaces.Callback in project DirtMultiversion by DirtPowered.

the class Client method createClient.

public void createClient(UUID key, Callback callback) {
    EventLoopGroup loopGroup = serverSession.getMain().getLoopGroup();
    Bootstrap clientBootstrap = new Bootstrap();
    clientBootstrap.group(loopGroup);
    clientBootstrap.channel(NioSocketChannel.class);
    clientBootstrap.option(ChannelOption.SO_KEEPALIVE, true);
    clientBootstrap.option(ChannelOption.TCP_NODELAY, true);
    Configuration c = serverSession.getMain().getConfiguration();
    clientBootstrap.remoteAddress(new InetSocketAddress(c.getRemoteServerAddress(), c.getRemoteServerPort()));
    clientBootstrap.handler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) {
            ch.pipeline().addLast(ChannelConstants.DEFAULT_PIPELINE, new PipelineFactory(serverSession.getMain(), serverSession.getUserData(), PacketDirection.TO_CLIENT));
            ch.pipeline().addLast(ChannelConstants.CLIENT_HANDLER, new ClientSession(serverSession.getMain(), key, serverSession, ch, callback));
        }
    });
    clientBootstrap.connect().addListener((ChannelFutureListener) channelFuture -> {
        if (!channelFuture.isSuccess()) {
            serverSession.disconnect(ChatUtils.LEGACY_COLOR_CHAR + "cUnable to connect to remote server");
            channelFuture.channel().close();
        }
    });
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) EventLoopGroup(io.netty.channel.EventLoopGroup) ChannelInitializer(io.netty.channel.ChannelInitializer) ChannelOption(io.netty.channel.ChannelOption) Configuration(com.github.dirtpowered.dirtmv.api.Configuration) ChatUtils(com.github.dirtpowered.dirtmv.data.utils.ChatUtils) UUID(java.util.UUID) InetSocketAddress(java.net.InetSocketAddress) PacketDirection(com.github.dirtpowered.dirtmv.data.translator.PacketDirection) PipelineFactory(com.github.dirtpowered.dirtmv.network.server.codec.PipelineFactory) Bootstrap(io.netty.bootstrap.Bootstrap) Callback(com.github.dirtpowered.dirtmv.data.interfaces.Callback) ChannelFutureListener(io.netty.channel.ChannelFutureListener) ServerSession(com.github.dirtpowered.dirtmv.network.server.ServerSession) ChannelConstants(com.github.dirtpowered.dirtmv.network.server.codec.ChannelConstants) SocketChannel(io.netty.channel.socket.SocketChannel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) EventLoopGroup(io.netty.channel.EventLoopGroup) Configuration(com.github.dirtpowered.dirtmv.api.Configuration) InetSocketAddress(java.net.InetSocketAddress) PipelineFactory(com.github.dirtpowered.dirtmv.network.server.codec.PipelineFactory) Bootstrap(io.netty.bootstrap.Bootstrap)

Aggregations

Configuration (com.github.dirtpowered.dirtmv.api.Configuration)1 Callback (com.github.dirtpowered.dirtmv.data.interfaces.Callback)1 PacketDirection (com.github.dirtpowered.dirtmv.data.translator.PacketDirection)1 ChatUtils (com.github.dirtpowered.dirtmv.data.utils.ChatUtils)1 ServerSession (com.github.dirtpowered.dirtmv.network.server.ServerSession)1 ChannelConstants (com.github.dirtpowered.dirtmv.network.server.codec.ChannelConstants)1 PipelineFactory (com.github.dirtpowered.dirtmv.network.server.codec.PipelineFactory)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 ChannelOption (io.netty.channel.ChannelOption)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 InetSocketAddress (java.net.InetSocketAddress)1 UUID (java.util.UUID)1