Server 2.10.5: far fewer save freezes

Saving makes the game of the asked player freeze for seconds. Joining now asks
for a fresh save only if the stored one is older than JoinSaveMaxAgeMinutes (15)
and something changed - otherwise the stored save plus the world state; regular
saves every 30 minutes (old untouched default 10 is migrated once) and marked
not urgent, so the game can wait for a calm moment (60 s deadline). 3 new tests (168).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-04 00:08:56 +02:00
co-authored by Claude Opus 5.5
parent 4cc71aa079
commit 6e2ef3b570
5 changed files with 63 additions and 13 deletions
+16 -1
View File
@@ -12,7 +12,7 @@ Directory.CreateDirectory(Path.Combine(dir, "save"));
foreach (var name in new[] { "defaultES2File.txt", "items.txt", "meshsave.txt", "graveyard.txt", "notepad.txt" })
File.WriteAllText(Path.Combine(dir, "save", name), "test " + name);
string configPath = Path.Combine(dir, "server.json");
var config = new ServerConfig { LicenseKey = "test", Name = "Test", Port = Port, MaxPlayers = 4, RequireSteam = false, Public = false, Admins = new() { AdminId } };
var config = new ServerConfig { LicenseKey = "test", Name = "Test", Port = Port, MaxPlayers = 4, RequireSteam = false, Public = false, Admins = new() { AdminId }, JoinSaveMaxAgeMinutes = 0 };
config.Save(configPath);
// Host wie im echten Betrieb: besitzt Port + Web-Panel (gleicher Port wie das Spiel) und startet den Gameserver
@@ -32,6 +32,20 @@ void Check(bool ok, string what) { if (ok) passed++; else failed++; Console.Writ
try
{
Console.WriteLine("== Settings migration");
{
string oldCfg = Path.Combine(Path.GetTempPath(), "msco-oldcfg-" + Guid.NewGuid().ToString("N") + ".json");
File.WriteAllText(oldCfg, "{ \"Name\": \"Old\", \"SaveSyncMinutes\": 10 }");
var migrated = ServerConfig.LoadOrCreate(oldCfg, out _);
File.WriteAllText(oldCfg, "{ \"Name\": \"Custom\", \"SaveSyncMinutes\": 5 }");
var custom = ServerConfig.LoadOrCreate(oldCfg, out _);
var again = ServerConfig.LoadOrCreate(oldCfg, out _);
File.Delete(oldCfg);
Check(migrated.SaveSyncMinutes == 30 && migrated.ConfigVersion == ServerConfig.CurrentConfigVersion,
"Old default 'save every 10 minutes' becomes 30 (less freezing)");
Check(custom.SaveSyncMinutes == 5 && again.SaveSyncMinutes == 5, "A value the owner chose is kept");
}
Console.WriteLine("== Join");
var alice = await TestClient.Join("Alice", 0, null);
Check(alice.Welcome != null, "Alice gets Welcome");
@@ -338,6 +352,7 @@ try
var joinTask = TestClient.Join("Newcomer", 0, null);
var request = await inGame.WaitFor(MsgType.SaveRequest, 5000);
Check(request != null, "Server asks the player in the game for the current save");
Check(request != null && request.Length == 5 && request[4] == 1, "A save request for a joining player is marked urgent");
if (request != null)
{
int reqId = BitConverter.ToInt32(request, 0);