2017-08-09 11:05:55 +02:00
|
|
|
class M2mp extends require('./core') {
|
|
|
|
constructor() {
|
|
|
|
super();
|
2014-10-29 08:02:03 +01:00
|
|
|
this.encoding = 'latin1';
|
2017-08-09 11:05:55 +02:00
|
|
|
}
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 11:05:55 +02:00
|
|
|
run(state) {
|
|
|
|
this.udpSend('M2MP',(buffer) => {
|
|
|
|
const reader = this.reader(buffer);
|
|
|
|
|
|
|
|
const header = reader.string({length:4});
|
|
|
|
if(header !== 'M2MP') return;
|
2014-10-29 08:02:03 +01:00
|
|
|
|
2017-08-09 11:05:55 +02:00
|
|
|
state.name = this.readString(reader);
|
|
|
|
state.raw.numplayers = this.readString(reader);
|
|
|
|
state.maxplayers = this.readString(reader);
|
|
|
|
state.raw.gamemode = this.readString(reader);
|
2014-10-29 08:02:03 +01:00
|
|
|
state.password = !!reader.uint(1);
|
|
|
|
|
|
|
|
while(!reader.done()) {
|
2017-08-09 11:05:55 +02:00
|
|
|
const name = this.readString(reader);
|
2014-10-29 08:02:03 +01:00
|
|
|
if(!name) break;
|
|
|
|
state.players.push({
|
|
|
|
name:name
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-09 11:05:55 +02:00
|
|
|
this.finish(state);
|
2014-10-29 08:02:03 +01:00
|
|
|
return true;
|
|
|
|
});
|
2017-08-09 11:05:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
readString(reader) {
|
|
|
|
const length = reader.uint(1);
|
2014-10-29 08:02:03 +01:00
|
|
|
return reader.string({length:length-1});
|
2017-08-09 11:05:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = M2mp;
|