mirror of
https://github.com/minetest/minetest.git
synced 2025-07-06 18:00:21 +02:00
Add online content repository
Replaces mods and texture pack tabs with a single content tab
This commit is contained in:
@ -358,6 +358,7 @@ add_custom_target(GenerateVersion
|
||||
|
||||
|
||||
add_subdirectory(threading)
|
||||
add_subdirectory(content)
|
||||
add_subdirectory(database)
|
||||
add_subdirectory(gui)
|
||||
add_subdirectory(mapgen)
|
||||
@ -372,6 +373,7 @@ set(common_SRCS
|
||||
${database_SRCS}
|
||||
${mapgen_SRCS}
|
||||
${server_SRCS}
|
||||
${content_SRCS}
|
||||
ban.cpp
|
||||
chat.cpp
|
||||
clientiface.cpp
|
||||
@ -403,7 +405,6 @@ set(common_SRCS
|
||||
mapsector.cpp
|
||||
metadata.cpp
|
||||
modchannels.cpp
|
||||
mods.cpp
|
||||
nameidmapping.cpp
|
||||
nodedef.cpp
|
||||
nodemetadata.cpp
|
||||
@ -428,7 +429,6 @@ set(common_SRCS
|
||||
serverobject.cpp
|
||||
settings.cpp
|
||||
staticobject.cpp
|
||||
subgame.cpp
|
||||
terminal_chat_console.cpp
|
||||
tileanimation.cpp
|
||||
tool.cpp
|
||||
|
@ -43,7 +43,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "mapblock.h"
|
||||
#include "minimap.h"
|
||||
#include "modchannels.h"
|
||||
#include "mods.h"
|
||||
#include "content/mods.h"
|
||||
#include "profiler.h"
|
||||
#include "shader.h"
|
||||
#include "gettext.h"
|
||||
|
7
src/content/CMakeLists.txt
Normal file
7
src/content/CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
||||
set(content_SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/content.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/packages.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/mods.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/subgames.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
108
src/content/content.cpp
Normal file
108
src/content/content.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
/*
|
||||
Minetest
|
||||
Copyright (C) 2018 rubenwardy <rw@rubenwardy.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <fstream>
|
||||
#include "content/content.h"
|
||||
#include "content/subgames.h"
|
||||
#include "content/mods.h"
|
||||
#include "filesys.h"
|
||||
#include "settings.h"
|
||||
|
||||
enum ContentType
|
||||
{
|
||||
ECT_UNKNOWN,
|
||||
ECT_MOD,
|
||||
ECT_MODPACK,
|
||||
ECT_GAME,
|
||||
ECT_TXP
|
||||
};
|
||||
|
||||
ContentType getContentType(const ContentSpec &spec)
|
||||
{
|
||||
std::ifstream modpack_is((spec.path + DIR_DELIM + "modpack.txt").c_str());
|
||||
if (modpack_is.good()) {
|
||||
modpack_is.close();
|
||||
return ECT_MODPACK;
|
||||
}
|
||||
|
||||
std::ifstream init_is((spec.path + DIR_DELIM + "init.lua").c_str());
|
||||
if (init_is.good()) {
|
||||
init_is.close();
|
||||
return ECT_MOD;
|
||||
}
|
||||
|
||||
std::ifstream game_is((spec.path + DIR_DELIM + "game.conf").c_str());
|
||||
if (game_is.good()) {
|
||||
game_is.close();
|
||||
return ECT_GAME;
|
||||
}
|
||||
|
||||
std::ifstream txp_is((spec.path + DIR_DELIM + "texture_pack.conf").c_str());
|
||||
if (txp_is.good()) {
|
||||
txp_is.close();
|
||||
return ECT_TXP;
|
||||
}
|
||||
|
||||
return ECT_UNKNOWN;
|
||||
}
|
||||
|
||||
void parseContentInfo(ContentSpec &spec)
|
||||
{
|
||||
std::string conf_path;
|
||||
|
||||
switch (getContentType(spec)) {
|
||||
case ECT_MOD:
|
||||
spec.type = "mod";
|
||||
conf_path = spec.path + DIR_DELIM + "mod.conf";
|
||||
break;
|
||||
case ECT_MODPACK:
|
||||
spec.type = "modpack";
|
||||
conf_path = spec.path + DIR_DELIM + "mod.conf";
|
||||
break;
|
||||
case ECT_GAME:
|
||||
spec.type = "game";
|
||||
conf_path = spec.path + DIR_DELIM + "game.conf";
|
||||
break;
|
||||
case ECT_TXP:
|
||||
spec.type = "txp";
|
||||
conf_path = spec.path + DIR_DELIM + "texture_pack.conf";
|
||||
break;
|
||||
default:
|
||||
spec.type = "unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
Settings conf;
|
||||
if (!conf_path.empty() && conf.readConfigFile(conf_path.c_str())) {
|
||||
if (conf.exists("name"))
|
||||
spec.name = conf.get("name");
|
||||
|
||||
if (conf.exists("description"))
|
||||
spec.desc = conf.get("description");
|
||||
|
||||
if (conf.exists("author"))
|
||||
spec.author = conf.get("author");
|
||||
}
|
||||
|
||||
if (spec.desc.empty()) {
|
||||
std::ifstream is((spec.path + DIR_DELIM + "description.txt").c_str());
|
||||
spec.desc = std::string((std::istreambuf_iterator<char>(is)),
|
||||
std::istreambuf_iterator<char>());
|
||||
}
|
||||
}
|
33
src/content/content.h
Normal file
33
src/content/content.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
Minetest
|
||||
Copyright (C) 2018 rubenwardy <rw@rubenwardy.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "config.h"
|
||||
#include "convert_json.h"
|
||||
|
||||
struct ContentSpec
|
||||
{
|
||||
std::string type;
|
||||
std::string author;
|
||||
std::string name;
|
||||
std::string desc;
|
||||
std::string path;
|
||||
};
|
||||
|
||||
void parseContentInfo(ContentSpec &spec);
|
@ -21,23 +21,23 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include <fstream>
|
||||
#include <json/json.h>
|
||||
#include <algorithm>
|
||||
#include "mods.h"
|
||||
#include "content/mods.h"
|
||||
#include "filesys.h"
|
||||
#include "log.h"
|
||||
#include "subgame.h"
|
||||
#include "content/subgames.h"
|
||||
#include "settings.h"
|
||||
#include "porting.h"
|
||||
#include "convert_json.h"
|
||||
|
||||
bool parseDependsString(std::string &dep,
|
||||
std::unordered_set<char> &symbols)
|
||||
bool parseDependsString(std::string &dep, std::unordered_set<char> &symbols)
|
||||
{
|
||||
dep = trim(dep);
|
||||
symbols.clear();
|
||||
size_t pos = dep.size();
|
||||
while (pos > 0 && !string_allowed(dep.substr(pos-1, 1), MODNAME_ALLOWED_CHARS)) {
|
||||
while (pos > 0 &&
|
||||
!string_allowed(dep.substr(pos - 1, 1), MODNAME_ALLOWED_CHARS)) {
|
||||
// last character is a symbol, not part of the modname
|
||||
symbols.insert(dep[pos-1]);
|
||||
symbols.insert(dep[pos - 1]);
|
||||
--pos;
|
||||
}
|
||||
dep = trim(dep.substr(0, pos));
|
||||
@ -48,19 +48,22 @@ void parseModContents(ModSpec &spec)
|
||||
{
|
||||
// NOTE: this function works in mutual recursion with getModsInPath
|
||||
Settings info;
|
||||
info.readConfigFile((spec.path+DIR_DELIM+"mod.conf").c_str());
|
||||
info.readConfigFile((spec.path + DIR_DELIM + "mod.conf").c_str());
|
||||
|
||||
if (info.exists("name"))
|
||||
spec.name = info.get("name");
|
||||
|
||||
if (info.exists("author"))
|
||||
spec.author = info.get("author");
|
||||
|
||||
spec.depends.clear();
|
||||
spec.optdepends.clear();
|
||||
spec.is_modpack = false;
|
||||
spec.modpack_content.clear();
|
||||
|
||||
// Handle modpacks (defined by containing modpack.txt)
|
||||
std::ifstream modpack_is((spec.path+DIR_DELIM+"modpack.txt").c_str());
|
||||
if (modpack_is.good()) { // a modpack, recursively get the mods in it
|
||||
std::ifstream modpack_is((spec.path + DIR_DELIM + "modpack.txt").c_str());
|
||||
if (modpack_is.good()) { // a modpack, recursively get the mods in it
|
||||
modpack_is.close(); // We don't actually need the file
|
||||
spec.is_modpack = true;
|
||||
spec.modpack_content = getModsInPath(spec.path, true);
|
||||
@ -73,8 +76,10 @@ void parseModContents(ModSpec &spec)
|
||||
if (info.exists("depends")) {
|
||||
mod_conf_has_depends = true;
|
||||
std::string dep = info.get("depends");
|
||||
// clang-format off
|
||||
dep.erase(std::remove_if(dep.begin(), dep.end(),
|
||||
static_cast<int(*)(int)>(&std::isspace)), dep.end());
|
||||
static_cast<int (*)(int)>(&std::isspace)), dep.end());
|
||||
// clang-format on
|
||||
for (const auto &dependency : str_split(dep, ',')) {
|
||||
spec.depends.insert(dependency);
|
||||
}
|
||||
@ -83,8 +88,10 @@ void parseModContents(ModSpec &spec)
|
||||
if (info.exists("optional_depends")) {
|
||||
mod_conf_has_depends = true;
|
||||
std::string dep = info.get("optional_depends");
|
||||
// clang-format off
|
||||
dep.erase(std::remove_if(dep.begin(), dep.end(),
|
||||
static_cast<int(*)(int)>(&std::isspace)), dep.end());
|
||||
static_cast<int (*)(int)>(&std::isspace)), dep.end());
|
||||
// clang-format on
|
||||
for (const auto &dependency : str_split(dep, ',')) {
|
||||
spec.optdepends.insert(dependency);
|
||||
}
|
||||
@ -116,15 +123,16 @@ void parseModContents(ModSpec &spec)
|
||||
if (info.exists("description")) {
|
||||
spec.desc = info.get("description");
|
||||
} else {
|
||||
std::ifstream is((spec.path + DIR_DELIM + "description.txt").c_str());
|
||||
std::ifstream is((spec.path + DIR_DELIM + "description.txt")
|
||||
.c_str());
|
||||
spec.desc = std::string((std::istreambuf_iterator<char>(is)),
|
||||
std::istreambuf_iterator<char>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, ModSpec> getModsInPath(const std::string &path,
|
||||
bool part_of_modpack)
|
||||
std::map<std::string, ModSpec> getModsInPath(
|
||||
const std::string &path, bool part_of_modpack)
|
||||
{
|
||||
// NOTE: this function works in mutual recursion with parseModContents
|
||||
|
||||
@ -143,9 +151,7 @@ std::map<std::string, ModSpec> getModsInPath(const std::string &path,
|
||||
continue;
|
||||
|
||||
modpath.clear();
|
||||
modpath.append(path)
|
||||
.append(DIR_DELIM)
|
||||
.append(modname);
|
||||
modpath.append(path).append(DIR_DELIM).append(modname);
|
||||
|
||||
ModSpec spec(modname, modpath, part_of_modpack);
|
||||
parseModContents(spec);
|
||||
@ -162,10 +168,9 @@ std::vector<ModSpec> flattenMods(std::map<std::string, ModSpec> mods)
|
||||
if (mod.is_modpack) {
|
||||
std::vector<ModSpec> content = flattenMods(mod.modpack_content);
|
||||
result.reserve(result.size() + content.size());
|
||||
result.insert(result.end(),content.begin(),content.end());
|
||||
result.insert(result.end(), content.begin(), content.end());
|
||||
|
||||
}
|
||||
else //not a modpack
|
||||
} else // not a modpack
|
||||
{
|
||||
result.push_back(mod);
|
||||
}
|
||||
@ -180,7 +185,8 @@ ModConfiguration::ModConfiguration(const std::string &worldpath)
|
||||
void ModConfiguration::printUnsatisfiedModsError() const
|
||||
{
|
||||
for (const ModSpec &mod : m_unsatisfied_mods) {
|
||||
errorstream << "mod \"" << mod.name << "\" has unsatisfied dependencies: ";
|
||||
errorstream << "mod \"" << mod.name
|
||||
<< "\" has unsatisfied dependencies: ";
|
||||
for (const std::string &unsatisfied_depend : mod.unsatisfied_depends)
|
||||
errorstream << " \"" << unsatisfied_depend << "\"";
|
||||
errorstream << std::endl;
|
||||
@ -197,12 +203,12 @@ void ModConfiguration::addMods(const std::vector<ModSpec> &new_mods)
|
||||
// Maintain a map of all existing m_unsatisfied_mods.
|
||||
// Keys are mod names and values are indices into m_unsatisfied_mods.
|
||||
std::map<std::string, u32> existing_mods;
|
||||
for(u32 i = 0; i < m_unsatisfied_mods.size(); ++i){
|
||||
for (u32 i = 0; i < m_unsatisfied_mods.size(); ++i) {
|
||||
existing_mods[m_unsatisfied_mods[i].name] = i;
|
||||
}
|
||||
|
||||
// Add new mods
|
||||
for(int want_from_modpack = 1; want_from_modpack >= 0; --want_from_modpack){
|
||||
for (int want_from_modpack = 1; want_from_modpack >= 0; --want_from_modpack) {
|
||||
// First iteration:
|
||||
// Add all the mods that come from modpacks
|
||||
// Second iteration:
|
||||
@ -218,14 +224,16 @@ void ModConfiguration::addMods(const std::vector<ModSpec> &new_mods)
|
||||
// GOOD CASE: completely new mod.
|
||||
m_unsatisfied_mods.push_back(mod);
|
||||
existing_mods[mod.name] = m_unsatisfied_mods.size() - 1;
|
||||
} else if(seen_this_iteration.count(mod.name) == 0) {
|
||||
} else if (seen_this_iteration.count(mod.name) == 0) {
|
||||
// BAD CASE: name conflict in different levels.
|
||||
u32 oldindex = existing_mods[mod.name];
|
||||
const ModSpec &oldmod = m_unsatisfied_mods[oldindex];
|
||||
warningstream<<"Mod name conflict detected: \""
|
||||
<<mod.name<<"\""<<std::endl
|
||||
<<"Will not load: "<<oldmod.path<<std::endl
|
||||
<<"Overridden by: "<<mod.path<<std::endl;
|
||||
warningstream << "Mod name conflict detected: \""
|
||||
<< mod.name << "\"" << std::endl
|
||||
<< "Will not load: " << oldmod.path
|
||||
<< std::endl
|
||||
<< "Overridden by: " << mod.path
|
||||
<< std::endl;
|
||||
m_unsatisfied_mods[oldindex] = mod;
|
||||
|
||||
// If there was a "VERY BAD CASE" name conflict
|
||||
@ -235,10 +243,12 @@ void ModConfiguration::addMods(const std::vector<ModSpec> &new_mods)
|
||||
// VERY BAD CASE: name conflict in the same level.
|
||||
u32 oldindex = existing_mods[mod.name];
|
||||
const ModSpec &oldmod = m_unsatisfied_mods[oldindex];
|
||||
warningstream<<"Mod name conflict detected: \""
|
||||
<<mod.name<<"\""<<std::endl
|
||||
<<"Will not load: "<<oldmod.path<<std::endl
|
||||
<<"Will not load: "<<mod.path<<std::endl;
|
||||
warningstream << "Mod name conflict detected: \""
|
||||
<< mod.name << "\"" << std::endl
|
||||
<< "Will not load: " << oldmod.path
|
||||
<< std::endl
|
||||
<< "Will not load: " << mod.path
|
||||
<< std::endl;
|
||||
m_unsatisfied_mods[oldindex] = mod;
|
||||
m_name_conflicts.insert(mod.name);
|
||||
}
|
||||
@ -248,7 +258,8 @@ void ModConfiguration::addMods(const std::vector<ModSpec> &new_mods)
|
||||
}
|
||||
}
|
||||
|
||||
void ModConfiguration::addModsFromConfig(const std::string &settings_path, const std::set<std::string> &mods)
|
||||
void ModConfiguration::addModsFromConfig(
|
||||
const std::string &settings_path, const std::set<std::string> &mods)
|
||||
{
|
||||
Settings conf;
|
||||
std::set<std::string> load_mod_names;
|
||||
@ -256,7 +267,7 @@ void ModConfiguration::addModsFromConfig(const std::string &settings_path, const
|
||||
conf.readConfigFile(settings_path.c_str());
|
||||
std::vector<std::string> names = conf.getNames();
|
||||
for (const std::string &name : names) {
|
||||
if (name.compare(0,9,"load_mod_")==0 && conf.getBool(name))
|
||||
if (name.compare(0, 9, "load_mod_") == 0 && conf.getBool(name))
|
||||
load_mod_names.insert(name.substr(9));
|
||||
}
|
||||
|
||||
@ -265,7 +276,7 @@ void ModConfiguration::addModsFromConfig(const std::string &settings_path, const
|
||||
std::vector<ModSpec> addon_mods_in_path = flattenMods(getModsInPath(i));
|
||||
for (std::vector<ModSpec>::const_iterator it = addon_mods_in_path.begin();
|
||||
it != addon_mods_in_path.end(); ++it) {
|
||||
const ModSpec& mod = *it;
|
||||
const ModSpec &mod = *it;
|
||||
if (load_mod_names.count(mod.name) != 0)
|
||||
addon_mods.push_back(mod);
|
||||
else
|
||||
@ -300,8 +311,10 @@ void ModConfiguration::checkConflictsAndDeps()
|
||||
if (!m_name_conflicts.empty()) {
|
||||
std::string s = "Unresolved name conflicts for mods ";
|
||||
for (std::unordered_set<std::string>::const_iterator it =
|
||||
m_name_conflicts.begin(); it != m_name_conflicts.end(); ++it) {
|
||||
if (it != m_name_conflicts.begin()) s += ", ";
|
||||
m_name_conflicts.begin();
|
||||
it != m_name_conflicts.end(); ++it) {
|
||||
if (it != m_name_conflicts.begin())
|
||||
s += ", ";
|
||||
s += std::string("\"") + (*it) + "\"";
|
||||
}
|
||||
s += ".";
|
||||
@ -340,12 +353,12 @@ void ModConfiguration::resolveDependencies()
|
||||
|
||||
// Step 3: mods without unmet dependencies can be appended to
|
||||
// the sorted list.
|
||||
while(!satisfied.empty()){
|
||||
while (!satisfied.empty()) {
|
||||
ModSpec mod = satisfied.back();
|
||||
m_sorted_mods.push_back(mod);
|
||||
satisfied.pop_back();
|
||||
for (auto it = unsatisfied.begin(); it != unsatisfied.end(); ) {
|
||||
ModSpec& mod2 = *it;
|
||||
for (auto it = unsatisfied.begin(); it != unsatisfied.end();) {
|
||||
ModSpec &mod2 = *it;
|
||||
mod2.unsatisfied_depends.erase(mod.name);
|
||||
if (mod2.unsatisfied_depends.empty()) {
|
||||
satisfied.push_back(mod2);
|
||||
@ -361,8 +374,8 @@ void ModConfiguration::resolveDependencies()
|
||||
}
|
||||
|
||||
#ifndef SERVER
|
||||
ClientModConfiguration::ClientModConfiguration(const std::string &path):
|
||||
ModConfiguration(path)
|
||||
ClientModConfiguration::ClientModConfiguration(const std::string &path) :
|
||||
ModConfiguration(path)
|
||||
{
|
||||
std::set<std::string> paths;
|
||||
std::string path_user = porting::path_user + DIR_DELIM + "clientmods";
|
||||
@ -374,8 +387,7 @@ ClientModConfiguration::ClientModConfiguration(const std::string &path):
|
||||
}
|
||||
#endif
|
||||
|
||||
ModMetadata::ModMetadata(const std::string &mod_name):
|
||||
m_mod_name(mod_name)
|
||||
ModMetadata::ModMetadata(const std::string &mod_name) : m_mod_name(mod_name)
|
||||
{
|
||||
}
|
||||
|
||||
@ -395,23 +407,25 @@ bool ModMetadata::save(const std::string &root_path)
|
||||
|
||||
if (!fs::PathExists(root_path)) {
|
||||
if (!fs::CreateAllDirs(root_path)) {
|
||||
errorstream << "ModMetadata[" << m_mod_name << "]: Unable to save. '"
|
||||
<< root_path << "' tree cannot be created." << std::endl;
|
||||
errorstream << "ModMetadata[" << m_mod_name
|
||||
<< "]: Unable to save. '" << root_path
|
||||
<< "' tree cannot be created." << std::endl;
|
||||
return false;
|
||||
}
|
||||
} else if (!fs::IsDir(root_path)) {
|
||||
errorstream << "ModMetadata[" << m_mod_name << "]: Unable to save. '"
|
||||
<< root_path << "' is not a directory." << std::endl;
|
||||
<< root_path << "' is not a directory." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool w_ok = fs::safeWriteToFile(root_path + DIR_DELIM + m_mod_name,
|
||||
fastWriteJson(json));
|
||||
bool w_ok = fs::safeWriteToFile(
|
||||
root_path + DIR_DELIM + m_mod_name, fastWriteJson(json));
|
||||
|
||||
if (w_ok) {
|
||||
m_modified = false;
|
||||
} else {
|
||||
errorstream << "ModMetadata[" << m_mod_name << "]: failed write file." << std::endl;
|
||||
errorstream << "ModMetadata[" << m_mod_name << "]: failed write file."
|
||||
<< std::endl;
|
||||
}
|
||||
return w_ok;
|
||||
}
|
||||
@ -420,7 +434,8 @@ bool ModMetadata::load(const std::string &root_path)
|
||||
{
|
||||
m_stringvars.clear();
|
||||
|
||||
std::ifstream is((root_path + DIR_DELIM + m_mod_name).c_str(), std::ios_base::binary);
|
||||
std::ifstream is((root_path + DIR_DELIM + m_mod_name).c_str(),
|
||||
std::ios_base::binary);
|
||||
if (!is.good()) {
|
||||
return false;
|
||||
}
|
||||
@ -431,8 +446,10 @@ bool ModMetadata::load(const std::string &root_path)
|
||||
std::string errs;
|
||||
|
||||
if (!Json::parseFromStream(builder, is, &root, &errs)) {
|
||||
errorstream << "ModMetadata[" << m_mod_name << "]: failed read data "
|
||||
"(Json decoding failure). Message: " << errs << std::endl;
|
||||
errorstream << "ModMetadata[" << m_mod_name
|
||||
<< "]: failed read data "
|
||||
"(Json decoding failure). Message: "
|
||||
<< errs << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
@ -36,10 +36,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
struct ModSpec
|
||||
{
|
||||
std::string name;
|
||||
std::string author;
|
||||
std::string path;
|
||||
std::string desc;
|
||||
|
||||
//if normal mod:
|
||||
// if normal mod:
|
||||
std::unordered_set<std::string> depends;
|
||||
std::unordered_set<std::string> optdepends;
|
||||
std::unordered_set<std::string> unsatisfied_depends;
|
||||
@ -48,26 +49,25 @@ struct ModSpec
|
||||
bool is_modpack = false;
|
||||
|
||||
// if modpack:
|
||||
std::map<std::string,ModSpec> modpack_content;
|
||||
ModSpec(const std::string &name_ = "", const std::string &path_ = ""):
|
||||
name(name_),
|
||||
path(path_)
|
||||
{}
|
||||
ModSpec(const std::string &name_, const std::string &path_, bool part_of_modpack_):
|
||||
name(name_),
|
||||
path(path_),
|
||||
part_of_modpack(part_of_modpack_)
|
||||
{}
|
||||
std::map<std::string, ModSpec> modpack_content;
|
||||
ModSpec(const std::string &name = "", const std::string &path = "") :
|
||||
name(name), path(path)
|
||||
{
|
||||
}
|
||||
ModSpec(const std::string &name, const std::string &path, bool part_of_modpack) :
|
||||
name(name), path(path), part_of_modpack(part_of_modpack)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
// Retrieves depends, optdepends, is_modpack and modpack_content
|
||||
void parseModContents(ModSpec &mod);
|
||||
|
||||
std::map<std::string,ModSpec> getModsInPath(const std::string &path,
|
||||
bool part_of_modpack = false);
|
||||
std::map<std::string, ModSpec> getModsInPath(
|
||||
const std::string &path, bool part_of_modpack = false);
|
||||
|
||||
// replaces modpack Modspecs with their content
|
||||
std::vector<ModSpec> flattenMods(std::map<std::string,ModSpec> mods);
|
||||
std::vector<ModSpec> flattenMods(std::map<std::string, ModSpec> mods);
|
||||
|
||||
// a ModConfiguration is a subset of installed mods, expected to have
|
||||
// all dependencies fullfilled, so it can be used as a list of mods to
|
||||
@ -76,15 +76,9 @@ class ModConfiguration
|
||||
{
|
||||
public:
|
||||
// checks if all dependencies are fullfilled.
|
||||
bool isConsistent() const
|
||||
{
|
||||
return m_unsatisfied_mods.empty();
|
||||
}
|
||||
bool isConsistent() const { return m_unsatisfied_mods.empty(); }
|
||||
|
||||
const std::vector<ModSpec> &getMods() const
|
||||
{
|
||||
return m_sorted_mods;
|
||||
}
|
||||
const std::vector<ModSpec> &getMods() const { return m_sorted_mods; }
|
||||
|
||||
const std::vector<ModSpec> &getUnsatisfiedMods() const
|
||||
{
|
||||
@ -102,9 +96,11 @@ protected:
|
||||
// adds all mods in the set.
|
||||
void addMods(const std::vector<ModSpec> &new_mods);
|
||||
|
||||
void addModsFromConfig(const std::string &settings_path, const std::set<std::string> &mods);
|
||||
void addModsFromConfig(const std::string &settings_path,
|
||||
const std::set<std::string> &mods);
|
||||
|
||||
void checkConflictsAndDeps();
|
||||
|
||||
protected:
|
||||
// list of mods sorted such that they can be loaded in the
|
||||
// given order with all dependencies being fullfilled. I.e.,
|
||||
@ -133,18 +129,17 @@ private:
|
||||
|
||||
// Deleted default constructor
|
||||
ModConfiguration() = default;
|
||||
|
||||
};
|
||||
|
||||
#ifndef SERVER
|
||||
class ClientModConfiguration: public ModConfiguration
|
||||
class ClientModConfiguration : public ModConfiguration
|
||||
{
|
||||
public:
|
||||
ClientModConfiguration(const std::string &path);
|
||||
};
|
||||
#endif
|
||||
|
||||
class ModMetadata: public Metadata
|
||||
class ModMetadata : public Metadata
|
||||
{
|
||||
public:
|
||||
ModMetadata() = delete;
|
||||
@ -160,6 +155,7 @@ public:
|
||||
const std::string &getModName() const { return m_mod_name; }
|
||||
|
||||
virtual bool setString(const std::string &name, const std::string &var);
|
||||
|
||||
private:
|
||||
std::string m_mod_name;
|
||||
bool m_modified = false;
|
68
src/content/packages.cpp
Normal file
68
src/content/packages.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
Minetest
|
||||
Copyright (C) 2018 rubenwardy <rw@rubenwardy.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "content/packages.h"
|
||||
#include "log.h"
|
||||
#include "filesys.h"
|
||||
#include "porting.h"
|
||||
#include "settings.h"
|
||||
#include "content/mods.h"
|
||||
#include "content/subgames.h"
|
||||
|
||||
#if USE_CURL
|
||||
std::vector<Package> getPackagesFromURL(const std::string &url)
|
||||
{
|
||||
std::vector<std::string> extra_headers;
|
||||
extra_headers.emplace_back("Accept: application/json");
|
||||
|
||||
Json::Value json = fetchJsonValue(url, &extra_headers);
|
||||
if (!json.isArray()) {
|
||||
errorstream << "Invalid JSON download " << std::endl;
|
||||
return std::vector<Package>();
|
||||
}
|
||||
|
||||
std::vector<Package> packages;
|
||||
|
||||
// Note: `unsigned int` is required to index JSON
|
||||
for (unsigned int i = 0; i < json.size(); ++i) {
|
||||
Package package;
|
||||
|
||||
package.name = json[i]["name"].asString();
|
||||
package.title = json[i]["title"].asString();
|
||||
package.author = json[i]["author"].asString();
|
||||
package.type = json[i]["type"].asString();
|
||||
package.shortDesc = json[i]["shortDesc"].asString();
|
||||
package.url = json[i]["url"].asString();
|
||||
|
||||
Json::Value jScreenshots = json[i]["screenshots"];
|
||||
for (unsigned int j = 0; j < jScreenshots.size(); ++j) {
|
||||
package.screenshots.push_back(jScreenshots[j].asString());
|
||||
}
|
||||
|
||||
if (package.valid()) {
|
||||
packages.push_back(package);
|
||||
} else {
|
||||
errorstream << "Invalid package at " << i << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return packages;
|
||||
}
|
||||
|
||||
#endif
|
49
src/content/packages.h
Normal file
49
src/content/packages.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
Minetest
|
||||
Copyright (C) 2018 rubenwardy <rw@rubenwardy.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "config.h"
|
||||
#include "convert_json.h"
|
||||
|
||||
struct Package
|
||||
{
|
||||
std::string name; // Technical name
|
||||
std::string title;
|
||||
std::string author;
|
||||
std::string type; // One of "mod", "game", or "txp"
|
||||
|
||||
std::string shortDesc;
|
||||
std::string url; // download URL
|
||||
std::vector<std::string> screenshots;
|
||||
|
||||
bool valid()
|
||||
{
|
||||
return !(name.empty() || title.empty() || author.empty() ||
|
||||
type.empty() || url.empty());
|
||||
}
|
||||
};
|
||||
|
||||
#if USE_CURL
|
||||
std::vector<Package> getPackagesFromURL(const std::string &url);
|
||||
#else
|
||||
inline std::vector<Package> getPackagesFromURL(const std::string &url)
|
||||
{
|
||||
return std::vector<Package>();
|
||||
}
|
||||
#endif
|
@ -17,18 +17,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "subgame.h"
|
||||
#include "content/subgames.h"
|
||||
#include "porting.h"
|
||||
#include "filesys.h"
|
||||
#include "settings.h"
|
||||
#include "log.h"
|
||||
#include "util/strfnd.h"
|
||||
#include "defaultsettings.h" // for override_default_settings
|
||||
#include "mapgen/mapgen.h" // for MapgenParams
|
||||
#include "defaultsettings.h" // for override_default_settings
|
||||
#include "mapgen/mapgen.h" // for MapgenParams
|
||||
#include "util/string.h"
|
||||
|
||||
#ifndef SERVER
|
||||
#include "client/tile.h" // getImagePath
|
||||
#include "client/tile.h" // getImagePath
|
||||
#endif
|
||||
|
||||
bool getGameMinetestConfig(const std::string &game_path, Settings &conf)
|
||||
@ -37,30 +37,14 @@ bool getGameMinetestConfig(const std::string &game_path, Settings &conf)
|
||||
return conf.readConfigFile(conf_path.c_str());
|
||||
}
|
||||
|
||||
bool getGameConfig(const std::string &game_path, Settings &conf)
|
||||
{
|
||||
std::string conf_path = game_path + DIR_DELIM + "game.conf";
|
||||
return conf.readConfigFile(conf_path.c_str());
|
||||
}
|
||||
|
||||
std::string getGameName(const std::string &game_path)
|
||||
{
|
||||
Settings conf;
|
||||
if(!getGameConfig(game_path, conf))
|
||||
return "";
|
||||
if(!conf.exists("name"))
|
||||
return "";
|
||||
return conf.get("name");
|
||||
}
|
||||
|
||||
struct GameFindPath
|
||||
{
|
||||
std::string path;
|
||||
bool user_specific;
|
||||
GameFindPath(const std::string &path, bool user_specific):
|
||||
path(path),
|
||||
user_specific(user_specific)
|
||||
{}
|
||||
GameFindPath(const std::string &path, bool user_specific) :
|
||||
path(path), user_specific(user_specific)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
std::string getSubgamePathEnv()
|
||||
@ -75,21 +59,24 @@ SubgameSpec findSubgame(const std::string &id)
|
||||
return SubgameSpec();
|
||||
std::string share = porting::path_share;
|
||||
std::string user = porting::path_user;
|
||||
std::vector<GameFindPath> find_paths;
|
||||
|
||||
// Get games install locations
|
||||
Strfnd search_paths(getSubgamePathEnv());
|
||||
|
||||
// Get all possible paths fo game
|
||||
std::vector<GameFindPath> find_paths;
|
||||
while (!search_paths.at_end()) {
|
||||
std::string path = search_paths.next(PATH_DELIM);
|
||||
find_paths.emplace_back(path + DIR_DELIM + id, false);
|
||||
find_paths.emplace_back(path + DIR_DELIM + id + "_game", false);
|
||||
}
|
||||
|
||||
find_paths.emplace_back(user + DIR_DELIM + "games" + DIR_DELIM + id + "_game", true);
|
||||
find_paths.emplace_back(
|
||||
user + DIR_DELIM + "games" + DIR_DELIM + id + "_game", true);
|
||||
find_paths.emplace_back(user + DIR_DELIM + "games" + DIR_DELIM + id, true);
|
||||
find_paths.emplace_back(share + DIR_DELIM + "games" + DIR_DELIM + id + "_game",
|
||||
false);
|
||||
find_paths.emplace_back(
|
||||
share + DIR_DELIM + "games" + DIR_DELIM + id + "_game", false);
|
||||
find_paths.emplace_back(share + DIR_DELIM + "games" + DIR_DELIM + id, false);
|
||||
|
||||
// Find game directory
|
||||
std::string game_path;
|
||||
bool user_game = true; // Game is in user's directory
|
||||
@ -101,24 +88,41 @@ SubgameSpec findSubgame(const std::string &id)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (game_path.empty())
|
||||
return SubgameSpec();
|
||||
|
||||
std::string gamemod_path = game_path + DIR_DELIM + "mods";
|
||||
|
||||
// Find mod directories
|
||||
std::set<std::string> mods_paths;
|
||||
if(!user_game)
|
||||
if (!user_game)
|
||||
mods_paths.insert(share + DIR_DELIM + "mods");
|
||||
if(user != share || user_game)
|
||||
if (user != share || user_game)
|
||||
mods_paths.insert(user + DIR_DELIM + "mods");
|
||||
std::string game_name = getGameName(game_path);
|
||||
if (game_name.empty())
|
||||
|
||||
// Get meta
|
||||
std::string conf_path = game_path + DIR_DELIM + "game.conf";
|
||||
Settings conf;
|
||||
conf.readConfigFile(conf_path.c_str());
|
||||
|
||||
std::string game_name;
|
||||
if (conf.exists("name"))
|
||||
game_name = conf.get("name");
|
||||
else
|
||||
game_name = id;
|
||||
|
||||
std::string game_author;
|
||||
if (conf.exists("author"))
|
||||
game_author = conf.get("author");
|
||||
|
||||
std::string menuicon_path;
|
||||
#ifndef SERVER
|
||||
menuicon_path = getImagePath(game_path + DIR_DELIM + "menu" + DIR_DELIM + "icon.png");
|
||||
menuicon_path = getImagePath(
|
||||
game_path + DIR_DELIM + "menu" + DIR_DELIM + "icon.png");
|
||||
#endif
|
||||
return SubgameSpec(id, game_path, gamemod_path, mods_paths, game_name,
|
||||
menuicon_path);
|
||||
menuicon_path, game_author);
|
||||
}
|
||||
|
||||
SubgameSpec findWorldSubgame(const std::string &world_path)
|
||||
@ -126,14 +130,21 @@ SubgameSpec findWorldSubgame(const std::string &world_path)
|
||||
std::string world_gameid = getWorldGameId(world_path, true);
|
||||
// See if world contains an embedded game; if so, use it.
|
||||
std::string world_gamepath = world_path + DIR_DELIM + "game";
|
||||
if(fs::PathExists(world_gamepath)){
|
||||
if (fs::PathExists(world_gamepath)) {
|
||||
SubgameSpec gamespec;
|
||||
gamespec.id = world_gameid;
|
||||
gamespec.path = world_gamepath;
|
||||
gamespec.gamemods_path= world_gamepath + DIR_DELIM + "mods";
|
||||
gamespec.name = getGameName(world_gamepath);
|
||||
if (gamespec.name.empty())
|
||||
gamespec.name = "unknown";
|
||||
gamespec.gamemods_path = world_gamepath + DIR_DELIM + "mods";
|
||||
|
||||
Settings conf;
|
||||
std::string conf_path = world_gamepath + DIR_DELIM + "game.conf";
|
||||
conf.readConfigFile(conf_path.c_str());
|
||||
|
||||
if (conf.exists("name"))
|
||||
gamespec.name = conf.get("name");
|
||||
else
|
||||
gamespec.name = world_gameid;
|
||||
|
||||
return gamespec;
|
||||
}
|
||||
return findSubgame(world_gameid);
|
||||
@ -154,12 +165,16 @@ std::set<std::string> getAvailableGameIds()
|
||||
for (const std::string &gamespath : gamespaths) {
|
||||
std::vector<fs::DirListNode> dirlist = fs::GetDirListing(gamespath);
|
||||
for (const fs::DirListNode &dln : dirlist) {
|
||||
if(!dln.dir)
|
||||
if (!dln.dir)
|
||||
continue;
|
||||
|
||||
// If configuration file is not found or broken, ignore game
|
||||
Settings conf;
|
||||
if(!getGameConfig(gamespath + DIR_DELIM + dln.name, conf))
|
||||
std::string conf_path = gamespath + DIR_DELIM + dln.name +
|
||||
DIR_DELIM + "game.conf";
|
||||
if (!conf.readConfigFile(conf_path.c_str()))
|
||||
continue;
|
||||
|
||||
// Add it to result
|
||||
const char *ends[] = {"_game", NULL};
|
||||
std::string shorter = removeStringEnd(dln.name, ends);
|
||||
@ -194,18 +209,18 @@ std::string getWorldGameId(const std::string &world_path, bool can_be_legacy)
|
||||
std::string conf_path = world_path + DIR_DELIM + "world.mt";
|
||||
Settings conf;
|
||||
bool succeeded = conf.readConfigFile(conf_path.c_str());
|
||||
if(!succeeded){
|
||||
if(can_be_legacy){
|
||||
if (!succeeded) {
|
||||
if (can_be_legacy) {
|
||||
// If map_meta.txt exists, it is probably an old minetest world
|
||||
if(fs::PathExists(world_path + DIR_DELIM + "map_meta.txt"))
|
||||
if (fs::PathExists(world_path + DIR_DELIM + "map_meta.txt"))
|
||||
return LEGACY_GAMEID;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
if(!conf.exists("gameid"))
|
||||
if (!conf.exists("gameid"))
|
||||
return "";
|
||||
// The "mesetint" gameid has been discarded
|
||||
if(conf.get("gameid") == "mesetint")
|
||||
if (conf.get("gameid") == "mesetint")
|
||||
return "minetest";
|
||||
return conf.get("gameid");
|
||||
}
|
||||
@ -229,10 +244,10 @@ std::vector<WorldSpec> getAvailableWorlds()
|
||||
worldspaths.insert(porting::path_user + DIR_DELIM + "worlds");
|
||||
infostream << "Searching worlds..." << std::endl;
|
||||
for (const std::string &worldspath : worldspaths) {
|
||||
infostream << " In " << worldspath << ": " <<std::endl;
|
||||
infostream << " In " << worldspath << ": " << std::endl;
|
||||
std::vector<fs::DirListNode> dirvector = fs::GetDirListing(worldspath);
|
||||
for (const fs::DirListNode &dln : dirvector) {
|
||||
if(!dln.dir)
|
||||
if (!dln.dir)
|
||||
continue;
|
||||
std::string fullpath = worldspath + DIR_DELIM + dln.name;
|
||||
std::string name = dln.name;
|
||||
@ -240,27 +255,27 @@ std::vector<WorldSpec> getAvailableWorlds()
|
||||
bool can_be_legacy = true;
|
||||
std::string gameid = getWorldGameId(fullpath, can_be_legacy);
|
||||
WorldSpec spec(fullpath, name, gameid);
|
||||
if(!spec.isValid()){
|
||||
infostream<<"(invalid: "<<name<<") ";
|
||||
if (!spec.isValid()) {
|
||||
infostream << "(invalid: " << name << ") ";
|
||||
} else {
|
||||
infostream<<name<<" ";
|
||||
infostream << name << " ";
|
||||
worlds.push_back(spec);
|
||||
}
|
||||
}
|
||||
infostream<<std::endl;
|
||||
infostream << std::endl;
|
||||
}
|
||||
// Check old world location
|
||||
do{
|
||||
do {
|
||||
std::string fullpath = porting::path_user + DIR_DELIM + "world";
|
||||
if(!fs::PathExists(fullpath))
|
||||
if (!fs::PathExists(fullpath))
|
||||
break;
|
||||
std::string name = "Old World";
|
||||
std::string gameid = getWorldGameId(fullpath, true);
|
||||
WorldSpec spec(fullpath, name, gameid);
|
||||
infostream<<"Old world found."<<std::endl;
|
||||
infostream << "Old world found." << std::endl;
|
||||
worlds.push_back(spec);
|
||||
}while(false);
|
||||
infostream<<worlds.size()<<" found."<<std::endl;
|
||||
} while (false);
|
||||
infostream << worlds.size() << " found." << std::endl;
|
||||
return worlds;
|
||||
}
|
||||
|
||||
@ -297,8 +312,9 @@ bool loadGameConfAndInitWorld(const std::string &path, const SubgameSpec &gamesp
|
||||
|
||||
// Create map_meta.txt if does not already exist
|
||||
std::string map_meta_path = path + DIR_DELIM + "map_meta.txt";
|
||||
if (!fs::PathExists(map_meta_path)){
|
||||
verbosestream << "Creating map_meta.txt (" << map_meta_path << ")" << std::endl;
|
||||
if (!fs::PathExists(map_meta_path)) {
|
||||
verbosestream << "Creating map_meta.txt (" << map_meta_path << ")"
|
||||
<< std::endl;
|
||||
fs::CreateAllDirs(path);
|
||||
std::ostringstream oss(std::ios_base::binary);
|
||||
|
||||
@ -314,4 +330,3 @@ bool loadGameConfAndInitWorld(const std::string &path, const SubgameSpec &gamesp
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -27,39 +27,33 @@ class Settings;
|
||||
|
||||
struct SubgameSpec
|
||||
{
|
||||
std::string id; // "" = game does not exist
|
||||
std::string path; // path to game
|
||||
std::string gamemods_path; //path to mods of the game
|
||||
std::set<std::string> addon_mods_paths; //paths to addon mods for this game
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::string author;
|
||||
std::string path;
|
||||
std::string gamemods_path;
|
||||
std::set<std::string> addon_mods_paths;
|
||||
std::string menuicon_path;
|
||||
|
||||
SubgameSpec(const std::string &id_ = "",
|
||||
const std::string &path_ = "",
|
||||
const std::string &gamemods_path_ = "",
|
||||
const std::set<std::string> &addon_mods_paths_ = std::set<std::string>(),
|
||||
const std::string &name_ = "",
|
||||
const std::string &menuicon_path_ = ""):
|
||||
id(id_),
|
||||
path(path_),
|
||||
gamemods_path(gamemods_path_),
|
||||
addon_mods_paths(addon_mods_paths_),
|
||||
name(name_),
|
||||
menuicon_path(menuicon_path_)
|
||||
{}
|
||||
|
||||
bool isValid() const
|
||||
SubgameSpec(const std::string &id = "", const std::string &path = "",
|
||||
const std::string &gamemods_path = "",
|
||||
const std::set<std::string> &addon_mods_paths =
|
||||
std::set<std::string>(),
|
||||
const std::string &name = "",
|
||||
const std::string &menuicon_path = "",
|
||||
const std::string &author = "") :
|
||||
id(id),
|
||||
name(name), author(author), path(path),
|
||||
gamemods_path(gamemods_path), addon_mods_paths(addon_mods_paths),
|
||||
menuicon_path(menuicon_path)
|
||||
{
|
||||
return (!id.empty() && !path.empty());
|
||||
}
|
||||
|
||||
bool isValid() const { return (!id.empty() && !path.empty()); }
|
||||
};
|
||||
|
||||
// minetest.conf
|
||||
bool getGameMinetestConfig(const std::string &game_path, Settings &conf);
|
||||
// game.conf
|
||||
bool getGameConfig(const std::string &game_path, Settings &conf);
|
||||
|
||||
std::string getGameName(const std::string &game_path);
|
||||
|
||||
SubgameSpec findSubgame(const std::string &id);
|
||||
SubgameSpec findWorldSubgame(const std::string &world_path);
|
||||
@ -68,8 +62,7 @@ std::set<std::string> getAvailableGameIds();
|
||||
std::vector<SubgameSpec> getAvailableGames();
|
||||
|
||||
bool getWorldExists(const std::string &world_path);
|
||||
std::string getWorldGameId(const std::string &world_path,
|
||||
bool can_be_legacy=false);
|
||||
std::string getWorldGameId(const std::string &world_path, bool can_be_legacy = false);
|
||||
|
||||
struct WorldSpec
|
||||
{
|
||||
@ -77,15 +70,12 @@ struct WorldSpec
|
||||
std::string name;
|
||||
std::string gameid;
|
||||
|
||||
WorldSpec(
|
||||
const std::string &path_="",
|
||||
const std::string &name_="",
|
||||
const std::string &gameid_=""
|
||||
):
|
||||
path(path_),
|
||||
name(name_),
|
||||
gameid(gameid_)
|
||||
{}
|
||||
WorldSpec(const std::string &path = "", const std::string &name = "",
|
||||
const std::string &gameid = "") :
|
||||
path(path),
|
||||
name(name), gameid(gameid)
|
||||
{
|
||||
}
|
||||
|
||||
bool isValid() const
|
||||
{
|
@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include <sstream>
|
||||
|
||||
#include "convert_json.h"
|
||||
#include "mods.h"
|
||||
#include "content/mods.h"
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "settings.h"
|
||||
|
@ -284,6 +284,7 @@ void set_default_settings(Settings *settings)
|
||||
#endif
|
||||
settings->setDefault("font_size", font_size_str);
|
||||
settings->setDefault("mono_font_size", font_size_str);
|
||||
settings->setDefault("contentdb_url", "https://contentdb.rubenwardy.com");
|
||||
|
||||
|
||||
// Server
|
||||
|
@ -245,7 +245,7 @@ HTTPFetchOngoing::HTTPFetchOngoing(const HTTPFetchRequest &request_,
|
||||
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3);
|
||||
curl_easy_setopt(curl, CURLOPT_ENCODING, "gzip");
|
||||
|
||||
std::string bind_address = g_settings->get("bind_address");
|
||||
|
@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "common/c_converter.h"
|
||||
#include "serverobject.h"
|
||||
#include "filesys.h"
|
||||
#include "mods.h"
|
||||
#include "content/mods.h"
|
||||
#include "porting.h"
|
||||
#include "util/string.h"
|
||||
#include "server.h"
|
||||
|
@ -20,7 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "lua_api/l_base.h"
|
||||
#include "lua_api/l_internal.h"
|
||||
#include "cpp_api/s_base.h"
|
||||
#include <mods.h>
|
||||
#include "content/mods.h"
|
||||
#include <server.h>
|
||||
|
||||
ScriptApiBase *ModApiBase::getScriptApiBase(lua_State *L)
|
||||
|
@ -25,11 +25,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "gui/guiMainMenu.h"
|
||||
#include "gui/guiKeyChangeMenu.h"
|
||||
#include "gui/guiPathSelectMenu.h"
|
||||
#include "subgame.h"
|
||||
#include "version.h"
|
||||
#include "porting.h"
|
||||
#include "filesys.h"
|
||||
#include "convert_json.h"
|
||||
#include "content/packages.h"
|
||||
#include "content/content.h"
|
||||
#include "content/subgames.h"
|
||||
#include "serverlist.h"
|
||||
#include "mapgen/mapgen.h"
|
||||
#include "settings.h"
|
||||
@ -449,6 +451,10 @@ int ModApiMainMenu::l_get_games(lua_State *L)
|
||||
lua_pushstring(L, game.path.c_str());
|
||||
lua_settable(L, top_lvl2);
|
||||
|
||||
lua_pushstring(L, "type");
|
||||
lua_pushstring(L, "game");
|
||||
lua_settable(L, top_lvl2);
|
||||
|
||||
lua_pushstring(L, "gamemods_path");
|
||||
lua_pushstring(L, game.gamemods_path.c_str());
|
||||
lua_settable(L, top_lvl2);
|
||||
@ -457,6 +463,10 @@ int ModApiMainMenu::l_get_games(lua_State *L)
|
||||
lua_pushstring(L, game.name.c_str());
|
||||
lua_settable(L, top_lvl2);
|
||||
|
||||
lua_pushstring(L, "author");
|
||||
lua_pushstring(L, game.author.c_str());
|
||||
lua_settable(L, top_lvl2);
|
||||
|
||||
lua_pushstring(L, "menuicon_path");
|
||||
lua_pushstring(L, game.menuicon_path.c_str());
|
||||
lua_settable(L, top_lvl2);
|
||||
@ -479,47 +489,56 @@ int ModApiMainMenu::l_get_games(lua_State *L)
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
int ModApiMainMenu::l_get_mod_info(lua_State *L)
|
||||
int ModApiMainMenu::l_get_content_info(lua_State *L)
|
||||
{
|
||||
std::string path = luaL_checkstring(L, 1);
|
||||
|
||||
ModSpec spec;
|
||||
ContentSpec spec;
|
||||
spec.path = path;
|
||||
parseModContents(spec);
|
||||
parseContentInfo(spec);
|
||||
|
||||
lua_newtable(L);
|
||||
|
||||
lua_pushstring(L, spec.name.c_str());
|
||||
lua_setfield(L, -2, "name");
|
||||
|
||||
lua_pushstring(L, spec.is_modpack ? "modpack" : "mod");
|
||||
lua_pushstring(L, spec.type.c_str());
|
||||
lua_setfield(L, -2, "type");
|
||||
|
||||
lua_pushstring(L, spec.author.c_str());
|
||||
lua_setfield(L, -2, "author");
|
||||
|
||||
lua_pushstring(L, spec.desc.c_str());
|
||||
lua_setfield(L, -2, "description");
|
||||
|
||||
lua_pushstring(L, spec.path.c_str());
|
||||
lua_setfield(L, -2, "path");
|
||||
|
||||
// Dependencies
|
||||
lua_newtable(L);
|
||||
int i = 1;
|
||||
for (const auto &dep : spec.depends) {
|
||||
lua_pushstring(L, dep.c_str());
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
}
|
||||
lua_setfield(L, -2, "depends");
|
||||
if (spec.type == "mod") {
|
||||
ModSpec spec;
|
||||
spec.path = path;
|
||||
parseModContents(spec);
|
||||
|
||||
// Optional Dependencies
|
||||
lua_newtable(L);
|
||||
i = 1;
|
||||
for (const auto &dep : spec.optdepends) {
|
||||
lua_pushstring(L, dep.c_str());
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
// Dependencies
|
||||
lua_newtable(L);
|
||||
int i = 1;
|
||||
for (const auto &dep : spec.depends) {
|
||||
lua_pushstring(L, dep.c_str());
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
}
|
||||
lua_setfield(L, -2, "depends");
|
||||
|
||||
// Optional Dependencies
|
||||
lua_newtable(L);
|
||||
i = 1;
|
||||
for (const auto &dep : spec.optdepends) {
|
||||
lua_pushstring(L, dep.c_str());
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
}
|
||||
lua_setfield(L, -2, "optional_depends");
|
||||
}
|
||||
lua_setfield(L, -2, "optional_depends");
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -838,6 +857,10 @@ bool ModApiMainMenu::isMinetestPath(std::string path)
|
||||
if (fs::PathStartsWith(path,fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM + "mods")))
|
||||
return true;
|
||||
|
||||
/* mods */
|
||||
if (fs::PathStartsWith(path,fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM + "textures")))
|
||||
return true;
|
||||
|
||||
/* worlds */
|
||||
if (fs::PathStartsWith(path,fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM + "worlds")))
|
||||
return true;
|
||||
@ -972,6 +995,54 @@ int ModApiMainMenu::l_get_screen_info(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ModApiMainMenu::l_get_package_list(lua_State *L)
|
||||
{
|
||||
std::string url = g_settings->get("contentdb_url");
|
||||
std::vector<Package> packages = getPackagesFromURL(url + "/packages/");
|
||||
|
||||
// Make table
|
||||
lua_newtable(L);
|
||||
int top = lua_gettop(L);
|
||||
unsigned int index = 1;
|
||||
|
||||
// Fill table
|
||||
for (const auto &package : packages) {
|
||||
lua_pushnumber(L, index);
|
||||
lua_newtable(L);
|
||||
|
||||
int top_lvl2 = lua_gettop(L);
|
||||
|
||||
lua_pushstring(L, "name");
|
||||
lua_pushstring(L, package.name.c_str());
|
||||
lua_settable (L, top_lvl2);
|
||||
|
||||
lua_pushstring(L, "title");
|
||||
lua_pushstring(L, package.title.c_str());
|
||||
lua_settable (L, top_lvl2);
|
||||
|
||||
lua_pushstring(L, "author");
|
||||
lua_pushstring(L, package.author.c_str());
|
||||
lua_settable (L, top_lvl2);
|
||||
|
||||
lua_pushstring(L, "type");
|
||||
lua_pushstring(L, package.type.c_str());
|
||||
lua_settable (L, top_lvl2);
|
||||
|
||||
lua_pushstring(L, "short_description");
|
||||
lua_pushstring(L, package.shortDesc.c_str());
|
||||
lua_settable (L, top_lvl2);
|
||||
|
||||
lua_pushstring(L, "url");
|
||||
lua_pushstring(L, package.url.c_str());
|
||||
lua_settable (L, top_lvl2);
|
||||
|
||||
lua_settable(L, top);
|
||||
index++;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
int ModApiMainMenu::l_get_min_supp_proto(lua_State *L)
|
||||
{
|
||||
@ -1015,7 +1086,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
|
||||
API_FCT(get_table_index);
|
||||
API_FCT(get_worlds);
|
||||
API_FCT(get_games);
|
||||
API_FCT(get_mod_info);
|
||||
API_FCT(get_content_info);
|
||||
API_FCT(start);
|
||||
API_FCT(close);
|
||||
API_FCT(get_favorites);
|
||||
@ -1042,6 +1113,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
|
||||
API_FCT(get_video_drivers);
|
||||
API_FCT(get_video_modes);
|
||||
API_FCT(get_screen_info);
|
||||
API_FCT(get_package_list);
|
||||
API_FCT(get_min_supp_proto);
|
||||
API_FCT(get_max_supp_proto);
|
||||
API_FCT(do_async_callback);
|
||||
@ -1050,7 +1122,6 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
|
||||
/******************************************************************************/
|
||||
void ModApiMainMenu::InitializeAsync(lua_State *L, int top)
|
||||
{
|
||||
|
||||
API_FCT(get_worlds);
|
||||
API_FCT(get_games);
|
||||
API_FCT(get_favorites);
|
||||
@ -1066,4 +1137,5 @@ void ModApiMainMenu::InitializeAsync(lua_State *L, int top)
|
||||
//API_FCT(extract_zip); //TODO remove dependency to GuiEngine
|
||||
API_FCT(download_file);
|
||||
//API_FCT(gettext); (gettext lib isn't threadsafe)
|
||||
API_FCT(get_package_list);
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ private:
|
||||
|
||||
static int l_get_games(lua_State *L);
|
||||
|
||||
static int l_get_mod_info(lua_State *L);
|
||||
static int l_get_content_info(lua_State *L);
|
||||
|
||||
//gui
|
||||
|
||||
@ -133,6 +133,9 @@ private:
|
||||
|
||||
static int l_get_video_modes(lua_State *L);
|
||||
|
||||
//content store
|
||||
static int l_get_package_list(lua_State *L);
|
||||
|
||||
//version compatibility
|
||||
static int l_get_min_supp_proto(lua_State *L);
|
||||
|
||||
|
@ -20,7 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
|
||||
#include "lua_api/l_storage.h"
|
||||
#include "l_internal.h"
|
||||
#include "mods.h"
|
||||
#include "content/mods.h"
|
||||
#include "server.h"
|
||||
|
||||
int ModApiStorage::l_get_mod_storage(lua_State *L)
|
||||
|
@ -18,7 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
*/
|
||||
|
||||
#include "scripting_mainmenu.h"
|
||||
#include "mods.h"
|
||||
#include "content/mods.h"
|
||||
#include "cpp_api/s_internal.h"
|
||||
#include "lua_api/l_base.h"
|
||||
#include "lua_api/l_mainmenu.h"
|
||||
|
@ -49,7 +49,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "content_mapnode.h"
|
||||
#include "content_nodemeta.h"
|
||||
#include "content_sao.h"
|
||||
#include "mods.h"
|
||||
#include "content/mods.h"
|
||||
#include "modchannels.h"
|
||||
#include "serverlist.h"
|
||||
#include "util/string.h"
|
||||
|
@ -24,9 +24,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "hud.h"
|
||||
#include "gamedef.h"
|
||||
#include "serialization.h" // For SER_FMT_VER_INVALID
|
||||
#include "mods.h"
|
||||
#include "content/mods.h"
|
||||
#include "inventorymanager.h"
|
||||
#include "subgame.h"
|
||||
#include "content/subgames.h"
|
||||
#include "tileanimation.h" // struct TileAnimationParams
|
||||
#include "network/peerhandler.h"
|
||||
#include "network/address.h"
|
||||
|
@ -21,7 +21,7 @@ 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"
|
||||
|
||||
/**
|
||||
* Manage server mods
|
||||
|
@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../mods.h"
|
||||
#include "content/mods.h"
|
||||
|
||||
class ServerScripting;
|
||||
|
||||
|
@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
|
||||
#include <iostream>
|
||||
#include "config.h"
|
||||
#include "mods.h"
|
||||
#include "content/mods.h"
|
||||
#include <json/json.h>
|
||||
|
||||
#pragma once
|
||||
|
@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "itemdef.h"
|
||||
#include "gamedef.h"
|
||||
#include "modchannels.h"
|
||||
#include "mods.h"
|
||||
#include "content/mods.h"
|
||||
#include "util/numeric.h"
|
||||
|
||||
content_t t_CONTENT_STONE;
|
||||
|
Reference in New Issue
Block a user