1
0

Merge pull request #3150 from LogicParrot/worldTweaks

Auto clean bad world linkages
This commit is contained in:
LogicParrot 2016-04-19 14:20:02 +03:00
commit 4348b2f5a4
3 changed files with 16 additions and 17 deletions

View File

@ -345,6 +345,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID,
if (World == nullptr) if (World == nullptr)
{ {
World = cRoot::Get()->GetDefaultWorld(); World = cRoot::Get()->GetDefaultWorld();
m_Player->SetPosition(World->GetSpawnX(), World->GetSpawnY(), World->GetSpawnZ());
} }
if (m_Player->GetGameMode() == eGameMode_NotSet) if (m_Player->GetGameMode() == eGameMode_NotSet)

View File

@ -410,7 +410,7 @@ void cRoot::LoadWorlds(cSettingsRepositoryInterface & a_Settings, bool a_IsNewIn
a_Settings.AddValue("Worlds", "World", "world_nether"); a_Settings.AddValue("Worlds", "World", "world_nether");
a_Settings.AddValue("Worlds", "World", "world_end"); a_Settings.AddValue("Worlds", "World", "world_end");
Worlds = a_Settings.GetValues("Worlds"); // Refresh the Worlds list so that the rest of the function works as usual Worlds = a_Settings.GetValues("Worlds"); // Refresh the Worlds list so that the rest of the function works as usual
LOG("The server detected an old default config with bad world linkages. This has been autofixed by adding \"world_nether\" and \"world_end\" to settings.ini"); LOG("The server detected an old default config with bad world linkages. This has been autofixed by adding \"world_nether\" and \"world_end\" to settings.ini. If you do not want this autofix to trigger, please remove the nether and / or end from settings.ini and from world/world.ini");
} }
} }
} }

View File

@ -530,38 +530,36 @@ void cWorld::Start(void)
m_LinkedOverworldName = IniFile.GetValueSet("LinkedWorlds", "OverworldName", GetLinkedOverworldName()); m_LinkedOverworldName = IniFile.GetValueSet("LinkedWorlds", "OverworldName", GetLinkedOverworldName());
} }
// If we are linked to one or more worlds that do not exist, ask the server to stop. // If we are linked to one or more worlds that do not exist, unlink them
AString BadWorlds = "";
cRoot * Root = cRoot::Get(); cRoot * Root = cRoot::Get();
if (GetDimension() == dimOverworld) if (GetDimension() == dimOverworld)
{ {
if ((!m_LinkedNetherWorldName.empty()) && (Root->GetWorld(m_LinkedNetherWorldName) == nullptr)) if ((!m_LinkedNetherWorldName.empty()) && (Root->GetWorld(m_LinkedNetherWorldName) == nullptr))
{ {
BadWorlds = m_LinkedNetherWorldName; IniFile.SetValue("LinkedWorlds", "NetherWorldName", "");
LOG("%s Is linked to a nonexisting nether world called \"%s\". The server has modified \"%s/world.ini\" and removed this invalid link.",
GetName().c_str(), m_LinkedNetherWorldName.c_str(), GetName().c_str());
m_LinkedNetherWorldName = "";
} }
if ((!m_LinkedEndWorldName.empty()) && (Root->GetWorld(m_LinkedEndWorldName) == nullptr)) if ((!m_LinkedEndWorldName.empty()) && (Root->GetWorld(m_LinkedEndWorldName) == nullptr))
{ {
if (!(BadWorlds.empty())) IniFile.SetValue("LinkedWorlds", "EndWorldName", "");
{ LOG("%s Is linked to a nonexisting end world called \"%s\". The server has modified \"%s/world.ini\" and removed this invalid link.",
BadWorlds += ", "; GetName().c_str(), m_LinkedEndWorldName.c_str(), GetName().c_str());
} m_LinkedEndWorldName = "";
BadWorlds += m_LinkedEndWorldName;
} }
} }
else else
{ {
if ((!m_LinkedOverworldName.empty()) && (Root->GetWorld(m_LinkedOverworldName) == nullptr)) if ((!m_LinkedOverworldName.empty()) && (Root->GetWorld(m_LinkedOverworldName) == nullptr))
{ {
BadWorlds = m_LinkedOverworldName; IniFile.SetValue("LinkedWorlds", "OverworldName", "");
LOG("%s Is linked to a nonexisting overworld called \"%s\". The server has modified \"%s/world.ini\" and removed this invalid link.",
GetName().c_str(), m_LinkedOverworldName.c_str(), GetName().c_str());
m_LinkedOverworldName = "";
} }
} }
if (!BadWorlds.empty())
{
const char * WorldName = m_WorldName.c_str();
LOGERROR("\n###### ERROR: \"%s\" is linked to the following nonexisting world/s:\n%s\n\nPlease edit %s/world.ini and fix this.\n\nNote that the server started enforcing proper world linkages recently. And people with older configs may naturally get this error. If you just want a working default config and don't mind losing this world, delete the folder \"%s\" and the server will receate one for you. Otherwise edit the world.ini file and fix the invalid linkages.\n\nMore help and info:\nhttps://forum.cuberite.org/thread-2366.html\n######\n",
WorldName, BadWorlds.c_str(), WorldName, WorldName);
cRoot::Get()->StopServer();
}
// Adjust the enum-backed variables into their respective bounds: // Adjust the enum-backed variables into their respective bounds: