use of de.dytanic.cloudnetwrapper.network.packet.out.PacketOutSetReadyWrapper 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;
}
Aggregations