Search in sources :

Example 1 with WebServer

use of de.dytanic.cloudnet.web.server.WebServer in project CloudNet by Dytanic.

the class CloudNet method bootstrap.

@Override
public boolean bootstrap() throws Exception {
    if (!optionSet.has("disable-autoupdate"))
        checkForUpdates();
    dbHandlers = new DatabaseBasicHandlers(databaseManager);
    dbHandlers.getStatisticManager().addStartup();
    this.moduleManager.setDisabledModuleList(config.getDisabledModules());
    if (!optionSet.has("disable-modules")) {
        System.out.println("Loading Modules...");
        moduleManager.loadModules();
    }
    for (WrapperMeta wrapperMeta : config.getWrappers()) {
        System.out.println("Loading Wrapper " + wrapperMeta.getId() + " @ " + wrapperMeta.getHostName());
        this.wrappers.put(wrapperMeta.getId(), new Wrapper(wrapperMeta));
    }
    // Packet Init
    this.users = config.getUsers();
    // Groups Loading
    NetworkUtils.addAll(this.serverGroups, config.getServerGroups(), new Acceptable<ServerGroup>() {

        @Override
        public boolean isAccepted(ServerGroup value) {
            System.out.println("Loading ServerGroup: " + value.getName());
            setupGroup(value);
            return true;
        }
    });
    NetworkUtils.addAll(this.proxyGroups, config.getProxyGroups(), new Acceptable<ProxyGroup>() {

        @Override
        public boolean isAccepted(ProxyGroup value) {
            System.out.println("Loading ProxyGroup: " + value.getName());
            setupProxy(value);
            return true;
        }
    });
    webServer = new WebServer(optionSet.has("ssl"), config.getWebServerConfig().getAddress(), config.getWebServerConfig().getPort());
    // CommandManager Appending
    this.initialCommands();
    this.initWebHandlers();
    this.initPacketHandlers();
    // Scheduler Startup
    {
        Thread thread = new Thread(scheduler);
        thread.setDaemon(true);
        thread.start();
    }
    {
        Thread thread = new Thread(subScheduler);
        thread.setDaemon(true);
        thread.start();
    }
    for (ConnectableAddress connectableAddress : config.getAddresses()) {
        Thread thread = new Thread(new Runnable() {

            @Override
            public void run() {
                new CloudNetServer(optionSet, connectableAddress);
            }
        });
        thread.setDaemon(true);
        thread.start();
    }
    webServer.bind();
    RUNNING = true;
    Runtime.getRuntime().addShutdownHook(new Thread(this));
    /*==================================*/
    {
        if (!optionSet.has("onlyConsole")) {
            CloudStartupHandler cloudStartupHandler = new CloudStartupHandler();
            CloudPriorityStartupHandler cloudPriorityStartupHandler = new CloudPriorityStartupHandler();
            CloudPriorityGroupStartupHandler cloudPriorityGroupStartupHandler = new CloudPriorityGroupStartupHandler();
            CloudPlayerRemoverHandler cloudPlayerRemoverHandler = new CloudPlayerRemoverHandler();
            scheduler.runTaskRepeatSync(cloudStartupHandler, 0, cloudStartupHandler.getTicks());
            scheduler.runTaskRepeatSync(cloudPriorityGroupStartupHandler, 0, cloudPriorityGroupStartupHandler.getTicks());
            scheduler.runTaskRepeatSync(cloudPriorityStartupHandler, 0, cloudPriorityStartupHandler.getTicks());
            scheduler.runTaskRepeatSync(cloudPlayerRemoverHandler, 0, cloudPlayerRemoverHandler.getTicks());
        }
        CloudStopCheckHandler cloudStopCheck = new CloudStopCheckHandler();
        scheduler.runTaskRepeatSync(cloudStopCheck, 0, cloudStopCheck.getTicks());
        scheduler.runTaskRepeatSync(serverLogManager, 0, 2000);
        scheduler.runTaskRepeatSync(new Runnable() {

            @Override
            public void run() {
                for (CloudPlayer cloudPlayer : networkManager.getWaitingPlayers().values()) {
                    if ((cloudPlayer.getLoginTimeStamp().getTime() + 10000L) < System.currentTimeMillis()) {
                        networkManager.getWaitingPlayers().remove(cloudPlayer.getUniqueId());
                    }
                }
            }
        }, 0, 100);
    }
    if (!optionSet.has("disable-modules"))
        System.out.println("Enabling Modules...");
    moduleManager.enableModules();
    // Event Init
    eventManager.callEvent(new CloudInitEvent());
    new LocalCloudWrapper().run(optionSet);
    return true;
}
Also used : LocalCloudWrapper(de.dytanic.cloudnetcore.setup.LocalCloudWrapper) ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) CloudPlayer(de.dytanic.cloudnet.lib.player.CloudPlayer) CloudInitEvent(de.dytanic.cloudnetcore.api.event.network.CloudInitEvent) ConnectableAddress(de.dytanic.cloudnet.lib.ConnectableAddress) CloudNetServer(de.dytanic.cloudnetcore.network.CloudNetServer) DatabaseBasicHandlers(de.dytanic.cloudnetcore.database.DatabaseBasicHandlers) WebServer(de.dytanic.cloudnet.web.server.WebServer) LocalCloudWrapper(de.dytanic.cloudnetcore.setup.LocalCloudWrapper)

Aggregations

ConnectableAddress (de.dytanic.cloudnet.lib.ConnectableAddress)1 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)1 ProxyGroup (de.dytanic.cloudnet.lib.server.ProxyGroup)1 WebServer (de.dytanic.cloudnet.web.server.WebServer)1 CloudInitEvent (de.dytanic.cloudnetcore.api.event.network.CloudInitEvent)1 DatabaseBasicHandlers (de.dytanic.cloudnetcore.database.DatabaseBasicHandlers)1 CloudNetServer (de.dytanic.cloudnetcore.network.CloudNetServer)1 LocalCloudWrapper (de.dytanic.cloudnetcore.setup.LocalCloudWrapper)1