Add BackupStoragePatch to wrap save folder backups, ensuring storage writes are paused during backups. Introduce ModStorage and ModTables for per-mod database management, supporting schema migrations and table versioning. Add ForgeInstance as a static reference to server-side Forge. Include relevant tests.

This commit is contained in:
Overlord committed 2026-10-02 13:57:50 +02:00
1 parent c56046469e
commit 68cd9fc4f9
31 files changed
+2124 -42

No files matched your search

@@ -0,0 +1,11 @@
package dev.overlord.zomboidforge.compat.b42;
import dev.overlord.zomboidforge.core.Forge;
/** The one {@link Forge} of the server, shared by the hook classes. */
public final class ForgeInstance
{
public static final Forge FORGE = Forge.fromSystemProperties();
private ForgeInstance() {}
}
@@ -2,10 +2,13 @@ package dev.overlord.zomboidforge.compat.b42.hooks;
import dev.overlord.zomboidforge.api.GameVersion;
import dev.overlord.zomboidforge.api.ZomboidForge;
import dev.overlord.zomboidforge.core.Forge;
import dev.overlord.zomboidforge.compat.b42.ForgeInstance;
import dev.overlord.zomboidforge.core.storage.StorageDatabase;
import dev.overlord.zomboidforge.core.mods.ModLoadException;
import zombie.ZomboidFileSystem;
import zombie.core.Core;
import zombie.network.GameServer;
import java.nio.file.Path;
@@ -17,8 +20,6 @@ import java.nio.file.Path;
@SuppressWarnings("CallToPrintStackTrace")
public final class ServerHooks
{
private static final Forge FORGE = Forge.fromSystemProperties();
private ServerHooks() {}
/**
@@ -39,7 +40,10 @@ public final class ServerHooks
GameVersion game = GameVersion.parse(Core.getInstance().getGameAndBuildVersion());
Path gameJar = Path.of(Core.class.getProtectionDomain().getCodeSource().getLocation().toURI());
ServerHooks.FORGE.load(game, gameJar, ServerHooks.class.getClassLoader());
// The save folder ZipBackup zips. getCurrentSaveDir() depends on Core.gameMode, which GameServer.main sets to "Multiplayer" only later.
Path storage = Path.of(ZomboidFileSystem.instance.getCacheDir(), "Saves", "Multiplayer", GameServer.serverName, StorageDatabase.FILE);
ForgeInstance.FORGE.load(game, gameJar, ServerHooks.class.getClassLoader(), storage);
return true;
}
@@ -68,7 +72,7 @@ public final class ServerHooks
{
try
{
ServerHooks.FORGE.started();
ForgeInstance.FORGE.started();
System.out.println("[ZomboidForge] Server started (ZomboidForge " + ZomboidForge.VERSION + ").");
}
catch (RuntimeException e) { e.printStackTrace(); }
@@ -82,7 +86,7 @@ public final class ServerHooks
*/
public static void onTick()
{
try { ServerHooks.FORGE.tick(); }
try { ForgeInstance.FORGE.tick(); }
catch (RuntimeException e) { e.printStackTrace(); }
}
@@ -99,7 +103,7 @@ public final class ServerHooks
try
{
System.out.println("[ZomboidForge] Server stopping.");
ServerHooks.FORGE.stopping();
ForgeInstance.FORGE.stopping();
}
catch (RuntimeException e) { e.printStackTrace(); }
}
@@ -0,0 +1,25 @@
package dev.overlord.zomboidforge.compat.b42.hooks;
import dev.overlord.zomboidforge.compat.b42.ForgeInstance;
/** Hooks called by patched {@code zombie.core.backup.ZipBackup} code. */
@SuppressWarnings("CallToPrintStackTrace")
public final class StorageHooks
{
private StorageHooks() {}
/**
* Called by the patched {@code ZipBackup.makeBackupFile} on the thread that makes the backup:
* with {@code true} before the vanilla method, with {@code false} after it, also when it threw.
* Storage writes wait in between, so the zipped {@code zomboidforge.db} is complete.
*/
public static void backupRunning(boolean running)
{
try
{
if (running) ForgeInstance.FORGE.backupStarted();
else ForgeInstance.FORGE.backupFinished();
}
catch (RuntimeException e) { e.printStackTrace(); }
}
}