1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Fix edge-case where manually set gameid isn't used

This commit is contained in:
sfan5 2025-04-08 12:15:16 +02:00
parent 9d81c02f27
commit 124d770823
4 changed files with 20 additions and 22 deletions

View file

@ -461,7 +461,7 @@ void Server::init()
m_mod_storage_database = openModStorageDatabase(m_path_world); m_mod_storage_database = openModStorageDatabase(m_path_world);
m_mod_storage_database->beginSave(); m_mod_storage_database->beginSave();
m_modmgr = std::make_unique<ServerModManager>(m_path_world); m_modmgr = std::make_unique<ServerModManager>(m_path_world, m_gamespec);
// complain about mods with unsatisfied dependencies // complain about mods with unsatisfied dependencies
if (!m_modmgr->isConsistent()) { if (!m_modmgr->isConsistent()) {

View file

@ -15,15 +15,8 @@
* All new calls to this class must be tested in test_servermodmanager.cpp * All new calls to this class must be tested in test_servermodmanager.cpp
*/ */
/** ServerModManager::ServerModManager(const std::string &worldpath, SubgameSpec gamespec)
* Creates a ServerModManager which targets worldpath
* @param worldpath
*/
ServerModManager::ServerModManager(const std::string &worldpath):
configuration()
{ {
SubgameSpec gamespec = findWorldSubgame(worldpath);
// Add all game mods and all world mods // Add all game mods and all world mods
configuration.addGameMods(gamespec); configuration.addGameMods(gamespec);
configuration.addModsInPath(worldpath + DIR_DELIM + "worldmods", "worldmods"); configuration.addModsInPath(worldpath + DIR_DELIM + "worldmods", "worldmods");

View file

@ -21,10 +21,11 @@ class ServerModManager
public: public:
/** /**
* Creates a ServerModManager which targets worldpath * Creates a ServerModManager
* @param worldpath * @param worldpath path to world
* @param gamespec game used by the world
*/ */
ServerModManager(const std::string &worldpath); ServerModManager(const std::string &worldpath, SubgameSpec gamespec);
/** /**
* Creates an empty ServerModManager. For testing purposes. * Creates an empty ServerModManager. For testing purposes.

View file

@ -20,6 +20,10 @@ public:
std::string m_worlddir; std::string m_worlddir;
static ServerModManager makeManager(const std::string &worldpath) {
return ServerModManager(worldpath, findWorldSubgame(worldpath));
}
void testCreation(); void testCreation();
void testIsConsistent(); void testIsConsistent();
void testUnsatisfiedMods(); void testUnsatisfiedMods();
@ -80,31 +84,31 @@ void TestServerModManager::testCreation()
world_config.set("load_mod_test_mod", "true"); world_config.set("load_mod_test_mod", "true");
UASSERTEQ(bool, world_config.updateConfigFile(path.c_str()), true); UASSERTEQ(bool, world_config.updateConfigFile(path.c_str()), true);
ServerModManager sm(m_worlddir); auto sm = makeManager(m_worlddir);
} }
void TestServerModManager::testGetModsWrongDir() void TestServerModManager::testGetModsWrongDir()
{ {
// Test in non worlddir to ensure no mods are found // Test in non worlddir to ensure no mods are found
ServerModManager sm(m_worlddir + DIR_DELIM + ".."); auto sm = makeManager(m_worlddir + DIR_DELIM "..");
UASSERTEQ(bool, sm.getMods().empty(), true); UASSERTEQ(bool, sm.getMods().empty(), true);
} }
void TestServerModManager::testUnsatisfiedMods() void TestServerModManager::testUnsatisfiedMods()
{ {
ServerModManager sm(m_worlddir); auto sm = makeManager(m_worlddir);
UASSERTEQ(bool, sm.getUnsatisfiedMods().empty(), true); UASSERTEQ(bool, sm.getUnsatisfiedMods().empty(), true);
} }
void TestServerModManager::testIsConsistent() void TestServerModManager::testIsConsistent()
{ {
ServerModManager sm(m_worlddir); auto sm = makeManager(m_worlddir);
UASSERTEQ(bool, sm.isConsistent(), true); UASSERTEQ(bool, sm.isConsistent(), true);
} }
void TestServerModManager::testGetMods() void TestServerModManager::testGetMods()
{ {
ServerModManager sm(m_worlddir); auto sm = makeManager(m_worlddir);
const auto &mods = sm.getMods(); const auto &mods = sm.getMods();
// `ls ./games/devtest/mods | wc -l` + 1 (test mod) // `ls ./games/devtest/mods | wc -l` + 1 (test mod)
UASSERTEQ(std::size_t, mods.size(), 34 + 1); UASSERTEQ(std::size_t, mods.size(), 34 + 1);
@ -132,14 +136,14 @@ void TestServerModManager::testGetMods()
void TestServerModManager::testGetModspec() void TestServerModManager::testGetModspec()
{ {
ServerModManager sm(m_worlddir); auto sm = makeManager(m_worlddir);
UASSERTEQ(const ModSpec *, sm.getModSpec("wrongmod"), NULL); UASSERTEQ(const ModSpec *, sm.getModSpec("wrongmod"), NULL);
UASSERT(sm.getModSpec("basenodes") != NULL); UASSERT(sm.getModSpec("basenodes") != NULL);
} }
void TestServerModManager::testGetModNamesWrongDir() void TestServerModManager::testGetModNamesWrongDir()
{ {
ServerModManager sm(m_worlddir + DIR_DELIM + ".."); auto sm = makeManager(m_worlddir + DIR_DELIM "..");
std::vector<std::string> result; std::vector<std::string> result;
sm.getModNames(result); sm.getModNames(result);
UASSERTEQ(bool, result.empty(), true); UASSERTEQ(bool, result.empty(), true);
@ -147,7 +151,7 @@ void TestServerModManager::testGetModNamesWrongDir()
void TestServerModManager::testGetModNames() void TestServerModManager::testGetModNames()
{ {
ServerModManager sm(m_worlddir); auto sm = makeManager(m_worlddir);
std::vector<std::string> result; std::vector<std::string> result;
sm.getModNames(result); sm.getModNames(result);
UASSERTEQ(bool, result.empty(), false); UASSERTEQ(bool, result.empty(), false);
@ -156,7 +160,7 @@ void TestServerModManager::testGetModNames()
void TestServerModManager::testGetModMediaPathsWrongDir() void TestServerModManager::testGetModMediaPathsWrongDir()
{ {
ServerModManager sm(m_worlddir + DIR_DELIM + ".."); auto sm = makeManager(m_worlddir + DIR_DELIM "..");
std::vector<std::string> result; std::vector<std::string> result;
sm.getModsMediaPaths(result); sm.getModsMediaPaths(result);
UASSERTEQ(bool, result.empty(), true); UASSERTEQ(bool, result.empty(), true);
@ -164,7 +168,7 @@ void TestServerModManager::testGetModMediaPathsWrongDir()
void TestServerModManager::testGetModMediaPaths() void TestServerModManager::testGetModMediaPaths()
{ {
ServerModManager sm(m_worlddir); auto sm = makeManager(m_worlddir);
std::vector<std::string> result; std::vector<std::string> result;
sm.getModsMediaPaths(result); sm.getModsMediaPaths(result);
UASSERTEQ(bool, result.empty(), false); UASSERTEQ(bool, result.empty(), false);