void Configuration::GetConfigListS(std::string Name, std::map<std::string, std::filesystem::path> &Out, std::string DefaultKeyName) { CSimpleIniA::TNamesDepend List; if (!Config) throw CfgNotLoaded; Config->GetAllKeys(Name.c_str(), List); if (!List.size() && DefaultKeyName != "") Config->SetValue(Name.c_str(), DefaultKeyName.c_str(), ""); for (CSimpleIniA::TNamesDepend::iterator i = List.begin(); i != List.end(); ++i) { if (Config->GetValue(Name.c_str(), i->pItem)) Out[std::string(i->pItem)] = Config->GetValue(Name.c_str(), i->pItem); } }
// ------------------------------------------------------------------------------------------------ SMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs* functions, PluginCallbacks* callbacks, PluginInfo* info) { using namespace SMod; // Output plug-in header puts(""); OutputMessage("------------------------------------------------------------------"); OutputMessage("Plug-in: %s", SMOD_NAME); OutputMessage("Author: %s", SMOD_AUTHOR); OutputMessage("Legal: %s", SMOD_COPYRIGHT); OutputMessage("------------------------------------------------------------------"); puts(""); // Store server proxies _Func = functions; _Clbk = callbacks; _Info = info; // Assign plug-in version _Info->pluginVersion = SMOD_VERSION; _Info->apiMajorVersion = PLUGIN_API_MAJOR; _Info->apiMinorVersion = PLUGIN_API_MINOR; // Assign the plug-in name snprintf(_Info->name, sizeof(_Info->name), "%s", SMOD_HOST_NAME); // Create the configuration loader CSimpleIniA conf(false, true, true); // Attempt to load the configurations from disk const SI_Error ini_ret = conf.LoadFile("announce.ini"); // See if the configurations could be loaded if (ini_ret < 0) { switch (ini_ret) { case SI_FAIL: OutputError("Failed to load the configuration file. Probably invalid"); case SI_NOMEM: OutputError("Run out of memory while loading the configuration file"); case SI_FILE: OutputError("Failed to load the configuration file: announce.ini"); default: OutputError("Failed to load the configuration file for some unforeseen reason"); } // Plug-in failed to load configurations return SMOD_FAILURE; } // See if the plug-in should output verbose information g_Verbose = conf.GetBoolValue("Options", "Verbose", false); // Attempt to retrieve the list of specified master-servers CSimpleIniA::TNamesDepend servers; conf.GetAllValues("Servers", "Address", servers); // See if any server address was specified if (servers.size() <= 0) { VerboseError("No master-servers specified. No reason to load the plug-in."); // No point in loading the plug-in return SMOD_FAILURE; } // Sort the list in it's original order servers.sort(CSimpleIniA::Entry::LoadOrder()); // Process each specified server addresses for (const auto & elem : servers) { // See if there's even something that could resemble a server address if (!elem.pItem) { continue; } // Attempt to extract URI information from the currently processed address URI addr(elem.pItem); // See if a valid host could be extracted if (addr.mHost.empty()) { VerboseError("Master-server '%s' is an ill formed address", elem.pItem); } // Construct a server instance using this address else { // Show which master-server is added to the list VerboseMessage("Master-server '%s' added to the announce list", addr.Full()); // Create the server instance g_Servers.emplace_back(std::move(addr)); } } // See if any server was valid if (g_Servers.size() <= 0) { VerboseError("No master-servers specified. No reason to load the plug-in."); // No point in loading the plug-in return SMOD_FAILURE; } // Bind to the server callbacks _Clbk->OnServerInitialise = OnServerInitialise; _Clbk->OnServerShutdown = OnServerShutdown; _Clbk->OnServerFrame = OnServerFrame; // Notify that the plug-in was successfully loaded VerboseMessage("Successfully loaded %s", SMOD_NAME); // Done! return SMOD_SUCCESS; }