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:
+28
-1
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user