mirror of
https://github.com/tribufu/node-gamedig
synced 2026-05-18 09:35:50 +00:00
Convert tabs to spaces
This commit is contained in:
parent
0dd25bfcda
commit
3674d384d0
39 changed files with 2414 additions and 2414 deletions
|
|
@ -1,98 +1,98 @@
|
|||
class Gamespy2 extends require('./core') {
|
||||
constructor() {
|
||||
super();
|
||||
this.sessionId = 1;
|
||||
this.encoding = 'latin1';
|
||||
this.byteorder = 'be';
|
||||
}
|
||||
constructor() {
|
||||
super();
|
||||
this.sessionId = 1;
|
||||
this.encoding = 'latin1';
|
||||
this.byteorder = 'be';
|
||||
}
|
||||
|
||||
run(state) {
|
||||
const request = Buffer.from([0xfe,0xfd,0x00,0x00,0x00,0x00,0x01,0xff,0xff,0xff]);
|
||||
run(state) {
|
||||
const request = Buffer.from([0xfe,0xfd,0x00,0x00,0x00,0x00,0x01,0xff,0xff,0xff]);
|
||||
const packets = [];
|
||||
this.udpSend(request,
|
||||
(buffer) => {
|
||||
if(packets.length && buffer.readUInt8(0) === 0)
|
||||
buffer = buffer.slice(1);
|
||||
packets.push(buffer);
|
||||
},
|
||||
() => {
|
||||
this.udpSend(request,
|
||||
(buffer) => {
|
||||
if(packets.length && buffer.readUInt8(0) === 0)
|
||||
buffer = buffer.slice(1);
|
||||
packets.push(buffer);
|
||||
},
|
||||
() => {
|
||||
const buffer = Buffer.concat(packets);
|
||||
const reader = this.reader(buffer);
|
||||
const header = reader.uint(1);
|
||||
if(header !== 0) return;
|
||||
if(header !== 0) return;
|
||||
const pingId = reader.uint(4);
|
||||
if(pingId !== 1) return;
|
||||
|
||||
while(!reader.done()) {
|
||||
if(pingId !== 1) return;
|
||||
|
||||
while(!reader.done()) {
|
||||
const key = reader.string();
|
||||
const value = reader.string();
|
||||
if(!key) break;
|
||||
state.raw[key] = value;
|
||||
}
|
||||
|
||||
if('hostname' in state.raw) state.name = state.raw.hostname;
|
||||
if('mapname' in state.raw) state.map = state.raw.mapname;
|
||||
if(this.trueTest(state.raw.password)) state.password = true;
|
||||
if('maxplayers' in state.raw) state.maxplayers = parseInt(state.raw.maxplayers);
|
||||
if(!key) break;
|
||||
state.raw[key] = value;
|
||||
}
|
||||
|
||||
state.players = this.readFieldData(reader);
|
||||
state.raw.teams = this.readFieldData(reader);
|
||||
if('hostname' in state.raw) state.name = state.raw.hostname;
|
||||
if('mapname' in state.raw) state.map = state.raw.mapname;
|
||||
if(this.trueTest(state.raw.password)) state.password = true;
|
||||
if('maxplayers' in state.raw) state.maxplayers = parseInt(state.raw.maxplayers);
|
||||
|
||||
this.finish(state);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
}
|
||||
state.players = this.readFieldData(reader);
|
||||
state.raw.teams = this.readFieldData(reader);
|
||||
|
||||
readFieldData(reader) {
|
||||
this.finish(state);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
readFieldData(reader) {
|
||||
const count = reader.uint(1);
|
||||
// count is unreliable (often it's wrong), so we don't use it.
|
||||
// read until we hit an empty first field string
|
||||
|
||||
if(this.debug) console.log("Reading fields, starting at: "+reader.rest());
|
||||
// count is unreliable (often it's wrong), so we don't use it.
|
||||
// read until we hit an empty first field string
|
||||
|
||||
if(this.debug) console.log("Reading fields, starting at: "+reader.rest());
|
||||
|
||||
const fields = [];
|
||||
while(!reader.done()) {
|
||||
while(!reader.done()) {
|
||||
let field = reader.string();
|
||||
if(!field) break;
|
||||
if(field.charCodeAt(0) <= 2) field = field.substring(1);
|
||||
fields.push(field);
|
||||
if(this.debug) console.log("field:"+field);
|
||||
}
|
||||
if(!field) break;
|
||||
if(field.charCodeAt(0) <= 2) field = field.substring(1);
|
||||
fields.push(field);
|
||||
if(this.debug) console.log("field:"+field);
|
||||
}
|
||||
|
||||
const units = [];
|
||||
outer: while(!reader.done()) {
|
||||
outer: while(!reader.done()) {
|
||||
const unit = {};
|
||||
for(let iField = 0; iField < fields.length; iField++) {
|
||||
for(let iField = 0; iField < fields.length; iField++) {
|
||||
let key = fields[iField];
|
||||
let value = reader.string();
|
||||
if(!value && iField === 0) break outer;
|
||||
if(this.debug) console.log("value:"+value);
|
||||
if(key === 'player_') key = 'name';
|
||||
else if(key === 'score_') key = 'score';
|
||||
else if(key === 'deaths_') key = 'deaths';
|
||||
else if(key === 'ping_') key = 'ping';
|
||||
else if(key === 'team_') key = 'team';
|
||||
else if(key === 'kills_') key = 'kills';
|
||||
else if(key === 'team_t') key = 'name';
|
||||
else if(key === 'tickets_t') key = 'tickets';
|
||||
|
||||
if(
|
||||
key === 'score' || key === 'deaths'
|
||||
|| key === 'ping' || key === 'team'
|
||||
|| key === 'kills' || key === 'tickets'
|
||||
) {
|
||||
if(value === '') continue;
|
||||
value = parseInt(value);
|
||||
}
|
||||
if(!value && iField === 0) break outer;
|
||||
if(this.debug) console.log("value:"+value);
|
||||
if(key === 'player_') key = 'name';
|
||||
else if(key === 'score_') key = 'score';
|
||||
else if(key === 'deaths_') key = 'deaths';
|
||||
else if(key === 'ping_') key = 'ping';
|
||||
else if(key === 'team_') key = 'team';
|
||||
else if(key === 'kills_') key = 'kills';
|
||||
else if(key === 'team_t') key = 'name';
|
||||
else if(key === 'tickets_t') key = 'tickets';
|
||||
|
||||
unit[key] = value;
|
||||
}
|
||||
units.push(unit);
|
||||
}
|
||||
if(
|
||||
key === 'score' || key === 'deaths'
|
||||
|| key === 'ping' || key === 'team'
|
||||
|| key === 'kills' || key === 'tickets'
|
||||
) {
|
||||
if(value === '') continue;
|
||||
value = parseInt(value);
|
||||
}
|
||||
|
||||
return units;
|
||||
}
|
||||
unit[key] = value;
|
||||
}
|
||||
units.push(unit);
|
||||
}
|
||||
|
||||
return units;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Gamespy2;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue