aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-12-03 03:32:30 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-12-03 03:32:30 +0200
commit6b2023dc3eb1b483c92ba967f3335bb6880d2db1 (patch)
tree0ba2a8ba46a47776d6ffbd9591f50560921cf022 /src
parent2f4a92d70192468096e35974f0725532aef837b1 (diff)
downloadminetest-6b2023dc3eb1b483c92ba967f3335bb6880d2db1.tar.gz
minetest-6b2023dc3eb1b483c92ba967f3335bb6880d2db1.tar.bz2
minetest-6b2023dc3eb1b483c92ba967f3335bb6880d2db1.zip
Properly handle mod name conflicts
Diffstat (limited to 'src')
-rw-r--r--src/mods.cpp18
-rw-r--r--src/server.cpp4
2 files changed, 20 insertions, 2 deletions
diff --git a/src/mods.cpp b/src/mods.cpp
index 285c4cbb9..db878d78b 100644
--- a/src/mods.cpp
+++ b/src/mods.cpp
@@ -21,8 +21,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <queue>
#include <fstream>
#include <sstream>
+#include <map>
#include "filesys.h"
#include "strfnd.h"
+#include "log.h"
// Get a dependency-sorted list of ModSpecs
core::list<ModSpec> getMods(core::list<std::string> &modspaths)
@@ -31,6 +33,8 @@ core::list<ModSpec> getMods(core::list<std::string> &modspaths)
std::queue<ModSpec> mods_satisfied;
core::list<ModSpec> mods_unsorted;
core::list<ModSpec> mods_sorted;
+ // name, path: For detecting name conflicts
+ std::map<std::string, std::string> mod_names;
for(core::list<std::string>::Iterator i = modspaths.begin();
i != modspaths.end(); i++){
std::string modspath = *i;
@@ -40,6 +44,19 @@ core::list<ModSpec> getMods(core::list<std::string> &modspaths)
continue;
std::string modname = dirlist[j].name;
std::string modpath = modspath + DIR_DELIM + modname;
+ // Detect mod name conflicts
+ {
+ std::map<std::string, std::string>::const_iterator i;
+ i = mod_names.find(modname);
+ if(i != mod_names.end()){
+ std::string s;
+ infostream<<"WARNING: Mod name conflict detected: "
+ <<std::endl
+ <<"Already loaded: "<<i->second<<std::endl
+ <<"Will not load: "<<modpath<<std::endl;
+ continue;
+ }
+ }
std::set<std::string> depends;
std::ifstream is((modpath+DIR_DELIM+"depends.txt").c_str(),
std::ios_base::binary);
@@ -54,6 +71,7 @@ core::list<ModSpec> getMods(core::list<std::string> &modspaths)
mods_unsorted.push_back(spec);
if(depends.empty())
mods_satisfied.push(spec);
+ mod_names[modname] = modpath;
}
}
// Sort by depencencies
diff --git a/src/server.cpp b/src/server.cpp
index e4052015d..032b57e3c 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -881,9 +881,9 @@ Server::Server(
std::string builtinpath = porting::path_data + DIR_DELIM + "builtin.lua";
// Add default global mod search path
- m_modspaths.push_back(porting::path_data + DIR_DELIM + "mods");
+ m_modspaths.push_front(porting::path_data + DIR_DELIM + "mods");
// Add world mod search path
- m_modspaths.push_back(mapsavedir + DIR_DELIM + "mods");
+ m_modspaths.push_front(mapsavedir + DIR_DELIM + "mods");
// Initialize scripting