Clear message instead of crash when data/ or the save is not readable

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-26 21:15:13 +02:00
co-authored by Claude Opus 5.5
parent f439f13268
commit 48f76e97cc
3 changed files with 67 additions and 7 deletions
+28 -1
View File
@@ -26,7 +26,34 @@ GameServer.Log("MSCO dedicated server " + GameServer.ModVersion + " (" + Runtime
GameServer.Log("Data folder: " + dataDir);
GameServer.Log("Master server: " + MasterServer.Url);
var config = ServerConfig.LoadOrCreate(configPath, out bool created);
// Datenordner beschreibbar? (Linux/Docker: gehört er einem anderen Benutzer, gleich klar melden statt abzustürzen)
try
{
string probe = Path.Combine(dataDir, ".write-test");
File.WriteAllText(probe, "ok");
File.Delete(probe);
}
catch (Exception e) when (e is UnauthorizedAccessException or IOException)
{
GameServer.Log("No write access to the data folder " + dataDir + ": " + e.Message);
GameServer.Log(GameServer.PermissionHint());
Pause();
return 1;
}
ServerConfig config;
bool created;
try
{
config = ServerConfig.LoadOrCreate(configPath, out created);
}
catch (Exception e) when (e is UnauthorizedAccessException or IOException)
{
GameServer.Log("Cannot read " + configPath + ": " + e.Message);
GameServer.Log(GameServer.PermissionHint());
Pause();
return 1;
}
var fromEnvironment = config.ApplyEnvironment();
if (fromEnvironment.Count > 0)
GameServer.Log("Settings overridden by environment (.env): " + string.Join(", ", fromEnvironment));