From 124d77082337e77a031ca681c6ec035a2ca918d9 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 8 Apr 2025 12:15:16 +0200 Subject: [PATCH] Fix edge-case where manually set gameid isn't used --- src/server.cpp | 2 +- src/server/mods.cpp | 9 +-------- src/server/mods.h | 7 ++++--- src/unittest/test_servermodmanager.cpp | 24 ++++++++++++++---------- 4 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index 13e46883a..4fe2d3c4a 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -461,7 +461,7 @@ void Server::init() m_mod_storage_database = openModStorageDatabase(m_path_world); m_mod_storage_database->beginSave(); - m_modmgr = std::make_unique(m_path_world); + m_modmgr = std::make_unique(m_path_world, m_gamespec); // complain about mods with unsatisfied dependencies if (!m_modmgr->isConsistent()) { diff --git a/src/server/mods.cpp b/src/server/mods.cpp index 1aee40a1a..e2d5debba 100644 --- a/src/server/mods.cpp +++ b/src/server/mods.cpp @@ -15,15 +15,8 @@ * All new calls to this class must be tested in test_servermodmanager.cpp */ -/** - * Creates a ServerModManager which targets worldpath - * @param worldpath - */ -ServerModManager::ServerModManager(const std::string &worldpath): - configuration() +ServerModManager::ServerModManager(const std::string &worldpath, SubgameSpec gamespec) { - SubgameSpec gamespec = findWorldSubgame(worldpath); - // Add all game mods and all world mods configuration.addGameMods(gamespec); configuration.addModsInPath(worldpath + DIR_DELIM + "worldmods", "worldmods"); diff --git a/src/server/mods.h b/src/server/mods.h index a82d4d572..b10b232b2 100644 --- a/src/server/mods.h +++ b/src/server/mods.h @@ -21,10 +21,11 @@ class ServerModManager public: /** - * Creates a ServerModManager which targets worldpath - * @param worldpath + * Creates a ServerModManager + * @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. diff --git a/src/unittest/test_servermodmanager.cpp b/src/unittest/test_servermodmanager.cpp index 500d0f288..5689658d9 100644 --- a/src/unittest/test_servermodmanager.cpp +++ b/src/unittest/test_servermodmanager.cpp @@ -20,6 +20,10 @@ public: std::string m_worlddir; + static ServerModManager makeManager(const std::string &worldpath) { + return ServerModManager(worldpath, findWorldSubgame(worldpath)); + } + void testCreation(); void testIsConsistent(); void testUnsatisfiedMods(); @@ -80,31 +84,31 @@ void TestServerModManager::testCreation() world_config.set("load_mod_test_mod", "true"); UASSERTEQ(bool, world_config.updateConfigFile(path.c_str()), true); - ServerModManager sm(m_worlddir); + auto sm = makeManager(m_worlddir); } void TestServerModManager::testGetModsWrongDir() { // 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); } void TestServerModManager::testUnsatisfiedMods() { - ServerModManager sm(m_worlddir); + auto sm = makeManager(m_worlddir); UASSERTEQ(bool, sm.getUnsatisfiedMods().empty(), true); } void TestServerModManager::testIsConsistent() { - ServerModManager sm(m_worlddir); + auto sm = makeManager(m_worlddir); UASSERTEQ(bool, sm.isConsistent(), true); } void TestServerModManager::testGetMods() { - ServerModManager sm(m_worlddir); + auto sm = makeManager(m_worlddir); const auto &mods = sm.getMods(); // `ls ./games/devtest/mods | wc -l` + 1 (test mod) UASSERTEQ(std::size_t, mods.size(), 34 + 1); @@ -132,14 +136,14 @@ void TestServerModManager::testGetMods() void TestServerModManager::testGetModspec() { - ServerModManager sm(m_worlddir); + auto sm = makeManager(m_worlddir); UASSERTEQ(const ModSpec *, sm.getModSpec("wrongmod"), NULL); UASSERT(sm.getModSpec("basenodes") != NULL); } void TestServerModManager::testGetModNamesWrongDir() { - ServerModManager sm(m_worlddir + DIR_DELIM + ".."); + auto sm = makeManager(m_worlddir + DIR_DELIM ".."); std::vector result; sm.getModNames(result); UASSERTEQ(bool, result.empty(), true); @@ -147,7 +151,7 @@ void TestServerModManager::testGetModNamesWrongDir() void TestServerModManager::testGetModNames() { - ServerModManager sm(m_worlddir); + auto sm = makeManager(m_worlddir); std::vector result; sm.getModNames(result); UASSERTEQ(bool, result.empty(), false); @@ -156,7 +160,7 @@ void TestServerModManager::testGetModNames() void TestServerModManager::testGetModMediaPathsWrongDir() { - ServerModManager sm(m_worlddir + DIR_DELIM + ".."); + auto sm = makeManager(m_worlddir + DIR_DELIM ".."); std::vector result; sm.getModsMediaPaths(result); UASSERTEQ(bool, result.empty(), true); @@ -164,7 +168,7 @@ void TestServerModManager::testGetModMediaPathsWrongDir() void TestServerModManager::testGetModMediaPaths() { - ServerModManager sm(m_worlddir); + auto sm = makeManager(m_worlddir); std::vector result; sm.getModsMediaPaths(result); UASSERTEQ(bool, result.empty(), false);