mirror of
https://github.com/tribufu/node-gamedig
synced 2026-06-01 09:42:41 +00:00
feat(protocol/sdtd): add optional more data via telnet (#697)
* feat(protocol/sdtd): add optional more data via telnet * docs: update CHANGELOG.md * feat: some refactoring * feat: add hordeDay to raw * docs: mention what extra data it is * docs: formatting
This commit is contained in:
parent
b9767ab99d
commit
a3fca5d590
3 changed files with 54 additions and 4 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
## 5.X.Y
|
## 5.X.Y
|
||||||
* Fix: HTTP requests would end up making more retries than needed due to got's internal retry mechanism (#690, thanks @RattleSN4K3)
|
* Fix: HTTP requests would end up making more retries than needed due to got's internal retry mechanism (#690, thanks @RattleSN4K3)
|
||||||
* Feat: 7 Days to Die add Telnet support for missing player names (#692, thanks @jammsen)
|
* Feat: 7 Days to Die add Telnet support for missing player names (#692, thanks @jammsen)
|
||||||
|
* Feat: 7 Days to Die get more optional Telnet data via an option (#693)
|
||||||
|
|
||||||
## 5.3.0
|
## 5.3.0
|
||||||
* Docs: Arma Reforger query setup note (#670, thanks @xCausxn)
|
* Docs: Arma Reforger query setup note (#670, thanks @xCausxn)
|
||||||
|
|
|
||||||
|
|
@ -552,3 +552,5 @@ Requires usage of the status query server enabled in the config.txt. `status_ser
|
||||||
Does not provide player names but can be provided via telnet commands, to use these make sure in `serverconfig.xml` you
|
Does not provide player names but can be provided via telnet commands, to use these make sure in `serverconfig.xml` you
|
||||||
have configured `TelnetEnabled` to `true`, `TelnetPort` and `TelnetPassword` and pass `telnetPort` and `telnetPassword`
|
have configured `TelnetEnabled` to `true`, `TelnetPort` and `TelnetPassword` and pass `telnetPort` and `telnetPassword`
|
||||||
to the query parameters.
|
to the query parameters.
|
||||||
|
|
||||||
|
To fetch more info via telnet (game and mods versions, date and time), at the cost of a longer query time, set `moreData` to `true`.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
import Valve from './valve.js'
|
import Valve from './valve.js'
|
||||||
import { Players } from '../lib/Results.js'
|
import { Players } from '../lib/Results.js'
|
||||||
|
|
||||||
const playerLineRegex = /(?<=id=\d+,\s*)(?<name>\S[^,]*)(?=,)/
|
const playerRegex = /(?<=id=\d+,\s*)(?<name>\S[^,]*)(?=,)/
|
||||||
|
const gameVersionsRegex = /V \d+\.\d+(?: \(b\d+\))?/g
|
||||||
|
const modRegex = /^Mod\s+([^:]+):\s*([\d.]+)$/
|
||||||
|
const dateTimeRegex = /Day\s+(\d+),\s*(\d{2}:\d{2})/
|
||||||
|
|
||||||
const sanitizeTelnetResponse = response => {
|
const sanitizeTelnetResponse = response => {
|
||||||
return response
|
return response
|
||||||
|
|
@ -25,7 +28,7 @@ export default class sdtd extends Valve {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.options.requestPlayers) {
|
if (!this.options.requestPlayers && !this.options.moreData) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,7 +40,13 @@ export default class sdtd extends Valve {
|
||||||
echoLines: 0
|
echoLines: 0
|
||||||
})
|
})
|
||||||
|
|
||||||
await this.telnetCallPlayers(state)
|
if (this.options.requestPlayers) {
|
||||||
|
await this.telnetCallPlayers(state)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.options.moreData) {
|
||||||
|
await this.telnetMoreData(state)
|
||||||
|
}
|
||||||
|
|
||||||
await this.telnetClose()
|
await this.telnetClose()
|
||||||
}
|
}
|
||||||
|
|
@ -46,7 +55,7 @@ export default class sdtd extends Valve {
|
||||||
const playersResponse = await this.telnetExecute('listplayers')
|
const playersResponse = await this.telnetExecute('listplayers')
|
||||||
state.players = new Players()
|
state.players = new Players()
|
||||||
for (const possiblePlayerLine of sanitizeTelnetResponse(playersResponse)) {
|
for (const possiblePlayerLine of sanitizeTelnetResponse(playersResponse)) {
|
||||||
const match = possiblePlayerLine.match(playerLineRegex)
|
const match = possiblePlayerLine.match(playerRegex)
|
||||||
|
|
||||||
const name = match?.groups?.name
|
const name = match?.groups?.name
|
||||||
if (name) {
|
if (name) {
|
||||||
|
|
@ -59,4 +68,42 @@ export default class sdtd extends Valve {
|
||||||
|
|
||||||
state.raw.telnetPlayersResponse = playersResponse
|
state.raw.telnetPlayersResponse = playersResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async telnetMoreData (state) {
|
||||||
|
const gettimeResponse = await this.telnetExecute('gettime')
|
||||||
|
const dateTime = sanitizeTelnetResponse(gettimeResponse)[0] || ''
|
||||||
|
const match = dateTime.match(dateTimeRegex)
|
||||||
|
if (match) {
|
||||||
|
state.raw.day = Number(match[1])
|
||||||
|
state.raw.time = match[2]
|
||||||
|
state.raw.hordeDay = state.raw.day % 7 === 0
|
||||||
|
} else {
|
||||||
|
state.raw.hordeDay = false
|
||||||
|
}
|
||||||
|
|
||||||
|
state.raw.telnetGettimeResponse = gettimeResponse
|
||||||
|
|
||||||
|
const versionResponse = await this.telnetExecute('version')
|
||||||
|
const versions = sanitizeTelnetResponse(versionResponse)
|
||||||
|
const gameVersions = versions[0] || ''
|
||||||
|
const gameVersionsMatch = gameVersions.match(gameVersionsRegex)
|
||||||
|
if (gameVersionsMatch) {
|
||||||
|
state.raw.gameVersion = gameVersionsMatch[0]
|
||||||
|
state.raw.compatibilityVersion = gameVersionsMatch[1]
|
||||||
|
}
|
||||||
|
|
||||||
|
const mods = []
|
||||||
|
for (const possibleMod of versions.slice(1)) {
|
||||||
|
const match = possibleMod.match(modRegex)
|
||||||
|
if (match) {
|
||||||
|
mods.push({
|
||||||
|
name: match[1],
|
||||||
|
version: match[2]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
state.raw.mods = mods
|
||||||
|
state.raw.telnetVersionResponse = versionResponse
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue