2017-08-09 11:05:55 +02:00
|
|
|
class Ase extends require('./core') {
|
2017-08-09 12:32:09 +02:00
|
|
|
run(state) {
|
2017-08-09 11:05:55 +02:00
|
|
|
this.udpSend('s',(buffer) => {
|
2017-08-09 12:32:09 +02:00
|
|
|
const reader = this.reader(buffer);
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 11:05:55 +02:00
|
|
|
const header = reader.string({length:4});
|
2017-08-09 12:32:09 +02:00
|
|
|
if(header !== 'EYE1') return;
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
state.raw.gamename = this.readString(reader);
|
|
|
|
state.raw.port = parseInt(this.readString(reader));
|
|
|
|
state.name = this.readString(reader);
|
|
|
|
state.raw.gametype = this.readString(reader);
|
|
|
|
state.map = this.readString(reader);
|
|
|
|
state.raw.version = this.readString(reader);
|
|
|
|
state.password = this.readString(reader) === '1';
|
|
|
|
state.raw.numplayers = parseInt(this.readString(reader));
|
|
|
|
state.maxplayers = parseInt(this.readString(reader));
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
while(!reader.done()) {
|
|
|
|
const key = this.readString(reader);
|
|
|
|
if(!key) break;
|
2017-08-09 11:05:55 +02:00
|
|
|
const value = this.readString(reader);
|
2017-08-09 12:32:09 +02:00
|
|
|
state.raw[key] = value;
|
|
|
|
}
|
2017-08-09 12:04:32 +02:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
while(!reader.done()) {
|
2017-08-09 11:05:55 +02:00
|
|
|
const flags = reader.uint(1);
|
|
|
|
const player = {};
|
2017-08-09 12:32:09 +02:00
|
|
|
if(flags & 1) player.name = this.readString(reader);
|
|
|
|
if(flags & 2) player.team = this.readString(reader);
|
|
|
|
if(flags & 4) player.skin = this.readString(reader);
|
|
|
|
if(flags & 8) player.score = parseInt(this.readString(reader));
|
|
|
|
if(flags & 16) player.ping = parseInt(this.readString(reader));
|
|
|
|
if(flags & 32) player.time = parseInt(this.readString(reader));
|
|
|
|
state.players.push(player);
|
|
|
|
}
|
2017-08-09 11:05:55 +02:00
|
|
|
|
2017-08-09 12:32:09 +02:00
|
|
|
this.finish(state);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
readString(reader) {
|
2017-08-09 11:05:55 +02:00
|
|
|
const len = reader.uint(1);
|
2017-08-09 12:32:09 +02:00
|
|
|
return reader.string({length:len-1});
|
|
|
|
}
|
2017-08-09 11:05:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Ase;
|