2017-08-09 11:05:55 +02:00
|
|
|
const gbxremote = require('gbxremote'),
|
2017-08-09 12:32:09 +02:00
|
|
|
async = require('async');
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 11:05:55 +02:00
|
|
|
class Nadeo extends require('./core') {
|
2017-08-09 12:32:09 +02:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.options.port = 2350;
|
|
|
|
this.options.port_query = 5000;
|
|
|
|
this.gbxclient = false;
|
|
|
|
}
|
2017-08-09 11:05:55 +02:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
reset() {
|
|
|
|
super.reset();
|
|
|
|
if(this.gbxclient) {
|
|
|
|
this.gbxclient.terminate();
|
|
|
|
this.gbxclient = false;
|
|
|
|
}
|
|
|
|
}
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
run(state) {
|
|
|
|
const cmds = [
|
|
|
|
['Connect'],
|
|
|
|
['Authenticate', this.options.login,this.options.password],
|
|
|
|
['GetStatus'],
|
|
|
|
['GetPlayerList',500,0],
|
|
|
|
['GetServerOptions'],
|
|
|
|
['GetCurrentChallengeInfo'],
|
|
|
|
['GetCurrentGameInfo']
|
|
|
|
];
|
2017-08-09 11:05:55 +02:00
|
|
|
const results = [];
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
async.eachSeries(cmds, (cmdset,c) => {
|
2017-08-09 11:05:55 +02:00
|
|
|
const cmd = cmdset[0];
|
|
|
|
const params = cmdset.slice(1);
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
if(cmd === 'Connect') {
|
2017-08-09 11:05:55 +02:00
|
|
|
const client = this.gbxclient = gbxremote.createClient(this.options.port_query,this.options.host, (err) => {
|
2017-08-09 12:32:09 +02:00
|
|
|
if(err) return this.fatal('GBX error '+JSON.stringify(err));
|
|
|
|
c();
|
|
|
|
});
|
|
|
|
client.on('error',() => {});
|
|
|
|
} else {
|
|
|
|
this.gbxclient.methodCall(cmd, params, (err, value) => {
|
|
|
|
if(err) return this.fatal('XMLRPC error '+JSON.stringify(err));
|
|
|
|
results.push(value);
|
|
|
|
c();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, () => {
|
2017-08-09 11:05:55 +02:00
|
|
|
let gamemode = '';
|
|
|
|
const igm = results[5].GameMode;
|
2017-08-09 12:32:09 +02:00
|
|
|
if(igm === 0) gamemode="Rounds";
|
|
|
|
if(igm === 1) gamemode="Time Attack";
|
|
|
|
if(igm === 2) gamemode="Team";
|
|
|
|
if(igm === 3) gamemode="Laps";
|
|
|
|
if(igm === 4) gamemode="Stunts";
|
|
|
|
if(igm === 5) gamemode="Cup";
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
state.name = this.stripColors(results[3].Name);
|
|
|
|
state.password = (results[3].Password !== 'No password');
|
|
|
|
state.maxplayers = results[3].CurrentMaxPlayers;
|
|
|
|
state.map = this.stripColors(results[4].Name);
|
|
|
|
state.raw.gametype = gamemode;
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
for (const player of results[2]) {
|
|
|
|
state.players.push({name:this.stripColors(player.Name)});
|
|
|
|
}
|
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:32:09 +02:00
|
|
|
stripColors(str) {
|
|
|
|
return str.replace(/\$([0-9a-f][^\$]?[^\$]?|[^\$]?)/g,'');
|
|
|
|
}
|
2017-08-09 11:05:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Nadeo;
|