Search in sources :

Example 1 with CloudServer

use of de.dytanic.cloudnetcore.network.components.CloudServer in project CloudNet by Dytanic.

the class CommandShutdown method onExecuteCommand.

@Override
public void onExecuteCommand(CommandSender sender, String[] args) {
    switch(args.length) {
        case 2:
            if (args[0].equalsIgnoreCase("wrapper")) {
                if (CloudNet.getInstance().getWrappers().containsKey(args[1])) {
                    Wrapper wrapper = CloudNet.getInstance().getWrappers().get(args[1]);
                    if (wrapper.getChannel() != null) {
                        wrapper.writeCommand("stop");
                    }
                    sender.sendMessage("Wrapper " + args[1] + " was stopped");
                } else {
                    sender.sendMessage("Wrapper doesn't exist");
                }
                return;
            }
            if (args[0].equalsIgnoreCase("group")) {
                if (CloudNet.getInstance().getServerGroups().containsKey(args[1])) {
                    System.out.println("All servers of the server group " + args[1] + " will be stopped...");
                    CollectionWrapper.iterator(CloudNet.getInstance().getServers(args[1]), new Runnabled<MinecraftServer>() {

                        @Override
                        public void run(MinecraftServer obj) {
                            obj.getWrapper().stopServer(obj);
                            NetworkUtils.sleepUninterruptedly(1000);
                        }
                    });
                    return;
                }
                if (CloudNet.getInstance().getProxyGroups().containsKey(args[1])) {
                    System.out.println("All proxies of the proxy group " + args[1] + " will be stopped");
                    CollectionWrapper.iterator(CloudNet.getInstance().getProxys(args[1]), new Runnabled<ProxyServer>() {

                        @Override
                        public void run(ProxyServer obj) {
                            obj.getWrapper().stopProxy(obj);
                            NetworkUtils.sleepUninterruptedly(1000);
                        }
                    });
                    return;
                }
                sender.sendMessage("Group doesn't exist");
                return;
            }
            if (args[0].equalsIgnoreCase("server")) {
                MinecraftServer proxyServer = CloudNet.getInstance().getServer(args[1]);
                if (proxyServer != null) {
                    proxyServer.getWrapper().stopServer(proxyServer);
                    sender.sendMessage("Server " + args[1] + " was stopped!");
                } else {
                    CloudServer proxyServers = CloudNet.getInstance().getCloudGameServer(args[1]);
                    if (proxyServers != null) {
                        proxyServers.getWrapper().stopServer(proxyServers);
                    } else {
                        sender.sendMessage("The server doesn't exist");
                    }
                }
                return;
            }
            if (args[0].equalsIgnoreCase("proxy")) {
                ProxyServer proxyServer = CloudNet.getInstance().getProxy(args[1]);
                if (proxyServer != null) {
                    proxyServer.getWrapper().stopProxy(proxyServer);
                    sender.sendMessage("Proxy server " + args[1] + " was stopped!");
                } else {
                    sender.sendMessage("The proxy doesn't exist");
                }
                return;
            }
            break;
        default:
            sender.sendMessage(NetworkUtils.SPACE_STRING, "shutdown WRAPPER <wrapper-id> | Stops a wrapper service with the respective \"wrapper ID\"", "shutdown GROUP <group-id> | Stops a group of either proxy or servergroup, and restarts it by default", "shutdown PROXY <proxy-id> | Stops a BungeeCord service and after preconfiguring the group, a new one is started", "shutdown SERVER <server-id> | Stops a Minecraft server service and after preconfiguring the group, a new one is started", NetworkUtils.SPACE_STRING);
            break;
    }
}
Also used : CollectionWrapper(de.dytanic.cloudnet.lib.utility.CollectionWrapper) Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) CloudServer(de.dytanic.cloudnetcore.network.components.CloudServer) MinecraftServer(de.dytanic.cloudnetcore.network.components.MinecraftServer) ProxyServer(de.dytanic.cloudnetcore.network.components.ProxyServer)

Example 2 with CloudServer

use of de.dytanic.cloudnetcore.network.components.CloudServer in project CloudNet by Dytanic.

the class PacketInStopServer method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    String serverId = data.getString("serverId");
    MinecraftServer minecraftServer = CloudNet.getInstance().getServer(serverId);
    if (minecraftServer != null) {
        minecraftServer.getWrapper().stopServer(minecraftServer);
        return;
    }
    CloudServer cloudServer = CloudNet.getInstance().getCloudGameServer(serverId);
    if (cloudServer != null) {
        cloudServer.getWrapper().stopServer(cloudServer);
    }
}
Also used : CloudServer(de.dytanic.cloudnetcore.network.components.CloudServer) MinecraftServer(de.dytanic.cloudnetcore.network.components.MinecraftServer)

Example 3 with CloudServer

use of de.dytanic.cloudnetcore.network.components.CloudServer in project CloudNet by Dytanic.

the class PacketInServerDispatchCommand method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    DefaultType defaultType = data.getObject("defaultType", new TypeToken<DefaultType>() {
    }.getType());
    String serverId = data.getString("serverId");
    String commandLine = data.getString("commandLine");
    if (defaultType == DefaultType.BUKKIT) {
        MinecraftServer minecraftServer = CloudNet.getInstance().getServer(serverId);
        if (minecraftServer != null) {
            minecraftServer.getWrapper().writeServerCommand(commandLine, minecraftServer.getServerInfo());
        }
        CloudServer cloudServer = CloudNet.getInstance().getCloudGameServer(serverId);
        if (cloudServer != null) {
            cloudServer.getWrapper().writeServerCommand(commandLine, minecraftServer.getServerInfo());
        }
    } else {
        ProxyServer proxyServer = CloudNet.getInstance().getProxy(serverId);
        if (proxyServer != null) {
            proxyServer.getWrapper().writeProxyCommand(commandLine, proxyServer.getProxyInfo());
        }
    }
}
Also used : DefaultType(de.dytanic.cloudnet.lib.DefaultType) TypeToken(com.google.gson.reflect.TypeToken) CloudServer(de.dytanic.cloudnetcore.network.components.CloudServer) MinecraftServer(de.dytanic.cloudnetcore.network.components.MinecraftServer) ProxyServer(de.dytanic.cloudnetcore.network.components.ProxyServer)

Example 4 with CloudServer

use of de.dytanic.cloudnetcore.network.components.CloudServer in project CloudNet by Dytanic.

the class PacketInAuthHandler method handleAuth.

@Override
public void handleAuth(Auth auth, AuthType authType, Document authData, PacketSender packetSender) {
    if (!(packetSender instanceof CloudNetClientAuth))
        return;
    CloudNetClientAuth client = (CloudNetClientAuth) packetSender;
    switch(authType) {
        case CLOUD_NET:
            {
                String key = authData.getString("key");
                String id = authData.getString("id");
                if (CloudNet.getInstance().getWrappers().containsKey(id)) {
                    Wrapper cn = CloudNet.getInstance().getWrappers().get(id);
                    String wrapperKey = CloudNet.getInstance().getConfig().getWrapperKey();
                    if (wrapperKey != null && cn.getChannel() == null && wrapperKey.equals(key)) {
                        Channel channel = client.getChannel();
                        channel.pipeline().remove("client");
                        client.getChannel().writeAndFlush(new PacketOutAuthResult(new AuthLoginResult(true))).syncUninterruptibly();
                        channel.pipeline().addLast(new CloudNetClient(cn, channel));
                        return;
                    } else {
                        client.getChannel().writeAndFlush(new PacketOutAuthResult(new AuthLoginResult(false))).syncUninterruptibly();
                        CloudNet.getLogger().info("Authentication failed [" + (wrapperKey != null ? "Invalid WrapperKey or Wrapper is already connected!" : "WrapperKey not found, please copy a wrapper key to this instance") + "]");
                    }
                } else {
                    client.getChannel().writeAndFlush(new PacketOutAuthResult(new AuthLoginResult(false))).syncUninterruptibly();
                }
            }
            return;
        case GAMESERVER_OR_BUNGEE:
            {
                ServiceId serviceId = authData.getObject("serviceId", ServiceId.class);
                if (CloudNet.getInstance().getWrappers().containsKey(serviceId.getWrapperId())) {
                    Wrapper wrapper = CloudNet.getInstance().getWrappers().get(serviceId.getWrapperId());
                    if (wrapper.getServers().containsKey(serviceId.getServerId())) {
                        MinecraftServer minecraftServer = wrapper.getServers().get(serviceId.getServerId());
                        if (minecraftServer.getChannel() == null && minecraftServer.getServerInfo().getServiceId().getUniqueId().equals(serviceId.getUniqueId())) {
                            Channel channel = client.getChannel();
                            channel.pipeline().remove("client");
                            channel.pipeline().addLast(new CloudNetClient(minecraftServer, channel));
                            return;
                        }
                    } else if (wrapper.getCloudServers().containsKey(serviceId.getServerId())) {
                        CloudServer minecraftServer = wrapper.getCloudServers().get(serviceId.getServerId());
                        if (minecraftServer.getChannel() == null && minecraftServer.getServerInfo().getServiceId().getUniqueId().equals(serviceId.getUniqueId())) {
                            Channel channel = client.getChannel();
                            channel.pipeline().remove("client");
                            channel.pipeline().addLast(new CloudNetClient(minecraftServer, channel));
                            return;
                        }
                    } else if (wrapper.getProxys().containsKey(serviceId.getServerId())) {
                        ProxyServer minecraftServer = wrapper.getProxys().get(serviceId.getServerId());
                        if (minecraftServer.getChannel() == null && minecraftServer.getProxyInfo().getServiceId().getUniqueId().equals(serviceId.getUniqueId())) {
                            Channel channel = client.getChannel();
                            channel.pipeline().remove("client");
                            channel.pipeline().addLast(new CloudNetClient(minecraftServer, channel));
                            return;
                        }
                    } else {
                        client.getChannel().close().syncUninterruptibly();
                    }
                } else {
                    client.getChannel().close().syncUninterruptibly();
                }
            }
            return;
        default:
            return;
    }
}
Also used : AuthLoginResult(de.dytanic.cloudnet.lib.network.auth.AuthLoginResult) Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) PacketOutAuthResult(de.dytanic.cloudnet.lib.network.auth.packetio.PacketOutAuthResult) Channel(io.netty.channel.Channel) CloudNetClientAuth(de.dytanic.cloudnetcore.network.CloudNetClientAuth) CloudNetClient(de.dytanic.cloudnetcore.network.CloudNetClient) CloudServer(de.dytanic.cloudnetcore.network.components.CloudServer) ServiceId(de.dytanic.cloudnet.lib.service.ServiceId) MinecraftServer(de.dytanic.cloudnetcore.network.components.MinecraftServer) ProxyServer(de.dytanic.cloudnetcore.network.components.ProxyServer)

Example 5 with CloudServer

use of de.dytanic.cloudnetcore.network.components.CloudServer 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)

Aggregations

CloudServer (de.dytanic.cloudnetcore.network.components.CloudServer)7 MinecraftServer (de.dytanic.cloudnetcore.network.components.MinecraftServer)5 ProxyServer (de.dytanic.cloudnetcore.network.components.ProxyServer)4 Wrapper (de.dytanic.cloudnetcore.network.components.Wrapper)4 TypeToken (com.google.gson.reflect.TypeToken)3 DefaultType (de.dytanic.cloudnet.lib.DefaultType)2 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)2 CloudServerMeta (de.dytanic.cloudnet.lib.cloudserver.CloudServerMeta)1 AuthLoginResult (de.dytanic.cloudnet.lib.network.auth.AuthLoginResult)1 PacketOutAuthResult (de.dytanic.cloudnet.lib.network.auth.packetio.PacketOutAuthResult)1 ServerGroup (de.dytanic.cloudnet.lib.server.ServerGroup)1 ServiceId (de.dytanic.cloudnet.lib.service.ServiceId)1 CollectionWrapper (de.dytanic.cloudnet.lib.utility.CollectionWrapper)1 Document (de.dytanic.cloudnet.lib.utility.document.Document)1 ScheduledTask (de.dytanic.cloudnet.lib.utility.threading.ScheduledTask)1 CloudNetClient (de.dytanic.cloudnetcore.network.CloudNetClient)1 CloudNetClientAuth (de.dytanic.cloudnetcore.network.CloudNetClientAuth)1 INetworkComponent (de.dytanic.cloudnetcore.network.components.INetworkComponent)1 PriorityStopTask (de.dytanic.cloudnetcore.network.components.priority.PriorityStopTask)1 ChannelFilter (de.dytanic.cloudnetcore.network.components.util.ChannelFilter)1