Search in sources :

Example 1 with ProxyGroup

use of de.dytanic.cloudnet.lib.server.ProxyGroup in project CloudNet by Dytanic.

the class CommandReload method onExecuteCommand.

@Override
public void onExecuteCommand(CommandSender sender, String[] args) {
    switch(args.length) {
        case 1:
            if (args[0].equalsIgnoreCase("all")) {
                sender.sendMessage("[RELOAD] Trying to reload CloudNet...");
                try {
                    CloudNet.getInstance().reload();
                    sender.sendMessage("[RELOAD] Reloading was completed successfully!");
                } catch (Exception e) {
                    sender.sendMessage("[RELOAD] Failed to reload CloudNet");
                    e.printStackTrace();
                }
                return;
            }
            if (args[0].equalsIgnoreCase("config")) {
                sender.sendMessage("[RELOAD] Trying to reload config");
                try {
                    CloudNet.getInstance().getConfig().load();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                CloudNet.getInstance().getServerGroups().clear();
                CloudNet.getInstance().getProxyGroups().clear();
                CloudNet.getInstance().getUsers().clear();
                CloudNet.getInstance().getUsers().addAll(CloudNet.getInstance().getConfig().getUsers());
                NetworkUtils.addAll(CloudNet.getInstance().getServerGroups(), CloudNet.getInstance().getConfig().getServerGroups(), new Acceptable<ServerGroup>() {

                    @Override
                    public boolean isAccepted(ServerGroup value) {
                        System.out.println("Loading ServerGroup: " + value.getName());
                        CloudNet.getInstance().setupGroup(value);
                        return true;
                    }
                });
                NetworkUtils.addAll(CloudNet.getInstance().getProxyGroups(), CloudNet.getInstance().getConfig().getProxyGroups(), new Acceptable<ProxyGroup>() {

                    public boolean isAccepted(ProxyGroup value) {
                        System.out.println("Loading ProxyGroup: " + value.getName());
                        CloudNet.getInstance().setupProxy(value);
                        return true;
                    }
                });
                CloudNet.getInstance().getNetworkManager().reload();
                CloudNet.getInstance().getNetworkManager().updateAll();
                CloudNet.getInstance().getWrappers().values().forEach(new Consumer<Wrapper>() {

                    @Override
                    public void accept(Wrapper wrapper) {
                        wrapper.updateWrapper();
                    }
                });
                sender.sendMessage("[RELOAD] Reloading was completed successfully");
            }
            if (args[0].equalsIgnoreCase("wrapper")) {
                for (Wrapper wrapper : CloudNet.getInstance().getWrappers().values()) {
                    if (wrapper.getChannel() != null)
                        wrapper.writeCommand("reload");
                }
            }
            break;
        default:
            sender.sendMessage("reload ALL | Loads all groups as well as modules, permissions, etc.", "reload CONFIG | Reload the configuration file, and its server groups etc.", "reload WRAPPER | Dispatched on all wrappers the command \"reload\"");
            break;
    }
}
Also used : Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup)

Example 2 with ProxyGroup

use of de.dytanic.cloudnet.lib.server.ProxyGroup in project CloudNet by Dytanic.

the class PacketInUpdateServerGroup method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    ServerGroup proxyGroup = data.getObject("group", new TypeToken<ServerGroup>() {
    }.getType());
    CloudNet.getInstance().getConfig().createGroup(proxyGroup);
    try {
        CloudNet.getInstance().getConfig().load();
    } catch (Exception e) {
        e.printStackTrace();
    }
    CloudNet.getInstance().getServerGroups().clear();
    CloudNet.getInstance().getProxyGroups().clear();
    NetworkUtils.addAll(CloudNet.getInstance().getServerGroups(), CloudNet.getInstance().getConfig().getServerGroups(), new Acceptable<ServerGroup>() {

        @Override
        public boolean isAccepted(ServerGroup value) {
            System.out.println("Loading server group: " + value.getName());
            return true;
        }
    });
    NetworkUtils.addAll(CloudNet.getInstance().getProxyGroups(), CloudNet.getInstance().getConfig().getProxyGroups(), new Acceptable<ProxyGroup>() {

        @Override
        public boolean isAccepted(ProxyGroup value) {
            System.out.println("Loading proxy group: " + value.getName());
            return true;
        }
    });
    CloudNet.getInstance().getNetworkManager().reload();
    CloudNet.getInstance().getNetworkManager().updateAll0();
    CloudNet.getInstance().getWrappers().values().forEach(new Consumer<Wrapper>() {

        @Override
        public void accept(Wrapper wrapper) {
            wrapper.updateWrapper();
        }
    });
}
Also used : Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) TypeToken(com.google.gson.reflect.TypeToken)

Example 3 with ProxyGroup

use of de.dytanic.cloudnet.lib.server.ProxyGroup in project CloudNet by Dytanic.

the class UtilExample method toDo.

public void toDo() {
    // Returns the OnlineCount
    CloudAPI.getInstance().getOnlineCount();
    /*===========================*/
    // Returns a proxygroup
    ProxyGroup proxyGroup = CloudAPI.getInstance().getProxyGroupData("Bungee");
    proxyGroup.getWrapper().add("Second-Wrapper");
    // update a proxy group
    CloudAPI.getInstance().updateProxyGroup(proxyGroup);
    // Returns from the CloudNet synchronized the server group objective
    ServerGroup serverGroup = CloudAPI.getInstance().getServerGroup("Lobby");
    serverGroup.setMaintenance(true);
    // update the server group
    CloudAPI.getInstance().updateServerGroup(serverGroup);
    // Returns a cached server group
    SimpleServerGroup simpleServerGroup = CloudAPI.getInstance().getServerGroupData("Lobby");
    if (simpleServerGroup.isMaintenance()) {
        System.out.println("Is a maintenance group");
    }
    // start a simple game server
    CloudAPI.getInstance().startGameServer(CloudAPI.getInstance().getServerGroupData("Lobby"));
}
Also used : ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) SimpleServerGroup(de.dytanic.cloudnet.lib.server.SimpleServerGroup) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) SimpleServerGroup(de.dytanic.cloudnet.lib.server.SimpleServerGroup)

Example 4 with ProxyGroup

use of de.dytanic.cloudnet.lib.server.ProxyGroup in project CloudNet by Dytanic.

the class PacketInCreateTemplate method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    if (data.getString("type").equals(DefaultType.BUKKIT.name())) {
        ServerGroup serverGroup = data.getObject("serverGroup", new TypeToken<ServerGroup>() {
        }.getType());
        try {
            for (Template template : serverGroup.getTemplates()) {
                if (!Files.exists(Paths.get("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName()))) {
                    System.out.println("Creating GroupTemplate for " + serverGroup.getName() + " " + template.getName() + "...");
                    Files.createDirectories(Paths.get("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + ""));
                }
                if (!Files.exists(Paths.get("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/server.properties"))) {
                    FileCopy.insertData("files/server.properties", "local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/server.properties");
                }
                if (!Files.exists(Paths.get("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/plugins"))) {
                    new File("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/plugins").mkdir();
                }
            }
            Template template = serverGroup.getGlobalTemplate();
            if (!Files.exists(Paths.get("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName()))) {
                System.out.println("Creating GroupTemplate for " + serverGroup.getName() + " " + template.getName() + "...");
                Files.createDirectories(Paths.get("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + ""));
            }
            if (!Files.exists(Paths.get("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/server.properties"))) {
                FileCopy.insertData("files/server.properties", "local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/server.properties");
            }
            if (!Files.exists(Paths.get("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/plugins"))) {
                new File("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/plugins").mkdir();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (serverGroup.getServerType().equals(ServerGroupType.CAULDRON)) {
            for (Template template : serverGroup.getTemplates()) {
                if (!Files.exists(Paths.get("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/cauldron.jar"))) {
                    try {
                        System.out.println("Downloading cauldron.zip...");
                        File file = new File("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/cauldron.zip");
                        URLConnection connection = new URL("https://yivesmirror.com/files/cauldron/cauldron-1.7.10-2.1403.1.54.zip").openConnection();
                        connection.setUseCaches(false);
                        connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
                        connection.connect();
                        Files.copy(connection.getInputStream(), Paths.get("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/cauldron.zip"));
                        System.out.println("Downloading Complete!");
                        ZipFile zip = new ZipFile(file);
                        Enumeration<? extends ZipEntry> entryEnumeration = zip.entries();
                        while (entryEnumeration.hasMoreElements()) {
                            ZipEntry entry = entryEnumeration.nextElement();
                            if (!entry.isDirectory()) {
                                extractEntry(zip, entry, "local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName());
                            }
                        }
                        zip.close();
                        file.delete();
                        new File("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/cauldron-1.7.10-2.1403.1.54-server.jar").renameTo(new File("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/cauldron.jar"));
                        System.out.println("Using a cauldron.jar for your minecraft service template " + serverGroup.getName() + ", please copy a eula.txt into the template or into the global folder");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            Template template = serverGroup.getGlobalTemplate();
            if (!Files.exists(Paths.get("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/cauldron.jar"))) {
                try {
                    System.out.println("Downloading cauldron.zip...");
                    File file = new File("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/cauldron.zip");
                    URLConnection connection = new URL("https://yivesmirror.com/files/cauldron/cauldron-1.7.10-2.1403.1.54.zip").openConnection();
                    connection.setUseCaches(false);
                    connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
                    connection.connect();
                    Files.copy(connection.getInputStream(), Paths.get("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/cauldron.zip"));
                    System.out.println("Download was completed successfully!");
                    ZipFile zip = new ZipFile(file);
                    Enumeration<? extends ZipEntry> entryEnumeration = zip.entries();
                    while (entryEnumeration.hasMoreElements()) {
                        ZipEntry entry = entryEnumeration.nextElement();
                        if (!entry.isDirectory()) {
                            extractEntry(zip, entry, "local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName());
                        }
                    }
                    zip.close();
                    file.delete();
                    new File("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/cauldron-1.7.10-2.1403.1.54-server.jar").renameTo(new File("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/cauldron.jar"));
                    System.out.println("Using a cauldron.jar for your minecraft service template " + serverGroup.getName() + ", please copy a eula.txt into the template or into the global folder");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        if (serverGroup.getServerType().equals(ServerGroupType.GLOWSTONE)) {
            for (Template template : serverGroup.getTemplates()) {
                Path path = Paths.get("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/glowstone.jar");
                if (!Files.exists(path)) {
                    try {
                        URLConnection connection = new URL("https://yivesmirror.com/grab/glowstone/Glowstone-latest.jar").openConnection();
                        connection.setUseCaches(false);
                        connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
                        connection.connect();
                        System.out.println("Downloading glowstone.jar...");
                        Files.copy(connection.getInputStream(), path);
                        System.out.println("Download was completed successfully");
                        ((HttpURLConnection) connection).disconnect();
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                }
            }
            Template template = serverGroup.getGlobalTemplate();
            Path path = Paths.get("local/templates/" + serverGroup.getName() + NetworkUtils.SLASH_STRING + template.getName() + "/glowstone.jar");
            if (!Files.exists(path)) {
                try {
                    URLConnection connection = new URL("https://yivesmirror.com/grab/glowstone/Glowstone-latest.jar").openConnection();
                    connection.setUseCaches(false);
                    connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
                    connection.connect();
                    System.out.println("Downloading glowstone.jar...");
                    Files.copy(connection.getInputStream(), path);
                    System.out.println("Download was completed successfully");
                    ((HttpURLConnection) connection).disconnect();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    } else {
        ProxyGroup proxyGroup = data.getObject("proxyGroup", new TypeToken<ProxyGroup>() {
        }.getType());
        try {
            if (!Files.exists(Paths.get("local/templates/" + proxyGroup.getName()))) {
                System.out.println("Creating GroupTemplate for " + proxyGroup.getName() + " DEFAULT...");
                Files.createDirectories(Paths.get("local/templates/" + proxyGroup.getName() + "/plugins"));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : Path(java.nio.file.Path) ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) ZipEntry(java.util.zip.ZipEntry) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection) URL(java.net.URL) Template(de.dytanic.cloudnet.lib.server.template.Template) HttpURLConnection(java.net.HttpURLConnection) ZipFile(java.util.zip.ZipFile) TypeToken(com.google.gson.reflect.TypeToken) ZipFile(java.util.zip.ZipFile)

Example 5 with ProxyGroup

use of de.dytanic.cloudnet.lib.server.ProxyGroup in project CloudNet by Dytanic.

the class PacketInWrapperInfo method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    WrapperExternal wrapperExternal = data.getObject("wrapper", new TypeToken<WrapperExternal>() {
    }.getType());
    CloudNetWrapper.getInstance().setSimpledUser(wrapperExternal.getUser());
    CloudNetWrapper.getInstance().getServerGroups().clear();
    NetworkUtils.addAll(CloudNetWrapper.getInstance().getServerGroups(), wrapperExternal.getServerGroups(), new Acceptable<ServerGroup>() {

        @Override
        public boolean isAccepted(ServerGroup value) {
            System.out.println("Importing server group [" + value.getName() + "] from CloudNet-Master");
            return true;
        }
    });
    CloudNetWrapper.getInstance().getProxyGroups().clear();
    NetworkUtils.addAll(CloudNetWrapper.getInstance().getProxyGroups(), wrapperExternal.getProxyGroups(), new Acceptable<ProxyGroup>() {

        @Override
        public boolean isAccepted(ProxyGroup value) {
            System.out.println("Importing proxy group [" + value.getName() + "] from CloudNet-Master");
            return true;
        }
    });
}
Also used : ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) TypeToken(com.google.gson.reflect.TypeToken) WrapperExternal(de.dytanic.cloudnet.lib.network.WrapperExternal)

Aggregations

ProxyGroup (de.dytanic.cloudnet.lib.server.ProxyGroup)14 ServerGroup (de.dytanic.cloudnet.lib.server.ServerGroup)8 TypeToken (com.google.gson.reflect.TypeToken)5 Wrapper (de.dytanic.cloudnetcore.network.components.Wrapper)4 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)3 Template (de.dytanic.cloudnet.lib.server.template.Template)3 WrapperExternal (de.dytanic.cloudnet.lib.network.WrapperExternal)2 ProxyConfig (de.dytanic.cloudnet.lib.proxylayout.ProxyConfig)2 SimpleServerGroup (de.dytanic.cloudnet.lib.server.SimpleServerGroup)2 User (de.dytanic.cloudnet.lib.user.User)2 Document (de.dytanic.cloudnet.lib.utility.document.Document)2 LocalCloudWrapper (de.dytanic.cloudnetcore.setup.LocalCloudWrapper)2 EventHandler (net.md_5.bungee.event.EventHandler)2 CloudProxy (de.dytanic.cloudnet.bridge.CloudProxy)1 CloudPlayerCommandSender (de.dytanic.cloudnet.bridge.internal.util.CloudPlayerCommandSender)1 DNSRecord (de.dytanic.cloudnet.cloudflare.util.DNSRecord)1 DefaultDNSRecord (de.dytanic.cloudnet.cloudflare.util.DefaultDNSRecord)1 ConnectableAddress (de.dytanic.cloudnet.lib.ConnectableAddress)1 WrapperInfo (de.dytanic.cloudnet.lib.network.WrapperInfo)1 PlayerConnection (de.dytanic.cloudnet.lib.player.PlayerConnection)1