Search in sources :

Example 1 with DragonPortalServer

use of org.dragonet.net.inf.portal.DragonPortalServer in project Dragonet-Legacy by DragonetMC.

the class DragonetServer method initialize.

/**
 * Initialize the server, DO NOT CALL IT YOURSELF. Only called by Glowstone
 * main class.
 */
public void initialize() {
    this.logger.info("Starting Dragonet Server version " + (RELEASE ? "Release " : "") + DragonetVersioning.DRAGONET_VERSION + "... ");
    if (!RELEASE) {
        this.logger.warn("** This is a snapshot or an un-official build of Dragonet, you may expirence bugs and errors! ");
    }
    File fileConfig = new File(this.server.getConfigDir() + File.separator + "dragonet.yml");
    if (!fileConfig.exists()) {
        try {
            InputStream inp = DragonetServer.class.getResourceAsStream("/defaults/dragonet.yml");
            try {
                FileOutputStream oup = new FileOutputStream(fileConfig);
                try {
                    int data = -1;
                    while ((data = inp.read()) != -1) {
                        oup.write(data);
                    }
                } finally {
                    oup.close();
                }
            } finally {
                if (inp != null) {
                    inp.close();
                }
            }
        } catch (IOException e) {
        }
    }
    Configuration config = YamlConfiguration.loadConfiguration(fileConfig);
    enabledJs = config.getBoolean("plugin-support.dapis", true);
    enabledPhp = config.getBoolean("plugin-support.php", true);
    enabledDragonPortal = config.getBoolean("dragonportal.enabled", false);
    if (RELEASE) {
        try {
            metrics = new DragonetMetrics(this);
            metrics.start();
        } catch (IOException ex) {
            this.logger.error("Faild to send statistics! ");
        }
    }
    this.logger.info("Current Minecraft PC Version: " + DragonetVersioning.MINECRAFT_PC_VERSION);
    this.logger.info("Current Minecraft: PE Version: " + DragonetVersioning.MINECRAFT_PE_VERSION);
    this.threadPool = Executors.newFixedThreadPool(64);
    String ip = config.getString("server-ip", "0.0.0.0");
    int port = config.getInt("server-port", 19132);
    this.logger.info("Trying to bind on UDP address " + ip + ":" + port + "... ");
    try {
        this.network = new RakNetInterface(sessionManager, ip, port);
    } catch (Exception ex) {
        this.getLogger().error("FAILD TO BIND ON THE Minecraft: Pocket Edition PORT " + port + "(UDP)! ");
        this.getLogger().error("CLOSE THE PROGRAM USING THAT PORT OR CHANGE THE PORT TO SOLVE THIS PROBLEM! ");
        this.getLogger().error("ERROR MESSAGE: " + ex.getMessage());
        ex.printStackTrace();
        this.getServer().shutdown();
        return;
    }
    this.rhino = new Rhino(this.getServer());
    if (enabledJs) {
        this.logger.info("Loading DAPIS scripts... ");
        this.rhino.loadScripts();
    } else {
        this.logger.info("DAPIS Javascript plugins disabled! ");
    }
    this.php = new PHPManager(this);
    if (enabledPhp) {
        this.logger.info("Loading PHP scripts");
        this.php.loadScripts();
    } else {
        this.logger.info("PHP plugins disabled! ");
    }
    // DragonPortal server
    if (enabledDragonPortal) {
        this.getLogger().info("Enabling DragonPortal server... ");
        try {
            this.portalServer = new DragonPortalServer(this, config.getString("dragonportal.bind-address", "127.0.0.1"), config.getInt("dragonportal.bind-port", 25590), config.getString("dragonportal.password", "NOT_SET"));
            this.portalServer.initialize();
        } catch (UnknownHostException ex) {
            this.getLogger().error("Faild to create DragonPoral server. ", ex);
        } catch (IOException ex) {
            this.getLogger().error("Faild to bind DragonPoral server on [" + config.getString("dragonportal.bind-address", "127.0.0.1") + ":" + config.getInt("dragonportal.bind-port", 25590) + "]. ", ex);
        } catch (PasswordNotSetException ex) {
            this.getLogger().error(ex.getMessage());
        }
        enabledDragonPortal = true;
    } else {
        enabledDragonPortal = false;
    }
    // This exists because ScriptAPI.addMethod() must be called AFTER Dragonet initialization
    for (Script s : rhino.getScripts()) {
        this.getLogger().info("[DragonetAPI] Loading script " + s.getUID());
        s.runFunction("onLoad", new Object[] { s });
    }
    this.playerSpawnThreshold = config.getInt("player-spawn-chunk-threshold", 36);
    this.logger.info("Dragonet successfully initialized! ");
}
Also used : Rhino(org.dragonet.rhino.Rhino) Script(org.dragonet.rhino.Script) Configuration(org.bukkit.configuration.Configuration) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) DragonPortalServer(org.dragonet.net.inf.portal.DragonPortalServer) UnknownHostException(java.net.UnknownHostException) InputStream(java.io.InputStream) RakNetInterface(org.dragonet.net.inf.mcpe.RakNetInterface) PHPManager(org.dragonet.plugin.php.PHPManager) IOException(java.io.IOException) PasswordNotSetException(org.dragonet.net.inf.portal.PasswordNotSetException) IOException(java.io.IOException) PasswordNotSetException(org.dragonet.net.inf.portal.PasswordNotSetException) UnknownHostException(java.net.UnknownHostException) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnknownHostException (java.net.UnknownHostException)1 Configuration (org.bukkit.configuration.Configuration)1 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)1 RakNetInterface (org.dragonet.net.inf.mcpe.RakNetInterface)1 DragonPortalServer (org.dragonet.net.inf.portal.DragonPortalServer)1 PasswordNotSetException (org.dragonet.net.inf.portal.PasswordNotSetException)1 PHPManager (org.dragonet.plugin.php.PHPManager)1 Rhino (org.dragonet.rhino.Rhino)1 Script (org.dragonet.rhino.Script)1