2017-08-09 11:05:55 +02:00
|
|
|
const request = require('request');
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 11:05:55 +02:00
|
|
|
class BuildAndShoot extends require('./core') {
|
|
|
|
run(state) {
|
2014-10-29 08:02:03 +01:00
|
|
|
request({
|
|
|
|
uri: 'http://'+this.options.address+':'+this.options.port_query+'/',
|
|
|
|
timeout: 3000,
|
2017-08-09 11:05:55 +02:00
|
|
|
}, (e,r,body) => {
|
|
|
|
if(e) return this.fatal('HTTP error');
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 11:05:55 +02:00
|
|
|
let m;
|
|
|
|
|
|
|
|
m = body.match(/status server for (.*?)\r|\n/);
|
2014-10-29 08:02:03 +01:00
|
|
|
if(m) state.name = m[1];
|
|
|
|
|
2017-08-09 11:05:55 +02:00
|
|
|
m = body.match(/Current uptime: (\d+)/);
|
2014-10-29 08:02:03 +01:00
|
|
|
if(m) state.raw.uptime = m[1];
|
|
|
|
|
2017-08-09 11:05:55 +02:00
|
|
|
m = body.match(/currently running (.*?) by /);
|
2014-10-29 08:02:03 +01:00
|
|
|
if(m) state.map = m[1];
|
|
|
|
|
2017-08-09 11:05:55 +02:00
|
|
|
m = body.match(/Current players: (\d+)\/(\d+)/);
|
2014-10-29 08:02:03 +01:00
|
|
|
if(m) {
|
|
|
|
state.raw.numplayers = m[1];
|
|
|
|
state.maxplayers = m[2];
|
|
|
|
}
|
|
|
|
|
2017-08-09 11:05:55 +02:00
|
|
|
m = body.match(/class="playerlist"([^]+?)\/table/);
|
2014-10-29 08:02:03 +01:00
|
|
|
if(m) {
|
2017-08-09 11:05:55 +02:00
|
|
|
const table = m[1];
|
|
|
|
const pre = /<tr>[^]*<td>([^]*)<\/td>[^]*<td>([^]*)<\/td>[^]*<td>([^]*)<\/td>[^]*<td>([^]*)<\/td>/g;
|
|
|
|
let pm;
|
2014-10-29 08:02:03 +01:00
|
|
|
while(pm = pre.exec(table)) {
|
2017-08-09 11:05:55 +02:00
|
|
|
if(pm[2] === 'Ping') continue;
|
2014-10-29 08:02:03 +01:00
|
|
|
state.players.push({
|
|
|
|
name: pm[1],
|
|
|
|
ping: pm[2],
|
|
|
|
team: pm[3],
|
|
|
|
score: pm[4]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
var m = this.options.address.match(/(\d+)\.(\d+)\.(\d+)\.(\d+)/);
|
|
|
|
if(m) {
|
|
|
|
var o1 = parseInt(m[1]);
|
|
|
|
var o2 = parseInt(m[2]);
|
|
|
|
var o3 = parseInt(m[3]);
|
|
|
|
var o4 = parseInt(m[4]);
|
|
|
|
var addr = o1+(o2<<8)+(o3<<16)+(o4<<24);
|
|
|
|
state.raw.url = 'aos://'+addr;
|
|
|
|
}
|
|
|
|
*/
|
2017-08-09 11:05:55 +02:00
|
|
|
this.finish(state);
|
2014-10-29 08:02:03 +01:00
|
|
|
});
|
|
|
|
}
|
2017-08-09 11:05:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = BuildAndShoot;
|