Search in sources :

Example 1 with ListenerInfo

use of net.md_5.bungee.api.config.ListenerInfo in project Geyser by GeyserMC.

the class GeyserBungeeInjector method initializeLocalChannel0.

@Override
@SuppressWarnings("unchecked")
protected void initializeLocalChannel0(GeyserBootstrap bootstrap) throws Exception {
    // TODO - allow Geyser to specify its own listener info properties
    if (proxy.getConfig().getListeners().size() != 1) {
        throw new UnsupportedOperationException("Geyser does not currently support multiple listeners with injection! " + "Please reach out to us on our Discord at https://discord.gg/GeyserMC so we can hear feedback on your setup.");
    }
    ListenerInfo listenerInfo = proxy.getConfig().getListeners().stream().findFirst().orElseThrow(IllegalStateException::new);
    Class<? extends ProxyServer> proxyClass = proxy.getClass();
    // Using the specified EventLoop is required, or else an error will be thrown
    EventLoopGroup bossGroup;
    EventLoopGroup workerGroup;
    try {
        EventLoopGroup eventLoops = (EventLoopGroup) proxyClass.getField("eventLoops").get(proxy);
        // Netty redirects ServerBootstrap#group(EventLoopGroup) to #group(EventLoopGroup, EventLoopGroup) and uses the same event loop for both.
        bossGroup = eventLoops;
        workerGroup = eventLoops;
        bootstrap.getGeyserLogger().debug("BungeeCord event loop style detected.");
    } catch (NoSuchFieldException e) {
        // Waterfall uses two separate event loops
        // https://github.com/PaperMC/Waterfall/blob/fea7ec356dba6c6ac28819ff11be604af6eb484e/BungeeCord-Patches/0022-Use-a-worker-and-a-boss-event-loop-group.patch
        bossGroup = (EventLoopGroup) proxyClass.getField("bossEventLoopGroup").get(proxy);
        workerGroup = (EventLoopGroup) proxyClass.getField("workerEventLoopGroup").get(proxy);
        bootstrap.getGeyserLogger().debug("Waterfall event loop style detected.");
    }
    // Is currently just AttributeKey.valueOf("ListerInfo") but we might as well copy the value itself.
    AttributeKey<ListenerInfo> listener = PipelineUtils.LISTENER;
    listenerInfo = new ListenerInfo(listenerInfo.getSocketAddress(), listenerInfo.getMotd(), listenerInfo.getMaxPlayers(), listenerInfo.getTabListSize(), listenerInfo.getServerPriority(), listenerInfo.isForceDefault(), listenerInfo.getForcedHosts(), listenerInfo.getTabListType(), listenerInfo.isSetLocalAddress(), listenerInfo.isPingPassthrough(), listenerInfo.getQueryPort(), listenerInfo.isQueryEnabled(), // If Geyser is expecting HAProxy, so should the Bungee end
    bootstrap.getGeyserConfig().getRemote().isUseProxyProtocol());
    // The field that stores all listeners in BungeeCord
    // As of https://github.com/ViaVersion/ViaVersion/pull/2698 ViaVersion adds a wrapper to this field to
    // add its connections
    Field listenerField = proxyClass.getDeclaredField("listeners");
    listenerField.setAccessible(true);
    bungeeChannels = (Set<Channel>) listenerField.get(proxy);
    // This method is what initializes the connection in Java Edition, after Netty is all set.
    Method initChannel = ChannelInitializer.class.getDeclaredMethod("initChannel", Channel.class);
    initChannel.setAccessible(true);
    ChannelFuture channelFuture = (new ServerBootstrap().channel(LocalServerChannelWrapper.class).childHandler(new ChannelInitializer<>() {

        @Override
        protected void initChannel(Channel ch) throws Exception {
            if (proxy.getConfig().getServers() == null) {
                // Proxy hasn't finished loading all plugins - it loads the config after all plugins
                // Probably doesn't need to be translatable?
                bootstrap.getGeyserLogger().info("Disconnecting player as Bungee has not finished loading");
                ch.close();
                return;
            }
            if (channelInitializer == null) {
                // Proxy has finished initializing; we can safely grab this variable without fear of plugins modifying it
                // (Older versions of ViaVersion replace this to inject)
                channelInitializer = PipelineUtils.SERVER_CHILD;
            }
            initChannel.invoke(channelInitializer, ch);
        }
    }).childAttr(listener, listenerInfo).group(bossGroup, workerGroup).localAddress(LocalAddress.ANY)).bind().syncUninterruptibly();
    this.localChannel = channelFuture;
    this.bungeeChannels.add(this.localChannel.channel());
    this.serverSocketAddress = channelFuture.channel().localAddress();
    if (!this.eventRegistered) {
        // Register reload listener
        this.proxy.getPluginManager().registerListener(this.plugin, this);
        this.eventRegistered = true;
    }
    // Only affects Waterfall, but there is no sure way to differentiate between a proxy with this patch and a proxy without this patch
    // Patch causing the issue: https://github.com/PaperMC/Waterfall/blob/7e6af4cef64d5d377a6ffd00a534379e6efa94cf/BungeeCord-Patches/0045-Don-t-use-a-bytebuf-for-packet-decoding.patch
    // If native compression is enabled, then this line is tripped up if a heap buffer is sent over in such a situation
    // as a new direct buffer is not created with that patch (HeapByteBufs throw an UnsupportedOperationException here):
    // https://github.com/SpigotMC/BungeeCord/blob/a283aaf724d4c9a815540cd32f3aafaa72df9e05/native/src/main/java/net/md_5/bungee/jni/zlib/NativeZlib.java#L43
    // This issue could be mitigated down the line by preventing Bungee from setting compression
    LocalSession.createDirectByteBufAllocator();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Channel(io.netty.channel.Channel) Method(java.lang.reflect.Method) LocalServerChannelWrapper(org.geysermc.geyser.network.netty.LocalServerChannelWrapper) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) Field(java.lang.reflect.Field) ListenerInfo(net.md_5.bungee.api.config.ListenerInfo) EventLoopGroup(io.netty.channel.EventLoopGroup)

Example 2 with ListenerInfo

use of net.md_5.bungee.api.config.ListenerInfo in project BungeeServerManager by tavonkelly.

the class ServerManagerCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    if (args.length == 0) {
        sendHelp(sender);
        return;
    }
    if (args[0].equalsIgnoreCase("help")) {
        sendHelp(sender);
        return;
    }
    if (args[0].equalsIgnoreCase("list")) {
        if (ServerHelper.getServers().isEmpty()) {
            sender.sendMessage(TextComponent.fromLegacyText(prefix + "No servers."));
            return;
        }
        sender.sendMessage(TextComponent.fromLegacyText(prefix + "Servers: " + ChatColor.GREEN + Joiner.on(ChatColor.GRAY + ", " + ChatColor.GREEN).join(ServerHelper.getServers().keySet())));
        return;
    }
    if (args[0].equalsIgnoreCase("info")) {
        if (args.length < 2) {
            sendUsage(sender, "/svm info <server>");
            return;
        }
        if (!ServerHelper.serverExists(args[1])) {
            sender.sendMessage(TextComponent.fromLegacyText(prefix + "The server " + ChatColor.GREEN + args[1] + ChatColor.GRAY + " does not exist."));
            return;
        }
        ServerInfo info = ServerHelper.getServerInfo(args[1]);
        if (info == null) {
            sender.sendMessage(TextComponent.fromLegacyText(prefix + "The server " + ChatColor.GREEN + args[1] + ChatColor.GRAY + " does not exist."));
            return;
        }
        Set<String> forcedHosts = new HashSet<>();
        for (ListenerInfo listenerInfo : BungeeServerManager.get().getProxy().getConfig().getListeners()) {
            for (Map.Entry<String, String> entry : listenerInfo.getForcedHosts().entrySet()) {
                if (entry.getValue().equalsIgnoreCase(info.getName())) {
                    forcedHosts.add(entry.getKey());
                }
            }
        }
        sender.sendMessage(TextComponent.fromLegacyText(ChatColor.GRAY + "--- " + ChatColor.GREEN + info.getName() + " Info" + ChatColor.GRAY + " ---"));
        sender.sendMessage(TextComponent.fromLegacyText(ChatColor.GREEN + "Name: " + ChatColor.GRAY + info.getName()));
        sender.sendMessage(TextComponent.fromLegacyText(ChatColor.GREEN + "Address: " + ChatColor.GRAY + ConfigHelper.socketAddressToString(info.getSocketAddress())));
        sender.sendMessage(TextComponent.fromLegacyText(ChatColor.GREEN + "Motd: " + ChatColor.GRAY + info.getMotd()));
        sender.sendMessage(TextComponent.fromLegacyText(ChatColor.GREEN + "Restricted: " + ChatColor.GRAY + info.isRestricted()));
        sender.sendMessage(TextComponent.fromLegacyText(ChatColor.GREEN + "Player Count: " + ChatColor.GRAY + info.getPlayers().size()));
        if (!forcedHosts.isEmpty()) {
            sender.sendMessage(TextComponent.fromLegacyText(ChatColor.GREEN + "Forced Hosts: " + ChatColor.GRAY + Joiner.on(", ").join(forcedHosts)));
        }
        sender.sendMessage(TextComponent.fromLegacyText(ChatColor.GRAY + "--------"));
        return;
    }
    if (args[0].equalsIgnoreCase("add")) {
        if (args.length < 2) {
            sendUsage(sender, "/svm add <server> [hostname]");
            return;
        }
        if (ServerHelper.serverExists(args[1])) {
            sender.sendMessage(TextComponent.fromLegacyText(prefix + "The server " + ChatColor.GREEN + args[1] + ChatColor.GRAY + " already exists."));
            return;
        }
        SocketAddress address = new InetSocketAddress(22565);
        boolean customAddress = false;
        if (args.length >= 3) {
            address = getIp(args[2]);
            customAddress = true;
            if (address == null) {
                sender.sendMessage(TextComponent.fromLegacyText(prefix + "Invalid address " + ChatColor.GREEN + args[2] + ChatColor.GRAY + ". Here's an example: " + ChatColor.GREEN + "127.0.0.1:25565"));
                return;
            }
        }
        ServerInfo info = ProxyServer.getInstance().constructServerInfo(args[1], address, "", false);
        ServerAddEvent addEvent = new ServerAddEvent(info, sender);
        BungeeServerManager.get().getProxy().getPluginManager().callEvent(addEvent);
        if (addEvent.isCancelled()) {
            return;
        }
        ServerHelper.addServer(addEvent.getServerModified());
        sender.sendMessage(TextComponent.fromLegacyText(prefix + "Added a server with the name " + ChatColor.GREEN + addEvent.getServerModified().getName() + (customAddress ? " and address " + ChatColor.GREEN + args[2] + ChatColor.GREEN + "." : "")));
        return;
    }
    if (args[0].equalsIgnoreCase("remove")) {
        if (args.length < 2) {
            sendUsage(sender, "/svm remove <server>");
            return;
        }
        if (!ServerHelper.serverExists(args[1])) {
            sender.sendMessage(TextComponent.fromLegacyText(prefix + "The server " + ChatColor.GREEN + args[1] + ChatColor.GRAY + " does not exist."));
            return;
        }
        ServerRemoveEvent removeEvent = new ServerRemoveEvent(ServerHelper.getServerInfo(args[1]), sender);
        BungeeServerManager.get().getProxy().getPluginManager().callEvent(removeEvent);
        if (removeEvent.isCancelled()) {
            return;
        }
        ServerHelper.removeServer(removeEvent.getServerModified().getName());
        sender.sendMessage(TextComponent.fromLegacyText(prefix + "Removed the server " + ChatColor.GREEN + removeEvent.getServerModified().getName()));
        return;
    }
    if (args[0].equalsIgnoreCase("edit")) {
        if (args.length < 2) {
            sendUsage(sender, "/svm edit <server>");
            return;
        }
        ServerInfo info = ServerHelper.getServerInfo(args[1]);
        if (info == null) {
            sender.sendMessage(TextComponent.fromLegacyText(prefix + "The server " + ChatColor.GREEN + args[1] + ChatColor.GRAY + " does not exist."));
            return;
        }
        if (args.length == 2) {
            sendEditMenu(sender, info.getName());
            return;
        }
        if (args[2].equalsIgnoreCase("name")) {
            if (args.length < 4) {
                sendUsage(sender, "/svm edit " + info.getName() + " name <name>");
                return;
            }
            ServerModifiedEvent<String> modifiedEvent = new ServerModifiedEvent<>(info, sender, ServerModifiedEvent.ServerField.NAME, args[3]);
            BungeeServerManager.get().getProxy().getPluginManager().callEvent(modifiedEvent);
            if (modifiedEvent.isCancelled()) {
                return;
            }
            info = modifiedEvent.getServerModified();
            ServerHelper.removeServer(info.getName());
            ServerHelper.addServer(ProxyServer.getInstance().constructServerInfo(modifiedEvent.getNewValue(), info.getSocketAddress(), info.getMotd(), false));
            sender.sendMessage(TextComponent.fromLegacyText(prefix + "Renamed " + ChatColor.GREEN + info.getName() + ChatColor.GRAY + " to " + ChatColor.GREEN + modifiedEvent.getNewValue() + ChatColor.GRAY + "."));
            return;
        }
        if (args[2].equalsIgnoreCase("ip")) {
            if (args.length < 4) {
                sendUsage(sender, "/svm edit " + info.getName() + " ip <hostname>");
                return;
            }
            SocketAddress address = getIp(args[3]);
            if (address == null) {
                sender.sendMessage(TextComponent.fromLegacyText(prefix + "Invalid address " + ChatColor.GREEN + args[3] + ChatColor.GRAY + ". Here's an example: " + ChatColor.GREEN + "127.0.0.1:25565"));
                return;
            }
            ServerModifiedEvent<SocketAddress> modifiedEvent = new ServerModifiedEvent<>(ServerHelper.getServerInfo(args[1]), sender, ServerModifiedEvent.ServerField.IP, address);
            BungeeServerManager.get().getProxy().getPluginManager().callEvent(modifiedEvent);
            if (modifiedEvent.isCancelled()) {
                return;
            }
            info = modifiedEvent.getServerModified();
            ServerHelper.removeServer(info.getName());
            ServerHelper.addServer(ProxyServer.getInstance().constructServerInfo(info.getName(), modifiedEvent.getNewValue(), info.getMotd(), false));
            sender.sendMessage(TextComponent.fromLegacyText(prefix + "Set the address of " + ChatColor.GREEN + info.getName() + ChatColor.GRAY + " to " + ChatColor.GREEN + args[3] + ChatColor.GRAY + "."));
            return;
        }
        if (args[2].equalsIgnoreCase("motd")) {
            if (args.length < 4) {
                sendUsage(sender, "/svm edit " + info.getName() + " motd <motd>");
                return;
            }
            StringBuilder builder = new StringBuilder();
            for (int i = 3; i < args.length; i++) {
                builder.append(args[i]).append(" ");
            }
            ServerModifiedEvent<String> modifiedEvent = new ServerModifiedEvent<>(info, sender, ServerModifiedEvent.ServerField.MOTD, ChatColor.translateAlternateColorCodes('&', builder.toString().trim()));
            BungeeServerManager.get().getProxy().getPluginManager().callEvent(modifiedEvent);
            if (modifiedEvent.isCancelled()) {
                return;
            }
            info = modifiedEvent.getServerModified();
            ServerHelper.removeServer(info.getName());
            ServerHelper.addServer(ProxyServer.getInstance().constructServerInfo(info.getName(), info.getSocketAddress(), modifiedEvent.getNewValue(), false));
            sender.sendMessage(TextComponent.fromLegacyText(prefix + "Set the motd of " + ChatColor.GREEN + info.getName() + ChatColor.GRAY + " to " + ChatColor.GREEN + ChatColor.translateAlternateColorCodes('&', builder.toString().trim()) + ChatColor.GRAY + "."));
            return;
        }
        if (args[2].equalsIgnoreCase("restricted")) {
            if (args.length < 4) {
                sendUsage(sender, "/svm edit " + info.getName() + " restricted <true|false>");
                return;
            }
            ServerModifiedEvent<Boolean> modifiedEvent = new ServerModifiedEvent<>(info, sender, ServerModifiedEvent.ServerField.RESTRICTED, Boolean.parseBoolean(args[3]));
            BungeeServerManager.get().getProxy().getPluginManager().callEvent(modifiedEvent);
            if (modifiedEvent.isCancelled()) {
                return;
            }
            info = modifiedEvent.getServerModified();
            ServerHelper.removeServer(info.getName());
            ServerHelper.addServer(ProxyServer.getInstance().constructServerInfo(info.getName(), info.getSocketAddress(), info.getMotd(), modifiedEvent.getNewValue()));
            sender.sendMessage(TextComponent.fromLegacyText(prefix + "Set the restriction of " + ChatColor.GREEN + info.getName() + ChatColor.GRAY + " to " + ChatColor.GREEN + Boolean.parseBoolean(args[3]) + ChatColor.GRAY + "."));
            return;
        }
        if (args[2].equalsIgnoreCase("domain")) {
            if (args.length < 5 || (!args[3].equalsIgnoreCase("add") && !args[3].equalsIgnoreCase("remove"))) {
                sendUsage(sender, "/svm edit " + info.getName() + " domain <add|remove> <domain>");
                return;
            }
            boolean addingDomain = args[3].equalsIgnoreCase("add");
            final SocketAddress address = getIp(args[4]);
            if (address == null) {
                sender.sendMessage(TextComponent.fromLegacyText(prefix + "Invalid address " + ChatColor.GREEN + args[4] + ChatColor.GRAY + ". Here's an example: " + ChatColor.GREEN + "pvp.md-5.net"));
                return;
            }
            String socketAddressStr = ConfigHelper.socketAddressToString(address, false);
            if (addingDomain) {
                ConfigHelper.addForcedHost(address, info);
                for (ListenerInfo listenerInfo : BungeeServerManager.get().getProxy().getConfig().getListeners()) {
                    listenerInfo.getForcedHosts().put(socketAddressStr, info.getName());
                }
                sender.sendMessage(TextComponent.fromLegacyText(prefix + "Added forced host of " + ChatColor.GREEN + socketAddressStr + " " + ChatColor.GRAY + " for server " + ChatColor.GREEN + info.getName() + " " + ChatColor.GRAY + "."));
            } else {
                boolean found = false;
                ConfigHelper.removeForcedHost(address, info);
                for (ListenerInfo listenerInfo : BungeeServerManager.get().getProxy().getConfig().getListeners()) {
                    String targetServer = listenerInfo.getForcedHosts().get(socketAddressStr);
                    if (targetServer != null && targetServer.equalsIgnoreCase(info.getName())) {
                        listenerInfo.getForcedHosts().remove(socketAddressStr);
                        found = true;
                    }
                }
                if (found) {
                    sender.sendMessage(TextComponent.fromLegacyText(prefix + "Removed forced host of " + ChatColor.GREEN + socketAddressStr + " " + ChatColor.GRAY + " for server " + ChatColor.GREEN + info.getName() + " " + ChatColor.GRAY + "."));
                } else {
                    sender.sendMessage(TextComponent.fromLegacyText(prefix + "Could not find forced host of " + ChatColor.GREEN + socketAddressStr + " " + ChatColor.GRAY + " for server " + ChatColor.GREEN + info.getName() + " " + ChatColor.GRAY + "."));
                }
            }
            return;
        }
        sender.sendMessage(TextComponent.fromLegacyText(prefix + "Unknown argument " + ChatColor.GREEN + args[2] + ChatColor.GRAY + " use " + ChatColor.GREEN + "/svm edit " + info.getName() + ChatColor.GRAY + " for help."));
        return;
    }
    sender.sendMessage(TextComponent.fromLegacyText(prefix + "Unknown argument " + ChatColor.GREEN + args[0] + ChatColor.GRAY + " use " + ChatColor.GREEN + "/svm help" + ChatColor.GRAY + " for help."));
}
Also used : ServerInfo(net.md_5.bungee.api.config.ServerInfo) InetSocketAddress(java.net.InetSocketAddress) ServerAddEvent(pw.teg.bsm.api.events.ServerAddEvent) ServerRemoveEvent(pw.teg.bsm.api.events.ServerRemoveEvent) ServerModifiedEvent(pw.teg.bsm.api.events.ServerModifiedEvent) ListenerInfo(net.md_5.bungee.api.config.ListenerInfo) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress)

Example 3 with ListenerInfo

use of net.md_5.bungee.api.config.ListenerInfo in project SubServers-2 by ME1312.

the class PacketDownloadPlatformInfo method send.

@Override
public ObjectMap<Integer> send(SubDataClient client) {
    ObjectMap<Integer> data = new ObjectMap<Integer>();
    if (tracker != null)
        data.set(0x0000, tracker);
    ObjectMap<String> info = new ObjectMap<String>();
    ObjectMap<String> subservers = new ObjectMap<String>();
    subservers.set("version", plugin.api.getWrapperVersion().toString());
    if (plugin.api.getWrapperBuild() != null)
        subservers.set("build", plugin.api.getWrapperBuild().toString());
    subservers.set("last-reload", plugin.resetDate);
    subservers.set("proxies", plugin.api.getProxies().size());
    subservers.set("hosts", plugin.api.getHosts().size());
    subservers.set("subservers", plugin.api.getSubServers().size());
    info.set("subservers", subservers);
    ObjectMap<String> bungee = new ObjectMap<String>();
    bungee.set("version", plugin.api.getProxyVersion().toString());
    bungee.set("disabled-cmds", plugin.getConfig().getDisabledCommands());
    bungee.set("player-limit", plugin.getConfig().getPlayerLimit());
    bungee.set("servers", plugin.api.getServers().size());
    LinkedList<ObjectMap<String>> listeners = new LinkedList<ObjectMap<String>>();
    for (ListenerInfo next : plugin.getConfig().getListeners()) {
        ObjectMap<String> listener = new ObjectMap<String>();
        listener.set("forced-hosts", next.getForcedHosts());
        listener.set("motd", next.getMotd());
        listener.set("priorities", next.getServerPriority());
        listener.set("player-limit", next.getMaxPlayers());
        listeners.add(listener);
    }
    bungee.set("listeners", listeners);
    info.set("bungee", bungee);
    ObjectMap<String> minecraft = new ObjectMap<String>();
    LinkedList<String> mcversions = new LinkedList<String>();
    for (Version version : plugin.api.getGameVersion()) mcversions.add(version.toString());
    minecraft.set("version", mcversions);
    minecraft.set("players", plugin.api.getRemotePlayers().size());
    info.set("minecraft", minecraft);
    ObjectMap<String> system = new ObjectMap<String>();
    ObjectMap<String> os = new ObjectMap<String>();
    os.set("name", System.getProperty("os.name"));
    os.set("version", System.getProperty("os.version"));
    system.set("os", os);
    ObjectMap<String> java = new ObjectMap<String>();
    java.set("version", System.getProperty("java.version"));
    system.set("java", java);
    info.set("system", system);
    data.set(0x0001, info);
    return data;
}
Also used : ListenerInfo(net.md_5.bungee.api.config.ListenerInfo) ObjectMap(net.ME1312.Galaxi.Library.Map.ObjectMap) Version(net.ME1312.Galaxi.Library.Version.Version) LinkedList(java.util.LinkedList)

Example 4 with ListenerInfo

use of net.md_5.bungee.api.config.ListenerInfo in project BungeeCord by SpigotMC.

the class Configuration method load.

public void load() {
    ConfigurationAdapter adapter = ProxyServer.getInstance().getConfigurationAdapter();
    adapter.load();
    File fav = new File("server-icon.png");
    if (fav.exists()) {
        try {
            favicon = Favicon.create(ImageIO.read(fav));
        } catch (IOException | IllegalArgumentException ex) {
            ProxyServer.getInstance().getLogger().log(Level.WARNING, "Could not load server icon", ex);
        }
    }
    listeners = adapter.getListeners();
    timeout = adapter.getInt("timeout", timeout);
    uuid = adapter.getString("stats", uuid);
    onlineMode = adapter.getBoolean("online_mode", onlineMode);
    logCommands = adapter.getBoolean("log_commands", logCommands);
    logPings = adapter.getBoolean("log_pings", logPings);
    remotePingCache = adapter.getInt("remote_ping_cache", remotePingCache);
    playerLimit = adapter.getInt("player_limit", playerLimit);
    serverConnectTimeout = adapter.getInt("server_connect_timeout", serverConnectTimeout);
    remotePingTimeout = adapter.getInt("remote_ping_timeout", remotePingTimeout);
    throttle = adapter.getInt("connection_throttle", throttle);
    throttleLimit = adapter.getInt("connection_throttle_limit", throttleLimit);
    ipForward = adapter.getBoolean("ip_forward", ipForward);
    compressionThreshold = adapter.getInt("network_compression_threshold", compressionThreshold);
    preventProxyConnections = adapter.getBoolean("prevent_proxy_connections", preventProxyConnections);
    forgeSupport = adapter.getBoolean("forge_support", forgeSupport);
    disabledCommands = new CaseInsensitiveSet((Collection<String>) adapter.getList("disabled_commands", Arrays.asList("disabledcommandhere")));
    Preconditions.checkArgument(listeners != null && !listeners.isEmpty(), "No listeners defined.");
    Map<String, ServerInfo> newServers = adapter.getServers();
    Preconditions.checkArgument(newServers != null && !newServers.isEmpty(), "No servers defined");
    if (servers == null) {
        servers = new CaseInsensitiveMap<>(newServers);
    } else {
        for (ServerInfo oldServer : servers.values()) {
            // Don't allow servers to be removed
            Preconditions.checkArgument(newServers.containsKey(oldServer.getName()), "Server %s removed on reload!", oldServer.getName());
        }
        // Add new servers
        for (Map.Entry<String, ServerInfo> newServer : newServers.entrySet()) {
            if (!servers.containsValue(newServer.getValue())) {
                servers.put(newServer.getKey(), newServer.getValue());
            }
        }
    }
    for (ListenerInfo listener : listeners) {
        for (int i = 0; i < listener.getServerPriority().size(); i++) {
            String server = listener.getServerPriority().get(i);
            Preconditions.checkArgument(servers.containsKey(server), "Server %s (priority %s) is not defined", server, i);
        }
        for (String server : listener.getForcedHosts().values()) {
            if (!servers.containsKey(server)) {
                ProxyServer.getInstance().getLogger().log(Level.WARNING, "Forced host server {0} is not defined", server);
            }
        }
    }
}
Also used : ServerInfo(net.md_5.bungee.api.config.ServerInfo) CaseInsensitiveSet(net.md_5.bungee.util.CaseInsensitiveSet) IOException(java.io.IOException) ListenerInfo(net.md_5.bungee.api.config.ListenerInfo) ConfigurationAdapter(net.md_5.bungee.api.config.ConfigurationAdapter) Collection(java.util.Collection) File(java.io.File) TMap(gnu.trove.map.TMap) Map(java.util.Map) CaseInsensitiveMap(net.md_5.bungee.util.CaseInsensitiveMap)

Example 5 with ListenerInfo

use of net.md_5.bungee.api.config.ListenerInfo 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

ListenerInfo (net.md_5.bungee.api.config.ListenerInfo)14 ObjectMap (net.ME1312.Galaxi.Library.Map.ObjectMap)4 ServerInfo (net.md_5.bungee.api.config.ServerInfo)4 File (java.io.File)3 IOException (java.io.IOException)3 InetSocketAddress (java.net.InetSocketAddress)3 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)2 ChannelFuture (io.netty.channel.ChannelFuture)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 SocketAddress (java.net.SocketAddress)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 Version (net.ME1312.Galaxi.Library.Version.Version)2 SubDataClient (net.ME1312.SubData.Client.SubDataClient)2 CachedPlayer (net.ME1312.SubServers.Sync.Server.CachedPlayer)2 ServerImpl (net.ME1312.SubServers.Sync.Server.ServerImpl)2 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)2 CommandCloud (de.dytanic.cloudnet.bridge.internal.command.proxied.CommandCloud)1