working logic

pull/2851/head
John McLear 2015-12-02 11:54:37 +00:00
parent 69c1d04dd2
commit 98016665e4
2 changed files with 47 additions and 11 deletions

View File

@ -74,16 +74,6 @@ async.waterfall([
// Call loadSettings hook
hooks.aCallAll("loadSettings", { settings: settings });
// Call applySettings hook
hooks.aCallAll("applySettings", settings, function(err, newSettings){
if(!newSettings) return;
newSettings.forEach(function (settingsBlob){
for (var setting in settingsBlob){
settings[setting] = settingsBlob[setting];
};
});
});
callback();
},
//initalize the http server

View File

@ -255,13 +255,20 @@ exports.reloadSettings = function reloadSettings() {
// Discover where the settings file lives
var settingsFilename = argv.settings || "settings.json";
// Discover if a credential file exists
var credentialsFilename = argv.credentials || "credentials.json";
if (path.resolve(settingsFilename)===settingsFilename) {
settingsFilename = path.resolve(settingsFilename);
} else {
settingsFilename = path.resolve(path.join(exports.root, settingsFilename));
}
var settingsStr;
if (path.resolve(credentialsFilename)===credentialsFilename) {
credentialsFilename = path.resolve(credentialsFilename);
}
var settingsStr, credentialsStr;
try{
//read the settings sync
settingsStr = fs.readFileSync(settingsFilename).toString();
@ -269,8 +276,16 @@ exports.reloadSettings = function reloadSettings() {
console.warn('No settings file found. Continuing using defaults!');
}
try{
//read the credentials sync
credentialsStr = fs.readFileSync(credentialsFilename).toString();
} catch(e){
// Doesn't matter if no credentials file found..
}
// try to parse the settings
var settings;
var credentials;
try {
if(settingsStr) {
settingsStr = jsonminify(settingsStr).replace(",]","]").replace(",}","}");
@ -281,6 +296,11 @@ exports.reloadSettings = function reloadSettings() {
process.exit(1);
}
if(credentialsStr) {
credentialsStr = jsonminify(credentialsStr).replace(",]","]").replace(",}","}");
credentials = JSON.parse(credentialsStr);
}
//loop trough the settings
for(var i in settings)
{
@ -307,6 +327,32 @@ exports.reloadSettings = function reloadSettings() {
}
}
//loop trough the settings
for(var i in credentials)
{
//test if the setting start with a low character
if(i.charAt(0).search("[a-z]") !== 0)
{
console.warn("Settings should start with a low character: '" + i + "'");
}
//we know this setting, so we overwrite it
//or it's a settings hash, specific to a plugin
if(exports[i] !== undefined || i.indexOf('ep_')==0)
{
if (_.isObject(credentials[i]) && !_.isArray(credentials[i])) {
exports[i] = _.defaults(credentials[i], exports[i]);
} else {
exports[i] = credentials[i];
}
}
//this setting is unkown, output a warning and throw it away
else
{
console.warn("Unknown Setting: '" + i + "'. This setting doesn't exist or it was removed");
}
}
log4js.configure(exports.logconfig);//Configure the logging appenders
log4js.setGlobalLogLevel(exports.loglevel);//set loglevel
process.env['DEBUG'] = 'socket.io:' + exports.loglevel; // Used by SocketIO for Debug