node-gamedig/protocols/mafia2mp.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

41 lines
1.1 KiB
JavaScript

import Core from './core.js'
export default class mafia2mp extends Core {
constructor () {
super()
this.encoding = 'latin1'
this.header = 'M2MP'
this.isMafia2Online = false
}
async run (state) {
const body = await this.udpSend(this.header, (buffer) => {
const reader = this.reader(buffer)
const header = reader.string(this.header.length)
if (header !== this.header) return
return reader.rest()
})
const reader = this.reader(body)
state.name = this.readString(reader)
state.numplayers = parseInt(this.readString(reader))
state.maxplayers = parseInt(this.readString(reader))
state.raw.gamemode = this.readString(reader)
state.password = !!reader.uint(1)
state.gamePort = this.options.port - 1
while (!reader.done()) {
const player = {}
player.name = this.readString(reader)
if (!player.name) break
if (this.isMafia2Online) {
player.ping = parseInt(this.readString(reader))
}
state.players.push(player)
}
}
readString (reader) {
return reader.pascalString(1, -1)
}
}