move converter to server

This commit is contained in:
Sen 2025-05-12 18:52:03 +02:00
parent f89724e2aa
commit 95b5d0e3e3
7 changed files with 183 additions and 707 deletions

View file

@ -6,9 +6,11 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.text.SimpleDateFormat;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -74,7 +76,6 @@ import common.util.WorldPos;
import common.world.Region;
import common.world.World;
import common.world.WorldServer;
import common.world.Region.FolderInfo;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelException;
@ -92,6 +93,7 @@ import server.command.CommandEnvironment;
import server.command.FixedExecutor;
import server.network.HandshakeHandler;
import server.network.Player;
import server.world.Converter;
public final class Server implements IThreadListener, IServer {
private static final LazyLoadBase<NioEventLoopGroup> SERVER_NIO_EVENTLOOP = new LazyLoadBase<NioEventLoopGroup>() {
@ -155,6 +157,63 @@ public final class Server implements IThreadListener, IServer {
Log.flushLog();
}
public static void saveServerConfig(long time) {
NBTTagCompound data = new NBTTagCompound();
data.setLong("Time", time);
data.setLong("LastAccess", System.currentTimeMillis());
data.setString("Version", Config.VERSION);
NBTTagCompound cfg = new NBTTagCompound();
for(String cvar : Config.VARS.keySet()) {
cfg.setString(cvar, Config.VARS.get(cvar).getValue());
}
data.setTag("Config", cfg);
data.setTag("Universe", UniverseRegistry.saveNbt());
File nfile = new File("server.nbt.tmp");
File lfile = new File("server.nbt");
try {
NBTLoader.writeGZip(data, nfile);
if(lfile.exists())
lfile.delete();
nfile.renameTo(lfile);
}
catch(Exception e) {
Log.IO.error(e, "Fehler beim Schreiben von " + nfile);
}
}
public static long loadServerConfig() {
Config.clear();
UniverseRegistry.clear();
File file = new File("server.nbt");
if(!file.exists())
file = new File("server.nbt.tmp");
if(file.exists()) {
try {
NBTTagCompound tag = NBTLoader.readGZip(file);
NBTTagCompound cfg = tag.getCompoundTag("Config");
for(String key : cfg.getKeySet()) {
Config.set(key, cfg.getString(key), null);
}
UniverseRegistry.loadNbt(tag.getCompoundTag("Universe"));
long lastPlayed = tag.getLong("LastAccess");
String version = tag.hasKey("Version", 8) ? tag.getString("Version") : null;
version = version != null && version.isEmpty() ? "<unbekannt>" : version;
long time = tag.hasKey("Time", 4) ? tag.getLong("Time") : World.START_TIME;
Log.IO.info("Version: %s", version);
Log.IO.info("Weltzeit: %d Ticks / %d Sekunden", time, time / 20L);
Log.IO.info("Zuletzt geladen: %s", new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date(lastPlayed)));
return time;
}
catch(Exception e) {
Log.IO.error(e, "Fehler beim Lesen von " + file);
Config.clear();
UniverseRegistry.clear();
}
}
Log.IO.info("Erstelle neue Welt und Konfiguration");
return World.START_TIME;
}
private Server(boolean debug, boolean ipc) {
this.debug = debug;
this.ipcpipe = ipc;
@ -182,7 +241,7 @@ public final class Server implements IThreadListener, IServer {
public void saveWorldInfo() {
if(!this.debug) {
Region.saveWorldInfo(null, this.space.getDayTime());
saveServerConfig(this.space.getDayTime());
WorldServer.saveWarps(this.warps);
}
}
@ -257,13 +316,14 @@ public final class Server implements IThreadListener, IServer {
long time = System.currentTimeMillis();
Log.JNI.info("Starte Server Version " + Config.VERSION);
if(!this.debug) {
Converter.convert();
this.setMessage("Welt wird erstellt und geladen");
FolderInfo info = Region.loadWorldInfo(null);
long wtime = loadServerConfig();
// if(dtime == -1L) // {
// dtime = World.START_TIME;
//// Config.set("spawnDim", "1", null);
//// }
this.worlds.add(this.space = new WorldServer(this, info == null ? World.START_TIME : info.time,
this.worlds.add(this.space = new WorldServer(this, wtime,
Space.INSTANCE, false));
this.dimensions.put(this.space.dimension.getDimensionId(), this.space);
new File("players").mkdirs();

File diff suppressed because it is too large Load diff