internal static bool LoadWorldList()
{
World newMainWorld = null;
Worlds = new World[0];
if (File.Exists(Paths.WorldListFileName))
{
try {
XDocument doc = XDocument.Load(Paths.WorldListFileName);
XElement root = doc.Root;
if (root != null)
{
foreach (XElement el in root.Elements("World"))
{
#if !DEBUG
try {
#endif
LoadWorldListEntry(el);
#if !DEBUG
}
catch (Exception ex) {
Logger.LogAndReportCrash("An error occured while trying to parse one of the entries on the world list",
"800Craft", ex, false);
}
#endif
}
XAttribute temp;
if ((temp = root.Attribute("main")) != null)
{
World suggestedMainWorld = FindWorldExact(temp.Value);
if (suggestedMainWorld != null)
{
newMainWorld = suggestedMainWorld;
}
else if (firstWorld != null)
{
// if specified main world does not exist, use first-defined world
Logger.Log(LogType.Warning,
"The specified main world \"{0}\" does not exist. " +
"\"{1}\" was designated main instead. You can use /WMain to change it.",
temp.Value, firstWorld.Name);
newMainWorld = firstWorld;
}
// if firstWorld was also null, LoadWorldList() should try creating a new mainWorld
}
else if (firstWorld != null)
{
newMainWorld = firstWorld;
}
}
} catch (Exception ex) {
Logger.LogAndReportCrash("Error occured while trying to load the world list.", "800Craft", ex, true);
return(false);
}
if (newMainWorld == null)
{
Logger.Log(LogType.Error,
"Server.Start: Could not load any of the specified worlds, or no worlds were specified. " +
"Creating default \"main\" world.");
newMainWorld = AddWorld(null, "main", MapGeneratorOld.GenerateFlatgrass(128, 128, 64), true);
}
}
else
{
Logger.Log(LogType.SystemActivity,
"Server.Start: No world list found. Creating default \"main\" world.");
newMainWorld = AddWorld(null, "main", MapGeneratorOld.GenerateFlatgrass(128, 128, 64), true);
}
// if there is no default world still, die.
if (newMainWorld == null)
{
throw new Exception("Could not create any worlds.");
}
else if (newMainWorld.AccessSecurity.HasRestrictions)
{
Logger.Log(LogType.Warning,
"Server.LoadWorldList: Main world cannot have any access restrictions. " +
"Access permission for \"{0}\" has been reset.",
newMainWorld.Name);
newMainWorld.AccessSecurity.Reset();
}
MainWorld = newMainWorld;
return(true);
}