From b4649248d12863a5898f805d48ab4361b9c61b26 Mon Sep 17 00:00:00 2001 From: Safwat Halaby Date: Thu, 24 Dec 2015 16:53:36 +0200 Subject: [PATCH] Nether and End in settings.ini by default, and created at startup --- src/Root.cpp | 20 +++++++++++++++++--- src/Root.h | 2 +- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Root.cpp b/src/Root.cpp index 1fbbaed3c..99dabc099 100644 --- a/src/Root.cpp +++ b/src/Root.cpp @@ -143,13 +143,16 @@ void cRoot::Start(std::unique_ptr a_OverridesRepo) LOG("Reading server config..."); auto IniFile = cpp14::make_unique(); - if (!IniFile->ReadFile("settings.ini")) + bool IsNewIniFile = !IniFile->ReadFile("settings.ini"); + + if (IsNewIniFile) { LOGWARN("Regenerating settings.ini, all settings will be reset"); IniFile->AddHeaderComment(" This is the main server configuration"); IniFile->AddHeaderComment(" Most of the settings here can be configured using the webadmin interface, if enabled in webadmin.ini"); IniFile->AddHeaderComment(" See: http://wiki.mc-server.org/doku.php?id=configure:settings.ini for further configuration help"); } + auto settingsRepo = cpp14::make_unique(std::move(IniFile), std::move(a_OverridesRepo)); LOG("Starting server..."); @@ -174,7 +177,7 @@ void cRoot::Start(std::unique_ptr a_OverridesRepo) m_BrewingRecipes.reset(new cBrewingRecipes()); LOGD("Loading worlds..."); - LoadWorlds(*settingsRepo); + LoadWorlds(*settingsRepo, IsNewIniFile); LOGD("Loading plugin manager..."); m_PluginManager = new cPluginManager(); @@ -341,10 +344,21 @@ void cRoot::LoadGlobalSettings() -void cRoot::LoadWorlds(cSettingsRepositoryInterface & a_Settings) +void cRoot::LoadWorlds(cSettingsRepositoryInterface & a_Settings, bool a_IsNewIniFile) { // First get the default world AString DefaultWorldName = a_Settings.GetValueSet("Worlds", "DefaultWorld", "world"); + if (a_IsNewIniFile) + { + a_Settings.AddValue("Worlds", "World", "world_nether"); + a_Settings.AddValue("Worlds", "World", "world_end"); + m_pDefaultWorld = new cWorld("world"); + m_WorldsByName["world"] = m_pDefaultWorld; + m_WorldsByName["world_nether"] = new cWorld("world_nether", dimNether, "world"); + m_WorldsByName["world_end"] = new cWorld("world_end", dimEnd, "world"); + return; + } + m_pDefaultWorld = new cWorld(DefaultWorldName.c_str()); m_WorldsByName[ DefaultWorldName ] = m_pDefaultWorld; diff --git a/src/Root.h b/src/Root.h index 142b323a5..064752ab4 100644 --- a/src/Root.h +++ b/src/Root.h @@ -224,7 +224,7 @@ private: void LoadGlobalSettings(); /** Loads the worlds from settings.ini, creates the worldmap */ - void LoadWorlds(cSettingsRepositoryInterface & a_Settings); + void LoadWorlds(cSettingsRepositoryInterface & a_Settings, bool a_NewIniFile); /** Starts each world's life */ void StartWorlds(void);