Upgrade syntax of everything to more modern javascript

This commit is contained in:
mmorrison 2017-08-09 04:05:55 -05:00
parent f8d903b982
commit 69288baebc
43 changed files with 1499 additions and 1521 deletions

View file

@ -1,79 +1,80 @@
var async = require('async');
const async = require('async');
module.exports = require('./core').extend({
init: function() {
this._super();
class Gamespy1 extends require('./core') {
constructor() {
super();
this.sessionId = 1;
this.encoding = 'latin1';
this.byteorder = 'be';
},
run: function(state) {
var self = this;
}
run(state) {
async.series([
function(c) {
self.sendPacket('info', function(data) {
(c) => {
this.sendPacket('info', (data) => {
state.raw = data;
if('hostname' in state.raw) state.name = state.raw.hostname;
if('mapname' in state.raw) state.map = state.raw.mapname;
if(self.trueTest(state.raw.password)) state.password = true;
if(this.trueTest(state.raw.password)) state.password = true;
if('maxplayers' in state.raw) state.maxplayers = parseInt(state.raw.maxplayers);
c();
});
},
function(c) {
self.sendPacket('rules', function(data) {
(c) => {
this.sendPacket('rules', (data) => {
state.raw.rules = data;
c();
});
},
function(c) {
self.sendPacket('players', function(data) {
var players = {};
var teams = {};
for(var ident in data) {
var split = ident.split('_');
var key = split[0];
var id = split[1];
var value = data[ident];
(c) => {
this.sendPacket('players', (data) => {
const players = {};
const teams = {};
for(const ident of Object.keys(data)) {
const split = ident.split('_');
let key = split[0];
const id = split[1];
let value = data[ident];
if(key == 'teamname') {
if(key === 'teamname') {
teams[id] = value;
} else {
if(!(id in players)) players[id] = {};
if(key == 'playername') key = 'name';
else if(key == 'team') value = parseInt(value);
else if(key == 'score' || key == 'ping' || key == 'deaths') value = parseInt(value);
if(key === 'playername') key = 'name';
else if(key === 'team') value = parseInt(value);
else if(key === 'score' || key === 'ping' || key === 'deaths') value = parseInt(value);
players[id][key] = value;
}
}
state.raw.teams = teams;
for(var i in players) state.players.push(players[i]);
self.finish(state);
for(const id of Object.keys(players)) {
state.players.push(players[id]);
}
this.finish(state);
});
}
]);
},
sendPacket: function(type,callback) {
var self = this;
var queryId = '';
var output = {};
this.udpSend('\\'+type+'\\',function(buffer) {
var reader = self.reader(buffer);
var str = reader.string({length:buffer.length});
var split = str.split('\\');
}
sendPacket(type,callback) {
const queryId = '';
const output = {};
this.udpSend('\\'+type+'\\', (buffer) => {
const reader = this.reader(buffer);
const str = reader.string({length:buffer.length});
const split = str.split('\\');
split.shift();
var data = {};
const data = {};
while(split.length) {
var key = split.shift();
var value = split.shift() || '';
const key = split.shift();
const value = split.shift() || '';
data[key] = value;
}
if(!('queryid' in data)) return;
if(queryId && data.queryid != queryId) return;
for(var i in data) output[i] = data[i];
if(queryId && data.queryid !== queryId) return;
for(const i of Object.keys(data)) output[i] = data[i];
if('final' in output) {
delete output.final;
delete output.queryid;
@ -82,4 +83,6 @@ module.exports = require('./core').extend({
}
});
}
});
}
module.exports = Gamespy1;