Search in sources :

Example 1 with IWrapperHandler

use of de.dytanic.cloudnetwrapper.handlers.IWrapperHandler in project CloudNet by Dytanic.

the class CloudNetWrapper method bootstrap.

@Override
public boolean bootstrap() throws Exception {
    if (!optionSet.has("disable-autoupdate"))
        checkForUpdates();
    if (!optionSet.has("disallow_bukkit_download") && !Files.exists(Paths.get("local/spigot.jar")))
        new SetupSpigotVersion().run(cloudNetLogging.getReader());
    Thread thread = new Thread(scheduler);
    thread.setDaemon(true);
    thread.start();
    commandManager.registerCommand(new CommandHelp()).registerCommand(new CommandClear()).registerCommand(new CommandVersion()).registerCommand(new CommandClearCache()).registerCommand(new CommandStop()).registerCommand(new CommandReload());
    networkConnection.getPacketManager().registerHandler(PacketRC.CN_CORE, PacketInWrapperInfo.class);
    networkConnection.getPacketManager().registerHandler(PacketRC.CN_CORE + 1, PacketInStartProxy.class);
    networkConnection.getPacketManager().registerHandler(PacketRC.CN_CORE + 2, PacketInStopProxy.class);
    networkConnection.getPacketManager().registerHandler(PacketRC.CN_CORE + 3, PacketInStartServer.class);
    networkConnection.getPacketManager().registerHandler(PacketRC.CN_CORE + 4, PacketInStopServer.class);
    networkConnection.getPacketManager().registerHandler(PacketRC.CN_CORE + 5, PacketInCreateTemplate.class);
    networkConnection.getPacketManager().registerHandler(PacketRC.CN_CORE + 6, PacketInScreen.class);
    networkConnection.getPacketManager().registerHandler(PacketRC.CN_CORE + 7, PacketInExecuteServerCommand.class);
    networkConnection.getPacketManager().registerHandler(PacketRC.CN_CORE + 8, PacketInInstallUpdate.class);
    networkConnection.getPacketManager().registerHandler(PacketRC.CN_CORE + 9, PacketInExecuteCommand.class);
    networkConnection.getPacketManager().registerHandler(PacketRC.CN_CORE + 10, PacketInCopyServer.class);
    networkConnection.getPacketManager().registerHandler(PacketRC.CN_CORE + 11, PacketInOnlineServer.class);
    networkConnection.getPacketManager().registerHandler(PacketRC.CN_CORE + 12, PacketInUpdateWrapperProperties.class);
    networkConnection.getPacketManager().registerHandler(PacketRC.CN_CORE + 13, PacketInStartCloudServer.class);
    networkConnection.getPacketManager().registerHandler(PacketRC.CN_CORE + 14, PacketInCopyDirectory.class);
    networkConnection.getPacketManager().registerHandler(PacketRC.TEST + 1, PacketInTestResult.class);
    System.out.println("Trying to connect " + networkConnection.getConnectableAddress().getHostName() + ":" + networkConnection.getConnectableAddress().getPort());
    while (networkConnection.getConnectionTrys() < 5 && networkConnection.getChannel() == null) {
        networkConnection.tryConnect(optionSet.has("ssl"), new NetDispatcher(networkConnection, false), auth);
        if (networkConnection.getChannel() != null) {
            networkConnection.sendPacketSynchronized(new PacketOutUpdateWrapperInfo());
            break;
        }
        Thread.sleep(2000);
        if (networkConnection.getConnectionTrys() == 5)
            System.exit(0);
    }
    if (!Files.exists(Paths.get("local/server-icon.png")))
        FileCopy.insertData("files/server-icon.png", "local/server-icon.png");
    System.out.println("Starting process queue...");
    scheduler.runTaskRepeatSync(serverProcessQueue, 0, 20);
    // Server Handlers
    {
        networkConnection.sendPacket(new PacketOutSetReadyWrapper(true));
        IWrapperHandler iWrapperHandler = new StopTimeHandler();
        scheduler.runTaskRepeatSync(iWrapperHandler.toExecutor(), 0, iWrapperHandler.getTicks());
        scheduler.runTaskRepeatSync(new Runnable() {

            @Override
            public void run() {
                networkConnection.sendPacket(new PacketOutUpdateCPUUsage(getCpuUsage()));
            }
        }, 0, 200);
    }
    cloudNetLogging.getHandler().add(new ICloudLoggerHandler() {

        @Override
        public void handleConsole(String input) {
            if (networkConnection.isConnected())
                networkConnection.sendPacket(new PacketOutWrapperScreen(input));
        }
    });
    canDeployed = true;
    RUNNING = true;
    Runtime.getRuntime().addShutdownHook(new Thread(this));
    return true;
}
Also used : PacketOutUpdateWrapperInfo(de.dytanic.cloudnetwrapper.network.packet.out.PacketOutUpdateWrapperInfo) PacketOutSetReadyWrapper(de.dytanic.cloudnetwrapper.network.packet.out.PacketOutSetReadyWrapper) StopTimeHandler(de.dytanic.cloudnetwrapper.handlers.StopTimeHandler) NetDispatcher(de.dytanic.cloudnet.lib.network.NetDispatcher) PacketOutUpdateCPUUsage(de.dytanic.cloudnetwrapper.network.packet.out.PacketOutUpdateCPUUsage) ICloudLoggerHandler(de.dytanic.cloudnet.logging.handler.ICloudLoggerHandler) IWrapperHandler(de.dytanic.cloudnetwrapper.handlers.IWrapperHandler) SetupSpigotVersion(de.dytanic.cloudnetwrapper.setup.SetupSpigotVersion) PacketOutWrapperScreen(de.dytanic.cloudnetwrapper.network.packet.out.PacketOutWrapperScreen)

Aggregations

NetDispatcher (de.dytanic.cloudnet.lib.network.NetDispatcher)1 ICloudLoggerHandler (de.dytanic.cloudnet.logging.handler.ICloudLoggerHandler)1 IWrapperHandler (de.dytanic.cloudnetwrapper.handlers.IWrapperHandler)1 StopTimeHandler (de.dytanic.cloudnetwrapper.handlers.StopTimeHandler)1 PacketOutSetReadyWrapper (de.dytanic.cloudnetwrapper.network.packet.out.PacketOutSetReadyWrapper)1 PacketOutUpdateCPUUsage (de.dytanic.cloudnetwrapper.network.packet.out.PacketOutUpdateCPUUsage)1 PacketOutUpdateWrapperInfo (de.dytanic.cloudnetwrapper.network.packet.out.PacketOutUpdateWrapperInfo)1 PacketOutWrapperScreen (de.dytanic.cloudnetwrapper.network.packet.out.PacketOutWrapperScreen)1 SetupSpigotVersion (de.dytanic.cloudnetwrapper.setup.SetupSpigotVersion)1