2019-01-09 12:35:11 +01:00
|
|
|
const Core = require('./core'),
|
|
|
|
cheerio = require('cheerio');
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2019-01-07 01:52:03 +01:00
|
|
|
class BuildAndShoot extends Core {
|
2019-01-09 12:35:11 +01:00
|
|
|
async run(state) {
|
|
|
|
const body = await this.request({
|
2020-07-05 06:28:03 +02:00
|
|
|
url: 'http://'+this.options.address+':'+this.options.port+'/',
|
2019-01-09 12:35:11 +01:00
|
|
|
});
|
2017-08-09 12:32:09 +02:00
|
|
|
|
2019-01-09 12:35:11 +01:00
|
|
|
let m;
|
2017-08-09 12:32:09 +02:00
|
|
|
|
2019-02-20 04:15:34 +01:00
|
|
|
m = body.match(/status server for (.*?)\.?[\r\n]/);
|
2019-01-09 12:35:11 +01:00
|
|
|
if(m) state.name = m[1];
|
2017-08-09 12:32:09 +02:00
|
|
|
|
2019-01-09 12:35:11 +01:00
|
|
|
m = body.match(/Current uptime: (\d+)/);
|
|
|
|
if(m) state.raw.uptime = m[1];
|
2017-08-09 12:32:09 +02:00
|
|
|
|
2019-01-09 12:35:11 +01:00
|
|
|
m = body.match(/currently running (.*?) by /);
|
|
|
|
if(m) state.map = m[1];
|
2017-08-09 12:32:09 +02:00
|
|
|
|
2019-01-09 12:35:11 +01:00
|
|
|
m = body.match(/Current players: (\d+)\/(\d+)/);
|
|
|
|
if(m) {
|
|
|
|
state.raw.numplayers = m[1];
|
|
|
|
state.maxplayers = m[2];
|
|
|
|
}
|
2017-08-09 12:32:09 +02:00
|
|
|
|
2019-01-12 12:45:09 +01:00
|
|
|
m = body.match(/aos:\/\/[0-9]+:[0-9]+/);
|
|
|
|
if (m) {
|
|
|
|
state.connect = m[0];
|
|
|
|
}
|
|
|
|
|
2019-01-09 12:35:11 +01:00
|
|
|
const $ = cheerio.load(body);
|
|
|
|
$('#playerlist tbody tr').each((i,tr) => {
|
|
|
|
if (!$(tr).find('td').first().attr('colspan')) {
|
|
|
|
state.players.push({
|
|
|
|
name: $(tr).find('td').eq(2).text(),
|
|
|
|
ping: $(tr).find('td').eq(3).text().trim(),
|
|
|
|
team: $(tr).find('td').eq(4).text().toLowerCase(),
|
|
|
|
score: parseInt($(tr).find('td').eq(5).text())
|
|
|
|
});
|
2017-08-09 12:32:09 +02:00
|
|
|
}
|
|
|
|
});
|
2019-01-09 12:35:11 +01:00
|
|
|
/*
|
|
|
|
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 12:32:09 +02:00
|
|
|
}
|
2017-08-09 11:05:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = BuildAndShoot;
|