2017-08-09 11:05:55 +02:00
|
|
|
const request = require('request');
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 12:04:32 +02:00
|
|
|
class GeneShift extends require('./core') {
|
2017-08-09 12:32:09 +02:00
|
|
|
run(state) {
|
|
|
|
request({
|
|
|
|
uri: 'http://geneshift.net/game/receiveLobby.php',
|
|
|
|
timeout: 3000,
|
|
|
|
}, (e,r,body) => {
|
|
|
|
if(e) return this.fatal('Lobby request error');
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 11:05:55 +02:00
|
|
|
const split = body.split('<br/>');
|
2017-08-09 12:32:09 +02:00
|
|
|
let found = false;
|
|
|
|
for(const line of split) {
|
2017-08-09 11:05:55 +02:00
|
|
|
const fields = line.split('::');
|
|
|
|
const ip = fields[2];
|
|
|
|
const port = fields[3];
|
2017-08-09 12:32:09 +02:00
|
|
|
if(ip === this.options.address && parseInt(port) === this.options.port) {
|
|
|
|
found = fields;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-01-18 08:44:19 +01:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
if(!found) return this.fatal('Server not found in list');
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
state.raw.countrycode = found[0];
|
|
|
|
state.raw.country = found[1];
|
|
|
|
state.name = found[4];
|
|
|
|
state.map = found[5];
|
|
|
|
state.raw.numplayers = parseInt(found[6]);
|
|
|
|
state.maxplayers = parseInt(found[7]);
|
|
|
|
// fields[8] is unknown?
|
|
|
|
state.raw.rules = found[9];
|
|
|
|
state.raw.gamemode = parseInt(found[10]);
|
|
|
|
state.raw.gangsters = parseInt(found[11]);
|
|
|
|
state.raw.cashrate = parseInt(found[12]);
|
|
|
|
state.raw.missions = !!parseInt(found[13]);
|
|
|
|
state.raw.vehicles = !!parseInt(found[14]);
|
|
|
|
state.raw.customweapons = !!parseInt(found[15]);
|
|
|
|
state.raw.friendlyfire = !!parseInt(found[16]);
|
|
|
|
state.raw.mercs = !!parseInt(found[17]);
|
|
|
|
// fields[18] is unknown? listen server?
|
|
|
|
state.raw.version = found[19];
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
for(let i = 0; i < state.raw.numplayers; i++) {
|
|
|
|
state.players.push({});
|
|
|
|
}
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
this.finish(state);
|
|
|
|
});
|
|
|
|
}
|
2017-08-09 11:05:55 +02:00
|
|
|
}
|
|
|
|
|
2017-08-09 12:04:32 +02:00
|
|
|
module.exports = GeneShift;
|