bool mod_manager::set_default_mods(const std::string &ident) { if (!has_mod(ident)) { return false; } MOD_INFORMATION *mod = mod_map[ident]; default_mods = mod->dependencies; return true; }
bool mod_manager::set_default_mods(const std::string &ident) { if (!has_mod(ident)) { return false; } MOD_INFORMATION &mod = *mod_map[ident]; auto deps = std::vector<std::string>( mod.dependencies.begin(), mod.dependencies.end() ); remove_invalid_mods( deps ); default_mods = deps; return true; }
void mod_manager::load_modfile( JsonObject &jo, const std::string &path ) { if (!jo.has_string("type") || jo.get_string("type") != "MOD_INFO") { // Ignore anything that is not a mod-info return; } std::string m_ident = jo.get_string("ident"); if (has_mod(m_ident)) { // TODO: change this to make unique ident for the mod // (instead of discarding it?) debugmsg("there is already a mod with ident %s", m_ident.c_str()); return; } std::string m_name = jo.get_string("name", ""); if (m_name.empty()) { // "No name" gets confusing if many mods have no name //~ name of a mod that has no name entry, (%s is the mods identifier) m_name = string_format(_("No name (%s)"), m_ident.c_str()); } else { m_name = _(m_name.c_str()); } std::string m_cat = jo.get_string("category", ""); std::pair<int, std::string> p_cat = {-1, ""}; bool bCatFound = false; do { for( size_t i = 0; i < get_mod_list_categories().size(); ++i ) { if( get_mod_list_categories()[i].first == m_cat ) { p_cat = { int(i), get_mod_list_categories()[i].second }; bCatFound = true; break; } } if( !bCatFound && m_cat != "" ) { m_cat = ""; } else { break; } } while( !bCatFound ); std::unique_ptr<MOD_INFORMATION> modfile( new MOD_INFORMATION ); modfile->ident = m_ident; modfile->name = m_name; modfile->category = p_cat; if( assign( jo, "path", modfile->path ) ) { modfile->path = path + "/" + modfile->path; } else { modfile->path = path; } if( assign( jo, "legacy", modfile->legacy ) ) { modfile->legacy = path + "/" + modfile->legacy; } assign( jo, "authors", modfile->authors ); assign( jo, "maintainers", modfile->maintainers ); assign( jo, "description", modfile->description ); assign( jo, "dependencies", modfile->dependencies ); assign( jo, "core", modfile->core ); assign( jo, "obsolete", modfile->obsolete ); if( modfile->dependencies.count( modfile->ident ) ) { jo.throw_error( "mod specifies self as a dependency", "dependencies" ); } mod_map[modfile->ident] = std::move( modfile ); }
void mod_manager::remove_invalid_mods( std::vector<std::string> &m ) const { m.erase( std::remove_if( m.begin(), m.end(), [this]( const std::string &mod ) { return !has_mod( mod ); } ), m.end() ); }
void mod_manager::load_modfile(JsonObject &jo, const std::string &main_path) { if (!jo.has_string("type") || jo.get_string("type") != "MOD_INFO") { // Ignore anything that is not a mod-info return; } std::string m_ident = jo.get_string("ident"); if (has_mod(m_ident)) { // TODO: change this to make unique ident for the mod // (instead of discarding it?) debugmsg("there is already a mod with ident %s", m_ident.c_str()); return; } if( jo.has_bool( "obsolete" ) ) { // Marked obsolete, no need to try to load anything else. MOD_INFORMATION *modfile = new MOD_INFORMATION; modfile->ident = m_ident; modfile->obsolete = true; mod_map[modfile->ident] = modfile; return; } std::string t_type = jo.get_string("mod-type", "SUPPLEMENTAL"); std::vector<std::string> m_authors; if (jo.has_array("authors")) { m_authors = jo.get_string_array("authors"); } else { if(jo.has_string("author")) { m_authors.push_back(jo.get_string("author")); } } std::string m_name = jo.get_string("name", ""); if (m_name.empty()) { // "No name" gets confusing if many mods have no name //~ name of a mod that has no name entry, (%s is the mods identifier) m_name = string_format(_("No name (%s)"), m_ident.c_str()); } else { m_name = _(m_name.c_str()); } std::string m_desc = jo.get_string("description", ""); if (m_desc.empty()) { m_desc = _("No description"); } else { m_desc = _(m_desc.c_str()); } std::string m_path; if (jo.has_string("path")) { m_path = jo.get_string("path"); if (m_path.empty()) { // If an empty path is given, use only the // folder of the modinfo.json m_path = main_path; } else { // prefix the folder of modinfo.json m_path = main_path + "/" + m_path; } } else { // Default if no path is given: // "<folder-of-modinfo.json>/data" m_path = main_path + "/data"; } std::vector<std::string> m_dependencies; if (jo.has_member("dependencies") && jo.has_array("dependencies")) { JsonArray jarr = jo.get_array("dependencies"); while(jarr.has_more()) { const std::string dep = jarr.next_string(); if (dep == m_ident) { debugmsg("mod %s has itself as dependency", m_ident.c_str()); continue; } if (std::find(m_dependencies.begin(), m_dependencies.end(), dep) != m_dependencies.end()) { // Some dependency listed twice, ignore it, what else can be done? continue; } m_dependencies.push_back(dep); } } mod_type m_type; if (t_type == "CORE") { m_type = MT_CORE; } else if (t_type == "SUPPLEMENTAL") { m_type = MT_SUPPLEMENTAL; } else { throw std::string("Invalid mod type: ") + t_type + " for mod " + m_ident; } MOD_INFORMATION *modfile = new MOD_INFORMATION; modfile->ident = m_ident; modfile->_type = m_type; modfile->authors = m_authors; modfile->name = m_name; modfile->description = m_desc; modfile->dependencies = m_dependencies; modfile->path = m_path; mod_map[modfile->ident] = modfile; }
h.setProperty(_T("CONF_OLD_FOUND"), _T("0")); h.setProperty(_T("CONF_HAS_ERRORS"), _T("1")); return ERROR_SUCCESS; } } h.setProperty(_T("CONFIGURATION_TYPE"), utf8::cvt<std::wstring>(settings_manager::get_settings()->get_context())); h.logMessage("CONFIGURATION_TYPE=" + settings_manager::get_settings()->get_context()); h.logMessage("CONFIGURATION_TYPE=" + settings_manager::get_settings()->get_info()); h.setProperty(_T("CONF_CAN_CHANGE"), _T("1")); h.setProperty(_T("CONF_HAS_ERRORS"), _T("0")); h.setPropertyAndOld(_T("ALLOWED_HOSTS"), utf8::cvt<std::wstring>(settings_manager::get_settings()->get_string("/settings/default", "allowed hosts", ""))); h.setPropertyAndOld(_T("NSCLIENT_PWD"), utf8::cvt<std::wstring>(settings_manager::get_settings()->get_string("/settings/default", "password", ""))); h.setPropertyAndOldBool(_T("CONF_NRPE"), has_mod("NRPEServer")); h.setPropertyAndOldBool(_T("CONF_SCHEDULER"), has_mod("Scheduler")); h.setPropertyAndOldBool(_T("CONF_NSCA"), has_mod("NSCAClient")); h.setPropertyAndOldBool(_T("CONF_NSCLIENT"), has_mod("NSClientServer")); h.setPropertyAndOldBool(_T("CONF_WEB"), has_mod("WEBServer")); std::string insecure = settings_manager::get_settings()->get_string("/settings/NRPE/server", "insecure", ""); std::string verify = settings_manager::get_settings()->get_string("/settings/NRPE/server", "verify mode", ""); h.logMessage(_T("insecure: ") + utf8::cvt<std::wstring>(insecure)); h.logMessage(_T("verify: ") + utf8::cvt<std::wstring>(verify)); if (insecure == "true" || insecure == "1") h.setPropertyAndOld(_T("NRPEMODE"), _T("LEGACY")); else if (verify == "peer-cert") h.setPropertyAndOld(_T("NRPEMODE"), _T("SECURE")); else h.setPropertyAndOld(_T("NRPEMODE"), _T("SAFE"));
void mod_manager::load_modfile(JsonObject &jo, const std::string &main_path) { if (!jo.has_string("type") || jo.get_string("type") != "MOD_INFO") { // Ignore anything that is not a mod-info return; } std::string m_ident = jo.get_string("ident"); if (has_mod(m_ident)) { // TODO: change this to make unique ident for the mod // (instead of discarding it?) debugmsg("there is already a mod with ident %s", m_ident.c_str()); return; } std::string t_type = jo.get_string("mod-type", "SUPPLEMENTAL"); std::vector<std::string> m_authors; if (jo.has_array("authors")) { m_authors = jo.get_string_array("authors"); } else { if(jo.has_string("author")) { m_authors.push_back(jo.get_string("author")); } } std::string m_name = jo.get_string("name", ""); if (m_name.empty()) { // "No name" gets confusing if many mods have no name //~ name of a mod that has no name entry, (%s is the mods identifier) m_name = string_format(_("No name (%s)"), m_ident.c_str()); } else { m_name = _(m_name.c_str()); } std::string m_desc = jo.get_string("description", ""); if (m_desc.empty()) { m_desc = _("No description"); } else { m_desc = _(m_desc.c_str()); } std::string m_cat = jo.get_string("category", ""); std::pair<int, std::string> p_cat = {-1, ""}; bool bCatFound = false; do { for( size_t i = 0; i < get_mod_list_categories().size(); ++i ) { if( get_mod_list_categories()[i].first == m_cat ) { p_cat = { i, get_mod_list_categories()[i].second }; bCatFound = true; break; } } if( !bCatFound && m_cat != "" ) { m_cat = ""; } else { break; } } while( !bCatFound ); std::string m_path; if (jo.has_string("path")) { m_path = jo.get_string("path"); if (m_path.empty()) { // If an empty path is given, use only the // folder of the modinfo.json m_path = main_path; } else { // prefix the folder of modinfo.json m_path = main_path + "/" + m_path; } } else { // Default if no path is given: // "<folder-of-modinfo.json>/data" m_path = main_path + "/data"; } bool m_need_lua = jo.get_bool("with-lua", false); if ( file_exist(m_path + "/main.lua") || file_exist(m_path + "/preload.lua") ) { m_need_lua = true; } std::vector<std::string> m_dependencies; if (jo.has_member("dependencies") && jo.has_array("dependencies")) { JsonArray jarr = jo.get_array("dependencies"); while(jarr.has_more()) { const std::string dep = jarr.next_string(); if (dep == m_ident) { debugmsg("mod %s has itself as dependency", m_ident.c_str()); continue; } if (std::find(m_dependencies.begin(), m_dependencies.end(), dep) != m_dependencies.end()) { // Some dependency listed twice, ignore it, what else can be done? continue; } m_dependencies.push_back(dep); } } mod_type m_type = MT_CORE; if (t_type == "CORE") { m_type = MT_CORE; } else if (t_type == "SUPPLEMENTAL") { m_type = MT_SUPPLEMENTAL; } else { jo.throw_error( std::string("Invalid mod type: ") + t_type + " for mod " + m_ident ); } MOD_INFORMATION *modfile = new MOD_INFORMATION; modfile->ident = m_ident; modfile->_type = m_type; modfile->authors = m_authors; modfile->name = m_name; modfile->description = m_desc; modfile->dependencies = m_dependencies; modfile->category = p_cat; modfile->path = m_path; modfile->need_lua = m_need_lua; mod_map[modfile->ident] = modfile; }