Search in sources :

Example 16 with Document

use of de.dytanic.cloudnet.lib.utility.document.Document in project CloudNet by Dytanic.

the class PacketDBInGetDocument method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    if (!data.contains("name")) {
        Map<String, Document> docs = ((DatabaseImpl) CloudNet.getInstance().getDatabaseManager().getDatabase(data.getString("db")).loadDocuments()).getDocuments();
        packetSender.sendPacket(getResult(new Document("docs", docs)));
    } else {
        String x = data.getString("name");
        String db = data.getString("db");
        Document document = CloudNet.getInstance().getDatabaseManager().getDatabase(db).getDocument(x);
        packetSender.sendPacket(getResult(new Document("result", document)));
    }
}
Also used : DatabaseImpl(de.dytanic.cloudnet.database.DatabaseImpl) Document(de.dytanic.cloudnet.lib.utility.document.Document)

Example 17 with Document

use of de.dytanic.cloudnet.lib.utility.document.Document in project CloudNet by Dytanic.

the class ServerGetExample method start.

public void start() {
    CloudAPI.getInstance().startGameServer(CloudAPI.getInstance().getServerGroupData("Lobby"), new ServerConfig(true, "4820", new Document("myUUID", "test"), System.currentTimeMillis()));
    CloudAPI.getInstance().startGameServer(CloudAPI.getInstance().getServerGroupData("Lobby"), new ServerConfig(true, "4820", new Document("myUUID", "test"), System.currentTimeMillis()), "Lobby-1");
}
Also used : ServerConfig(de.dytanic.cloudnet.lib.server.ServerConfig) Document(de.dytanic.cloudnet.lib.utility.document.Document)

Example 18 with Document

use of de.dytanic.cloudnet.lib.utility.document.Document in project CloudNet by Dytanic.

the class MessageConfig method load.

public Document load() {
    boolean resave = false;
    Document document = Document.loadDocument(path);
    if (!document.contains("server-kick-proxy-disallow")) {
        document.append("server-kick-proxy-disallow", "§cYou have to connect from a internal proxy server!");
        resave = true;
    }
    if (resave)
        document.saveAsConfig(path);
    return document;
}
Also used : Document(de.dytanic.cloudnet.lib.utility.document.Document)

Example 19 with Document

use of de.dytanic.cloudnet.lib.utility.document.Document in project CloudNet by Dytanic.

the class GameServer method shutdown.

@Override
public boolean shutdown() {
    if (instance == null) {
        if (serverGroup.getGroupMode().equals(ServerGroupMode.DYNAMIC)) {
            try {
                FileUtils.deleteDirectory(dir.toFile());
            } catch (IOException e) {
            }
        }
        return true;
    }
    kill();
    if (CloudNetWrapper.getInstance().getWrapperConfig().isSavingRecords()) {
        try {
            FileCopy.copyFilesInDirectory(new File(path + "/logs"), new File("local/records/" + serverProcess.getMeta().getServiceId().toString()));
            new Document("meta", serverProcess.getMeta()).saveAsConfig(Paths.get("local/records/" + serverProcess.getMeta().getServiceId().toString() + "/metadata.json"));
        } catch (IOException e) {
        }
    }
    if (serverGroup.isMaintenance() && (CloudNetWrapper.getInstance().getWrapperConfig().isMaintenance_copy() && !serverGroup.getGroupMode().equals(ServerGroupMode.STATIC)))
        copy();
    if (!serverGroup.getGroupMode().equals(ServerGroupMode.STATIC) && !serverGroup.getGroupMode().equals(ServerGroupMode.STATIC_LOBBY))
        try {
            try {
                FileUtils.deleteDirectory(dir.toFile());
            } catch (Exception e) {
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    CloudNetWrapper.getInstance().getServers().remove(getServiceId().getServerId());
    CloudNetWrapper.getInstance().getNetworkConnection().sendPacket(new PacketOutRemoveServer(serverInfo));
    System.out.println("Server " + toString() + " was stopped");
    try {
        this.finalize();
    } catch (Throwable throwable) {
    }
    return true;
}
Also used : PacketOutRemoveServer(de.dytanic.cloudnetwrapper.network.packet.out.PacketOutRemoveServer) Document(de.dytanic.cloudnet.lib.utility.document.Document)

Example 20 with Document

use of de.dytanic.cloudnet.lib.utility.document.Document in project CloudNet by Dytanic.

the class GameServer method bootstrap.

@Override
public boolean bootstrap() throws Exception {
    serverProcess.setServerStage(ServerStage.DOWNLOAD);
    long startupTime = System.currentTimeMillis();
    for (ServerInstallablePlugin url : serverProcess.getMeta().getDownloadablePlugins()) {
        switch(url.getPluginResourceType()) {
            case URL:
                {
                    if (!Files.exists(Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"))) {
                        try {
                            URLConnection urlConnection = new java.net.URL(url.getUrl()).openConnection();
                            urlConnection.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");
                            Files.copy(urlConnection.getInputStream(), Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"));
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                }
                break;
            case MASTER:
                {
                    if (!Files.exists(Paths.get("local/cache/web_plugins/" + url.getName() + ".jar")) && CloudNetWrapper.getInstance().getSimpledUser() != null) {
                        try {
                            URLConnection urlConnection = new java.net.URL(new StringBuilder(CloudNetWrapper.getInstance().getOptionSet().has("ssl") ? "https://" : "http://").append(CloudNetWrapper.getInstance().getWrapperConfig().getCloudnetHost()).append(":").append(CloudNetWrapper.getInstance().getWrapperConfig().getWebPort()).append("/cloudnet/api/v1/download").substring(0)).openConnection();
                            urlConnection.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");
                            SimpledUser simpledUser = CloudNetWrapper.getInstance().getSimpledUser();
                            urlConnection.setRequestProperty("-Xcloudnet-user", simpledUser.getUserName());
                            urlConnection.setRequestProperty("-Xcloudnet-token", simpledUser.getApiToken());
                            urlConnection.setRequestProperty("-Xmessage", "plugin");
                            urlConnection.setRequestProperty("-Xvalue", url.getName());
                            urlConnection.connect();
                            System.out.println("Downloading " + url.getName() + ".jar");
                            Files.copy(urlConnection.getInputStream(), Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"));
                            System.out.println("Download was completed successfully!");
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                }
                break;
            default:
                break;
        }
    }
    for (ServerInstallablePlugin url : serverProcess.getMeta().getTemplate().getInstallablePlugins()) {
        switch(url.getPluginResourceType()) {
            case URL:
                {
                    if (!Files.exists(Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"))) {
                        try {
                            URLConnection urlConnection = new java.net.URL(url.getUrl()).openConnection();
                            urlConnection.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");
                            Files.copy(urlConnection.getInputStream(), Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"));
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                }
                break;
            case MASTER:
                {
                    if (!Files.exists(Paths.get("local/cache/web_plugins/" + url.getName() + ".jar")) && CloudNetWrapper.getInstance().getSimpledUser() != null) {
                        try {
                            URLConnection urlConnection = new java.net.URL(new StringBuilder(CloudNetWrapper.getInstance().getOptionSet().has("ssl") ? "https://" : "http://").append(CloudNetWrapper.getInstance().getWrapperConfig().getCloudnetHost()).append(":").append(CloudNetWrapper.getInstance().getWrapperConfig().getWebPort()).append("/cloudnet/api/v1/download").substring(0)).openConnection();
                            urlConnection.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");
                            SimpledUser simpledUser = CloudNetWrapper.getInstance().getSimpledUser();
                            urlConnection.setRequestProperty("-Xcloudnet-user", simpledUser.getUserName());
                            urlConnection.setRequestProperty("-Xcloudnet-token", simpledUser.getApiToken());
                            urlConnection.setRequestProperty("-Xmessage", "plugin");
                            urlConnection.setRequestProperty("-Xvalue", url.getName());
                            urlConnection.connect();
                            System.out.println("Downloading " + url.getName() + ".jar");
                            Files.copy(urlConnection.getInputStream(), Paths.get("local/cache/web_plugins/" + url.getName() + ".jar"));
                            System.out.println("Download was completed successfully!");
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }
                }
                break;
            default:
                break;
        }
    }
    if (serverGroup.getTemplates().size() == 0 && serverProcess.getMeta().getUrl() == null)
        return false;
    if (serverGroup.getGroupMode().equals(ServerGroupMode.STATIC)) {
        if (!Files.exists(dir))
            if (!a())
                return false;
    } else if (!a())
        return false;
    for (ServerInstallablePlugin plugin : serverProcess.getMeta().getDownloadablePlugins()) FileCopy.copyFileToDirectory(new File("local/cache/web_plugins/" + plugin.getName() + ".jar"), new File(path + "/plugins"));
    for (ServerInstallablePlugin plugin : serverProcess.getMeta().getTemplate().getInstallablePlugins()) FileCopy.copyFileToDirectory(new File("local/cache/web_plugins/" + plugin.getName() + ".jar"), new File(path + "/plugins"));
    serverProcess.setServerStage(ServerStage.COPY);
    if (serverGroup.getServerType().equals(ServerGroupType.BUKKIT))
        if (!Files.exists(Paths.get(path + "/spigot.jar")))
            FileCopy.copyFileToDirectory(new File("local/spigot.jar"), new File(path));
    if (serverGroup.getServerType().equals(ServerGroupType.GLOWSTONE)) {
        if (!Files.exists(Paths.get(path + "/config")))
            Files.createDirectories(Paths.get(path + "/config"));
        if (!Files.exists(Paths.get(path + "/config/glowstone.yml")))
            FileCopy.insertData("files/glowstone.yml", path + "/config/glowstone.yml");
    }
    if (!Files.exists(Paths.get(path + "/server.properties")))
        FileCopy.insertData("files/server.properties", path + "/server.properties");
    if (!Files.exists(Paths.get(path + "/bukkit.yml")))
        FileCopy.insertData("files/bukkit.yml", path + "/bukkit.yml");
    if (!serverProcess.getMeta().isOnlineMode())
        if (!Files.exists(Paths.get(path + "/spigot.yml")))
            FileCopy.insertData("files/spigot.yml", path + "/spigot.yml");
    Files.deleteIfExists(Paths.get(path + "/plugins/CloudNetAPI.jar"));
    FileCopy.insertData("files/CloudNetAPI.jar", path + "/plugins/CloudNetAPI.jar");
    FileCopy.copyFilesInDirectory(new File("local/global"), new File(path));
    String motd = "Default Motd";
    int maxPlayers = 0;
    if (!serverGroup.getServerType().equals(ServerGroupType.GLOWSTONE)) {
        Properties properties = new Properties();
        try (InputStreamReader inputStreamReader = new InputStreamReader(Files.newInputStream(Paths.get(path + "/server.properties")))) {
            properties.load(inputStreamReader);
        }
        Enumeration enumeration = this.serverProcess.getMeta().getServerProperties().keys();
        while (enumeration.hasMoreElements()) {
            String x = enumeration.nextElement().toString();
            properties.setProperty(x, this.serverProcess.getMeta().getServerProperties().getProperty(x));
        }
        properties.setProperty("server-ip", CloudNetWrapper.getInstance().getWrapperConfig().getInternalIP());
        properties.setProperty("server-port", serverProcess.getMeta().getPort() + NetworkUtils.EMPTY_STRING);
        properties.setProperty("online-mode", serverProcess.getMeta().isOnlineMode() + NetworkUtils.EMPTY_STRING);
        // properties.setProperty("server-name", serverProcess.getMeta().getServiceId().getServerId());
        motd = properties.getProperty("motd");
        maxPlayers = Integer.parseInt(properties.getProperty("max-players"));
        try (OutputStream outputStream = Files.newOutputStream(Paths.get(path + "/server.properties"))) {
            properties.store(outputStream, "CloudNet-Wrapper EDIT");
        }
    } else {
        try (InputStreamReader inputStreamReader = new InputStreamReader(Files.newInputStream(Paths.get(path + "/config/glowstone.yml")), StandardCharsets.UTF_8)) {
            Configuration configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(inputStreamReader);
            Configuration section = configuration.getSection("server");
            section.set("ip", CloudNetWrapper.getInstance().getWrapperConfig().getInternalIP());
            section.set("port", serverProcess.getMeta().getPort());
            maxPlayers = section.getInt("max-players");
            motd = section.getString("motd");
            configuration.set("server", section);
            configuration.set("console.use-jline", false);
            try (OutputStreamWriter outputStreamWriter = new OutputStreamWriter(Files.newOutputStream(Paths.get(path + "/config/glowstone.yml")), StandardCharsets.UTF_8)) {
                ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, outputStreamWriter);
            }
        }
    }
    this.serverInfo = new ServerInfo(serverProcess.getMeta().getServiceId(), CloudNetWrapper.getInstance().getWrapperConfig().getInternalIP(), this.getServerProcess().getMeta().getPort(), false, new ArrayList<>(), serverProcess.getMeta().getMemory(), motd, 0, maxPlayers, ServerState.OFFLINE, this.serverProcess.getMeta().getServerConfig(), serverProcess.getMeta().getTemplate());
    if (!Files.exists(Paths.get(path + "/CLOUD"))) {
        Files.createDirectory(Paths.get(path + "/CLOUD"));
    }
    new Document().append("serviceId", serverProcess.getMeta().getServiceId()).append("serverProcess", serverProcess.getMeta()).append("serverInfo", serverInfo).append("ssl", CloudNetWrapper.getInstance().getOptionSet().has("ssl")).append("memory", serverProcess.getMeta().getMemory()).saveAsConfig(Paths.get(path + "/CLOUD/config.json"));
    new Document().append("connection", new ConnectableAddress(CloudNetWrapper.getInstance().getWrapperConfig().getCloudnetHost(), CloudNetWrapper.getInstance().getWrapperConfig().getCloudnetPort())).saveAsConfig(Paths.get(path + "/CLOUD/connection.json"));
    CloudNetWrapper.getInstance().getNetworkConnection().sendPacket(new PacketOutAddServer(this.serverInfo, this.serverProcess.getMeta()));
    System.out.println("Server " + toString() + " started in [" + (System.currentTimeMillis() - startupTime) + " milliseconds]");
    this.startupTimeStamp = System.currentTimeMillis();
    startProcess();
    serverProcess.setServerStage(ServerStage.PROCESS);
    CloudNetWrapper.getInstance().getServers().put(this.serverProcess.getMeta().getServiceId().getServerId(), this);
    serverProcess.setServerStage(ServerStage.NET_INIT);
    return true;
}
Also used : ServerInstallablePlugin(de.dytanic.cloudnet.lib.service.plugin.ServerInstallablePlugin) PacketOutAddServer(de.dytanic.cloudnetwrapper.network.packet.out.PacketOutAddServer) Enumeration(java.util.Enumeration) Configuration(net.md_5.bungee.config.Configuration) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) ArrayList(java.util.ArrayList) Properties(java.util.Properties) YamlConfiguration(net.md_5.bungee.config.YamlConfiguration) Document(de.dytanic.cloudnet.lib.utility.document.Document) SimpledUser(de.dytanic.cloudnet.lib.user.SimpledUser) URLConnection(java.net.URLConnection) ConnectableAddress(de.dytanic.cloudnet.lib.ConnectableAddress)

Aggregations

Document (de.dytanic.cloudnet.lib.utility.document.Document)69 DatabaseDocument (de.dytanic.cloudnet.lib.database.DatabaseDocument)26 TypeToken (com.google.gson.reflect.TypeToken)7 ArrayList (java.util.ArrayList)7 File (java.io.File)6 UUID (java.util.UUID)6 OfflinePlayer (de.dytanic.cloudnet.lib.player.OfflinePlayer)5 ServerGroup (de.dytanic.cloudnet.lib.server.ServerGroup)5 ServerConfig (de.dytanic.cloudnet.lib.server.ServerConfig)4 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)4 HttpURLConnection (java.net.HttpURLConnection)4 URL (java.net.URL)4 ConnectableAddress (de.dytanic.cloudnet.lib.ConnectableAddress)3 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)3 Template (de.dytanic.cloudnet.lib.server.template.Template)3 ServerInstallablePlugin (de.dytanic.cloudnet.lib.service.plugin.ServerInstallablePlugin)3 SimpledUser (de.dytanic.cloudnet.lib.user.SimpledUser)3 Acceptable (de.dytanic.cloudnet.lib.utility.Acceptable)3 MinecraftServer (de.dytanic.cloudnetcore.network.components.MinecraftServer)3 IOException (java.io.IOException)3