addServer.js (1407B)
1 /** 2 * Build and setup csgoserver 3 * 4 * @module nBot 5 * @submodule addServer 6 * @requires server, progress, https, fs 7 */ 8 var socket = require("../web/server.js") 9 var ProgressBar = require('progress'); 10 var https = require('https'); 11 var fs = require('fs'); 12 /** 13 * @class addServer 14 * @static 15 */ 16 var addServer = module.exports = {} 17 /** 18 * @method start 19 * @beta Work in Progress 20 */ 21 addServer.start = function (socket, command) { 22 var req = https.request({ 23 host: 'raw.githubusercontent.com', 24 port: 443, 25 path: '/dgibbs64/linuxgameservers/master/CounterStrikeGlobalOffensive/csgoserver' 26 }); 27 28 req.on('response', function(res){ 29 res.on('data', function (chunk) { 30 fs.writeFile("csgo_servers/csgoserver", chunk, function(err) { 31 if(err) { 32 return console.log(err); 33 } 34 35 console.log("The file was saved!"); 36 socket.emit('ScriptDownloaded', {response: "Download Success", command: command.command}) 37 }); 38 }); 39 40 res.on('end', function () { 41 console.log('\n'); 42 }); 43 console.log('statusCode: ', res.statusCode); 44 }); 45 req.end(); 46 req.on('error', (e) => { 47 console.error(e); 48 socket.emit('ScriptDownloaded', {response: "Download Failed --> " + e, command: command.command}) 49 }); 50 }, 51 /** 52 * @method step2 53 */ 54 addServer.step2 = function () { 55 //TODO Start Script 56 }