Search in sources :

Example 1 with CloudNetServer

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

Example 2 with CloudNetServer

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

the class CloudNet method shutdown.

@Deprecated
@Override
public boolean shutdown() {
    if (!RUNNING)
        return false;
    TaskScheduler.runtimeScheduler().shutdown();
    this.scheduler.cancelAllTasks();
    this.subScheduler.cancelAllTasks();
    for (Wrapper wrapper : wrappers.values()) {
        System.out.println("Disconnecting wrapper " + wrapper.getServerId());
        wrapper.disconnct();
    }
    if (!optionSet.has("disable-modules")) {
        System.out.println("Disabling Modules...");
        this.moduleManager.disableModules();
    }
    dbHandlers.getStatisticManager().cloudOnlineTime(startupTime);
    this.databaseManager.save().clear();
    CollectionWrapper.iterator(this.cloudServers, new Runnabled<CloudNetServer>() {

        @Override
        public void run(CloudNetServer obj) {
            obj.getBossGroup().shutdownGracefully();
            obj.getWorkerGroup().shutdownGracefully();
        }
    });
    System.out.println("\n    _  _     _______   _                       _          \n" + "  _| || |_  |__   __| | |                     | |         \n" + " |_  __  _|    | |    | |__     __ _   _ __   | | __  ___ \n" + "  _| || |_     | |    | '_ \\   / _` | | '_ \\  | |/ / / __|\n" + " |_  __  _|    | |    | | | | | (_| | | | | | |   <  \\__ \\\n" + "   |_||_|      |_|    |_| |_|  \\__,_| |_| |_| |_|\\_\\ |___/\n" + "                                                          \n" + "                                                          ");
    RUNNING = false;
    this.logger.shutdownAll();
    if (downTown)
        System.exit(0);
    return true;
}
Also used : LocalCloudWrapper(de.dytanic.cloudnetcore.setup.LocalCloudWrapper) CloudNetServer(de.dytanic.cloudnetcore.network.CloudNetServer)

Aggregations

CloudNetServer (de.dytanic.cloudnetcore.network.CloudNetServer)2 LocalCloudWrapper (de.dytanic.cloudnetcore.setup.LocalCloudWrapper)2 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