summaryrefslogtreecommitdiffstats
path: root/src/Root.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Root.cpp')
-rw-r--r--src/Root.cpp108
1 files changed, 75 insertions, 33 deletions
diff --git a/src/Root.cpp b/src/Root.cpp
index 737d350ff..87c255b9c 100644
--- a/src/Root.cpp
+++ b/src/Root.cpp
@@ -327,6 +327,17 @@ void cRoot::Start(std::unique_ptr<cSettingsRepositoryInterface> a_OverridesRepo)
+void cRoot::StopServer()
+{
+ m_TerminateEventRaised = true;
+ m_StopEvent.Set();
+ m_InputThreadRunFlag.clear();
+}
+
+
+
+
+
void cRoot::LoadGlobalSettings()
{
// Nothing needed yet
@@ -338,9 +349,9 @@ void cRoot::LoadGlobalSettings()
void cRoot::LoadWorlds(cSettingsRepositoryInterface & a_Settings, bool a_IsNewIniFile)
{
- // First get the default world
if (a_IsNewIniFile)
{
+ a_Settings.AddValue("Worlds", "DefaultWorld", "world");
a_Settings.AddValue("Worlds", "World", "world_nether");
a_Settings.AddValue("Worlds", "World", "world_end");
m_pDefaultWorld = new cWorld("world");
@@ -350,6 +361,7 @@ void cRoot::LoadWorlds(cSettingsRepositoryInterface & a_Settings, bool a_IsNewIn
return;
}
+ // First get the default world
AString DefaultWorldName = a_Settings.GetValueSet("Worlds", "DefaultWorld", "world");
m_pDefaultWorld = new cWorld(DefaultWorldName.c_str());
m_WorldsByName[ DefaultWorldName ] = m_pDefaultWorld;
@@ -398,6 +410,7 @@ void cRoot::LoadWorlds(cSettingsRepositoryInterface & a_Settings, bool a_IsNewIn
a_Settings.AddValue("Worlds", "World", "world_nether");
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
+ 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");
}
}
}
@@ -409,6 +422,28 @@ void cRoot::LoadWorlds(cSettingsRepositoryInterface & a_Settings, bool a_IsNewIn
return;
}
+ /* Here are the world creation rules. Note that these only apply for a world which is in settings.ini but has no world.ini file.
+ If an ini file is present, it overrides the world linkages and the dimension type in cWorld::start()
+ The creation rules are as follows:
+
+ - If a world exists in settings.ini but has no world.ini, then:
+ - If the world name is x_nether, create a world.ini with the dimension type "nether".
+ - If a world called x exists, set it as x_nether's overworld.
+ - Otherwise set the default world as x_nether's overworld.
+
+ - If the world name is x_end, create a world.ini with the dimension type "end".
+ - If a world called x exists, set it as x_end's overworld.
+ - Otherwise set the default world as x_end's overworld.
+
+ - If the world name is x (and doesn't end with _end or _nether)
+ - Create a world.ini with a dimension type of "overworld".
+ - If a world called x_nether exists, set it as x's nether world.
+ - Otherwise set x's nether world to blank.h
+ - If a world called x_end exists, set it as x's end world.
+ - Otherwise set x's nether world to blank.
+
+ */
+
bool FoundAdditionalWorlds = false;
for (auto WorldNameValue : Worlds)
{
@@ -423,7 +458,43 @@ void cRoot::LoadWorlds(cSettingsRepositoryInterface & a_Settings, bool a_IsNewIn
continue;
}
FoundAdditionalWorlds = true;
- cWorld * NewWorld = new cWorld(WorldName.c_str());
+ cWorld * NewWorld;
+ AString LowercaseName = StrToLower(WorldName);
+ AString NetherAppend="_nether";
+ AString EndAppend="_end";
+
+ // if the world is called x_nether
+ if ((LowercaseName.size() > NetherAppend.size()) && (LowercaseName.substr(LowercaseName.size() - NetherAppend.size()) == NetherAppend))
+ {
+ // The world is called x_nether, see if a world called x exists. If yes, choose it as the linked world,
+ // otherwise, choose the default world as the linked world.
+ // As before, any ini settings will completely override this if an ini is already present.
+
+ AString LinkTo = WorldName.substr(0, WorldName.size() - NetherAppend.size());
+ if (GetWorld(LinkTo) == nullptr)
+ {
+ LinkTo = DefaultWorldName;
+ }
+ NewWorld = new cWorld(WorldName.c_str(), dimNether, LinkTo);
+ }
+ // if the world is called x_end
+ else if ((LowercaseName.size() > EndAppend.size()) && (LowercaseName.substr(LowercaseName.size() - EndAppend.size()) == EndAppend))
+ {
+ // The world is called x_end, see if a world called x exists. If yes, choose it as the linked world,
+ // otherwise, choose the default world as the linked world.
+ // As before, any ini settings will completely override this if an ini is already present.
+
+ AString LinkTo = WorldName.substr(0, WorldName.size() - EndAppend.size());
+ if (GetWorld(LinkTo) == nullptr)
+ {
+ LinkTo = DefaultWorldName;
+ }
+ NewWorld = new cWorld(WorldName.c_str(), dimEnd, LinkTo);
+ }
+ else
+ {
+ NewWorld = new cWorld(WorldName.c_str());
+ }
m_WorldsByName[WorldName] = NewWorld;
} // for i - Worlds
@@ -441,29 +512,6 @@ void cRoot::LoadWorlds(cSettingsRepositoryInterface & a_Settings, bool a_IsNewIn
-cWorld * cRoot::CreateAndInitializeWorld(const AString & a_WorldName, eDimension a_Dimension, const AString & a_OverworldName, bool a_InitSpawn)
-{
- cWorld * World = m_WorldsByName[a_WorldName];
- if (World != nullptr)
- {
- return World;
- }
-
- cWorld * NewWorld = new cWorld(a_WorldName.c_str(), a_Dimension, a_OverworldName);
- m_WorldsByName[a_WorldName] = NewWorld;
- NewWorld->Start();
- if (a_InitSpawn)
- {
- NewWorld->InitializeSpawn();
- }
- m_PluginManager->CallHookWorldStarted(*NewWorld);
- return NewWorld;
-}
-
-
-
-
-
void cRoot::StartWorlds(void)
{
for (WorldMap::iterator itr = m_WorldsByName.begin(); itr != m_WorldsByName.end(); ++itr)
@@ -513,7 +561,7 @@ cWorld * cRoot::GetDefaultWorld()
-cWorld * cRoot::GetWorld(const AString & a_WorldName, bool a_SearchForFolder)
+cWorld * cRoot::GetWorld(const AString & a_WorldName)
{
WorldMap::iterator itr = m_WorldsByName.find(a_WorldName);
if (itr != m_WorldsByName.end())
@@ -521,10 +569,6 @@ cWorld * cRoot::GetWorld(const AString & a_WorldName, bool a_SearchForFolder)
return itr->second;
}
- if (a_SearchForFolder && cFile::IsFolder(FILE_IO_PREFIX + a_WorldName))
- {
- return CreateAndInitializeWorld(a_WorldName);
- }
return nullptr;
}
@@ -597,9 +641,7 @@ void cRoot::ExecuteConsoleCommand(const AString & a_Cmd, cCommandOutputCallback
// Some commands are built-in:
if (a_Cmd == "stop")
{
- m_TerminateEventRaised = true;
- m_StopEvent.Set();
- m_InputThreadRunFlag.clear();
+ StopServer();
return;
}
else if (a_Cmd == "restart")