Search in sources :

Example 11 with ServerGroup

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

the class CommandCloudDev method execute.

@Override
public void execute(CommandSender commandSender, String[] args) {
    if (!(commandSender instanceof ProxiedPlayer))
        return;
    switch(args.length) {
        case 0:
            for (ServerInfo serverInfo : CloudProxy.getInstance().getCachedServers().values()) {
                if (serverInfo.getServerConfig().getProperties().contains(NetworkUtils.DEV_PROPERTY)) {
                    DevService service = serverInfo.getServerConfig().getProperties().getObject(NetworkUtils.DEV_PROPERTY, DevService.class);
                    if (service.getUniqueId().equals(((ProxiedPlayer) commandSender).getUniqueId())) {
                        ((ProxiedPlayer) commandSender).connect(ProxyServer.getInstance().getServerInfo(serverInfo.getServiceId().getServerId()));
                        return;
                    }
                }
            }
            commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cdev forTemplate <group> <template>");
            commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cdev forTemplate <group>");
            commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cdev testServer <group>");
            commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cdev testServer <group> <template>");
            break;
        case 2:
            {
                for (ServerInfo serverInfo : CloudProxy.getInstance().getCachedServers().values()) {
                    if (serverInfo.getServerConfig().getProperties().contains(NetworkUtils.DEV_PROPERTY)) {
                        DevService service = serverInfo.getServerConfig().getProperties().getObject(NetworkUtils.DEV_PROPERTY, DevService.class);
                        if (service.getUniqueId().equals(((ProxiedPlayer) commandSender).getUniqueId())) {
                            ((ProxiedPlayer) commandSender).connect(ProxyServer.getInstance().getServerInfo(serverInfo.getServiceId().getServerId()));
                            return;
                        }
                    }
                }
                if (args[0].equalsIgnoreCase("forTemplate")) {
                    if (!CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The group doesn't exist");
                        return;
                    }
                    ServerConfig serverConfig = new ServerConfig(true, commandSender.getName(), new Document(NetworkUtils.DEV_PROPERTY, new DevService(((ProxiedPlayer) commandSender).getUniqueId(), true)), System.currentTimeMillis());
                    CloudAPI.getInstance().startGameServer(CloudAPI.getInstance().getServerGroupData(args[1]), serverConfig, "Dev" + args[1] + "-" + commandSender.getName());
                    ((ProxiedPlayer) commandSender).sendMessage(CloudAPI.getInstance().getPrefix() + "The server will start up now...");
                    return;
                }
                if (args[0].equalsIgnoreCase("testServer")) {
                    if (!CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The group doesn't exist");
                        return;
                    }
                    ServerConfig serverConfig = new ServerConfig(true, commandSender.getName(), new Document(), System.currentTimeMillis());
                    CloudAPI.getInstance().startCloudServer("TestServer-" + ((ProxiedPlayer) commandSender).getUniqueId(), serverConfig, 356, true);
                    ((ProxiedPlayer) commandSender).sendMessage(CloudAPI.getInstance().getPrefix() + "The server will start up now...");
                    return;
                }
            }
        case 3:
            {
                for (ServerInfo serverInfo : CloudProxy.getInstance().getCachedServers().values()) {
                    if (serverInfo.getServerConfig().getProperties().contains(NetworkUtils.DEV_PROPERTY)) {
                        DevService service = serverInfo.getServerConfig().getProperties().getObject(NetworkUtils.DEV_PROPERTY, DevService.class);
                        if (service.getUniqueId().equals(((ProxiedPlayer) commandSender).getUniqueId())) {
                            ((ProxiedPlayer) commandSender).connect(ProxyServer.getInstance().getServerInfo(serverInfo.getServiceId().getServerId()));
                            return;
                        }
                    }
                }
                if (args[0].equalsIgnoreCase("forTemplate")) {
                    if (!CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The group doesn't exist");
                        return;
                    }
                    ServerGroup serverGroup = CloudAPI.getInstance().getServerGroup(args[1]);
                    if (CollectionWrapper.filter(serverGroup.getTemplates(), new Acceptable<Template>() {

                        @Override
                        public boolean isAccepted(Template template) {
                            return template.getName().equalsIgnoreCase(args[2]);
                        }
                    }) == null) {
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The template doesn't exist");
                        return;
                    }
                    ServerConfig serverConfig = new ServerConfig(true, commandSender.getName(), new Document(NetworkUtils.DEV_PROPERTY, new DevService(((ProxiedPlayer) commandSender).getUniqueId(), true)), System.currentTimeMillis());
                    CloudAPI.getInstance().startGameServer(CloudAPI.getInstance().getServerGroupData(args[1]), serverConfig, CloudAPI.getInstance().getServerGroupData(args[1]).getMemory(), true, new Properties(), CollectionWrapper.filter(serverGroup.getTemplates(), new Acceptable<Template>() {

                        @Override
                        public boolean isAccepted(Template e) {
                            return e.getName().equalsIgnoreCase(args[2]);
                        }
                    }), "Dev" + args[1] + "-" + commandSender.getName());
                    ((ProxiedPlayer) commandSender).sendMessage(CloudAPI.getInstance().getPrefix() + "The server will start up now...");
                    return;
                }
                if (args[0].equalsIgnoreCase("testServer")) {
                    if (!CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The group doesn't exist");
                        return;
                    }
                    ServerGroup serverGroup = CloudAPI.getInstance().getServerGroup(args[1]);
                    if (CollectionWrapper.filter(serverGroup.getTemplates(), new Acceptable<Template>() {

                        @Override
                        public boolean isAccepted(Template template) {
                            return template.getName().equalsIgnoreCase(args[2]);
                        }
                    }) == null) {
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The template doesn't exist");
                        return;
                    }
                    ServerConfig serverConfig = new ServerConfig(true, commandSender.getName(), new Document(), System.currentTimeMillis());
                    /*
                    CloudAPI.getInstance().startGameServer(CloudAPI.getInstance().getServerGroupData(args[1]), serverConfig,
                            CloudAPI.getInstance().getServerGroupData(args[1]).getMemory(),
                            new String[0], null, "TestServer-" + commandSender.getName(), false, true, new Properties(),
                            null, Arrays.asList()
                            , "Dev" + args[1] + "-" + commandSender.getName());
                    */
                    CloudAPI.getInstance().startCloudServer("TestServer-" + ((ProxiedPlayer) commandSender).getUniqueId(), serverConfig, 356, true);
                    ((ProxiedPlayer) commandSender).sendMessage(CloudAPI.getInstance().getPrefix() + "The server will start up now...");
                    return;
                }
            }
            break;
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ServerConfig(de.dytanic.cloudnet.lib.server.ServerConfig) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) DevService(de.dytanic.cloudnet.lib.server.advanced.DevService) Document(de.dytanic.cloudnet.lib.utility.document.Document) Properties(java.util.Properties) Template(de.dytanic.cloudnet.lib.server.template.Template)

Example 12 with ServerGroup

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

the class NetworkManager method newCloudNetwork.

public CloudNetwork newCloudNetwork() {
    CloudNetwork cloudNetwork = new CloudNetwork();
    cloudNetwork.setOnlineCount(getOnlineCount());
    cloudNetwork.setMessages(messageConfig.load());
    cloudNetwork.setModules(moduleProperties);
    // cloudNetwork.setNotifySystem(CloudNet.getInstance().getConfig().isNotifyService());
    cloudNetwork.setWebPort(CloudNet.getInstance().getConfig().getWebServerConfig().getPort());
    // cloudNetwork.setDevServices(CloudNet.getInstance().getConfig().isCloudDevServices());
    Collection<WrapperInfo> wrappers = new LinkedList<>();
    for (Wrapper wrapper : CloudNet.getInstance().getWrappers().values()) if (wrapper.getWrapperInfo() != null)
        wrappers.add(wrapper.getWrapperInfo());
    cloudNetwork.setWrappers(wrappers);
    cloudNetwork.setServerGroups(MapWrapper.transform(CloudNet.getInstance().getServerGroups(), new Catcher<String, String>() {

        @Override
        public String doCatch(String key) {
            return key;
        }
    }, new Catcher<SimpleServerGroup, ServerGroup>() {

        @Override
        public SimpleServerGroup doCatch(ServerGroup key) {
            return key.toSimple();
        }
    }));
    // cloudNetwork.setPermissionPool(permissionPool);
    cloudNetwork.setProxyGroups(CloudNet.getInstance().getProxyGroups());
    cloudNetwork.setModules(moduleProperties);
    return cloudNetwork;
}
Also used : Catcher(de.dytanic.cloudnet.lib.utility.Catcher) MapWrapper(de.dytanic.cloudnet.lib.utility.MapWrapper) CollectionWrapper(de.dytanic.cloudnet.lib.utility.CollectionWrapper) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) SimpleServerGroup(de.dytanic.cloudnet.lib.server.SimpleServerGroup) WrapperInfo(de.dytanic.cloudnet.lib.network.WrapperInfo) CloudNetwork(de.dytanic.cloudnet.lib.CloudNetwork)

Example 13 with ServerGroup

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

the class Wrapper method updateWrapper.

public Wrapper updateWrapper() {
    if (getChannel() == null)
        return this;
    java.util.Map<String, ServerGroup> groups = NetworkUtils.newConcurrentHashMap();
    for (ServerGroup serverGroup : CloudNet.getInstance().getServerGroups().values()) if (serverGroup.getWrapper().contains(networkInfo.getId())) {
        groups.put(serverGroup.getName(), serverGroup);
        sendPacket(new PacketOutCreateTemplate(serverGroup));
    }
    java.util.Map<String, ProxyGroup> proxyGroups = NetworkUtils.newConcurrentHashMap();
    for (ProxyGroup serverGroup : CloudNet.getInstance().getProxyGroups().values()) if (serverGroup.getWrapper().contains(networkInfo.getId())) {
        proxyGroups.put(serverGroup.getName(), serverGroup);
        sendPacket(new PacketOutCreateTemplate(serverGroup));
    }
    SimpledUser simpledUser = null;
    User user = CollectionWrapper.filter(CloudNet.getInstance().getUsers(), new Acceptable<User>() {

        @Override
        public boolean isAccepted(User value) {
            return networkInfo.getUser().equals(value.getName());
        }
    });
    if (user != null) {
        simpledUser = user.toSimple();
    }
    WrapperExternal wrapperExternal = new WrapperExternal(CloudNet.getInstance().getNetworkManager().newCloudNetwork(), simpledUser, groups, proxyGroups);
    sendPacket(new PacketOutWrapperInfo(wrapperExternal));
    return this;
}
Also used : ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) SimpledUser(de.dytanic.cloudnet.lib.user.SimpledUser) User(de.dytanic.cloudnet.lib.user.User) SimpledUser(de.dytanic.cloudnet.lib.user.SimpledUser) WrapperExternal(de.dytanic.cloudnet.lib.network.WrapperExternal)

Example 14 with ServerGroup

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

the class PacketInUpdateProxyGroup method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    ProxyGroup proxyGroup = data.getObject("group", new TypeToken<ProxyGroup>() {
    }.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 15 with ServerGroup

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

the class CloudPriorityGroupStartupHandler method onHandle.

@Override
public void onHandle(CloudNet cloudNet) {
    for (ServerGroup group : CloudNet.getInstance().getServerGroups().values()) {
        double onlineCount = CloudNet.getInstance().getOnlineCount(group.getName());
        if (group.getPriorityService().getGroup().getOnlineServers() == 0 || group.getPriorityService().getGlobal().getOnlineCount() == 0 || group.getGroupMode() == ServerGroupMode.STATIC || group.isMaintenance())
            continue;
        double priority = (group.getPriorityService().getGroup().getOnlineServers() / ((double) group.getPriorityService().getGroup().getOnlineCount())) * (onlineCount == 0 ? 1.0D : (onlineCount));
        Collection<String> servers = CloudNet.getInstance().getServersAndWaitings(group.getName());
        if (servers.size() == 0 && servers.size() < (priority <= 1 ? 1 : priority)) {
            CloudNet.getInstance().startGameServer(group);
            continue;
        }
        if (servers.size() < (priority <= 1 ? 1 : priority)) {
            CloudNet.getInstance().startGameServer(group, new Document(), true);
        }
    }
}
Also used : ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) Document(de.dytanic.cloudnet.lib.utility.document.Document)

Aggregations

ServerGroup (de.dytanic.cloudnet.lib.server.ServerGroup)16 ProxyGroup (de.dytanic.cloudnet.lib.server.ProxyGroup)8 TypeToken (com.google.gson.reflect.TypeToken)7 Document (de.dytanic.cloudnet.lib.utility.document.Document)5 Wrapper (de.dytanic.cloudnetcore.network.components.Wrapper)5 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)4 SimpleServerGroup (de.dytanic.cloudnet.lib.server.SimpleServerGroup)3 Template (de.dytanic.cloudnet.lib.server.template.Template)3 WrapperExternal (de.dytanic.cloudnet.lib.network.WrapperExternal)2 WrapperInfo (de.dytanic.cloudnet.lib.network.WrapperInfo)2 ServerConfig (de.dytanic.cloudnet.lib.server.ServerConfig)2 ScheduledTask (de.dytanic.cloudnet.lib.utility.threading.ScheduledTask)2 MinecraftServer (de.dytanic.cloudnetcore.network.components.MinecraftServer)2 PriorityStopTask (de.dytanic.cloudnetcore.network.components.priority.PriorityStopTask)2 CloudNetwork (de.dytanic.cloudnet.lib.CloudNetwork)1 CloudServerMeta (de.dytanic.cloudnet.lib.cloudserver.CloudServerMeta)1 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)1 AutoSlot (de.dytanic.cloudnet.lib.proxylayout.AutoSlot)1 ServerProcessMeta (de.dytanic.cloudnet.lib.server.ServerProcessMeta)1 DevService (de.dytanic.cloudnet.lib.server.advanced.DevService)1