Search in sources :

Example 11 with MinecraftServer

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

the class ServerLogManager method append.

public void append(String rnd, String serverId) {
    for (String key : screenInfos.keySet()) {
        if (this.screenInfos.getF(key).getFirst().equals(serverId)) {
            screenInfos.add(rnd, new MultiValue<>(serverId, (System.currentTimeMillis() + 600000L)), new ConcurrentLinkedQueue<>(this.screenInfos.getS(key)));
            return;
        }
    }
    MinecraftServer minecraftServer = CloudNet.getInstance().getServer(serverId);
    if (minecraftServer != null) {
        minecraftServer.getWrapper().enableScreen(minecraftServer.getServerInfo());
        screenInfos.add(rnd, new MultiValue<>(serverId, (System.currentTimeMillis() + 600000L)), new ConcurrentLinkedQueue<>());
        return;
    }
    ProxyServer proxyServer = CloudNet.getInstance().getProxy(serverId);
    if (proxyServer != null) {
        proxyServer.getWrapper().enableScreen(proxyServer.getProxyInfo());
        screenInfos.add(rnd, new MultiValue<>(serverId, (System.currentTimeMillis() + 600000L)), new ConcurrentLinkedQueue<>());
    }
}
Also used : MinecraftServer(de.dytanic.cloudnetcore.network.components.MinecraftServer) ProxyServer(de.dytanic.cloudnetcore.network.components.ProxyServer)

Example 12 with MinecraftServer

use of de.dytanic.cloudnetcore.network.components.MinecraftServer 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 13 with MinecraftServer

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

the class PacketInCustomSubChannelMessage method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    DefaultType defaultType = data.getObject("defaultType", DefaultType.class);
    String channel = data.getString("channel");
    String message = data.getString("message");
    Document document = data.getDocument("value");
    if (defaultType.equals(DefaultType.BUKKIT)) {
        if (data.contains("serverId")) {
            MinecraftServer minecraftServer = CloudNet.getInstance().getServer(data.getString("serverId"));
            if (minecraftServer != null) {
                minecraftServer.sendPacket(new PacketOutCustomSubChannelMessage(channel, message, document));
                return;
            }
            CloudServer cloudServer = CloudNet.getInstance().getCloudGameServer(data.getString("serverId"));
            if (cloudServer != null) {
                cloudServer.sendPacket(new PacketOutCustomSubChannelMessage(channel, message, document));
            }
        } else {
            CloudNet.getInstance().getNetworkManager().sendAll(new PacketOutCustomSubChannelMessage(channel, message, document), new ChannelFilter() {

                @Override
                public boolean accept(INetworkComponent networkComponent) {
                    return networkComponent instanceof MinecraftServer || networkComponent instanceof CloudServer;
                }
            });
        }
    } else {
        if (data.contains("serverId")) {
            ProxyServer proxyServer = CloudNet.getInstance().getProxy(data.getString("serverId"));
            if (proxyServer != null) {
                proxyServer.sendPacket(new PacketOutCustomSubChannelMessage(channel, message, document));
            }
        } else {
            CloudNet.getInstance().getNetworkManager().sendToProxy(new PacketOutCustomSubChannelMessage(channel, message, document));
        }
    }
}
Also used : ChannelFilter(de.dytanic.cloudnetcore.network.components.util.ChannelFilter) PacketOutCustomSubChannelMessage(de.dytanic.cloudnetcore.network.packet.out.PacketOutCustomSubChannelMessage) INetworkComponent(de.dytanic.cloudnetcore.network.components.INetworkComponent) DefaultType(de.dytanic.cloudnet.lib.DefaultType) CloudServer(de.dytanic.cloudnetcore.network.components.CloudServer) Document(de.dytanic.cloudnet.lib.utility.document.Document) MinecraftServer(de.dytanic.cloudnetcore.network.components.MinecraftServer) ProxyServer(de.dytanic.cloudnetcore.network.components.ProxyServer)

Example 14 with MinecraftServer

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

the class WebsiteUtils method get.

@Override
public FullHttpResponse get(ChannelHandlerContext channelHandlerContext, QueryDecoder queryDecoder, PathProvider path, HttpRequest httpRequest) throws Exception {
    FullHttpResponse fullHttpResponse = new DefaultFullHttpResponse(httpRequest.getProtocolVersion(), HttpResponseStatus.UNAUTHORIZED);
    fullHttpResponse.headers().set("Content-Type", "application/json");
    Document dataDocument = new Document("success", false).append("reason", new ArrayList<>()).append("response", new Document());
    if (!httpRequest.headers().contains("-Xcloudnet-user") || (!httpRequest.headers().contains("-Xcloudnet-token") && !httpRequest.headers().contains("-Xcloudnet-password")) || !httpRequest.headers().contains("-Xmessage")) {
        dataDocument.append("reason", Arrays.asList("-Xcloudnet-user, -Xcloudnet-token or -Xmessage not found!"));
        fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
        return fullHttpResponse;
    }
    if (httpRequest.headers().contains("-Xcloudnet-token") ? !CloudNet.getInstance().authorization(httpRequest.headers().get("-Xcloudnet-user"), httpRequest.headers().get("-Xcloudnet-token")) : !CloudNet.getInstance().authorizationPassword(httpRequest.headers().get("-Xcloudnet-user"), httpRequest.headers().get("-Xcloudnet-password"))) {
        dataDocument.append("reason", Arrays.asList("failed authorization!"));
        fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
        return fullHttpResponse;
    }
    User user = CloudNet.getInstance().getUser(httpRequest.headers().get("-Xcloudnet-user"));
    switch(httpRequest.headers().get("-Xmessage").toLowerCase()) {
        case "serverinfos":
            {
                if (!user.getPermissions().contains("cloudnet.web.serverinfos") && !user.getPermissions().contains("*")) {
                    dataDocument.append("reason", Arrays.asList("permission denied!"));
                    fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
                    fullHttpResponse.setStatus(HttpResponseStatus.FORBIDDEN);
                    return fullHttpResponse;
                }
                dataDocument.append("success", true);
                Document response = new Document();
                for (MinecraftServer minecraftServer : CloudNet.getInstance().getServers().values()) {
                    response.append(minecraftServer.getServiceId().getServerId(), minecraftServer.getServerInfo());
                }
                dataDocument.append("response", response);
                fullHttpResponse.setStatus(HttpResponseStatus.OK);
                fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
                return fullHttpResponse;
            }
        case "proxyinfos":
            {
                if (!user.getPermissions().contains("cloudnet.web.proxyinfos") && !user.getPermissions().contains("*")) {
                    dataDocument.append("reason", Arrays.asList("permission denied!"));
                    fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
                    fullHttpResponse.setStatus(HttpResponseStatus.FORBIDDEN);
                    return fullHttpResponse;
                }
                dataDocument.append("success", true);
                Document response = new Document();
                for (ProxyServer minecraftServer : CloudNet.getInstance().getProxys().values()) {
                    response.append(minecraftServer.getServiceId().getServerId(), minecraftServer.getProxyInfo());
                }
                dataDocument.append("response", response);
                fullHttpResponse.setStatus(HttpResponseStatus.OK);
                fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
                return fullHttpResponse;
            }
        case "onlinePlayers":
            if (!user.getPermissions().contains("cloudnet.web.onlineplayers") && !user.getPermissions().contains("*")) {
                dataDocument.append("reason", Arrays.asList("permission denied!"));
                fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
                fullHttpResponse.setStatus(HttpResponseStatus.FORBIDDEN);
                return fullHttpResponse;
            }
            dataDocument.append("success", true);
            Document response = new Document();
            for (CloudPlayer cloudPlayer : CloudNet.getInstance().getNetworkManager().getOnlinePlayers().values()) {
                response.append(cloudPlayer.getUniqueId().toString(), cloudPlayer);
            }
            dataDocument.append("response", response);
            fullHttpResponse.setStatus(HttpResponseStatus.OK);
            fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
            return fullHttpResponse;
        case "statistic":
            if (!user.getPermissions().contains("cloudnet.web.statistic") && !user.getPermissions().contains("*")) {
                dataDocument.append("reason", Arrays.asList("permission denied!"));
                fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
                fullHttpResponse.setStatus(HttpResponseStatus.FORBIDDEN);
                return fullHttpResponse;
            }
            dataDocument.append("success", true).append("response", StatisticManager.getInstance().getStatistics());
            fullHttpResponse.setStatus(HttpResponseStatus.OK);
            fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
            return fullHttpResponse;
        case "cloudnetwork":
            if (!user.getPermissions().contains("cloudnet.web.cloudnetwork") && !user.getPermissions().contains("*")) {
                dataDocument.append("reason", Arrays.asList("permission denied!"));
                fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
                fullHttpResponse.setStatus(HttpResponseStatus.FORBIDDEN);
                return fullHttpResponse;
            }
            dataDocument.append("success", true).append("response", CloudNet.getInstance().getNetworkManager().newCloudNetwork());
            fullHttpResponse.setStatus(HttpResponseStatus.OK);
            fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
            return fullHttpResponse;
        case "startServer":
            if (!user.getPermissions().contains("cloudnet.web.startserver") && !user.getPermissions().contains("*")) {
                dataDocument.append("reason", Arrays.asList("permission denied!"));
                fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
                fullHttpResponse.setStatus(HttpResponseStatus.FORBIDDEN);
                return fullHttpResponse;
            }
            dataDocument.append("success", true);
            fullHttpResponse.setStatus(HttpResponseStatus.OK);
            fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
            if (httpRequest.headers().contains("-Xvalue")) {
                String group = httpRequest.headers().get("-Xvalue");
                CloudNet.getInstance().getScheduler().runTaskSync(new Runnable() {

                    @Override
                    public void run() {
                        CloudNet.getInstance().startGameServer(CloudNet.getInstance().getServerGroup(group));
                    }
                });
            }
            return fullHttpResponse;
        case "startProxy":
            if (!user.getPermissions().contains("cloudnet.web.startproxy") && !user.getPermissions().contains("*")) {
                dataDocument.append("reason", Arrays.asList("permission denied!"));
                fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
                fullHttpResponse.setStatus(HttpResponseStatus.FORBIDDEN);
                return fullHttpResponse;
            }
            dataDocument.append("success", true);
            fullHttpResponse.setStatus(HttpResponseStatus.OK);
            fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
            if (httpRequest.headers().contains("-Xvalue")) {
                String group = httpRequest.headers().get("-Xvalue");
                CloudNet.getInstance().getScheduler().runTaskSync(new Runnable() {

                    @Override
                    public void run() {
                        CloudNet.getInstance().startProxy(CloudNet.getInstance().getProxyGroup(group));
                    }
                });
            }
            return fullHttpResponse;
        default:
            {
                dataDocument.append("success", true).append("reason", Arrays.asList("No available -Xmessage command found!"));
                fullHttpResponse.setStatus(HttpResponseStatus.OK);
                fullHttpResponse.content().writeBytes(dataDocument.convertToJsonString().getBytes(StandardCharsets.UTF_8));
                return fullHttpResponse;
            }
    }
}
Also used : User(de.dytanic.cloudnet.lib.user.User) ArrayList(java.util.ArrayList) CloudPlayer(de.dytanic.cloudnet.lib.player.CloudPlayer) Document(de.dytanic.cloudnet.lib.utility.document.Document) MinecraftServer(de.dytanic.cloudnetcore.network.components.MinecraftServer) ProxyServer(de.dytanic.cloudnetcore.network.components.ProxyServer)

Example 15 with MinecraftServer

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

Aggregations

MinecraftServer (de.dytanic.cloudnetcore.network.components.MinecraftServer)17 ProxyServer (de.dytanic.cloudnetcore.network.components.ProxyServer)12 Wrapper (de.dytanic.cloudnetcore.network.components.Wrapper)9 CloudServer (de.dytanic.cloudnetcore.network.components.CloudServer)5 TypeToken (com.google.gson.reflect.TypeToken)3 Document (de.dytanic.cloudnet.lib.utility.document.Document)3 DefaultType (de.dytanic.cloudnet.lib.DefaultType)2 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)2 ServerGroup (de.dytanic.cloudnet.lib.server.ServerGroup)2 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)2 ServiceId (de.dytanic.cloudnet.lib.service.ServiceId)2 AuthLoginResult (de.dytanic.cloudnet.lib.network.auth.AuthLoginResult)1 PacketOutAuthResult (de.dytanic.cloudnet.lib.network.auth.packetio.PacketOutAuthResult)1 ServerProcessMeta (de.dytanic.cloudnet.lib.server.ServerProcessMeta)1 User (de.dytanic.cloudnet.lib.user.User)1 CollectionWrapper (de.dytanic.cloudnet.lib.utility.CollectionWrapper)1 ScheduledTask (de.dytanic.cloudnet.lib.utility.threading.ScheduledTask)1 WrapperChannelDisconnectEvent (de.dytanic.cloudnetcore.api.event.network.WrapperChannelDisconnectEvent)1 CloudNetClient (de.dytanic.cloudnetcore.network.CloudNetClient)1 CloudNetClientAuth (de.dytanic.cloudnetcore.network.CloudNetClientAuth)1