Implement proper logger, shutdown, and IP checking

This commit is contained in:
DoctorMacc 2020-10-06 13:41:50 -04:00
parent e7c00d897f
commit be07a47f9f
2 changed files with 25 additions and 9 deletions

View file

@ -25,10 +25,14 @@
package org.geysermc.platform.fabric;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.geysermc.connector.GeyserLogger;
public class GeyserFabricLogger implements GeyserLogger {
private final Logger logger = LogManager.getLogger("geyser-fabric");
private boolean debug;
public GeyserFabricLogger(boolean isDebug) {
@ -37,38 +41,38 @@ public class GeyserFabricLogger implements GeyserLogger {
@Override
public void severe(String message) {
System.out.println(message);
logger.fatal(message);
}
@Override
public void severe(String message, Throwable error) {
System.out.println(message);
logger.fatal(message, error);
}
@Override
public void error(String message) {
System.out.println(message);
logger.error(message);
}
@Override
public void error(String message, Throwable error) {
System.out.println(message);
logger.error(message, error);
}
@Override
public void warning(String message) {
System.out.println(message);
logger.warn(message);
}
@Override
public void info(String message) {
System.out.println(message);
logger.info(message);
}
@Override
public void debug(String message) {
if (debug) {
info(message);
logger.info(message);
}
}

View file

@ -28,8 +28,9 @@ package org.geysermc.platform.fabric;
import net.fabricmc.api.DedicatedServerModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.dedicated.DedicatedServer;
import org.apache.logging.log4j.LogManager;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.GeyserLogger;
import org.geysermc.connector.bootstrap.GeyserBootstrap;
@ -76,7 +77,7 @@ public class GeyserFabricMod implements DedicatedServerModInitializer, GeyserBoo
(x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
this.geyserConfig = FileUtils.loadConfig(configFile, GeyserFabricConfiguration.class);
} catch (IOException ex) {
System.out.println(LanguageUtils.getLocaleStringLog("geyser.config.failed"));
LogManager.getLogger("geyser-fabric").error(LanguageUtils.getLocaleStringLog("geyser.config.failed"), ex);
ex.printStackTrace();
}
@ -86,6 +87,14 @@ public class GeyserFabricMod implements DedicatedServerModInitializer, GeyserBoo
if (this.geyserConfig.getRemote().getAddress().equalsIgnoreCase("auto")) {
this.geyserConfig.setAutoconfiguredRemote(true);
ServerLifecycleEvents.SERVER_STARTING.register((server) -> {
String ip = server.getServerIp();
int port = server.getServerPort();
if (ip != null && !ip.isEmpty() && !ip.equals("0.0.0.0")) {
this.geyserConfig.getRemote().setAddress(ip);
}
this.geyserConfig.getRemote().setPort(port);
});
}
if (geyserConfig.getBedrock().isCloneRemotePort()) {
@ -94,6 +103,9 @@ public class GeyserFabricMod implements DedicatedServerModInitializer, GeyserBoo
this.connector = GeyserConnector.start(PlatformType.ANDROID, this);
// Register onDisable so players are properly kicked
ServerLifecycleEvents.SERVER_STOPPING.register((server) -> onDisable());
this.geyserPingPassthrough = GeyserLegacyPingPassthrough.init(connector);
this.geyserCommandManager = new GeyserFabricCommandManager(connector);