/* Minetest-c55 Copyright (C) 2010-2011 celeron55, Perttu Ahola Copyright (C) 2011 Kahrl This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 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 General Public License for more details. You should have received a copy of the GNU 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 "itemdef.h" #include "gamedef.h" #include "nodedef.h" #include "tool.h" #include "inventory.h" #ifndef SERVER #include "mapblock_mesh.h" #include "mesh.h" #include "tile.h" #endif #include "log.h" #include "utility.h" #include #include /* ItemDefinition */ ItemDefinition::ItemDefinition() { resetInitial(); } ItemDefinition::ItemDefinition(const ItemDefinition &def) { resetInitial(); *this = def; } ItemDefinition& ItemDefinition::operator=(const ItemDefinition &def) { if(this == &def) return *this; reset(); type = def.type; name = def.name; description = def.description; inventory_image = def.inventory_image; wield_image = def.wield_image; wield_scale = def.wield_scale; stack_max = def.stack_max; usable = def.usable; liquids_pointable = def.liquids_pointable; if(def.tool_capabilities) { tool_capabilities = new ToolCapabilities( *def.tool_capabilities); } groups = def.groups; #ifndef SERVER inventory_texture = def.inventory_texture; if(def.wield_mesh) { wield_mesh = def.wield_mesh; wield_mesh->grab(); } #endif return *this; } ItemDefinition::~ItemDefinition() { reset(); } void ItemDefinition::resetInitial() { // Initialize pointers to NULL so reset() does not delete undefined pointers tool_capabilities = NULL; #ifndef SERVER inventory_texture = NULL; wield_mesh = NULL; #endif reset(); } void ItemDefinition::reset() { type = ITEM_NONE; name = ""; description = ""; inventory_image = ""; wield_image = ""; wield_scale = v3f(1.0, 1.0, 1.0); stack_max = 99; usable = false; liquids_pointable = false; if(tool_capabilities) { delete tool_capabilities; tool_capabilities = NULL; } groups.clear(); #ifndef SERVER inventory_texture = NULL; if(wield_mesh) { wield_mesh->drop(); wield_mesh = NULL; } #endif } void ItemDefinition::serialize(std::ostream &os) const { writeU8(os, 1); // version writeU8(os, type); os<serialize(tmp_os); tool_capabilities_s = tmp_os.str(); } os<::const_iterator i = groups.begin(); i != groups.end(); i++){ os<first); writeS16(os, i->second); } } void ItemDefinition::deSerialize(std::istream &is) { // Reset everything reset(); // Deserialize int version = readU8(is); if(version != 1) throw SerializationError("unsupported ItemDefinition version"); type = (enum ItemType)readU8(is); name = deSerializeString(is); description = deSerializeString(is); inventory_image = deSerializeString(is); wield_image = deSerializeString(is); wield_scale = readV3F1000(is); stack_max = readS16(is); usable = readU8(is); liquids_pointable = readU8(is); std::string tool_capabilities_s = deSerializeString(is); if(!tool_capabilities_s.empty()) { std::istringstream tmp_is(tool_capabilities_s, std::ios::binary); tool_capabilities = new ToolCapabilities; tool_capabilities->deSerialize(tmp_is); } groups.clear(); u32 groups_size = readU16(is); for(u32 i=0; i::const_iterator i; i = m_item_definitions.find(name); if(i == m_item_definitions.end()) i = m_item_definitions.find("unknown"); assert(i != m_item_definitions.end()); return *(i->second); } virtual std::string getAlias(const std::string &name) const { std::map::const_iterator i; i = m_aliases.find(name); if(i != m_aliases.end()) return i->second; return name; } virtual std::set getAll() const { std::set result; for(std::map::const_iterator i = m_item_definitions.begin(); i != m_item_definitions.end(); i++) { result.insert(i->first); } for(std::map::const_iterator i = m_aliases.begin(); i != m_aliases.end(); i++) { result.insert(i->first); } return result; } virtual bool isKnown(const std::string &name_) const { // Convert name according to possible alias std::string name = getAlias(name_); // Get the definition std::map::const_iterator i; return m_item_definitions.find(name) != m_item_definitions.end(); } void clear() { for(std::map::const_iterator i = m_item_definitions.begin(); i != m_item_definitions.end(); i++) { delete i->second; } m_item_definitions.clear(); m_aliases.clear(); // Add the four builtin items: // "" is the hand // /* Minetest Copyright (C) 2018 nerzhul, Loic Blot <loic.blot@unix-experience.fr> 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 "mods.h" #include "filesys.h" #include "log.h" #include "scripting_server.h" #include "content/subgames.h" #include "porting.h" #include "util/metricsbackend.h" /** * Manage server mods * * 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) : ModConfiguration(worldpath) { SubgameSpec gamespec = findWorldSubgame(worldpath); // Add all game mods and all world mods addModsInPath(gamespec.gamemods_path); addModsInPath(worldpath + DIR_DELIM + "worldmods"); // Load normal mods std::string worldmt = worldpath + DIR_DELIM + "world.mt"; 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) { // Print mods infostream << "Server: Loading mods: "; for (const ModSpec &mod : m_sorted_mods) { infostream << mod.name << " "; } infostream << std::endl; // Load and run "mod" scripts for (const ModSpec &mod : m_sorted_mods) { mod.checkAndLog(); std::string script_path = mod.path + DIR_DELIM + "init.lua"; auto t = porting::getTimeMs(); script->loadMod(script_path, mod.name); infostream << "Mod \"" << mod.name << "\" loaded after " << (porting::getTimeMs() - t) << " ms" << std::endl;