Search in sources :

Example 6 with ServiceId

use of de.dytanic.cloudnet.lib.service.ServiceId in project CloudNet by Dytanic.

the class PacketInDisableScreen method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    ServiceId serviceId = data.getObject("serviceId", new TypeToken<ServiceId>() {
    }.getType());
    CloudNet.getInstance().getScreenProvider().handleDisableScreen(serviceId);
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) ServiceId(de.dytanic.cloudnet.lib.service.ServiceId)

Example 7 with ServiceId

use of de.dytanic.cloudnet.lib.service.ServiceId in project CloudNet by Dytanic.

the class PacketInEnableScreen method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    if (!(packetSender instanceof Wrapper))
        return;
    ServiceId serviceId = data.getObject("serviceId", new TypeToken<ServiceId>() {
    }.getType());
    CloudNet.getInstance().getScreenProvider().handleEnableScreen(serviceId, ((Wrapper) packetSender));
}
Also used : Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) TypeToken(com.google.gson.reflect.TypeToken) ServiceId(de.dytanic.cloudnet.lib.service.ServiceId)

Example 8 with ServiceId

use of de.dytanic.cloudnet.lib.service.ServiceId in project CloudNet by Dytanic.

the class Wrapper method getUsedMemoryAndWaitings.

public int getUsedMemoryAndWaitings() {
    AtomicInteger integer = new AtomicInteger(getUsedMemory());
    CollectionWrapper.iterator(this.waitingServices.values(), new Runnabled<Quad<Integer, Integer, ServiceId, Template>>() {

        @Override
        public void run(Quad<Integer, Integer, ServiceId, Template> obj) {
            integer.addAndGet(obj.getSecond());
        }
    });
    return integer.get();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Quad(de.dytanic.cloudnet.lib.utility.Quad) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServiceId(de.dytanic.cloudnet.lib.service.ServiceId) Template(de.dytanic.cloudnet.lib.server.template.Template)

Example 9 with ServiceId

use of de.dytanic.cloudnet.lib.service.ServiceId in project CloudNet by Dytanic.

the class CloudNet method startGameServerAsync.

public void startGameServerAsync(Wrapper wrapper, String serverId, ServerGroup serverGroup, ServerConfig config, int memory, boolean prioritystop, String url, String[] processParameters, boolean onlineMode, Collection<ServerInstallablePlugin> plugins, String customServerName, Properties serverProperties) {
    if (wrapper == null)
        return;
    if (serverGroup.getTemplates().size() == 0)
        return;
    Map<String, Integer> templateMap = new WeakHashMap<>();
    Collection<Integer> collection = CollectionWrapper.getCollection(wrapper.getServers(), new Catcher<Integer, MinecraftServer>() {

        @Override
        public Integer doCatch(MinecraftServer key) {
            return key.getServerInfo().getPort();
        }
    });
    collection.addAll(wrapper.getBinndedPorts());
    CollectionWrapper.iterator(getServers(serverGroup.getName()), new Runnabled<MinecraftServer>() {

        @Override
        public void run(MinecraftServer obj) {
            Template template = obj.getProcessMeta().getTemplate();
            if (!templateMap.containsKey(template.getName()))
                templateMap.put(template.getName(), 1);
            else
                templateMap.put(template.getName(), templateMap.get(template.getName()) + 1);
        }
    });
    CollectionWrapper.iterator(wrapper.getWaitingServices().values(), new Runnabled<Quad<Integer, Integer, ServiceId, Template>>() {

        @Override
        public void run(Quad<Integer, Integer, ServiceId, Template> obj) {
            Template template = obj.getFourth();
            if (template != null) {
                if (!templateMap.containsKey(template.getName()))
                    templateMap.put(template.getName(), 1);
                else
                    templateMap.put(template.getName(), templateMap.get(template.getName()) + 1);
            }
        }
    });
    for (Template template : serverGroup.getTemplates()) {
        if (!templateMap.containsKey(template.getName()))
            templateMap.put(template.getName(), 1);
        else
            templateMap.put(template.getName(), templateMap.get(template.getName()) + 1);
    }
    Map.Entry<String, Integer> entry = null;
    for (Map.Entry<String, Integer> values : templateMap.entrySet()) {
        if (entry == null) {
            entry = values;
        } else {
            if (entry.getValue() >= values.getValue()) {
                entry = values;
            }
        }
    }
    Template template = null;
    for (Template t : serverGroup.getTemplates()) {
        if (entry.getKey().equalsIgnoreCase(t.getName())) {
            template = t;
            break;
        }
    }
    if (template == null)
        return;
    int startport = wrapper.getWrapperInfo().getStartPort();
    startport = (startport + NetworkUtils.RANDOM.nextInt(20) + 1);
    while (collection.contains(startport)) {
        startport = (startport + NetworkUtils.RANDOM.nextInt(20) + 1);
    }
    List<Template> templates = CollectionWrapper.transform(serverGroup.getTemplates());
    if (templates.size() == 0)
        return;
    ServerProcessMeta serverProcessMeta = new ServerProcessMeta(newServiceId(serverGroup, wrapper, serverId), memory, prioritystop, url, processParameters, onlineMode, plugins, config, customServerName, startport, serverProperties, template);
    wrapper.startGameServerAsync(serverProcessMeta);
}
Also used : Template(de.dytanic.cloudnet.lib.server.template.Template) ServiceId(de.dytanic.cloudnet.lib.service.ServiceId) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

ServiceId (de.dytanic.cloudnet.lib.service.ServiceId)9 Template (de.dytanic.cloudnet.lib.server.template.Template)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Wrapper (de.dytanic.cloudnetcore.network.components.Wrapper)3 TypeToken (com.google.gson.reflect.TypeToken)2 MinecraftServer (de.dytanic.cloudnetcore.network.components.MinecraftServer)2 ProxyServer (de.dytanic.cloudnetcore.network.components.ProxyServer)2 LocalCloudWrapper (de.dytanic.cloudnetcore.setup.LocalCloudWrapper)2 AuthLoginResult (de.dytanic.cloudnet.lib.network.auth.AuthLoginResult)1 PacketOutAuthResult (de.dytanic.cloudnet.lib.network.auth.packetio.PacketOutAuthResult)1 Quad (de.dytanic.cloudnet.lib.utility.Quad)1 CloudNetClient (de.dytanic.cloudnetcore.network.CloudNetClient)1 CloudNetClientAuth (de.dytanic.cloudnetcore.network.CloudNetClientAuth)1 CloudServer (de.dytanic.cloudnetcore.network.components.CloudServer)1 Channel (io.netty.channel.Channel)1