Fix Server triggering wrong errors if environment init fails
authorsfan5 <sfan5@live.de>
Thu, 7 May 2020 19:39:04 +0000 (21:39 +0200)
committersfan5 <sfan5@live.de>
Thu, 7 May 2020 20:02:22 +0000 (22:02 +0200)
src/serverenvironment.cpp
src/serverenvironment.h

index 27432e9736544330de7e674384375fa730f66224..6bf7399cff43c8625e745c3947e25686c1fd41a4 100644 (file)
@@ -624,6 +624,9 @@ PlayerSAO *ServerEnvironment::loadPlayer(RemotePlayer *player, bool *new_player,
 
 void ServerEnvironment::saveMeta()
 {
+       if (!m_meta_loaded)
+               return;
+
        std::string path = m_path_world + DIR_DELIM "env_meta.txt";
 
        // Open file and serialize
@@ -650,6 +653,9 @@ void ServerEnvironment::saveMeta()
 
 void ServerEnvironment::loadMeta()
 {
+       SANITY_CHECK(!m_meta_loaded);
+       m_meta_loaded = true;
+
        // If file doesn't exist, load default environment metadata
        if (!fs::PathExists(m_path_world + DIR_DELIM "env_meta.txt")) {
                infostream << "ServerEnvironment: Loading default environment metadata"
index f814b95c0297bdadba410dc40dc889f2141e5956..e2f1a3784092d7292a232797667cdef3214f29a4 100644 (file)
@@ -440,6 +440,8 @@ private:
        IntervalLimiter m_active_blocks_management_interval;
        IntervalLimiter m_active_block_modifier_interval;
        IntervalLimiter m_active_blocks_nodemetadata_interval;
+       // Whether the variables below have been read from file yet
+       bool m_meta_loaded = false;
        // Time from the beginning of the game in seconds.
        // Incremented in step().
        u32 m_game_time = 0;