node-gamedig/protocols/ase.js
CosminPerRam da7a4a6334
Remove Players::setNum and stabilize field numplayers (#389)
* Remove Players Set Num

* Stabilize numplayers on armagetron

* Stabilize numplayers on ase

* Stabilize numplayers on assettocorsa

* Optimize away a variable declaration

* Stabilize numplayers on buildandshoot

* Stabilize numplayers on cs2d

* Fix wrong raw field parsed on Doom3

* Updated CHANGELOG and README regarding doom3 fix and numplayers

* Stabilize numplayers on doom3

* Stabilize numplayers on eco

* Stabilize numplayers on ffow

* Stabilize numplayers on quake2

* Stabilize numplayers on gamespy1

* Stabilize numplayers on gamespy2

* Stabilize numplayers on gamespy3

* Remove reductant numplayers setter in jc2mp

* Stabilize numplayers on kspdmp

* Stabilize numplayers on mafia2mp

* Stabilize numplayers on minecraftvanilla and remove players empty placeholders

* Stabilize numplayers on nadeo

* Stabilize numplayers on samp and reduce unused setters

* Stabilize numplayers on terraria

* Stabilize numplayers on tribes1

* Stabilize numplayers on unreal2

* Stabilize numplayers on valve

* Stabilize numplayers on ventrilo

* Battlefield: Set numplayers from info, not players

* Stabilize numplayers on minecraft

* Stabilize numplayers on teamspeak2

* Stabilize numplayers on teamspeak3

* Update CHANGELOG.md to add removal of players placeholders

* Replaced minecraft gamespy numplayers
2023-10-27 19:48:56 +03:00

46 lines
1.5 KiB
JavaScript

import Core from './core.js'
export default class ase extends Core {
async run (state) {
const buffer = await this.udpSend('s', (buffer) => {
const reader = this.reader(buffer)
const header = reader.string(4)
if (header === 'EYE1') return reader.rest()
})
const reader = this.reader(buffer)
state.raw.gamename = this.readString(reader)
state.gamePort = 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.numplayers = parseInt(this.readString(reader))
state.maxplayers = parseInt(this.readString(reader))
while (!reader.done()) {
const key = this.readString(reader)
if (!key) break
const value = this.readString(reader)
state.raw[key] = value
}
while (!reader.done()) {
const flags = reader.uint(1)
const player = {}
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)
}
}
readString (reader) {
return reader.pascalString(1, -1)
}
}