]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/server/mods.cpp
Fix revoke debug privs not reliably turn off stuff (#11409)
[dragonfireclient.git] / src / server / mods.cpp
index 778241b953069bb90ae5498aadc5e5c0224b55c4..83fa12da9f5ba12b36412c0931d4b0513c48c6c6 100644 (file)
@@ -21,7 +21,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "filesys.h"
 #include "log.h"
 #include "scripting_server.h"
-#include "subgame.h"
+#include "content/subgames.h"
+#include "porting.h"
+#include "util/metricsbackend.h"
 
 /**
  * Manage server mods
@@ -47,6 +49,7 @@ ServerModManager::ServerModManager(const std::string &worldpath) :
        addModsFromConfig(worldmt, gamespec.addon_mods_paths);
 }
 
+// clang-format off
 // This function cannot be currenctly easily tested but it should be ASAP
 void ServerModManager::loadMods(ServerScripting *script)
 {
@@ -65,12 +68,17 @@ void ServerModManager::loadMods(ServerScripting *script)
                                        "Only characters [a-z0-9_] are allowed.");
                }
                std::string script_path = mod.path + DIR_DELIM + "init.lua";
-               infostream << "  [" << padStringRight(mod.name, 12) << "] [\""
-                          << script_path << "\"]" << std::endl;
+               auto t = porting::getTimeMs();
                script->loadMod(script_path, mod.name);
+               infostream << "Mod \"" << mod.name << "\" loaded after "
+                       << (porting::getTimeMs() - t) << " ms" << std::endl;
        }
+
+       // Run a callback when mods are loaded
+       script->on_mods_loaded();
 }
 
+// clang-format on
 const ModSpec *ServerModManager::getModSpec(const std::string &modname) const
 {
        std::vector<ModSpec>::const_iterator it;
@@ -90,11 +98,12 @@ void ServerModManager::getModNames(std::vector<std::string> &modlist) const
 
 void ServerModManager::getModsMediaPaths(std::vector<std::string> &paths) const
 {
-       for (const ModSpec &spec : m_sorted_mods) {
-               paths.push_back(spec.path + DIR_DELIM + "textures");
-               paths.push_back(spec.path + DIR_DELIM + "sounds");
-               paths.push_back(spec.path + DIR_DELIM + "media");
-               paths.push_back(spec.path + DIR_DELIM + "models");
-               paths.push_back(spec.path + DIR_DELIM + "locale");
+       for (auto it = m_sorted_mods.crbegin(); it != m_sorted_mods.crend(); it++) {
+               const ModSpec &spec = *it;
+               fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "textures");
+               fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "sounds");
+               fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "media");
+               fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "models");
+               fs::GetRecursiveDirs(paths, spec.path + DIR_DELIM + "locale");
        }
 }