mirror of
https://github.com/gamedig/node-gamedig.git
synced 2024-11-17 17:25:19 +01:00
Add support for build and shoot
This commit is contained in:
parent
3a1490b8a5
commit
1df81277f0
1 changed files with 50 additions and 0 deletions
50
protocols/buildandshoot.js
Normal file
50
protocols/buildandshoot.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
var request = require('request');
|
||||
|
||||
module.exports = require('./core').extend({
|
||||
init: function() {
|
||||
this._super();
|
||||
this.pretty = 'Build and Shoot';
|
||||
this.options.port = 32886;
|
||||
},
|
||||
run: function(state) {
|
||||
var self = this;
|
||||
request({
|
||||
uri: 'http://'+this.options.address+':'+this.options.port+'/',
|
||||
timeout: 3000,
|
||||
}, function(e,r,body) {
|
||||
if(e) return self.error('HTTP error');
|
||||
|
||||
var m = body.match(/status server for (.*?)\r|\n/);
|
||||
if(m) state.name = m[1];
|
||||
|
||||
var m = body.match(/Current uptime: (\d+)/);
|
||||
if(m) state.raw.uptime = m[1];
|
||||
|
||||
var m = body.match(/currently running (.*?) by /);
|
||||
if(m) state.map = m[1];
|
||||
|
||||
var m = body.match(/Current players: (\d+)\/(\d+)/);
|
||||
if(m) {
|
||||
state.raw.numplayers = m[1];
|
||||
state.maxplayers = m[2];
|
||||
}
|
||||
|
||||
var m = body.match(/class="playerlist"([^]+?)\/table/);
|
||||
if(m) {
|
||||
var table = m[1];
|
||||
var pre = /<tr>[^]*<td>([^]*)<\/td>[^]*<td>([^]*)<\/td>[^]*<td>([^]*)<\/td>[^]*<td>([^]*)<\/td>/g;
|
||||
while(pm = pre.exec(table)) {
|
||||
if(pm[2] == 'Ping') continue;
|
||||
state.players.push({
|
||||
name: pm[1],
|
||||
ping: pm[2],
|
||||
team: pm[3],
|
||||
score: pm[4]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
self.finish(state);
|
||||
});
|
||||
}
|
||||
});
|
Loading…
Reference in a new issue