]> git.lizzy.rs Git - minetest.git/blobdiff - src/serverenvironment.cpp
Fix undeclared global in devtest (#10133)
[minetest.git] / src / serverenvironment.cpp
index 32d10f8c0757d7ebed086b7b7bb51edc688b28b9..2c6a39ee31aadb1f37c6829b5e19bb072da86448 100644 (file)
@@ -44,6 +44,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #if USE_POSTGRESQL
 #include "database/database-postgresql.h"
 #endif
+#if USE_LEVELDB
+#include "database/database-leveldb.h"
+#endif
 #include "server/luaentity_sao.h"
 #include "server/player_sao.h"
 
@@ -621,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
@@ -647,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"
@@ -1219,6 +1228,11 @@ void ServerEnvironment::step(float dtime)
                }
        }
 
+       if (m_database_check_interval.step(dtime, 10.0f)) {
+               m_auth_database->pingDatabase();
+               m_player_database->pingDatabase();
+               m_map->pingDatabase();
+       }
        /*
                Manage active block list
        */
@@ -1589,28 +1603,28 @@ void ServerEnvironment::setStaticForActiveObjectsInBlock(
        }
 }
 
-ActiveObjectMessage ServerEnvironment::getActiveObjectMessage()
+bool ServerEnvironment::getActiveObjectMessage(ActiveObjectMessage *dest)
 {
        if(m_active_object_messages.empty())
-               return ActiveObjectMessage(0);
+               return false;
 
-       ActiveObjectMessage message = m_active_object_messages.front();
+       *dest = std::move(m_active_object_messages.front());
        m_active_object_messages.pop();
-       return message;
+       return true;
 }
 
 void ServerEnvironment::getSelectedActiveObjects(
        const core::line3d<f32> &shootline_on_map,
        std::vector<PointedThing> &objects)
 {
-       std::vector<u16> objectIds;
-       getObjectsInsideRadius(objectIds, shootline_on_map.start,
-               shootline_on_map.getLength() + 10.0f);
+       std::vector<ServerActiveObject *> objs;
+       getObjectsInsideRadius(objs, shootline_on_map.start,
+               shootline_on_map.getLength() + 10.0f, nullptr);
        const v3f line_vector = shootline_on_map.getVector();
 
-       for (u16 objectId : objectIds) {
-               ServerActiveObject* obj = getActiveObject(objectId);
-
+       for (auto obj : objs) {
+               if (obj->isGone())
+                       continue;
                aabb3f selection_box;
                if (!obj->getSelectionBox(&selection_box))
                        continue;
@@ -1625,7 +1639,7 @@ void ServerEnvironment::getSelectedActiveObjects(
                if (boxLineCollision(offsetted_box, shootline_on_map.start, line_vector,
                                &current_intersection, &current_normal)) {
                        objects.emplace_back(
-                               (s16) objectId, current_intersection, current_normal,
+                               (s16) obj->getId(), current_intersection, current_normal,
                                (current_intersection - shootline_on_map.start).getLengthSQ());
                }
        }
@@ -2075,6 +2089,7 @@ PlayerDatabase *ServerEnvironment::openPlayerDatabase(const std::string &name,
 
        if (name == "dummy")
                return new Database_Dummy();
+
 #if USE_POSTGRESQL
        if (name == "postgresql") {
                std::string connect_string;
@@ -2082,6 +2097,12 @@ PlayerDatabase *ServerEnvironment::openPlayerDatabase(const std::string &name,
                return new PlayerDatabasePostgreSQL(connect_string);
        }
 #endif
+
+#if USE_LEVELDB
+       if (name == "leveldb")
+               return new PlayerDatabaseLevelDB(savedir);
+#endif
+
        if (name == "files")
                return new PlayerDatabaseFiles(savedir + DIR_DELIM + "players");
 
@@ -2102,7 +2123,7 @@ bool ServerEnvironment::migratePlayersDatabase(const GameParams &game_params,
        if (!world_mt.exists("player_backend")) {
                errorstream << "Please specify your current backend in world.mt:"
                        << std::endl
-                       << "    player_backend = {files|sqlite3|postgresql}"
+                       << "    player_backend = {files|sqlite3|leveldb|postgresql}"
                        << std::endl;
                return false;
        }
@@ -2181,9 +2202,22 @@ AuthDatabase *ServerEnvironment::openAuthDatabase(
        if (name == "sqlite3")
                return new AuthDatabaseSQLite3(savedir);
 
+#if USE_POSTGRESQL
+       if (name == "postgresql") {
+               std::string connect_string;
+               conf.getNoEx("pgsql_auth_connection", connect_string);
+               return new AuthDatabasePostgreSQL(connect_string);
+       }
+#endif
+
        if (name == "files")
                return new AuthDatabaseFiles(savedir);
 
+#if USE_LEVELDB
+       if (name == "leveldb")
+               return new AuthDatabaseLevelDB(savedir);
+#endif
+
        throw BaseException(std::string("Database backend ") + name + " not supported.");
 }