Search in sources :

Example 6 with Wrapper

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

the class CloudNetClient method channelInactive.

@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
    if ((!channel.isActive() || !channel.isOpen() || !channel.isWritable())) {
        System.out.println("Channel disconnected [" + channel.remoteAddress().toString() + "/serverId=" + networkComponent.getServerId() + "]");
        ctx.close().syncUninterruptibly();
        if (networkComponent instanceof MinecraftServer) {
            ((MinecraftServer) networkComponent).setChannelLostTime(System.currentTimeMillis());
        }
        if (networkComponent instanceof ProxyServer) {
            ((ProxyServer) networkComponent).setChannelLostTime(System.currentTimeMillis());
        }
        if (networkComponent instanceof Wrapper) {
            try {
                ((Wrapper) networkComponent).disconnct();
            } catch (Exception ex) {
                ((Wrapper) networkComponent).getServers().clear();
                ((Wrapper) networkComponent).getProxys().clear();
            }
            CloudNet.getInstance().getEventManager().callEvent(new WrapperChannelDisconnectEvent(((Wrapper) networkComponent)));
        }
        networkComponent.setChannel(null);
    }
}
Also used : Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) WrapperChannelDisconnectEvent(de.dytanic.cloudnetcore.api.event.network.WrapperChannelDisconnectEvent) IOException(java.io.IOException) MinecraftServer(de.dytanic.cloudnetcore.network.components.MinecraftServer) ProxyServer(de.dytanic.cloudnetcore.network.components.ProxyServer)

Example 7 with Wrapper

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

the class CloudNetServer method initChannel.

@Override
protected void initChannel(Channel channel) throws Exception {
    System.out.println("Channel [" + channel.remoteAddress().toString() + "] connecting...");
    ChannelConnectEvent channelConnectEvent = new ChannelConnectEvent(false, channel);
    CloudNet.getInstance().getEventManager().callEvent(channelConnectEvent);
    if (channelConnectEvent.isCancelled()) {
        channel.close().syncUninterruptibly();
        return;
    }
    String[] address = channel.remoteAddress().toString().split(":");
    String host = address[0].replaceFirst(NetworkUtils.SLASH_STRING, NetworkUtils.EMPTY_STRING);
    for (Wrapper cn : CloudNet.getInstance().getWrappers().values()) {
        if (cn.getChannel() == null && cn.getNetworkInfo().getHostName().equalsIgnoreCase(host)) {
            if (sslContext != null)
                channel.pipeline().addLast(sslContext.newHandler(channel.alloc()));
            NetworkUtils.initChannel(channel);
            channel.pipeline().addLast("client", new CloudNetClientAuth(channel, this));
            return;
        }
        if (cn.getNetworkInfo().getHostName().equals(host)) {
            if (sslContext != null)
                channel.pipeline().addLast(sslContext.newHandler(channel.alloc()));
            NetworkUtils.initChannel(channel);
            CloudNetClientAuth cloudNetProxyClientAuth = new CloudNetClientAuth(channel, this);
            channel.pipeline().addLast("client", cloudNetProxyClientAuth);
            return;
        }
    }
    channel.close().addListener(ChannelFutureListener.CLOSE_ON_FAILURE).addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
}
Also used : Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) ChannelConnectEvent(de.dytanic.cloudnetcore.api.event.network.ChannelConnectEvent)

Example 8 with Wrapper

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

the class PacketInUpdateServerGroup method handleInput.

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

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

the class PacketInCopyDirectory method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    if (!data.contains("serverInfo") || !data.contains("directory"))
        return;
    ServerInfo info = data.getObject("serverInfo", ServerInfo.TYPE);
    Wrapper wrapper = CloudNet.getInstance().getWrappers().get(info.getServiceId().getWrapperId());
    if (wrapper != null && wrapper.getChannel() != null)
        wrapper.sendPacket(new Packet(PacketRC.CN_CORE + 14, data));
}
Also used : Wrapper(de.dytanic.cloudnetcore.network.components.Wrapper) Packet(de.dytanic.cloudnet.lib.network.protocol.packet.Packet) ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo)

Example 10 with Wrapper

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

Aggregations

Wrapper (de.dytanic.cloudnetcore.network.components.Wrapper)23 TypeToken (com.google.gson.reflect.TypeToken)11 MinecraftServer (de.dytanic.cloudnetcore.network.components.MinecraftServer)9 ProxyServer (de.dytanic.cloudnetcore.network.components.ProxyServer)9 ServerGroup (de.dytanic.cloudnet.lib.server.ServerGroup)5 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)5 ProxyGroup (de.dytanic.cloudnet.lib.server.ProxyGroup)4 CloudServer (de.dytanic.cloudnetcore.network.components.CloudServer)4 ServiceId (de.dytanic.cloudnet.lib.service.ServiceId)3 ProxyInfo (de.dytanic.cloudnet.lib.server.info.ProxyInfo)2 CollectionWrapper (de.dytanic.cloudnet.lib.utility.CollectionWrapper)2 MapWrapper (de.dytanic.cloudnet.lib.utility.MapWrapper)2 ScheduledTask (de.dytanic.cloudnet.lib.utility.threading.ScheduledTask)2 PriorityStopTask (de.dytanic.cloudnetcore.network.components.priority.PriorityStopTask)2 CloudFlareService (de.dytanic.cloudnet.cloudflare.CloudFlareService)1 CloudFlareDatabase (de.dytanic.cloudnet.cloudflare.database.CloudFlareDatabase)1 CloudServerMeta (de.dytanic.cloudnet.lib.cloudserver.CloudServerMeta)1 WrapperInfo (de.dytanic.cloudnet.lib.network.WrapperInfo)1 AuthLoginResult (de.dytanic.cloudnet.lib.network.auth.AuthLoginResult)1 PacketOutAuthResult (de.dytanic.cloudnet.lib.network.auth.packetio.PacketOutAuthResult)1