Search in sources :

Example 16 with ServerInfo

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

the class PacketInAddCloudServer method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    if (!(packetSender instanceof Wrapper))
        return;
    Wrapper cn = ((Wrapper) packetSender);
    ServerInfo nullServerInfo = data.getObject("serverInfo", new TypeToken<ServerInfo>() {
    }.getType());
    CloudServerMeta serverProcessMeta = data.getObject("cloudServerMeta", new TypeToken<CloudServerMeta>() {
    }.getType());
    CloudServer minecraftServer = new CloudServer(cn, nullServerInfo, serverProcessMeta);
    cn.getCloudServers().put(nullServerInfo.getServiceId().getServerId(), minecraftServer);
    cn.getWaitingServices().remove(minecraftServer.getServerId());
    {
        if (serverProcessMeta.isPriorityStop()) {
            ServerGroup serverGroup = CloudNet.getInstance().getServerGroups().get(serverProcessMeta.getServiceId().getGroup());
            if (serverGroup != null) {
                PriorityStopTask priorityStopTask = new PriorityStopTask(cn, minecraftServer, serverGroup.getPriorityService().getStopTimeInSeconds());
                ScheduledTask scheduledTask = CloudNet.getInstance().getSubScheduler().runTaskRepeatSync(priorityStopTask, 0, 50);
                priorityStopTask.setScheduledTask(scheduledTask);
            }
        }
    }
    CloudNet.getInstance().getNetworkManager().handleServerAdd(minecraftServer);
}
Also used : CloudServerMeta(de.dytanic.cloudnet.lib.cloudserver.CloudServerMeta) PriorityStopTask(de.dytanic.cloudnetcore.network.components.priority.PriorityStopTask) Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) TypeToken(com.google.gson.reflect.TypeToken) CloudServer(de.dytanic.cloudnetcore.network.components.CloudServer) ScheduledTask(de.dytanic.cloudnet.lib.utility.threading.ScheduledTask)

Example 17 with ServerInfo

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

the class PacketInAddServer method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    if (!(packetSender instanceof Wrapper))
        return;
    Wrapper cn = ((Wrapper) packetSender);
    ServerInfo nullServerInfo = data.getObject("serverInfo", new TypeToken<ServerInfo>() {
    }.getType());
    ServerProcessMeta serverProcessMeta = data.getObject("serverProcess", new TypeToken<ServerProcessMeta>() {
    }.getType());
    MinecraftServer minecraftServer = new MinecraftServer(serverProcessMeta, cn, CloudNet.getInstance().getServerGroups().get(nullServerInfo.getServiceId().getGroup()), nullServerInfo);
    cn.getServers().put(nullServerInfo.getServiceId().getServerId(), minecraftServer);
    cn.getWaitingServices().remove(minecraftServer.getServerId());
    {
        if (serverProcessMeta.isPriorityStop()) {
            ServerGroup serverGroup = CloudNet.getInstance().getServerGroups().get(serverProcessMeta.getServiceId().getGroup());
            if (serverGroup != null) {
                PriorityStopTask priorityStopTask = new PriorityStopTask(cn, minecraftServer, serverGroup.getPriorityService().getStopTimeInSeconds());
                ScheduledTask scheduledTask = CloudNet.getInstance().getSubScheduler().runTaskRepeatSync(priorityStopTask, 0, 50);
                priorityStopTask.setScheduledTask(scheduledTask);
            }
        }
    }
    CloudNet.getInstance().getNetworkManager().handleServerAdd(minecraftServer);
}
Also used : PriorityStopTask(de.dytanic.cloudnetcore.network.components.priority.PriorityStopTask) Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) ServerProcessMeta(de.dytanic.cloudnet.lib.server.ServerProcessMeta) ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) TypeToken(com.google.gson.reflect.TypeToken) ScheduledTask(de.dytanic.cloudnet.lib.utility.threading.ScheduledTask) MinecraftServer(de.dytanic.cloudnetcore.network.components.MinecraftServer)

Example 18 with ServerInfo

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

the class PacketInRemoveCloudServer method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    if (!(packetSender instanceof Wrapper))
        return;
    Wrapper cn = (Wrapper) packetSender;
    ServerInfo serverInfo = data.getObject("serverInfo", new TypeToken<ServerInfo>() {
    }.getType());
    if (cn.getServers().containsKey(serverInfo.getServiceId().getServerId())) {
        CloudServer minecraftServer = cn.getCloudServers().get(serverInfo.getServiceId().getServerId());
        if (minecraftServer.getChannel() != null) {
            minecraftServer.getChannel().close().syncUninterruptibly();
        }
        cn.getCloudServers().remove(serverInfo.getServiceId().getServerId());
        CloudNet.getInstance().getNetworkManager().handleServerRemove(minecraftServer);
    }
}
Also used : Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) TypeToken(com.google.gson.reflect.TypeToken) CloudServer(de.dytanic.cloudnetcore.network.components.CloudServer)

Example 19 with ServerInfo

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

the class PacketInRemoveServer method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    if (!(packetSender instanceof Wrapper))
        return;
    Wrapper cn = (Wrapper) packetSender;
    ServerInfo serverInfo = data.getObject("serverInfo", new TypeToken<ServerInfo>() {
    }.getType());
    if (cn.getServers().containsKey(serverInfo.getServiceId().getServerId())) {
        MinecraftServer minecraftServer = cn.getServers().get(serverInfo.getServiceId().getServerId());
        if (minecraftServer.getChannel() != null)
            minecraftServer.getChannel().close();
        cn.getServers().remove(serverInfo.getServiceId().getServerId());
        CloudNet.getInstance().getNetworkManager().handleServerRemove(minecraftServer);
        CloudNet.getInstance().getScreenProvider().handleDisableScreen(serverInfo.getServiceId());
    }
}
Also used : Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) TypeToken(com.google.gson.reflect.TypeToken) MinecraftServer(de.dytanic.cloudnetcore.network.components.MinecraftServer)

Example 20 with ServerInfo

use of de.dytanic.cloudnet.lib.server.info.ServerInfo 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)

Aggregations

ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)24 TypeToken (com.google.gson.reflect.TypeToken)6 Wrapper (de.dytanic.cloudnetcore.network.components.Wrapper)5 ArrayList (java.util.ArrayList)5 ServerGroup (de.dytanic.cloudnet.lib.server.ServerGroup)4 Document (de.dytanic.cloudnet.lib.utility.document.Document)4 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)3 ServerFallback (de.dytanic.cloudnet.lib.proxylayout.ServerFallback)3 Properties (java.util.Properties)3 PacketOutUpdateServerInfo (de.dytanic.cloudnet.api.network.packet.out.PacketOutUpdateServerInfo)2 ProxiedPlayerFallbackEvent (de.dytanic.cloudnet.bridge.event.proxied.ProxiedPlayerFallbackEvent)2 ConnectableAddress (de.dytanic.cloudnet.lib.ConnectableAddress)2 OfflinePlayer (de.dytanic.cloudnet.lib.player.OfflinePlayer)2 ServerConfig (de.dytanic.cloudnet.lib.server.ServerConfig)2 Template (de.dytanic.cloudnet.lib.server.template.Template)2 ServerInstallablePlugin (de.dytanic.cloudnet.lib.service.plugin.ServerInstallablePlugin)2 SimpledUser (de.dytanic.cloudnet.lib.user.SimpledUser)2 Acceptable (de.dytanic.cloudnet.lib.utility.Acceptable)2 ScheduledTask (de.dytanic.cloudnet.lib.utility.threading.ScheduledTask)2 CloudServer (de.dytanic.cloudnetcore.network.components.CloudServer)2