Search in sources :

Example 1 with GlobalConfig

use of org.lanternpowered.server.config.GlobalConfig in project LanternServer by LanternPowered.

the class LanternServer method start.

void start() throws IOException {
    final GlobalConfig globalConfig = this.game.getGlobalConfig();
    // Enable the query server if needed
    if (globalConfig.isQueryEnabled()) {
        this.queryServer = new QueryServer(this.game, globalConfig.getShowPluginsToQuery());
    }
    // Enable the rcon server if needed
    if (globalConfig.isRconEnabled()) {
        this.rconServer = new RconServer(globalConfig.getRconPassword());
        this.game.getServiceManager().setProvider(this.pluginContainer, RconService.class, this.rconServer);
    }
    if (globalConfig.getProxyType() == ProxyType.NONE && !globalConfig.isOnlineMode()) {
        this.logger.warn("It is not recommend to run the server in offline mode, this allows people to");
        this.logger.warn("choose any username they want. The server does will use the account attached");
        this.logger.warn("to the username, it doesn't care if it's in offline mode, this will only");
        this.logger.warn("disable the authentication and allow non registered usernames to be used.");
    }
    this.consoleManager.start();
    try {
        bind();
    } catch (BindException e) {
        // descriptive bind error messages
        this.logger.error("The server could not bind to the requested address.");
        if (e.getMessage().startsWith("Cannot assign requested address")) {
            this.logger.error("The 'server.ip' in your global.conf file may not be valid.");
            this.logger.error("Unless you are sure you need it, try removing it.");
            this.logger.error(e.toString());
        } else if (e.getMessage().startsWith("Address already in use")) {
            this.logger.error("The address was already in use. Check that no server is");
            this.logger.error("already running on that port. If needed, try killing all");
            this.logger.error("Java processes using Task Manager or similar.");
            this.logger.error(e.toString());
        } else {
            this.logger.error("An unknown bind error has occurred.", e);
        }
        System.exit(1);
        return;
    }
    bindQuery();
    bindRcon();
    this.logger.info("Ready for connections.");
    this.worldManager.init();
    final Cause gameCause = Cause.of(EventContext.empty(), this.game);
    this.game.postGameStateChange(SpongeEventFactory.createGameAboutToStartServerEvent(gameCause));
    this.game.postGameStateChange(SpongeEventFactory.createGameStartingServerEvent(gameCause));
    final GlobalConfig config = this.game.getGlobalConfig();
    this.maxPlayers = config.getMaxPlayers();
    this.onlineMode = config.isOnlineMode();
    final Path faviconPath = Paths.get(config.getFavicon());
    if (Files.exists(faviconPath)) {
        try {
            this.favicon = LanternFavicon.load(faviconPath);
        } catch (IOException e) {
            this.logger.error("Failed to load the favicon", e);
        }
    } else {
        try {
            this.favicon = LanternFavicon.load(getGame().getAssetManager().getAsset(InternalPluginsInfo.Implementation.IDENTIFIER, "icon/favicon.png").get().getUrl());
        } catch (IOException e) {
            throw new IllegalStateException("Failed to load the default favicon.");
        }
    }
    final String resourcePackPath = config.getDefaultResourcePack();
    if (!resourcePackPath.isEmpty()) {
        try {
            this.resourcePack = ResourcePacks.fromUri(URI.create(resourcePackPath));
        } catch (FileNotFoundException e) {
            this.logger.warn("Couldn't find a valid resource pack at the location: {}", resourcePackPath, e);
        }
    }
    // Initialize a CauseStack on the server thread.
    this.executor.submit(() -> CauseStack.set(new LanternCauseStack()));
    // Start server ticking.
    this.executor.scheduleAtFixedRate(() -> {
        try {
            pulse();
        } catch (Exception e) {
            this.logger.error("Error while pulsing", e);
        }
    }, 0, LanternGame.TICK_DURATION, TimeUnit.MILLISECONDS);
    this.game.postGameStateChange(SpongeEventFactory.createGameStartedServerEvent(gameCause));
}
Also used : Path(java.nio.file.Path) GlobalConfig(org.lanternpowered.server.config.GlobalConfig) QueryServer(org.lanternpowered.server.network.query.QueryServer) RconServer(org.lanternpowered.server.network.rcon.RconServer) Cause(org.spongepowered.api.event.cause.Cause) FileNotFoundException(java.io.FileNotFoundException) BindException(java.net.BindException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BindException(java.net.BindException) IOException(java.io.IOException) LanternCauseStack(org.lanternpowered.server.event.LanternCauseStack)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 BindException (java.net.BindException)1 Path (java.nio.file.Path)1 GlobalConfig (org.lanternpowered.server.config.GlobalConfig)1 LanternCauseStack (org.lanternpowered.server.event.LanternCauseStack)1 QueryServer (org.lanternpowered.server.network.query.QueryServer)1 RconServer (org.lanternpowered.server.network.rcon.RconServer)1 Cause (org.spongepowered.api.event.cause.Cause)1