nbot

A clone of the eBot by @deStrO fully based on node.js with build in Web Page - WIP
git clone git://archive.git.mtrnord.blog/MTRNord/nbot.git
Log | Files | Refs | README | LICENSE

commit 626e295ad32005ffbf51672a20860885ee5131ab
parent 0f7313262b192519bda46837ba77a710a122f968
Author: MTRNord <mtrnord1@gmail.com>
Date:   Tue,  2 Aug 2016 19:13:19 +0200

fix(pluginManager) Getting Versions is now working

Diffstat:
Mbackend/pluginManager.js | 26++++++++++++++------------
Abackend/rcon_new.js | 110+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackage.json | 1+
Mstart.js | 4++--
Mweb/server.js | 8+++-----
Mweb/theme/js/pluginManagerConnect.js | 15+++++++--------
6 files changed, 137 insertions(+), 27 deletions(-)

diff --git a/backend/pluginManager.js b/backend/pluginManager.js @@ -8,17 +8,16 @@ var GitHubApi = require("github"); var github = new GitHubApi({ - // required - version: "3.0.0", // optional - debug: true, + debug: false, protocol: "https", host: "api.github.com", // should be api.github.com for GitHub pathPrefix: "", // for some GHEs; none for GitHub - timeout: 5000, headers: { - "user-agent": "nBot" // GitHub is happy with a unique user agent - } + "user-agent": "MTRNord" // GitHub is happy with a unique user agent + }, + followRedirects: false, // default: true; there's currently an issue with non-get redirects, so allow ability to disable follow-redirects + timeout: 5000 }); /** * @class pluginManager @@ -28,15 +27,18 @@ var github = new GitHubApi({ * @method getSourcemodVersions * @beta Work in Progress */ -exports.getSourcemodVersions = function () { +var pluginManager = module.exports = {} +pluginManager.getSourcemodVersions = function (socket, command) { github.repos.getTags({ user: "alliedmodders", repo: "sourcemod" }, function(err, res) { - console.log("test"); - console.log(JSON.stringify(res)); - console.log("test2"); - console.log(err) - return res + if (err) { + socket.emit('SourcemodList', {response: err, command: command.command}) + console.error(err) + }else { + socket.emit('SourcemodList', {response: res, command: command.command}) + //console.log(JSON.stringify(res)) + } }) } diff --git a/backend/rcon_new.js b/backend/rcon_new.js @@ -0,0 +1,110 @@ +/** +* Rcon connection to csgo Server +* +* @module nBot +* @submodule rcon +* @requires rcon +*/ +var options = { + tcp: true, // false for UDP, true for TCP (default true) + challenge: false // true to use the challenge protocol (default true) +}; +var host = "127.0.0.1"; +var port = "27015"; +var password = "1199"; +client = new Rcon(host, port, password, options); +/** +* @class rcon_commands +* @static +*/ +var rcon_commands = module.exports = {} + /** + * @method start + * @deprecated Could later make problems at start + */ + rcon.start = function () { + conn.connect().then(() => { + return conn.send('changelevel de_dust2').then(() => { + console.log('changed map'); + }); + }).then( + () => conn.send('sv_lan 0').then(() => console.log('changed sv_lan')) + ).then( + () => conn.send('mp_restartgame 1').then(() => console.log('restarted game')) + ).then( + () => conn.disconnect() + ).catch(err => { + console.log('caught', err); + console.log(err.stack); + }); + }, + /** + * @method restart_game + */ + rcon.restart_game = function () { + rcon_lib.connect().then(() => { + return rcon_lib.command('mp_restartgame 1').then(() =>{ + console.log('game restarted'); + }); + }).then( + () => rcon_lib.disconnect() + ).catch(err => { + console.log('caught', err); + console.log(err.stack); + }); + }, + /** + * @method status + * @return {String} Status from the Server. + */ + rcon.status = function () { + return rcon_lib.connect().then(() => { + return rcon_lib.command('status') + }).then( + () => rcon_lib.disconnect() + ).catch(err => { + console.log('caught', err); + console.log(err.stack); + }); + }, + /** + * @method live_on + */ + rcon.live_on = function () { + rcon_lib.connect().then(() => { + return rcon_lib.command('mp_restartgame 1').then(() => { + console.log('game restarted 0'); + }); + }).then( + () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 1')) + ).then( + () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 2')) + ).then( + () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 3')) + ).then( + () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 4')) + ).then( + () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 5')) + ).then( + () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 6')) + ).then( + () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 7')) + ).then( + () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 8')) + ).then( + () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 9')) + ).then( + () => rcon_lib.command('mp_restartgame 1').then(() => console.log('game restarted 10')) + ).then( + () => rcon_lib.command('say LIVE!!!').then(() => console.log('LIVE!!!')) + ).then( + () => rcon_lib.command('say LIVE!!!').then(() => console.log('LIVE!!!')) + ).then( + () => rcon_lib.command('say LIVE!!!').then(() => console.log('LIVE!!!')) + ).then( + () => rcon_lib.disconnect() + ).catch(err => { + console.log('caught', err); + console.log(err.stack); + }); + } diff --git a/package.json b/package.json @@ -31,6 +31,7 @@ "express": "^4.13.4", "github": "^2.0.0", "progress": "^1.1.8", + "rcon": "^1.0.2", "socket.io": "^1.4.5", "srcds-rcon": "^2.2.1" }, diff --git a/start.js b/start.js @@ -8,8 +8,8 @@ */ var web = require("./web/server.js") var rcon = require("./backend/rcon.js") -var pluginManager = require("./backend/pluginManager") +var pluginManager = require("./backend/pluginManager.js") rcon.start() -console.log(pluginManager.getSourcemodVersions()) +//console.log(pluginManager.getSourcemodVersions()) web.start() web.iojs() diff --git a/web/server.js b/web/server.js @@ -35,8 +35,8 @@ var server = module.exports = {}; app.use('/css', express.static(path.join(__dirname, '/theme/css'))); app.use('/js', express.static(path.join(__dirname, '/theme/js'))); app.use('/fonts', express.static(path.join(__dirname, '/theme/fonts'))); - http.listen((process.env.PORT || 5000), "0.0.0.0", function(){ - console.log('listening on *:3001'); + http.listen((process.env.PORT || 8080), "0.0.0.0", function(){ + console.log('listening on *:8080'); }); }, /** @@ -64,9 +64,7 @@ var server = module.exports = {}; addserver.start() }else { if (command.command === "refreshSourcemod") { - console.log("here"); - console.log(typeof pluginManager.getSourcemodVersions()) - socket.emit('SourcemodList', {response: pluginManager.getSourcemodVersions(), command: command.command}) + pluginManager.getSourcemodVersions(socket, command) }else { console.log("unknown command"); } diff --git a/web/theme/js/pluginManagerConnect.js b/web/theme/js/pluginManagerConnect.js @@ -16,15 +16,17 @@ socket.on('status_alert', function (message) { }); socket.on('SourcemodList', function (message) { - console.log(message) drawTable(message.response); }); function drawTable(data) { for (var key in data) { if (data.hasOwnProperty(key)) { - var data1 = data[key]; - for (var i = 0; i < data1.length; i++) { - drawRow(data1[i]); + for (var i = 0; i < data.length; i++) { + var name = data[key].name; + var check = name.indexOf("sourcemod") > -1; + if (check) { + drawRow(data[key]); + } } } } @@ -34,9 +36,6 @@ function drawRow(rowData) { var row = $("<tr />") $("#SourcemodVersions_body").append(row); //this will append tr element to table... keep its reference for a while since we will add cels into it row.append($("<td>" + rowData.name + "</td>")); - console.error(rowData.name); row.append($("<td>" + rowData.zipball_url + "</td>")); - console.error(rowData.zipball_url); - row.append($("<td>" + rowData.commit + "</td>")); - console.error(rowData.commit); + row.append($("<td>" + rowData.commit.sha + "</td>")); }