mirror of
https://github.com/gamedig/node-gamedig.git
synced 2024-11-17 17:25:19 +01:00
da7a4a6334
* 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
88 lines
2.9 KiB
JavaScript
88 lines
2.9 KiB
JavaScript
import Core from './core.js'
|
|
|
|
export default class quake2 extends Core {
|
|
constructor () {
|
|
super()
|
|
this.encoding = 'latin1'
|
|
this.delimiter = '\n'
|
|
this.sendHeader = 'status'
|
|
this.responseHeader = 'print'
|
|
this.isQuake1 = false
|
|
}
|
|
|
|
async run (state) {
|
|
const body = await this.udpSend('\xff\xff\xff\xff' + this.sendHeader + '\x00', packet => {
|
|
const reader = this.reader(packet)
|
|
const header = reader.string({ length: 4, encoding: 'latin1' })
|
|
if (header !== '\xff\xff\xff\xff') return
|
|
let type
|
|
if (this.isQuake1) {
|
|
type = reader.string(this.responseHeader.length)
|
|
} else {
|
|
type = reader.string({ encoding: 'latin1' })
|
|
}
|
|
if (type !== this.responseHeader) return
|
|
return reader.rest()
|
|
})
|
|
|
|
const reader = this.reader(body)
|
|
const info = reader.string().split('\\')
|
|
if (info[0] === '') info.shift()
|
|
|
|
while (true) {
|
|
const key = info.shift()
|
|
const value = info.shift()
|
|
if (typeof value === 'undefined') break
|
|
state.raw[key] = value
|
|
}
|
|
|
|
while (!reader.done()) {
|
|
const line = reader.string()
|
|
if (!line || line.charAt(0) === '\0') break
|
|
|
|
const args = []
|
|
const split = line.split('"')
|
|
split.forEach((part, i) => {
|
|
const inQuote = (i % 2 === 1)
|
|
if (inQuote) {
|
|
args.push(part)
|
|
} else {
|
|
const splitSpace = part.split(' ')
|
|
for (const subpart of splitSpace) {
|
|
if (subpart) args.push(subpart)
|
|
}
|
|
}
|
|
})
|
|
|
|
const player = {}
|
|
if (this.isQuake1) {
|
|
player.id = parseInt(args.shift())
|
|
player.score = parseInt(args.shift())
|
|
player.time = parseInt(args.shift())
|
|
player.ping = parseInt(args.shift())
|
|
player.name = args.shift()
|
|
player.skin = args.shift()
|
|
player.color1 = parseInt(args.shift())
|
|
player.color2 = parseInt(args.shift())
|
|
} else {
|
|
player.frags = parseInt(args.shift())
|
|
player.ping = parseInt(args.shift())
|
|
player.name = args.shift() || ''
|
|
if (!player.name) delete player.name
|
|
player.address = args.shift() || ''
|
|
if (!player.address) delete player.address
|
|
}
|
|
|
|
(player.ping ? state.players : state.bots).push(player)
|
|
}
|
|
|
|
if ('g_needpass' in state.raw) state.password = state.raw.g_needpass
|
|
if ('mapname' in state.raw) state.map = state.raw.mapname
|
|
if ('sv_maxclients' in state.raw) state.maxplayers = state.raw.sv_maxclients
|
|
if ('maxclients' in state.raw) state.maxplayers = state.raw.maxclients
|
|
if ('sv_hostname' in state.raw) state.name = state.raw.sv_hostname
|
|
if ('hostname' in state.raw) state.name = state.raw.hostname
|
|
if ('clients' in state.raw) state.numplayers = state.raw.clients
|
|
else state.numplayers = state.players.length + state.bots.length
|
|
}
|
|
}
|