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
71 lines
2.2 KiB
JavaScript
71 lines
2.2 KiB
JavaScript
import Core from './core.js'
|
|
|
|
export default class teamspeak2 extends Core {
|
|
async run (state) {
|
|
const queryPort = this.options.teamspeakQueryPort || 51234
|
|
|
|
await this.withTcp(async socket => {
|
|
{
|
|
const data = await this.sendCommand(socket, 'sel ' + this.options.port)
|
|
if (data !== '[TS]') throw new Error('Invalid header')
|
|
}
|
|
|
|
{
|
|
const data = await this.sendCommand(socket, 'si')
|
|
for (const line of data.split('\r\n')) {
|
|
const equals = line.indexOf('=')
|
|
const key = equals === -1 ? line : line.substring(0, equals)
|
|
const value = equals === -1 ? '' : line.substring(equals + 1)
|
|
state.raw[key] = value
|
|
}
|
|
}
|
|
|
|
{
|
|
const data = await this.sendCommand(socket, 'pl')
|
|
const split = data.split('\r\n')
|
|
const fields = split.shift().split('\t')
|
|
for (const line of split) {
|
|
const split2 = line.split('\t')
|
|
const player = {}
|
|
split2.forEach((value, i) => {
|
|
let key = fields[i]
|
|
if (!key) return
|
|
if (key === 'nick') key = 'name'
|
|
const m = value.match(/^"(.*)"$/)
|
|
if (m) value = m[1]
|
|
player[key] = value
|
|
})
|
|
state.players.push(player)
|
|
}
|
|
state.numplayers = state.players.length
|
|
}
|
|
|
|
{
|
|
const data = await this.sendCommand(socket, 'cl')
|
|
const split = data.split('\r\n')
|
|
const fields = split.shift().split('\t')
|
|
state.raw.channels = []
|
|
for (const line of split) {
|
|
const split2 = line.split('\t')
|
|
const channel = {}
|
|
split2.forEach((value, i) => {
|
|
const key = fields[i]
|
|
if (!key) return
|
|
const m = value.match(/^"(.*)"$/)
|
|
if (m) value = m[1]
|
|
channel[key] = value
|
|
})
|
|
state.raw.channels.push(channel)
|
|
}
|
|
}
|
|
}, queryPort)
|
|
}
|
|
|
|
async sendCommand (socket, cmd) {
|
|
return await this.tcpSend(socket, cmd + '\x0A', buffer => {
|
|
if (buffer.length < 6) return
|
|
if (buffer.slice(-6).toString() !== '\r\nOK\r\n') return
|
|
return buffer.slice(0, -6).toString()
|
|
})
|
|
}
|
|
}
|