Search in sources :

Example 1 with RemoteQuery

use of net.md_5.bungee.query.RemoteQuery in project BungeeCord by SpigotMC.

the class BungeeCord method startListeners.

public void startListeners() {
    for (final ListenerInfo info : config.getListeners()) {
        if (info.isProxyProtocol()) {
            getLogger().log(Level.WARNING, "Using PROXY protocol for listener {0}, please ensure this listener is adequately firewalled.", info.getSocketAddress());
            if (connectionThrottle != null) {
                connectionThrottle = null;
                getLogger().log(Level.WARNING, "Since PROXY protocol is in use, internal connection throttle has been disabled.");
            }
        }
        ChannelFutureListener listener = new ChannelFutureListener() {

            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                if (future.isSuccess()) {
                    listeners.add(future.channel());
                    getLogger().log(Level.INFO, "Listening on {0}", info.getSocketAddress());
                } else {
                    getLogger().log(Level.WARNING, "Could not bind to host " + info.getSocketAddress(), future.cause());
                }
            }
        };
        new ServerBootstrap().channel(PipelineUtils.getServerChannel(info.getSocketAddress())).option(ChannelOption.SO_REUSEADDR, // TODO: Move this elsewhere!
        true).childAttr(PipelineUtils.LISTENER, info).childHandler(PipelineUtils.SERVER_CHILD).group(eventLoops).localAddress(info.getSocketAddress()).bind().addListener(listener);
        if (info.isQueryEnabled()) {
            Preconditions.checkArgument(info.getSocketAddress() instanceof InetSocketAddress, "Can only create query listener on UDP address");
            ChannelFutureListener bindListener = new ChannelFutureListener() {

                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    if (future.isSuccess()) {
                        listeners.add(future.channel());
                        getLogger().log(Level.INFO, "Started query on {0}", future.channel().localAddress());
                    } else {
                        getLogger().log(Level.WARNING, "Could not bind to host " + info.getSocketAddress(), future.cause());
                    }
                }
            };
            new RemoteQuery(this, info).start(PipelineUtils.getDatagramChannel(), new InetSocketAddress(info.getHost().getAddress(), info.getQueryPort()), eventLoops, bindListener);
        }
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ListenerInfo(net.md_5.bungee.api.config.ListenerInfo) InetSocketAddress(java.net.InetSocketAddress) RemoteQuery(net.md_5.bungee.query.RemoteQuery) ChannelFutureListener(io.netty.channel.ChannelFutureListener) ServerBootstrap(io.netty.bootstrap.ServerBootstrap)

Aggregations

ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelFutureListener (io.netty.channel.ChannelFutureListener)1 InetSocketAddress (java.net.InetSocketAddress)1 ListenerInfo (net.md_5.bungee.api.config.ListenerInfo)1 RemoteQuery (net.md_5.bungee.query.RemoteQuery)1