Search in sources :

Example 1 with WrapperExternal

use of de.dytanic.cloudnet.lib.network.WrapperExternal in project CloudNet by Dytanic.

the class PacketInWrapperInfo method handleInput.

@Override
public void handleInput(Document data, PacketSender packetSender) {
    WrapperExternal wrapperExternal = data.getObject("wrapper", new TypeToken<WrapperExternal>() {
    }.getType());
    CloudNetWrapper.getInstance().setSimpledUser(wrapperExternal.getUser());
    CloudNetWrapper.getInstance().getServerGroups().clear();
    NetworkUtils.addAll(CloudNetWrapper.getInstance().getServerGroups(), wrapperExternal.getServerGroups(), new Acceptable<ServerGroup>() {

        @Override
        public boolean isAccepted(ServerGroup value) {
            System.out.println("Importing server group [" + value.getName() + "] from CloudNet-Master");
            return true;
        }
    });
    CloudNetWrapper.getInstance().getProxyGroups().clear();
    NetworkUtils.addAll(CloudNetWrapper.getInstance().getProxyGroups(), wrapperExternal.getProxyGroups(), new Acceptable<ProxyGroup>() {

        @Override
        public boolean isAccepted(ProxyGroup value) {
            System.out.println("Importing proxy group [" + value.getName() + "] from CloudNet-Master");
            return true;
        }
    });
}
Also used : ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) TypeToken(com.google.gson.reflect.TypeToken) WrapperExternal(de.dytanic.cloudnet.lib.network.WrapperExternal)

Example 2 with WrapperExternal

use of de.dytanic.cloudnet.lib.network.WrapperExternal in project CloudNet by Dytanic.

the class Wrapper method updateWrapper.

public Wrapper updateWrapper() {
    if (getChannel() == null)
        return this;
    java.util.Map<String, ServerGroup> groups = NetworkUtils.newConcurrentHashMap();
    for (ServerGroup serverGroup : CloudNet.getInstance().getServerGroups().values()) if (serverGroup.getWrapper().contains(networkInfo.getId())) {
        groups.put(serverGroup.getName(), serverGroup);
        sendPacket(new PacketOutCreateTemplate(serverGroup));
    }
    java.util.Map<String, ProxyGroup> proxyGroups = NetworkUtils.newConcurrentHashMap();
    for (ProxyGroup serverGroup : CloudNet.getInstance().getProxyGroups().values()) if (serverGroup.getWrapper().contains(networkInfo.getId())) {
        proxyGroups.put(serverGroup.getName(), serverGroup);
        sendPacket(new PacketOutCreateTemplate(serverGroup));
    }
    SimpledUser simpledUser = null;
    User user = CollectionWrapper.filter(CloudNet.getInstance().getUsers(), new Acceptable<User>() {

        @Override
        public boolean isAccepted(User value) {
            return networkInfo.getUser().equals(value.getName());
        }
    });
    if (user != null) {
        simpledUser = user.toSimple();
    }
    WrapperExternal wrapperExternal = new WrapperExternal(CloudNet.getInstance().getNetworkManager().newCloudNetwork(), simpledUser, groups, proxyGroups);
    sendPacket(new PacketOutWrapperInfo(wrapperExternal));
    return this;
}
Also used : ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) SimpledUser(de.dytanic.cloudnet.lib.user.SimpledUser) User(de.dytanic.cloudnet.lib.user.User) SimpledUser(de.dytanic.cloudnet.lib.user.SimpledUser) WrapperExternal(de.dytanic.cloudnet.lib.network.WrapperExternal)

Aggregations

WrapperExternal (de.dytanic.cloudnet.lib.network.WrapperExternal)2 ProxyGroup (de.dytanic.cloudnet.lib.server.ProxyGroup)2 ServerGroup (de.dytanic.cloudnet.lib.server.ServerGroup)2 TypeToken (com.google.gson.reflect.TypeToken)1 SimpledUser (de.dytanic.cloudnet.lib.user.SimpledUser)1 User (de.dytanic.cloudnet.lib.user.User)1