More async conversion

This commit is contained in:
mmorrison 2019-01-10 06:03:07 -06:00
parent 484e99b29c
commit efe12a00aa
25 changed files with 774 additions and 858 deletions

View file

@ -6,30 +6,28 @@ class M2mp extends Core {
this.encoding = 'latin1';
}
run(state) {
this.udpSend('M2MP',(buffer) => {
async run(state) {
const body = await this.udpSend('M2MP',(buffer) => {
const reader = this.reader(buffer);
const header = reader.string({length:4});
if(header !== 'M2MP') return;
state.name = this.readString(reader);
state.raw.numplayers = this.readString(reader);
state.maxplayers = this.readString(reader);
state.raw.gamemode = this.readString(reader);
state.password = !!reader.uint(1);
while(!reader.done()) {
const name = this.readString(reader);
if(!name) break;
state.players.push({
name:name
});
}
this.finish(state);
return true;
const header = reader.string({length: 4});
if (header !== 'M2MP') return;
return reader.rest();
});
const reader = this.reader(body);
state.name = this.readString(reader);
state.raw.numplayers = this.readString(reader);
state.maxplayers = this.readString(reader);
state.raw.gamemode = this.readString(reader);
state.password = !!reader.uint(1);
while(!reader.done()) {
const name = this.readString(reader);
if(!name) break;
state.players.push({
name:name
});
}
}
readString(reader) {