Skip to content
Snippets Groups Projects
Commit b60bb985 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Add support for ctrl/modopts/*.ini

How these files differ from modopts.ini (and by extension,
ctrl/modopts.d/*.ini):

- The root section is always parsed, part of the returned object
- [sections] denote ARS that if matched (current user meets requirements)
  then those key/values are added as properties of the returned object
  possibly overriding previously defined properties (options), this allows
  different users (or clients/hosts, terminals) to get different option
  values much more easily
parent afbc482b
No related branches found
No related tags found
No related merge requests found
/* Load Synchronet JS Module Control/Enable options from ctrl/modopts.ini */
/* Parse a single .ini section using the argument (to load) as the section name */
/* and return an object containing the key=value pairs as properties */
/* If the section [module:lang=user-lang] exists in the .ini file,
that section (or key value from it) will be returned instead of the [module] section.
If the section [module:charset=terminal-charset] exists in the .ini file,
that section (or key value from it) will be returned instead of the [module] section.
*/
/* To avoid over-writing the parent script's "argc" and "argv" values,
pass a scope object to load(), like this:
options=load(new Object, "modopts.js", "your_module_name");
/* Load Synchronet JS Module simple control/enable/string options from
* ctrl/modopts.ini (and by extension ctrl/modopts.d/*.ini) or
* ctrl/modopts/modname.ini
*
* For ctrl/modopts.ini (and ctrl/modopts.d/*.ini):
* Parses a single .ini section using the first argument to load() as the
* section name and return an object containing the section keys as
* properties with Boolean, Number, or String values.
*
* Or parses and return a single option/key value when a key name is
* specified in the fourth argument to load(). The default value of the
* option may be specified in the fifth argument to load() in this case.
*
* If the section [module:lang=user-lang] exists in the modopts.ini file,
* that section (or key value from it) may be returned instead of the
* [module] section.
*
* If the section [module:charset=terminal-charset] exists in the
* modopts.ini file, that section (or key value from it) may be returned
* instead of the [module] section.
*
* For ctrl/modopts/modname.ini:
* Parses the entire root section of the modname.ini file and for each
* [section] in the .ini file, treat the section name as an Access
* Requirement String (ARS) and if the current user meets the requirements,
* parse the keys from that section and add the keys/values as properties to
* the returned object. Later sections/keys can override previous property
* values.
*
* If an option/key name is passed to load(), returns just that one option
* value (String, Number, or Boolean, not an object).
*
* Examples:
*
* var options = load({}, "modopts.js", "your_module_name");
*
* var opt = load({}, "modopts.js", "your_module_name", "opt_name", default_opt_value);
*/
// Another valid use is to request the value of a single module option, like this:
// opt_value = load({}, "modopts.js", "your_module", "opt_name");
// or:
// opt_value = load({}, "modopts.js", "your_module", "opt_name", default_opt_value);
"use strict";
function get_mod_options(modname, optname, default_optval)
{
var ini_file = new File(file_cfgname(system.ctrl_dir, "modopts.ini"));
var ini_file = new File(system.ctrl_dir + "modopts/" + modname + ".ini");
if(ini_file.open("r")) {
var obj = ini_file.iniGetObject(/* lowercase */false, /* blanks: */true);
var sections = ini_file.iniGetSections();
for(var i in sections) {
var section = sections[i];
if((js.global.bbs && bbs.compare_ars(section)) || (js.global.user && user.compare_ars(section))) {
var subobj = ini_file.iniGetObject(section, /* lowercase */false, /* blanks: */true);
for(var j in subobj)
obj[j] = subobj[j];
}
}
ini_file.close();
if(optname)
return obj[optname];
return obj;
}
ini_file = new File(file_cfgname(system.ctrl_dir, "modopts.ini"));
if(!ini_file.open("r")) {
return undefined;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment