Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
HTTPServer.prototype.validateConfig = function(done) { done() }
// Rhizome servers and connection manager
manager = new rhizome.connections.ConnectionManager({ store: config.server.tmpDir })
httpServer = new HTTPServer()
wsServer = new rhizome.websockets.Server({ serverInstance: httpServer._httpServer })
oscServer = new rhizome.osc.Server({ port: config.osc.port })
// Set error handlers
;([wsServer, oscServer, manager]).forEach((server) => {
server.on('error', (err) => console.error(err.stack ? err.stack : err))
})
// Create tmp and build folders
asyncOps.push(mkdirp.bind(mkdirp, buildDir))
// If `config.instruments` are provided, write it to a config file
if (config.instruments) {
asyncOps.push(
fs.writeFile.bind(fs, instrumentConfigFile, 'fields.config = ' + config.instruments.toString())
)
}
// Start servers
asyncOps.push(rhizome.starter.bind(rhizome.starter, manager, [oscServer, httpServer, wsServer]))
// Async operations
async.series(asyncOps, function(err) {
if (err) throw err
console.log(clc.bold('Fields ' + version +' running') )
console.log(clc.black('GPL license. Copyright (C) 2016 Sébastien Piquemal, Tim Shaw'))
function linkPkg (dir, pkg, cb) {
var dstPath = path.join(dir, 'node_modules', pkg.name)
var srcPath = path.relative(
path.join(dstPath, 'node_modules'),
path.join(dir, 'node_modules', pkg.uid)
)
// path.dirname('@hello/world') #=> 'hello'
// path.dirname('world') #=> '.'
async.series([
mkdirp.bind(null, path.join(dir, 'node_modules', path.dirname(pkg.name))),
forceSymlink.bind(null, srcPath, dstPath, config.symlinkType)
], cb)
}
exports.clone = function(repo, url, callback) {
async.series([
// 0755 = 493
mkdirp.bind(null, path.dirname(repo), 493),
git.bind(null, ['clone', url, repo])
],
function(err) {
callback(err);
});
};
function download(url, filename, callback) {
console.log(`Downloading ${url}`);
let body;
async.series([
callback => { //[1]
request(url, (err, response, resBody) => {
if(err) {
return callback(err);
}
body = resBody;
callback();
});
},
mkdirp.bind(null, path.dirname(filename)), //[2]
callback => { //[3]
fs.writeFile(filename, body, callback);
}
], err => { //[4]
if(err) {
return callback(err);
}
console.log(`Downloaded and saved: ${url}`);
callback(null, body);
});
}
Game.prototype.downloadChunk = co(function *(dir, id) {
try {
yield mkdirp.bind(null, dir + '/chunks')
}
catch (err) {
return console.error(err)
}
var ws = fs.createWriteStream(dir + '/chunks/' + id)
var decipher = crypto.createDecipheriv('bf-ecb', this.cryptoKey, "")
var gunzip = zlib.createGunzip()
var url = this.baseUrl + 'consumer/getGameDataChunk/' + this.region + '/' + this.id + '/' + id + '/token'
console.log('[', id, '] GET ', url)
var req = http.request(url, function(res) {
console.log('[', id, ']', res.statusCode)
if(res.statusCode !== 200) {
console.log('ERR[', id, '] HTTP:', res.statusCode, res.headers)
return;
}
setup: function(cb) {
log('Setting up...');
async.series([
mkdirp.bind(undefined, config.dataDir),
mkdirp.bind(undefined, config.tmpDir)
], function(error) {
if (error) {
return cb(error);
}
cb();
});
}
};
module.exports = function dumpCore(scriptPath, destDirectory, options, callback) {
if (typeof options === 'function') {
callback = options;
options = null;
}
var coreDumpProgressMsg;
if (options && options.progress) {
coreDumpProgressMsg = progressMsg.startProgressMsg(CORE_DUMPS_PROGRESS_MSG,
CORE_DUMPS_PROGRESS_DELAY);
}
async.series([
mkdirp.bind(global, destDirectory),
generateCoreDump.bind(global, scriptPath, destDirectory)
], function coreDumped(err, results) {
if (coreDumpProgressMsg) {
progressMsg.stopProgressMsg(coreDumpProgressMsg);
}
if (err) {
debug('Error when dumping core: ' + err);
}
return callback(err, results[1]);
});
}
setup: function(cb) {
log('Setting up...');
async.series([
mkdirp.bind(undefined, config.dataDir),
mkdirp.bind(undefined, config.tmpDir)
], function(error) {
if (error) {
return cb(error);
}
cb();
});
}
};
CA.create = function (caFolder, callback) {
var ca = new CA();
ca.baseCAFolder = caFolder;
ca.certsFolder = path.join(ca.baseCAFolder, 'certs');
ca.keysFolder = path.join(ca.baseCAFolder, 'keys');
async.series([
mkdirp.bind(null, ca.baseCAFolder),
mkdirp.bind(null, ca.certsFolder),
mkdirp.bind(null, ca.keysFolder),
function (callback) {
FS.exists(path.join(ca.certsFolder, 'ca.pem'), function (exists) {
if (exists) {
ca.loadCA(callback);
} else {
ca.generateCA(callback);
}
});
}
], function (err) {
if (err) {
return callback(err);
}
return callback(null, ca);
});
}).map(function (directory) {
return mkdirp.bind(mkdirp, buildDescription.directories[directory]);
}), function (err) {
callback(err, buildDescription);