mirror of
https://github.com/tribufu/node-gamedig
synced 2026-06-01 09:42:41 +00:00
Upgrade syntax of everything to more modern javascript
This commit is contained in:
parent
f8d903b982
commit
69288baebc
43 changed files with 1499 additions and 1521 deletions
|
|
@ -1,24 +1,24 @@
|
|||
var gbxremote = require('gbxremote'),
|
||||
const gbxremote = require('gbxremote'),
|
||||
async = require('async');
|
||||
|
||||
module.exports = require('./core').extend({
|
||||
init: function() {
|
||||
this._super();
|
||||
class Nadeo extends require('./core') {
|
||||
constructor() {
|
||||
super();
|
||||
this.options.port = 2350;
|
||||
this.options.port_query = 5000;
|
||||
this.gbxclient = false;
|
||||
},
|
||||
reset: function() {
|
||||
this._super();
|
||||
}
|
||||
|
||||
reset() {
|
||||
super.reset();
|
||||
if(this.gbxclient) {
|
||||
this.gbxclient.terminate();
|
||||
this.gbxclient = false;
|
||||
}
|
||||
},
|
||||
run: function(state) {
|
||||
var self = this;
|
||||
}
|
||||
|
||||
var cmds = [
|
||||
run(state) {
|
||||
const cmds = [
|
||||
['Connect'],
|
||||
['Authenticate', this.options.login,this.options.password],
|
||||
['GetStatus'],
|
||||
|
|
@ -27,49 +27,52 @@ module.exports = require('./core').extend({
|
|||
['GetCurrentChallengeInfo'],
|
||||
['GetCurrentGameInfo']
|
||||
];
|
||||
var results = [];
|
||||
const results = [];
|
||||
|
||||
async.eachSeries(cmds, function(cmdset,c) {
|
||||
var cmd = cmdset[0];
|
||||
var params = cmdset.slice(1);
|
||||
async.eachSeries(cmds, (cmdset,c) => {
|
||||
const cmd = cmdset[0];
|
||||
const params = cmdset.slice(1);
|
||||
|
||||
if(cmd == 'Connect') {
|
||||
var client = self.gbxclient = gbxremote.createClient(self.options.port_query,self.options.host, function(err) {
|
||||
if(err) return self.fatal('GBX error '+JSON.stringify(err));
|
||||
if(cmd === 'Connect') {
|
||||
const client = this.gbxclient = gbxremote.createClient(this.options.port_query,this.options.host, (err) => {
|
||||
if(err) return this.fatal('GBX error '+JSON.stringify(err));
|
||||
c();
|
||||
});
|
||||
client.on('error',function(){});
|
||||
client.on('error',() => {});
|
||||
} else {
|
||||
self.gbxclient.methodCall(cmd, params, function(err, value) {
|
||||
if(err) return self.fatal('XMLRPC error '+JSON.stringify(err));
|
||||
this.gbxclient.methodCall(cmd, params, (err, value) => {
|
||||
if(err) return this.fatal('XMLRPC error '+JSON.stringify(err));
|
||||
results.push(value);
|
||||
c();
|
||||
});
|
||||
}
|
||||
}, function() {
|
||||
var gamemode = '';
|
||||
var igm = results[5].GameMode;
|
||||
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";
|
||||
}, () => {
|
||||
let gamemode = '';
|
||||
const igm = results[5].GameMode;
|
||||
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";
|
||||
|
||||
state.name = self.stripColors(results[3].Name);
|
||||
state.password = (results[3].Password != 'No password');
|
||||
state.name = this.stripColors(results[3].Name);
|
||||
state.password = (results[3].Password !== 'No password');
|
||||
state.maxplayers = results[3].CurrentMaxPlayers;
|
||||
state.map = self.stripColors(results[4].Name);
|
||||
state.map = this.stripColors(results[4].Name);
|
||||
state.raw.gametype = gamemode;
|
||||
|
||||
results[2].forEach(function(player) {
|
||||
state.players.push({name:self.stripColors(player.Name)});
|
||||
});
|
||||
for (const player of results[2]) {
|
||||
state.players.push({name:this.stripColors(player.Name)});
|
||||
}
|
||||
|
||||
self.finish(state);
|
||||
this.finish(state);
|
||||
});
|
||||
},
|
||||
stripColors: function(str) {
|
||||
}
|
||||
|
||||
stripColors(str) {
|
||||
return str.replace(/\$([0-9a-f][^\$]?[^\$]?|[^\$]?)/g,'');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = Nadeo;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue