mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-18 09:35:50 +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,62 +1,62 @@
|
|||
module.exports = require('./core').extend({
|
||||
init: function() {
|
||||
this._super();
|
||||
class Starmade extends require('./core') {
|
||||
constructor() {
|
||||
super();
|
||||
this.encoding = 'latin1';
|
||||
this.byteorder = 'be';
|
||||
},
|
||||
run: function(state) {
|
||||
var self = this;
|
||||
}
|
||||
run(state) {
|
||||
const b = Buffer.from([0x00,0x00,0x00,0x09,0x2a,0xff,0xff,0x01,0x6f,0x00,0x00,0x00,0x00]);
|
||||
|
||||
var b = new Buffer([0x00,0x00,0x00,0x09,0x2a,0xff,0xff,0x01,0x6f,0x00,0x00,0x00,0x00]);
|
||||
|
||||
this.tcpSend(b,function(buffer) {
|
||||
var reader = self.reader(buffer);
|
||||
this.tcpSend(b,(buffer) => {
|
||||
const reader = this.reader(buffer);
|
||||
|
||||
if(buffer.length < 4) return false;
|
||||
var packetLength = reader.uint(4);
|
||||
const packetLength = reader.uint(4);
|
||||
if(buffer.length < packetLength+12) return false;
|
||||
|
||||
var data = [];
|
||||
const data = [];
|
||||
state.raw.data = data;
|
||||
|
||||
reader.skip(2);
|
||||
while(!reader.done()) {
|
||||
var mark = reader.uint(1);
|
||||
if(mark == 1) {
|
||||
const mark = reader.uint(1);
|
||||
if(mark === 1) {
|
||||
// signed int
|
||||
data.push(reader.int(4));
|
||||
} else if(mark == 3) {
|
||||
} else if(mark === 3) {
|
||||
// float
|
||||
data.push(reader.float());
|
||||
} else if(mark == 4) {
|
||||
} else if(mark === 4) {
|
||||
// string
|
||||
var length = reader.uint(2);
|
||||
const length = reader.uint(2);
|
||||
data.push(reader.string(length));
|
||||
} else if(mark == 6) {
|
||||
} else if(mark === 6) {
|
||||
// byte
|
||||
data.push(reader.uint(1));
|
||||
}
|
||||
}
|
||||
|
||||
if(data.length < 9) {
|
||||
self.fatal("Not enough units in data packet");
|
||||
this.fatal("Not enough units in data packet");
|
||||
return true;
|
||||
}
|
||||
|
||||
if(typeof data[3] == 'number') state.raw.version = data[3].toFixed(7).replace(/0+$/, '');
|
||||
if(typeof data[4] == 'string') state.name = data[4];
|
||||
if(typeof data[5] == 'string') state.raw.description = data[5];
|
||||
if(typeof data[7] == 'number') state.raw.numplayers = data[7];
|
||||
if(typeof data[8] == 'number') state.maxplayers = data[8];
|
||||
if(typeof data[3] === 'number') state.raw.version = data[3].toFixed(7).replace(/0+$/, '');
|
||||
if(typeof data[4] === 'string') state.name = data[4];
|
||||
if(typeof data[5] === 'string') state.raw.description = data[5];
|
||||
if(typeof data[7] === 'number') state.raw.numplayers = data[7];
|
||||
if(typeof data[8] === 'number') state.maxplayers = data[8];
|
||||
|
||||
if('numplayers' in state.raw) {
|
||||
for(var i = 0; i < state.raw.numplayers; i++) {
|
||||
for(let i = 0; i < state.raw.numplayers; i++) {
|
||||
state.players.push({});
|
||||
}
|
||||
}
|
||||
|
||||
self.finish(state);
|
||||
this.finish(state);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = Starmade;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue